import type { PaymentStatus } from "@/features/opportunities/payment";

/**
 * BE-125 — the i18n key for one payment status, and the colours that go with
 * it.
 *
 * `null` is its own case rather than a default: a registration on a **free**
 * opportunity, and one on a paid opportunity whose transaction row has not
 * been created, both arrive with no status. Reading that as "pending" would
 * tell an organizer a free participant owes money.
 */
const STATUS_KEYS: Record<PaymentStatus, string> = {
  pending: "COMMON.PAYMENT_STATUS_PENDING",
  paid: "COMMON.PAYMENT_STATUS_PAID",
  refunded: "COMMON.PAYMENT_STATUS_REFUNDED",
  partially_refunded: "COMMON.PAYMENT_STATUS_PARTIALLY_REFUNDED",
  failed: "COMMON.PAYMENT_STATUS_FAILED",
  canceled: "COMMON.PAYMENT_STATUS_CANCELED",
};

/** Tailwind classes per status — the palette the rest of the app already uses. */
const STATUS_CLASSES: Record<PaymentStatus, string> = {
  pending: "bg-[#FFF4E5] text-[#B26A00]",
  paid: "bg-[#E7F6EC] text-[#1C7C3C]",
  refunded: "bg-[#F1F1F5] text-secondary-102",
  partially_refunded: "bg-amber-50 text-amber-800",
  failed: "bg-[#FDECEC] text-[#D32F2F]",
  canceled: "bg-[#F1F1F5] text-secondary-102",
};

export function paymentStatusKey(status: PaymentStatus | null | undefined): string {
  return status ? STATUS_KEYS[status] ?? "COMMON.PAYMENT_STATUS_NONE"
    : "COMMON.PAYMENT_STATUS_NONE";
}

export function paymentStatusClass(status: PaymentStatus | null | undefined): string {
  return (status && STATUS_CLASSES[status]) || "bg-[#F1F1F5] text-secondary-102";
}
