"use client"; import Link from "next/link"; import { AlertTriangle, CheckCircle2, ClipboardList, Ticket, XCircle, XIcon } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { formatMinorAsCurrency } from "@/lib/money"; import { playLabel } from "@/lib/play-labels"; import { cn } from "@/lib/utils"; import type { TicketPlaceData } from "@/types/api/ticket"; type HallBetResultDialogProps = { open: boolean; onOpenChange: (open: boolean) => void; currencyCode: string; data: TicketPlaceData | null; jackpotEnabled?: boolean; creditMode?: boolean; }; const SUCCESS_ITEM_STATUSES = new Set(["pending_draw", "placed"]); const FAILURE_ITEM_STATUSES = new Set(["failed", "refunded"]); function providerLabel(providerName?: string | null, providerCode?: string | null): string { return providerName || providerCode || "-"; } export function HallBetResultDialog({ open, onOpenChange, currencyCode, data, jackpotEnabled = false, creditMode = false, }: HallBetResultDialogProps) { const { t } = useTranslation("player"); const successItems = data?.items.filter( (item) => item.status != null && SUCCESS_ITEM_STATUSES.has(item.status), ) ?? []; const failedItems = data?.items.filter( (item) => item.status != null && FAILURE_ITEM_STATUSES.has(item.status), ) ?? []; const pendingItems = data?.items.filter((item) => item.status === "pending_confirm") ?? []; const orderStatus = data?.summary.order_status; const isRefundedOrder = orderStatus === "refunded"; const totalSuccess = data?.summary.success_count ?? successItems.length; const totalFailure = data?.summary.failure_count ?? failedItems.length; const pendingConfirmCount = data?.summary.pending_confirm_count ?? pendingItems.length; const isAllFailed = isRefundedOrder || (totalFailure > 0 && totalSuccess === 0 && pendingConfirmCount === 0); const isPartial = !isRefundedOrder && totalSuccess > 0 && (totalFailure > 0 || pendingConfirmCount > 0); const isPendingOnly = !isRefundedOrder && pendingConfirmCount > 0 && totalSuccess === 0 && totalFailure === 0; const ResultIcon = isAllFailed ? XCircle : isPartial || isPendingOnly ? AlertTriangle : CheckCircle2; const iconWrapClass = isAllFailed ? "border-rose-100 text-rose-600 shadow-[0_10px_24px_rgba(225,29,72,0.12)]" : isPartial || isPendingOnly ? "border-amber-100 text-amber-600 shadow-[0_10px_24px_rgba(217,119,6,0.12)]" : "border-emerald-100 text-emerald-600 shadow-[0_10px_24px_rgba(22,163,74,0.12)]"; return (
{isRefundedOrder ? t("hall.result.titleRefunded") : isAllFailed ? t("hall.result.titleAllFailed") : isPartial ? t("hall.result.titlePartial") : isPendingOnly ? t("hall.result.titlePendingConfirm") : t("hall.result.title")} {data ? ( {t("hall.result.draw")}{" "} {data.draw.draw_id} ) : null}
{!data ? (

{t("hall.result.empty")}

) : ( <> {isRefundedOrder ? (

{t("hall.result.refundedHint")}

) : null} {isPendingOnly ? (

{t("hall.result.pendingConfirmHint")}

) : null}

{t("hall.result.successCount")}

{totalSuccess}

{t("hall.result.failureCount")}

{totalFailure}

{t("hall.result.actual")}
{formatMinorAsCurrency(data.summary.total_actual_deduct, currencyCode)}

{t("hall.result.orderNo")}:{" "} {data.order_no}

{creditMode ? t("hall.result.creditBalanceAfter", { defaultValue: "可用信用" }) : t("hall.result.balanceAfter")} :{" "} {formatMinorAsCurrency(data.balance_after, currencyCode)}

{jackpotEnabled ? (

{t("hall.jackpotParticipation.title")}

{t("hall.jackpotParticipation.resultDescription")}

) : null}

{t("hall.result.items")}

{successItems.map((item, index) => ( ))}
{t("hall.table.no")} {t("hall.result.number")} {t("orders.play")} {t("hall.providers.title")} {t("hall.result.actualDeduct")}
{index + 1} {item.number} {item.ticket_no} {playLabel(item.play_code, t)} {providerLabel(item.provider_name, item.provider_code)} {formatMinorAsCurrency(item.actual_deduct_amount, currencyCode)}
{failedItems.length === 0 && pendingItems.length === 0 ? (
{t("hall.result.noFailures")}
) : (
{failedItems.length > 0 ? ( <>

{t("hall.result.failedItems")}

{failedItems.map((item, index) => (
{item.number}{" "} {playLabel(item.play_code, t)} · {providerLabel(item.provider_name, item.provider_code)} {item.fail_reason_text ?? item.fail_reason_code ?? t("hall.result.failed")}
))} ) : null} {pendingItems.length > 0 ? (

{t("hall.result.pendingConfirmLines", { count: pendingItems.length })}

) : null}
)}
)}
); }