export function getEmailAssetUrl(path: string) {
  const normalizedPath = path.startsWith("/") ? path : `/${path}`
  const baseUrl = process.env.NEXT_PUBLIC_APP_URL || process.env.APP_BASE_URL || ""
  if (baseUrl) return `${baseUrl}${normalizedPath}`
  return `/static${normalizedPath}`
}

export function formatStatus(statusRaw: string) {
  const status = statusRaw.trim().toUpperCase()
  const labels: Record<string, string> = {
    PENDING: "Pendente",
    AWAITING_ATTENDANCE: "Em andamento",
    PAUSED: "Pausado",
    RESOLVED: "Resolvido",
  }
  return labels[status] ?? statusRaw
}

export function formatPriority(priorityRaw: string) {
  const priority = priorityRaw.trim().toUpperCase()
  const labels: Record<string, string> = {
    LOW: "Baixa",
    MEDIUM: "Média",
    HIGH: "Alta",
    URGENT: "Urgente",
  }
  return labels[priority] ?? priorityRaw
}

export function normalizeTextToParagraphs(text: string): string[] {
  const trimmed = text.replace(/\r\n/g, "\n").trim()
  if (!trimmed) return []
  return trimmed.split(/\n{2,}/g).map((p) => p.trim()).filter(Boolean)
}

