import { absenceLabel } from "@/lib/absence";
import { STATUS_STYLES } from "@/lib/colors";
import { fmtDate } from "@/lib/format";
import type { EmploymentStatus } from "@/lib/supabase/types";

type StatusChipProps = {
  status: EmploymentStatus;
  entryDate?: string | null; // shown as "Eintritt {date}" when status is Geplant
  /** Shown instead of the generic label when the kind of absence is known. */
  absenceType?: string | null;
};

export function StatusChip({ status, entryDate, absenceType }: StatusChipProps) {
  // The stored status is still 'Karenz'; absenceLabel maps it to
  // "Langzeitabwesenheit", or to the specific kind when one is recorded.
  const label = status === "Geplant" && entryDate ? `Eintritt ${fmtDate(entryDate)}` : absenceLabel(status, absenceType);
  return (
    <span
      className={`inline-flex items-center whitespace-nowrap rounded-full px-2.5 py-0.5 text-xs font-semibold ${STATUS_STYLES[status]}`}
    >
      {label}
    </span>
  );
}
