"use client" import * as React from "react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Badge } from "@/components/ui/badge" import { Separator } from "@/components/ui/separator" import { ScrollArea } from "@/components/ui/scroll-area" import { FileTextIcon, MessageSquareIcon } from "lucide-react" import { VendorPO } from "./types" interface VendorPONoteDialogProps { open: boolean onOpenChange: (open: boolean) => void po: VendorPO | null } interface PONoteItem { itemNo: string description: string remark: string } export function VendorPONoteDialog({ open, onOpenChange, po, }: VendorPONoteDialogProps) { // 계약서 내용 및 노트 데이터를 추출하는 함수 const extractContent = React.useCallback(() => { if (!po) return { contractContent: null, remarks: null, itemNotes: [] } const contractContent = po.contractContent || null // contracts.contractContent (ZMM_NOTE에서 추출) const remarks = po.remarks || null // contracts.remarks (추가 비고) const itemNotes: PONoteItem[] = [] // items 배열에서 remark이 있는 항목들 추출 if (po.items && po.items.length > 0) { po.items.forEach((item, index) => { if (item.remark && item.remark.trim()) { itemNotes.push({ itemNo: item.itemNo || `Item ${index + 1}`, description: item.itemDescription || item.materialSpec || '', remark: item.remark, }) } }) } return { contractContent, remarks, itemNotes } }, [po]) const { contractContent, remarks, itemNotes } = extractContent() const hasAnyContent = contractContent || remarks || itemNotes.length > 0 return ( 계약서 내용 - {po?.contractNo} {po?.contractName} 계약의 계약서 내용 및 관련 노트입니다.
{/* 계약서 내용 (메인) */} {contractContent && (

계약서 내용

{contractContent}

)} {/* 구분선 */} {contractContent && (remarks || itemNotes.length > 0) && } {/* 계약 비고 */} {remarks && (

계약 비고

{remarks}

)} {/* 구분선 */} {(contractContent || remarks) && itemNotes.length > 0 && } {/* 아이템별 노트들 */} {itemNotes.length > 0 && (

품목별 노트 ({itemNotes.length}개)

{itemNotes.map((item, index) => (
{item.itemNo}
{item.description && (

{item.description}

)}

{item.remark}

))}
)} {/* 내용이 없는 경우 */} {!hasAnyContent && (

등록된 계약서 내용이 없습니다.

)}
) }