import type { TicketPriority } from "@/lib/schemas/ticket"

export type TicketPriorityStyle = {
  label: string
  badgeClass: string
}

const FALLBACK_PRIORITY: TicketPriority = "MEDIUM"

export const priorityStyles: Record<TicketPriority, TicketPriorityStyle> = {
  LOW: { label: "Baixa", badgeClass: "bg-slate-100 text-slate-700" },
  MEDIUM: { label: "Média", badgeClass: "bg-[#dff1fb] text-[#0a4760]" },
  HIGH: { label: "Alta", badgeClass: "bg-[#fde8d1] text-[#7d3b05]" },
  URGENT: { label: "Urgente", badgeClass: "bg-[#fbd9dd] text-[#8b0f1c]" },
}

function resolvePriority(priority: TicketPriority | string | null | undefined): TicketPriorityStyle {
  if (!priority) {
    return priorityStyles[FALLBACK_PRIORITY]
  }
  const normalized = priority.toString().trim().toUpperCase() as TicketPriority
  return priorityStyles[normalized] ?? priorityStyles[FALLBACK_PRIORITY]
}

export function getTicketPriorityMeta(priority: TicketPriority | string | null | undefined): TicketPriorityStyle {
  return resolvePriority(priority)
}

export function getTicketPriorityLabel(priority: TicketPriority | string | null | undefined): string {
  return resolvePriority(priority).label
}

export function getTicketPriorityBadgeClass(priority: TicketPriority | string | null | undefined): string {
  return resolvePriority(priority).badgeClass
}
