// ═══════════════════════════════════════════════════════════════
//  lib/api/mappers/checklist.mappers.ts
//
// Matches the STATUS_CONFIG / TYPE_CONFIG pattern confirmed in
// my-audits.mappers.ts - display config keyed by the real status enum,
// not scattered inline conditionals in the component.
// ═══════════════════════════════════════════════════════════════

import type { ChecklistItemStatus } from "../types/checklist.types";

export const CHECKLIST_STATUS_CONFIG: Record<
  ChecklistItemStatus,
  { label: string; bg: string; text: string; dot: string }
> = {
  missing: { label: "Missing", bg: "#fef2f2", text: "#991b1b", dot: "#dc2626" },
  uploaded: { label: "Pending review", bg: "#f8fafc", text: "#64748b", dot: "#94a3b8" },
  approved: { label: "Approved", bg: "#f0fdf4", text: "#166534", dot: "#16a34a" },
  rejected: { label: "Rejected", bg: "#fef2f2", text: "#991b1b", dot: "#dc2626" },
};

// ── Template "type" pill config ──────────────────────────────────
// Mirrors TYPE_CONFIG from my-audits.mappers.ts (icon / label / bg / color),
// so ChecklistTemplateRow renders the pill exactly like MyAuditRow renders
// the audit-type pill under the audit code.
export type TemplateKind = "GENERIC" | "SPECIFIC";

export const TEMPLATE_TYPE_CONFIG: Record<
  TemplateKind,
  { label: string; icon: string; bg: string; color: string }
> = {
  GENERIC: { label: "Generic", icon: "🌐", bg: "#f0fdfa", color: "#0f766e" },
  SPECIFIC: { label: "Standard-specific", icon: "🎯", bg: "#f5f3ff", color: "#7c3aed" },
};

export function templateKind(isGeneric: boolean): TemplateKind {
  return isGeneric ? "GENERIC" : "SPECIFIC";
}

export function formatChecklistUploaderName(user?: { firstName?: string; lastName?: string } | null): string {
  if (!user) return "";
  return [user.firstName, user.lastName].filter(Boolean).join(" ");
}

// ── Checklist lifecycle stage pills (audit tab header) ───────────
import type { ChecklistStage } from "../types/checklist.types";

export const CHECKLIST_STAGE_CONFIG: Record<
  ChecklistStage,
  { label: string; bg: string; text: string }
> = {
  none:             { label: "Not started",        bg: "#f1f5f9", text: "#475569" },
  review:           { label: "Draft — review PDF", bg: "#fffbeb", text: "#92400e" },
  notify:           { label: "Ready to notify",    bg: "#eff6ff", text: "#1e40af" },
  with_client:      { label: "With client",        bg: "#f5f3ff", text: "#5b21b6" },
  client_submitted: { label: "Submitted by client", bg: "#f0fdfa", text: "#0f766e" },
  completed:        { label: "Completed ✓",        bg: "#f0fdf4", text: "#166534" },
};

export function formatChecklistDate(iso?: string | null): string {
  if (!iso) return "";
  try {
    return new Date(iso).toLocaleString(undefined, {
      day: "2-digit", month: "short", hour: "2-digit", minute: "2-digit",
    });
  } catch { return iso; }
}
