/**
 * French presentation helpers for the web tickets/sprints surface (ticket #86).
 *
 * Deliberately **not** a reuse of `@/features/tickets/ticketMeta`: that module's
 * `statusLabel`/`priorityLabel`/badges render English text for the desktop
 * surface. Per carnet #86 (French UI by default, decision #78) the web surface
 * needs its own French labels — a separate, tiny module rather than adding an
 * i18n layer to the shared desktop component. The pure type/constant arrays
 * (`TICKET_STATUSES`, `TICKET_PRIORITIES`, `TICKET_LINK_KINDS`) ARE reused from
 * `ticketMeta` since they carry no English text.
 */

import type { TicketLinkKind, TicketPriority, TicketStatus } from "@/domain";
import { cn } from "@/shared";

export function webStatusLabel(status: TicketStatus): string {
  switch (status) {
    case "open":
      return "Ouvert";
    case "inProgress":
      return "En cours";
    case "QA":
      return "QA";
    case "closed":
      return "Fermé";
  }
}

export function webPriorityLabel(priority: TicketPriority): string {
  switch (priority) {
    case "low":
      return "Faible";
    case "medium":
      return "Moyenne";
    case "high":
      return "Haute";
    case "critical":
      return "Critique";
  }
}

export function webLinkKindLabel(kind: TicketLinkKind): string {
  switch (kind) {
    case "relatesTo":
      return "en relation avec";
    case "blocks":
      return "bloque";
    case "blockedBy":
      return "bloqué par";
    case "duplicates":
      return "duplique";
    case "dependsOn":
      return "dépend de";
  }
}

function statusClass(status: TicketStatus): string {
  switch (status) {
    case "open":
      return "bg-raised text-muted";
    case "inProgress":
      return "bg-warning/15 text-warning";
    case "QA":
      return "bg-primary/15 text-primary";
    case "closed":
      return "bg-success/15 text-success";
  }
}

function priorityClass(priority: TicketPriority): string {
  switch (priority) {
    case "low":
      return "bg-raised text-muted";
    case "medium":
      return "bg-primary/10 text-primary";
    case "high":
      return "bg-warning/15 text-warning";
    case "critical":
      return "bg-danger/15 text-danger";
  }
}

function badgeBase(className?: string): string {
  return cn(
    "inline-flex shrink-0 items-center rounded-full px-2 py-0.5 text-xs font-medium",
    className,
  );
}

export function WebStatusBadge({ status }: { status: TicketStatus }) {
  return <span className={badgeBase(statusClass(status))}>{webStatusLabel(status)}</span>;
}

export function WebPriorityBadge({ priority }: { priority: TicketPriority }) {
  return (
    <span className={badgeBase(priorityClass(priority))}>
      {webPriorityLabel(priority)}
    </span>
  );
}
