import { StatusBadge } from "@/components/ui/badge";
import type { CaptainBalanceState, LedgerEntryType } from "@/types/ledger";

type Variant = "secondary" | "success" | "warning" | "destructive" | "info";

/**
 * `owes` is a warning, not a failure: a captain carrying the day's cash back to the desk is the
 * normal state of affairs, not a fault. Red would train a cashier to read every busy captain as a
 * problem. `owed` is informational — it is money *we* have to find, and it should look different
 * from money they have to bring.
 */
const BALANCE_VARIANT: Record<CaptainBalanceState, Variant> = {
  owes: "warning",
  owed: "info",
  clear: "success",
};

export function BalanceStateBadge({
  state,
  label,
}: {
  state: CaptainBalanceState;
  label: string;
}) {
  return <StatusBadge variant={BALANCE_VARIANT[state]}>{label}</StatusBadge>;
}

/**
 * Coloured by what the line *does to the balance*, which is what a cashier scanning a statement
 * is actually reading for — not by who wrote it.
 */
const ENTRY_VARIANT: Record<LedgerEntryType, Variant> = {
  supplier_payment: "info",
  cash_collected: "warning",
  cash_paid_out: "success",
  cash_handed_in: "success",
  adjustment: "secondary",
};

export function LedgerEntryTypeBadge({
  type,
  label,
}: {
  type: LedgerEntryType;
  label: string;
}) {
  return <StatusBadge variant={ENTRY_VARIANT[type]}>{label}</StatusBadge>;
}
