"use client";

import { Badge } from "@/components/ds";
import {
  campaignApplicationStatusLabels,
  campaignStatusLabels,
  ledgerEntryTypeLabels,
  memberStatusLabels,
  pointAccountStatusLabels,
  programStatusLabels,
  redemptionStatusLabels,
  referralAttributionStatusLabels,
  referralCodeStatusLabels,
  referralProgramStatusLabels,
  rewardStatusLabels,
  rewardTypeLabels,
  tierStatusLabels,
  walletAccountStatusLabels,
  walletLedgerEntryTypeLabels,
} from "./tokens";

type Tone = "default" | "primary" | "success" | "warning" | "danger" | "info";

const toneMap: Record<string, Tone> = {
  draft: "default",
  active: "success",
  suspended: "warning",
  archived: "default",
  pending: "info",
  frozen: "warning",
  expired: "danger",
  cancelled: "danger",
  transferred: "info",
  closed: "default",
  inactive: "default",
  open: "success",
  scheduled: "info",
  paused: "warning",
  applied: "success",
  reversed: "danger",
  fulfilled: "success",
  revoked: "danger",
  converted: "primary",
  rewarded: "success",
  earn: "success",
  redeem: "primary",
  adjust: "warning",
  credit: "success",
  debit: "warning",
  transfer_in: "info",
  transfer_out: "info",
};

export function LoyaltyStatusChip({
  status,
  domain = "generic",
}: {
  status: string;
  domain?:
    | "program"
    | "member"
    | "tier"
    | "point-account"
    | "point_account"
    | "ledger"
    | "reward"
    | "reward-type"
    | "reward_type"
    | "redemption"
    | "campaign"
    | "campaign-application"
    | "referral-program"
    | "referral_program"
    | "referral-code"
    | "referral_code"
    | "referral-attribution"
    | "referral_attribution"
    | "wallet"
    | "wallet-ledger"
    | "generic";
}) {
  void domain;
  const labels: Record<string, string> = {
    ...programStatusLabels,
    ...memberStatusLabels,
    ...tierStatusLabels,
    ...pointAccountStatusLabels,
    ...ledgerEntryTypeLabels,
    ...rewardStatusLabels,
    ...rewardTypeLabels,
    ...redemptionStatusLabels,
    ...campaignStatusLabels,
    ...campaignApplicationStatusLabels,
    ...referralProgramStatusLabels,
    ...referralCodeStatusLabels,
    ...referralAttributionStatusLabels,
    ...walletAccountStatusLabels,
    ...walletLedgerEntryTypeLabels,
  };
  const label = labels[status] ?? status;
  const tone = toneMap[status] ?? "default";
  return <Badge tone={tone}>{label}</Badge>;
}
