"use client"; import { useState } from "react"; import { FLOCK_UI } from "@/lib/flock/ui-labels"; import type { FlockDisplayLine } from "@/modules/flock/quote-storage"; import type { FlockCheckoutTier } from "@/lib/flock/flock-checkout-selection"; import { validateFlockCheckoutSelection } from "@/lib/flock/flock-checkout-selection"; import { ErrorBanner } from "@/components/ui/error-banner"; export type FlockCheckoutIntent = { preferredTier: FlockCheckoutTier; line: FlockDisplayLine; }; export interface FlockQuoteResultProps { lines: FlockDisplayLine[]; reference?: string | null; onReset?: () => void; /** 登录态:允许选档结账 */ checkoutEnabled?: boolean; checkoutBusy?: boolean; checkoutMessage?: string | null; onCheckout?: (intent: FlockCheckoutIntent) => void; } function formatUsd(n: number): string { return n.toLocaleString("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0, }); } /** Flock 两档对比结果卡(中文);登录态可选手选档结账 */ export function FlockQuoteResult({ lines, reference, onReset, checkoutEnabled = false, checkoutBusy = false, checkoutMessage = null, onCheckout, }: FlockQuoteResultProps) { const direct = lines.find((l) => l.tier === "flock_direct"); const standard = lines.find((l) => l.tier === "standard"); const [selectedTier, setSelectedTier] = useState( null, ); const [localError, setLocalError] = useState(null); const selectedLine = selectedTier === "flock_direct" ? direct : selectedTier === "standard" ? standard : null; if (!direct && !standard) { return (
{FLOCK_UI.emptyResult}
); } const selectTier = (tier: FlockCheckoutTier) => { if (!checkoutEnabled) return; setSelectedTier(tier); setLocalError(null); }; return (

{FLOCK_UI.resultTitle}

{reference && (

{FLOCK_UI.reference} #{reference}

)}
{onReset && ( )}
{direct && (
selectTier("flock_direct")} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); selectTier("flock_direct"); } }} role={checkoutEnabled ? "button" : undefined} tabIndex={checkoutEnabled ? 0 : undefined} aria-pressed={ checkoutEnabled ? selectedTier === "flock_direct" : undefined } >
{FLOCK_UI.directTag}

{FLOCK_UI.directName}

{FLOCK_UI.pricesFrom} {formatUsd(direct.final_total_usd)}

{FLOCK_UI.transit}:{direct.transitDescription || direct.transitDays}

    {FLOCK_UI.directFeatures.map((f) => (
  • ✓ {f}
  • ))}
)} {standard && (
selectTier("standard")} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); selectTier("standard"); } }} role={checkoutEnabled ? "button" : undefined} tabIndex={checkoutEnabled ? 0 : undefined} aria-pressed={ checkoutEnabled ? selectedTier === "standard" : undefined } >
{FLOCK_UI.standardTag}

{FLOCK_UI.standardName}

{FLOCK_UI.pricesFrom} {formatUsd(standard.final_total_usd)}

{FLOCK_UI.transit}: {standard.transitDescription || standard.transitDays}

    {FLOCK_UI.standardFeatures.map((f, i) => (
  • {i === 0 ? "✓" : "×"} {f}
  • ))}

{FLOCK_UI.standardNote}

)}
{checkoutEnabled && (
{(localError || checkoutMessage) && (
{localError || checkoutMessage}
)} {selectedLine && selectedTier && (

{FLOCK_UI.checkoutSelected}: {selectedTier === "flock_direct" ? FLOCK_UI.directName : FLOCK_UI.standardName}{" "} · {formatUsd(selectedLine.final_total_usd)}

)} {!selectedTier && (

{FLOCK_UI.checkoutSelectHint}

)}

{FLOCK_UI.checkoutFootnote}

)}
); }