import { useState } from 'react'; import { X, RefreshCw, Loader2 } from 'lucide-react'; import { useScrollLock } from '@/lib/useScrollLock'; import { Button } from '@/components/ui/button'; import { Typography } from '@/components/ui/typography'; import { type Partner, sessionStatusLabel } from '../../types'; type RegenerateModalProps = { open: boolean; /** 현재 견적에 연결된 공급사만. */ partners: Partner[]; /** 공급사별 협상 단계(세션 상태 코드) — 행에 함께 표시. */ sessionStatusBySupplier?: Record; /** 기본 선택 = 원 라운드의 공급사들. */ defaultSupplierIds: string[]; /** 확정 → 재생성 호출. 성공(true) 시 모달 닫힘. */ onConfirm: (supplierIds: string[]) => Promise | boolean; onClose: () => void; }; // 마감된 견적의 '다음 라운드'를 만들 때 부를 공급사를 고르는 모달. // 상품·견적번호·협상기간·카드는 원 견적에서 이어받으므로 여기선 공급사만 선택한다. export function RegenerateModal({ open, partners, sessionStatusBySupplier, defaultSupplierIds, onConfirm, onClose }: RegenerateModalProps) { useScrollLock(open); // 모달 열린 동안 배경(부모) 스크롤 잠금 const [selected, setSelected] = useState(defaultSupplierIds); const [submitting, setSubmitting] = useState(false); if (!open) return null; const toggle = (id: string) => setSelected((prev) => (prev.includes(id) ? prev.filter((p) => p !== id) : [...prev, id])); // 공급사 1곳=재협상(1:1), 여러 곳=재견적(1:N) — 백엔드 타입 자동결정과 동일하게 미리 안내. const nextTypeLabel = selected.length <= 1 ? '재협상 (1:1)' : '재견적 (1:N)'; const handle = async () => { if (submitting || selected.length === 0) return; setSubmitting(true); try { const ok = await onConfirm(selected); if (ok) onClose(); } finally { setSubmitting(false); } }; return (
{/* Header */}
다음 견적 재생성
{/* Body */}
상품 · 견적번호 · 협상기간 · 카드는 이 견적에서 이어받습니다. 다음 견적에 부를 공급사만 고르세요.
{partners.map((part) => { const isChecked = selected.includes(part.id ?? ''); return ( ); })}
선택: {selected.length}곳 유형: {nextTypeLabel}
{/* Footer */}
); }