"use client"; import React from "react"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from "@/components/ui/dialog"; import { Button } from "@/components/ui/button"; import { Loader2, AlertTriangle, Check, X, Trash2, Play } from "lucide-react"; import { cn } from "@/lib/utils"; import { statusOptions } from "../config"; interface PreviewItem { item_code: string; item_name: string; required_qty: number; daily_capacity: number; hourly_capacity: number; production_days: number; start_date: string; end_date: string; due_date: string; order_count: number; status: string; } interface ExistingSchedule { id: string; plan_no: string; item_code: string; item_name: string; plan_qty: string; start_date: string; end_date: string; status: string; completed_qty?: string; } interface PreviewSummary { total: number; new_count: number; kept_count: number; deleted_count: number; } interface SchedulePreviewDialogProps { open: boolean; onOpenChange: (open: boolean) => void; isLoading: boolean; summary: PreviewSummary | null; previews: PreviewItem[]; deletedSchedules: ExistingSchedule[]; keptSchedules: ExistingSchedule[]; onConfirm: () => void; isApplying: boolean; title?: string; description?: string; } const summaryCards = [ { key: "total", label: "총 계획", color: "bg-primary/10 text-primary" }, { key: "new_count", label: "신규 입력", color: "bg-emerald-50 text-emerald-600 dark:bg-emerald-950 dark:text-emerald-400" }, { key: "deleted_count", label: "삭제될", color: "bg-destructive/10 text-destructive" }, { key: "kept_count", label: "유지(진행중)", color: "bg-amber-50 text-amber-600 dark:bg-amber-950 dark:text-amber-400" }, ]; function formatDate(d: string | null | undefined): string { if (!d) return "-"; const s = typeof d === "string" ? d : String(d); return s.split("T")[0]; } export function SchedulePreviewDialog({ open, onOpenChange, isLoading, summary, previews, deletedSchedules, keptSchedules, onConfirm, isApplying, title, description, }: SchedulePreviewDialogProps) { return ( {title || "생산계획 변경사항 확인"} {description || "변경사항을 확인해주세요"} {isLoading ? (
미리보기 생성 중...
) : summary ? (
{/* 경고 배너 */}

변경사항을 확인해주세요

아래 변경사항을 검토하신 후 확인 버튼을 눌러주시면 생산계획이 업데이트됩니다.

{/* 요약 카드 */}
{summaryCards.map((card) => (

{(summary as any)[card.key] ?? 0}

{card.label}

))}
{/* 신규 생성 목록 */} {previews.length > 0 && (

신규 생성되는 계획 ({previews.length}건)

{previews.map((item, idx) => { const statusInfo = statusOptions.find((s) => s.value === item.status); return (

{item.item_code} - {item.item_name}

{statusInfo?.label || item.status}

수량: {(item.required_qty || (item as any).plan_qty || 0).toLocaleString()} EA

시작일: {formatDate(item.start_date)} 종료일: {formatDate(item.end_date)}
{item.order_count ? (

{item.order_count}건 수주 통합 (총 {item.required_qty.toLocaleString()} EA)

) : (item as any).parent_item_name ? (

상위: {(item as any).parent_plan_no} ({(item as any).parent_item_name}) | BOM 수량: {(item as any).bom_qty || 1}

) : null}
); })}
)} {/* 삭제될 목록 */} {deletedSchedules.length > 0 && (

삭제될 기존 계획 ({deletedSchedules.length}건)

{deletedSchedules.map((item, idx) => (

{item.item_code} - {item.item_name}

삭제 예정

{item.plan_no} | 수량: {Number(item.plan_qty || 0).toLocaleString()} EA

시작일: {formatDate(item.start_date)} 종료일: {formatDate(item.end_date)}
))}
)} {/* 유지될 목록 (진행중) */} {keptSchedules.length > 0 && (

유지되는 진행중 계획 ({keptSchedules.length}건)

{keptSchedules.map((item, idx) => { const statusInfo = statusOptions.find((s) => s.value === item.status); return (

{item.item_code} - {item.item_name}

{statusInfo?.label || item.status}

{item.plan_no} | 수량: {Number(item.plan_qty || 0).toLocaleString()} EA {item.completed_qty ? ` (완료: ${Number(item.completed_qty).toLocaleString()} EA)` : ""}

시작일: {formatDate(item.start_date)} 종료일: {formatDate(item.end_date)}
); })}
)}
) : (
미리보기 데이터를 불러올 수 없습니다
)}
); }