import { formatPoints } from "@/app/lib/format"; import type { AdminRefundDetail, AdminRefundRequest } from "@/app/lib/types"; // Display helpers for the Refund Requests page (add-refund-requests). Message codes resolve // through DEFAULT_MESSAGES (RefundQueue*), so raw status/reason/effect codes never reach the UI. type T = (code: string, params?: Record) => string; type BadgeVariant = "positive" | "warning" | "negative"; export function statusLabel(t: T, status: AdminRefundRequest["status"]): string { switch (status) { case "P": return t("RefundQueueStatusPending"); case "I": return t("RefundQueueStatusInProgress"); case "A": return t("RefundQueueStatusApproved"); default: return t("RefundQueueStatusRejected"); } } export function statusVariant(status: AdminRefundRequest["status"]): BadgeVariant { if (status === "A") return "positive"; if (status === "R") return "negative"; return "warning"; } export function reasonLabel(t: T, code: string): string { const key = `RefundQueueReason_${code}`; const label = t(key); return label === key ? code : label; } /** One line per delivery order: what approving will do to its stock (mirrors RefundStockService). */ export function effectLabel(t: T, e: AdminRefundDetail["stockEffects"][number]): string { const params = { doNo: e.deliveryOrderNo ?? "—", warehouse: e.warehouseId ?? "—" }; switch (e.effect) { case "CANCEL_DO_LINES": return t("RefundQueueEffectCancelDo", params); case "RELEASE_RESERVATION": return t("RefundQueueEffectRelease", params); default: return t("RefundQueueEffectRestock", params); } } /** Channel label of a MANUAL payout (add-admin-initiated-refund). */ export function channelLabel(t: T, channel: AdminRefundRequest["payoutChannel"]): string { return channel ? t(`RefundQueueChannel_${channel}`) : "—"; } /** "Acorns wallet", "Gift card first, then Acorns wallet", or "Manual · Cash" plus the reference when there is one. Old rows have no payoutMethod: Acorns. */ export function payoutLabel(t: T, r: AdminRefundRequest, giftPaid?: boolean): string { if (r.payoutMethod !== "MANUAL") { if (giftPaid) return t("RefundQueuePayoutGiftCardFirst"); return t("RefundQueuePayoutAcorns"); } if (giftPaid) { const label = t("RefundQueuePayoutManualGiftCardFirst", { channel: channelLabel(t, r.payoutChannel) }); return r.payoutReference ? `${label} · ${r.payoutReference}` : label; } const label = t("RefundQueuePayoutManual", { channel: channelLabel(t, r.payoutChannel) }); return r.payoutReference ? `${label} · ${r.payoutReference}` : label; } /** Formats an amount without a currency prefix (used for RM and Acorn values; message strings add "RM"), null-safe. */ export function money(amount: number | null | undefined): string { return formatPoints(Number(amount ?? 0)); }