"use client" import { useFormContext, useFieldArray } from "react-hook-form" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Input } from "@/components/ui/input" import { Textarea } from "@/components/ui/textarea" import { Checkbox } from "@/components/ui/checkbox" import { Button } from "@/components/ui/button" import { Calendar } from "@/components/ui/calendar" import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { Badge } from "@/components/ui/badge" import { Label } from "@/components/ui/label" import { CalendarIcon, Eye, Calculator, AlertCircle } from "lucide-react" import { format } from "date-fns" import { cn, formatCurrency } from "@/lib/utils" import { useState } from "react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog" interface QuotationItemsTableProps { prItems: any[] } export default function QuotationItemsTable({ prItems }: QuotationItemsTableProps) { const { control, register, setValue, watch } = useFormContext() const { fields } = useFieldArray({ control, name: "quotationItems" }) const [selectedItem, setSelectedItem] = useState(null) const [showDetail, setShowDetail] = useState(false) const currency = watch("vendorCurrency") || "USD" const quotationItems = watch("quotationItems") // 단가 * 수량 계산 const calculateTotal = (index: number) => { const item = quotationItems[index] const prItem = prItems[index] if (item && prItem) { const total = (item.unitPrice || 0) * (prItem.quantity || 0) setValue(`quotationItems.${index}.totalPrice`, total) } } // 할인 적용 const applyDiscount = (index: number) => { const item = quotationItems[index] const prItem = prItems[index] if (item && prItem && item.discountRate) { const originalTotal = (item.unitPrice || 0) * (prItem.quantity || 0) const discountAmount = originalTotal * (item.discountRate / 100) const finalTotal = originalTotal - discountAmount setValue(`quotationItems.${index}.totalPrice`, finalTotal) } } const totalAmount = quotationItems?.reduce( (sum: number, item: any) => sum + (item.totalPrice || 0), 0 ) || 0 // 상세 정보 다이얼로그 const ItemDetailDialog = ({ item, prItem, index }: any) => ( 견적 상세 정보 {prItem.materialCode} - {prItem.materialDescription}
{/* PR 아이템 정보 */} PR 아이템 정보

{prItem.prNo}

{prItem.materialCode}

{prItem.quantity} {prItem.uom}

{prItem.deliveryDate ? format(new Date(prItem.deliveryDate), "yyyy-MM-dd") : '-'}

{prItem.specNo && (

{prItem.specNo}

)} {prItem.trackingNo && (

{prItem.trackingNo}

)}
{/* 제조사 정보 */} 제조사 정보
{/* 기술 준수 및 대안 */} 기술 사양
setValue(`quotationItems.${index}.technicalCompliance`, checked) } />
{!watch(`quotationItems.${index}.technicalCompliance`) && (