import { fmtDate } from "@/lib/format";
import type { Database } from "@/lib/supabase/types";

type EmployeeRow = Database["public"]["Tables"]["employees"]["Row"];

const PAYGRADE_LABELS: Record<string, string> = {
  A: "A – Einstieg",
  B: "B – Qualifiziert",
  C: "C – Erfahren",
  D: "D – Spezialist:in",
  E: "E – Teamleitung",
  F: "F – Bereichsleitung / GF",
};

export function VertragTab({ employee }: { employee: EmployeeRow }) {
  const flags = [
    employee.is_betriebsrat && "Betriebsrat",
    employee.has_dienstwagen && "Dienstwagen",
    employee.is_laterale_fuehrung && "Laterale Führung",
    employee.is_c_level && "C-Level",
  ].filter(Boolean);
  const rows: [string, string][] = [
    ["Eintrittsdatum", fmtDate(employee.entry_date)],
    ["Vertragsart", employee.contract_type === "befristet" ? `befristet bis ${fmtDate(employee.contract_end_date)}` : "unbefristet"],
    ["Kollektivvertrag", employee.collective_agreement ?? "–"],
    ["Beschäftigungsausmaß", employee.employment_type],
    ["Wochenstunden", `${employee.weekly_hours} h`],
    ["Urlaubsanspruch", "25 Tage"],
    ["Paygrade", PAYGRADE_LABELS[employee.paygrade] ?? employee.paygrade],
    ["Angestellte:r / Arbeiter:in", employee.worker_type ?? "–"],
    ["Arbeitstage", employee.work_days?.join(", ") || "–"],
    ["Merkmale", flags.length > 0 ? flags.join(", ") : "–"],
  ];
  if (employee.exit_date) rows.push(["Austrittsdatum", fmtDate(employee.exit_date)]);

  return (
    <dl className="grid grid-cols-1 gap-x-8 gap-y-4 sm:grid-cols-2 lg:grid-cols-3">
      {rows.map(([label, value]) => (
        <div key={label}>
          <dt className="text-xs font-semibold uppercase tracking-wide text-ink-muted">{label}</dt>
          <dd className="mt-1 text-sm text-ink">{value}</dd>
        </div>
      ))}
    </dl>
  );
}
