import { Registration } from './registration';
import { herregistratieDeadline } from './registration.policy';

/**
 * What the dashboard's "Wat moet ik regelen" list needs. Pure presentation data
 * derived from the registration — no Angular. Mirrors the shared TaskItem shape.
 */
export interface PortalTask {
  title: string;
  description: string;
  to: string;
  actionLabel: string;
}

function formatNL(d: Date): string {
  return d.toLocaleDateString('nl-NL', { day: 'numeric', month: 'long', year: 'numeric' });
}

/**
 * Derive the open tasks for a professional (pure). Eligibility is the server's
 * decision (`decisions.eligibleForHerregistratie`), passed in — the FE renders it,
 * it does not recompute the rule (ADR-0001). The deadline is still formatted
 * client-side for the task copy (presentation, not a rule).
 */
export function tasksFromProfile(reg: Registration, eligibleForHerregistratie: boolean): PortalTask[] {
  const tasks: PortalTask[] = [];

  if (eligibleForHerregistratie) {
    const deadline = herregistratieDeadline(reg);
    tasks.push({
      title: $localize`:@@task.herregistratie.title:Vraag uw herregistratie aan`,
      description: deadline
        ? $localize`:@@task.herregistratie.deadline:Verleng uw registratie vóór ${formatNL(deadline)}:deadline:.`
        : $localize`:@@task.herregistratie.nodeadline:U kunt nu uw herregistratie aanvragen.`,
      to: '/herregistratie',
      actionLabel: $localize`:@@task.herregistratie.action:Herregistratie aanvragen`,
    });
  }

  if (reg.status.tag === 'Geschorst') {
    tasks.push({
      title: $localize`:@@task.geschorst.title:Uw registratie is geschorst`,
      description: reg.status.reden,
      to: '/registratie',
      actionLabel: $localize`:@@task.bekijkGegevens.action:Bekijk uw gegevens`,
    });
  }

  if (reg.status.tag === 'Doorgehaald') {
    tasks.push({
      title: $localize`:@@task.doorgehaald.title:Uw registratie is doorgehaald`,
      description: reg.status.reden,
      to: '/registratie',
      actionLabel: $localize`:@@task.bekijkGegevens.action:Bekijk uw gegevens`,
    });
  }

  return tasks;
}
