"use client"; import { useEffect, useState } from "react"; import type { MothershipAddressCandidate } from "@/lib/frontend/types"; import { PrimaryButton } from "@/components/ui/primary-button"; export interface AddressDisambiguationModalProps { open: boolean; pickupCandidates: MothershipAddressCandidate[]; deliveryCandidates: MothershipAddressCandidate[]; onConfirm: (pickup: MothershipAddressCandidate, delivery: MothershipAddressCandidate) => void; onCancel: () => void; } function isCandidateSelectable(item: MothershipAddressCandidate): boolean { return item.selectable !== false; } function pickDefaultId( candidates: MothershipAddressCandidate[], ): string | null { if (candidates.length === 0) { return null; } const selectable = candidates.filter(isCandidateSelectable); if (selectable.length === 1) { return selectable[0]!.option_id; } return null; } function findSelectableById( candidates: MothershipAddressCandidate[], id: string | null, ): MothershipAddressCandidate | null { if (!id) { return null; } const hit = candidates.find((c) => c.option_id === id); if (!hit || !isCandidateSelectable(hit)) { return null; } return hit; } function CandidateGroup({ title, candidates, selectedId, onSelect, }: { title: string; candidates: MothershipAddressCandidate[]; selectedId: string | null; onSelect: (id: string) => void; }) { if (candidates.length === 0) { return null; } const multi = candidates.length > 1; return (
); } export function AddressDisambiguationModal({ open, pickupCandidates, deliveryCandidates, onConfirm, onCancel, }: AddressDisambiguationModalProps) { const [pickupId, setPickupId] = useState{hasMultiple ? "系统检测到 MotherShip 对您的地址有多个精确坐标。错误选择会导致报价不准,请逐项确认后再获取报价。" : "请确认 MotherShip 解析的提货/派送地址是否准确,确认无误后再获取报价。"}