export interface Audit {
  id: number;
  audit_code?: string;
  status?: string;
  schedule_status?: string;
  audit_type?: string;
  proposed_date?: string;
  location?: string;
  mode?: string;
  branch?: {
    id: number;
    branchName?: string;
    mobile?: string;
    contactPerson?: string;
  } | null;
  lead_auditor?: { id: number; firstName?: string; lastName?: string } | null;
  co_auditors?: { id: number; firstName?: string; lastName?: string }[];
  standards?: { id: number; name?: string }[];
}

export function statusMeta(status: string | undefined, styles: any): { label: string; badgeClass: string } {
  const s = (status || "scheduled").toLowerCase();
  if (s === "completed") return { label: "Completed", badgeClass: styles.statusCompleted };
  if (s === "in_progress") return { label: "In progress", badgeClass: styles.statusProgress };
  if (s === "cancelled") return { label: "Cancelled", badgeClass: styles.statusCancelled };
  return { label: "Scheduled", badgeClass: styles.statusReview };
}

export function typeMeta(auditType?: string): { bg: string; color: string; label: string } {
  const t = (auditType || "").toUpperCase();
  if (t === "INITIAL") return { bg: "#fef3c7", color: "#92400e", label: "Initial" };
  if (t === "SURVEILLANCE") return { bg: "#ffedd5", color: "#9a3412", label: "Surveillance" };
  if (t === "RECERTIFICATION") return { bg: "#eef2ff", color: "#4338ca", label: "Recertification" };
  return { bg: "#f3f4f6", color: "#4b5563", label: "—" };
}

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

export function getPageNumbers(current: number, total: number): (number | "...")[] {
  if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1);
  const pages: (number | "...")[] = [1];
  if (current > 3) pages.push("...");
  for (let p = Math.max(2, current - 1); p <= Math.min(total - 1, current + 1); p++) {
    pages.push(p);
  }
  if (current < total - 2) pages.push("...");
  pages.push(total);
  return pages;
}
