import type { ComponentType } from "react"; import { AlertCircle, CheckCircle2, Clock, XCircle } from "lucide-react"; import type { SelectOption } from "@/components/formInput"; import type { StatusBadgeVariant } from "@/components/ui/statusBadge"; import { buildEnumOptions, getEnumLabel, isEnumValue, type EnumConfig, type TranslateFn } from "@/constants/enumLabels"; // ─── Gateway status ─────────────────────────────────────────────────────────── export const GATEWAY_STATUS_VALUES = ["pending", "paid", "unpaid", "failed", "success", "completed"] as const; export type GatewayStatusValue = (typeof GATEWAY_STATUS_VALUES)[number]; export const GATEWAY_STATUS_LABELS: Record = { pending: "Pending", paid: "Paid", unpaid: "Unpaid", failed: "Failed", success: "Success", completed: "Completed", }; const GATEWAY_STATUS_ENUM: EnumConfig = { values: GATEWAY_STATUS_VALUES, labels: GATEWAY_STATUS_LABELS, prefix: "onlinePayments.gatewayStatus", }; export const GATEWAY_STATUS_BADGE_VARIANTS: Record = { pending: "warning", paid: "success", unpaid: "default", failed: "error", success: "success", completed: "info", }; export const GATEWAY_STATUS_ICONS: Record = { pending: AlertCircle, paid: CheckCircle2, unpaid: Clock, failed: XCircle, success: CheckCircle2, completed: CheckCircle2, }; // ─── Paid flag ──────────────────────────────────────────────────────────────── export const PAID_VALUES = ["paid", "unpaid"] as const; export type PaidValue = (typeof PAID_VALUES)[number]; export const PAID_LABELS: Record = { paid: "Paid", unpaid: "Unpaid", }; const PAID_ENUM: EnumConfig = { values: PAID_VALUES, labels: PAID_LABELS, prefix: "onlinePayments.paid", }; export const PAID_BADGE_VARIANTS: Record = { paid: "success", unpaid: "error", }; export const PAID_ICONS: Record = { paid: CheckCircle2, unpaid: XCircle, }; // ─── Helpers ────────────────────────────────────────────────────────────────── function withPrefix(config: EnumConfig, prefix?: string): EnumConfig { return prefix ? { ...config, prefix } : config; } export function isGatewayStatusValue(status: string): status is GatewayStatusValue { return isEnumValue(GATEWAY_STATUS_VALUES, status); } export function getGatewayStatusLabel(status: string, t?: TranslateFn, prefix?: string): string { return getEnumLabel(withPrefix(GATEWAY_STATUS_ENUM, prefix), status, t); } export function getGatewayStatusOptions(t?: TranslateFn, prefix?: string): SelectOption[] { return buildEnumOptions(withPrefix(GATEWAY_STATUS_ENUM, prefix), t); } export const PAYMENT_HISTORY_STATUS_VALUES = ["failed", "pending", "success", "completed"] as const; export function getPaymentHistoryStatusOptions(t?: TranslateFn, prefix?: string): SelectOption[] { return buildEnumOptions( withPrefix( { values: PAYMENT_HISTORY_STATUS_VALUES, labels: GATEWAY_STATUS_LABELS, prefix: "onlinePayments.gatewayStatus", }, prefix, ), t, ); } export function toPaidValue(paid: boolean): PaidValue { return paid ? "paid" : "unpaid"; } export function getPaidLabel(paid: boolean, t?: TranslateFn, prefix?: string): string { return getEnumLabel(withPrefix(PAID_ENUM, prefix), toPaidValue(paid), t); }