import type {
  InitiativeStatus,
  InitiativeType,
  MarketingRole,
  MeetingStatus,
  MilestoneStatus,
  OpinionPublica,
  TaskStatus,
} from "@/lib/marketing/types";

export const MARKETING_ROLE_LABELS: Record<MarketingRole, string> = {
  owner: "Dueño",
  lead: "Lider",
  employee: "Empleado",
};

export const MARKETING_DATE_RANGE_LABELS: Record<"7d" | "30d" | "qtd", string> = {
  "7d": "Últimos 7 días",
  "30d": "Últimos 30 días",
  qtd: "Trimestre",
};

export const INITIATIVE_TYPE_LABELS: Record<InitiativeType, string> = {
  evento: "Evento",
  campania: "Campaña",
  cambio: "Cambio",
  implementacion: "Implementación",
  otro: "Otro",
};

export const INITIATIVE_STATUS_LABELS: Record<InitiativeStatus, string> = {
  planning: "Planning",
  in_progress: "En progreso",
  completion: "Completada",
  results: "Resultados",
  evaluation: "Evaluación",
};

export const MEETING_STATUS_LABELS: Record<MeetingStatus, string> = {
  requested: "Solicitada",
  scheduled: "Agendada",
  completed: "Completada",
  cancelled: "Cancelada",
};

export const TASK_STATUS_LABELS: Record<TaskStatus, string> = {
  todo: "Pendiente",
  in_progress: "En proceso",
  blocked: "Bloqueada",
  done: "Completada",
};

export const MILESTONE_STATUS_LABELS: Record<MilestoneStatus, string> = {
  pending: "Pendiente",
  in_progress: "En progreso",
  completed: "Completada",
};

export const OPINION_PUBLICA_LABELS: Record<OpinionPublica, string> = {
  positive: "Positiva",
  mixed: "Mixta",
  negative: "Negativa",
};

export function getStatusPillClass(status: InitiativeStatus | MeetingStatus | TaskStatus | MilestoneStatus): string {
  if (status === "completion" || status === "completed" || status === "done") {
    return "bg-benell-green/15 text-benell-green";
  }

  if (status === "in_progress" || status === "scheduled") {
    return "bg-benell-amber/15 text-benell-amber";
  }

  if (status === "planning" || status === "results" || status === "evaluation" || status === "requested") {
    return "bg-benell-brown/10 text-benell-brown";
  }

  if (status === "cancelled" || status === "blocked") {
    return "bg-benell-red/15 text-benell-red";
  }

  return "bg-benell-surface-muted text-benell-text-soft";
}

export function formatDate(dateIso: string | null): string {
  if (!dateIso) {
    return "-";
  }

  return new Intl.DateTimeFormat("es-MX", {
    day: "2-digit",
    month: "short",
    year: "numeric",
  }).format(new Date(dateIso));
}

export function formatDateTime(dateIso: string | null): string {
  if (!dateIso) {
    return "-";
  }

  return new Intl.DateTimeFormat("es-MX", {
    day: "2-digit",
    month: "short",
    year: "numeric",
    hour: "2-digit",
    minute: "2-digit",
  }).format(new Date(dateIso));
}

export function formatCompactNumber(value: number): string {
  return new Intl.NumberFormat("es-MX", {
    notation: "compact",
    maximumFractionDigits: 1,
  }).format(value);
}

export function formatCurrency(value: number): string {
  return new Intl.NumberFormat("es-MX", {
    style: "currency",
    currency: "MXN",
    maximumFractionDigits: 0,
  }).format(value);
}
