import React from 'react';
import { X, FileText, Clipboard, ClipboardList, Printer, Download, Mail, Package, Truck } from 'lucide-react';

// 견적서 다이얼로그
export const QuoteSheetDialog = ({ quote, onClose }) => {
  if (!quote) return null;

  return (
    <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
      <div className="bg-white rounded-xl shadow-2xl w-full max-w-4xl max-h-[90vh] overflow-hidden flex flex-col">
        {/* 헤더 */}
        <div className="flex items-center justify-between p-4 border-b bg-gray-50">
          <div className="flex items-center gap-2">
            <FileText className="w-5 h-5 text-blue-600" />
            <h2 className="text-lg font-bold text-gray-900">견적서</h2>
          </div>
          <div className="flex items-center gap-2">
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Printer className="w-4 h-4" />
            </button>
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Download className="w-4 h-4" />
            </button>
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Mail className="w-4 h-4" />
            </button>
            <button onClick={onClose} className="p-2 hover:bg-gray-200 rounded-lg">
              <X className="w-5 h-5" />
            </button>
          </div>
        </div>

        {/* 견적서 내용 */}
        <div className="flex-1 overflow-y-auto p-6">
          <div className="max-w-3xl mx-auto bg-white border rounded-lg p-8">
            {/* 문서 제목 */}
            <div className="text-center mb-8">
              <h1 className="text-3xl font-bold text-gray-900 mb-2">견 적 서</h1>
              <p className="text-sm text-gray-500">QUOTATION</p>
            </div>

            {/* 견적 정보 */}
            <div className="grid grid-cols-2 gap-8 mb-8">
              {/* 수신자 정보 */}
              <div className="border rounded-lg p-4">
                <h3 className="text-sm font-medium text-gray-500 mb-3 border-b pb-2">수신자 정보</h3>
                <div className="space-y-2 text-sm">
                  <div className="flex">
                    <span className="w-20 text-gray-500">상호</span>
                    <span className="font-medium">{quote.customerName}</span>
                  </div>
                  <div className="flex">
                    <span className="w-20 text-gray-500">담당자</span>
                    <span>{quote.manager}</span>
                  </div>
                  <div className="flex">
                    <span className="w-20 text-gray-500">연락처</span>
                    <span>{quote.contact}</span>
                  </div>
                  <div className="flex">
                    <span className="w-20 text-gray-500">현장명</span>
                    <span>{quote.siteName}</span>
                  </div>
                </div>
              </div>

              {/* 발신자 정보 */}
              <div className="border rounded-lg p-4">
                <h3 className="text-sm font-medium text-gray-500 mb-3 border-b pb-2">발신자 정보</h3>
                <div className="space-y-2 text-sm">
                  <div className="flex">
                    <span className="w-20 text-gray-500">상호</span>
                    <span className="font-medium">(주) 코드빌더스</span>
                  </div>
                  <div className="flex">
                    <span className="w-20 text-gray-500">대표자</span>
                    <span>홍길동</span>
                  </div>
                  <div className="flex">
                    <span className="w-20 text-gray-500">사업자번호</span>
                    <span>123-45-67890</span>
                  </div>
                  <div className="flex">
                    <span className="w-20 text-gray-500">연락처</span>
                    <span>02-1234-5678</span>
                  </div>
                </div>
              </div>
            </div>

            {/* 견적 요약 */}
            <div className="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-8">
              <div className="flex justify-between items-center">
                <div>
                  <span className="text-sm text-gray-600">견적번호</span>
                  <p className="font-mono font-bold text-blue-600">{quote.quoteNo}</p>
                </div>
                <div>
                  <span className="text-sm text-gray-600">견적일</span>
                  <p className="font-medium">{quote.quoteDate}</p>
                </div>
                <div>
                  <span className="text-sm text-gray-600">유효기간</span>
                  <p className="font-medium">견적일로부터 30일</p>
                </div>
                <div className="text-right">
                  <span className="text-sm text-gray-600">견적금액 (VAT별도)</span>
                  <p className="text-2xl font-bold text-blue-600">{quote.totalAmount?.toLocaleString()}원</p>
                </div>
              </div>
            </div>

            {/* 품목 테이블 */}
            <table className="w-full text-sm border-collapse mb-8">
              <thead>
                <tr className="bg-gray-100">
                  <th className="border px-3 py-2 text-left">No</th>
                  <th className="border px-3 py-2 text-left">품목명</th>
                  <th className="border px-3 py-2 text-center">규격</th>
                  <th className="border px-3 py-2 text-center">수량</th>
                  <th className="border px-3 py-2 text-right">단가</th>
                  <th className="border px-3 py-2 text-right">금액</th>
                </tr>
              </thead>
              <tbody>
                {quote.items && quote.items.length > 0 ? (
                  quote.items.map((item, idx) => (
                    <tr key={item.id || idx}>
                      <td className="border px-3 py-2">{idx + 1}</td>
                      <td className="border px-3 py-2">{item.productName}</td>
                      <td className="border px-3 py-2 text-center">{item.width}x{item.height}</td>
                      <td className="border px-3 py-2 text-center">{item.qty}</td>
                      <td className="border px-3 py-2 text-right">{item.unitPrice?.toLocaleString()}</td>
                      <td className="border px-3 py-2 text-right">{item.amount?.toLocaleString()}</td>
                    </tr>
                  ))
                ) : (
                  <tr>
                    <td className="border px-3 py-2">1</td>
                    <td className="border px-3 py-2">{quote.productName || '스크린 셔터'}</td>
                    <td className="border px-3 py-2 text-center">-</td>
                    <td className="border px-3 py-2 text-center">{quote.qty || 1}</td>
                    <td className="border px-3 py-2 text-right">-</td>
                    <td className="border px-3 py-2 text-right">{quote.totalAmount?.toLocaleString()}</td>
                  </tr>
                )}
              </tbody>
              <tfoot>
                <tr className="bg-gray-50 font-medium">
                  <td colSpan={5} className="border px-3 py-2 text-right">합계</td>
                  <td className="border px-3 py-2 text-right font-bold">{quote.totalAmount?.toLocaleString()}원</td>
                </tr>
                <tr className="bg-gray-50">
                  <td colSpan={5} className="border px-3 py-2 text-right">부가세 (10%)</td>
                  <td className="border px-3 py-2 text-right">{Math.round(quote.totalAmount * 0.1)?.toLocaleString()}원</td>
                </tr>
                <tr className="bg-blue-50 font-bold">
                  <td colSpan={5} className="border px-3 py-2 text-right">총 견적금액</td>
                  <td className="border px-3 py-2 text-right text-blue-600">{Math.round(quote.totalAmount * 1.1)?.toLocaleString()}원</td>
                </tr>
              </tfoot>
            </table>

            {/* 비고 */}
            {quote.note && (
              <div className="border rounded-lg p-4">
                <h3 className="text-sm font-medium text-gray-500 mb-2">비고</h3>
                <p className="text-sm text-gray-700">{quote.note}</p>
              </div>
            )}
          </div>
        </div>
      </div>
    </div>
  );
};

// 산출내역서 다이얼로그
export const CalculationSheetDialog = ({ quote, onClose }) => {
  if (!quote) return null;

  return (
    <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
      <div className="bg-white rounded-xl shadow-2xl w-full max-w-5xl max-h-[90vh] overflow-hidden flex flex-col">
        {/* 헤더 */}
        <div className="flex items-center justify-between p-4 border-b bg-gray-50">
          <div className="flex items-center gap-2">
            <Clipboard className="w-5 h-5 text-green-600" />
            <h2 className="text-lg font-bold text-gray-900">산출내역서</h2>
          </div>
          <div className="flex items-center gap-2">
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Printer className="w-4 h-4" />
            </button>
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Download className="w-4 h-4" />
            </button>
            <button onClick={onClose} className="p-2 hover:bg-gray-200 rounded-lg">
              <X className="w-5 h-5" />
            </button>
          </div>
        </div>

        {/* 산출내역서 내용 */}
        <div className="flex-1 overflow-y-auto p-6">
          <div className="max-w-4xl mx-auto">
            {/* 문서 헤더 */}
            <div className="text-center mb-6">
              <h1 className="text-2xl font-bold text-gray-900">산 출 내 역 서</h1>
              <p className="text-sm text-gray-500 mt-1">CALCULATION DETAILS</p>
            </div>

            {/* 기본 정보 */}
            <div className="grid grid-cols-3 gap-4 mb-6 text-sm">
              <div className="border rounded p-3">
                <span className="text-gray-500">견적번호</span>
                <p className="font-mono font-medium">{quote.quoteNo}</p>
              </div>
              <div className="border rounded p-3">
                <span className="text-gray-500">현장명</span>
                <p className="font-medium">{quote.siteName}</p>
              </div>
              <div className="border rounded p-3">
                <span className="text-gray-500">작성일</span>
                <p className="font-medium">{quote.quoteDate}</p>
              </div>
            </div>

            {/* 산출 내역 테이블 */}
            <table className="w-full text-sm border-collapse mb-6">
              <thead>
                <tr className="bg-gray-100">
                  <th className="border px-3 py-2 text-left">No</th>
                  <th className="border px-3 py-2 text-left">품목</th>
                  <th className="border px-3 py-2 text-center">층/부호</th>
                  <th className="border px-3 py-2 text-center">가로(mm)</th>
                  <th className="border px-3 py-2 text-center">세로(mm)</th>
                  <th className="border px-3 py-2 text-center">면적(m2)</th>
                  <th className="border px-3 py-2 text-center">수량</th>
                  <th className="border px-3 py-2 text-right">단가</th>
                  <th className="border px-3 py-2 text-right">금액</th>
                </tr>
              </thead>
              <tbody>
                {quote.items && quote.items.length > 0 ? (
                  quote.items.map((item, idx) => {
                    const area = ((item.width || 0) * (item.height || 0) / 1000000).toFixed(2);
                    return (
                      <tr key={item.id || idx}>
                        <td className="border px-3 py-2">{idx + 1}</td>
                        <td className="border px-3 py-2">{item.productName}</td>
                        <td className="border px-3 py-2 text-center">{item.floor || '-'}/{item.location || '-'}</td>
                        <td className="border px-3 py-2 text-center">{item.width || '-'}</td>
                        <td className="border px-3 py-2 text-center">{item.height || '-'}</td>
                        <td className="border px-3 py-2 text-center">{area}</td>
                        <td className="border px-3 py-2 text-center">{item.qty}</td>
                        <td className="border px-3 py-2 text-right">{item.unitPrice?.toLocaleString()}</td>
                        <td className="border px-3 py-2 text-right">{item.amount?.toLocaleString()}</td>
                      </tr>
                    );
                  })
                ) : (
                  <tr>
                    <td colSpan={9} className="border px-3 py-8 text-center text-gray-500">
                      산출 내역이 없습니다.
                    </td>
                  </tr>
                )}
              </tbody>
              <tfoot>
                <tr className="bg-gray-50 font-medium">
                  <td colSpan={8} className="border px-3 py-2 text-right">합계</td>
                  <td className="border px-3 py-2 text-right font-bold">{quote.totalAmount?.toLocaleString()}원</td>
                </tr>
              </tfoot>
            </table>

            {/* 산출 기준 안내 */}
            <div className="bg-gray-50 border rounded-lg p-4">
              <h3 className="text-sm font-medium text-gray-700 mb-2">산출 기준</h3>
              <ul className="text-xs text-gray-600 space-y-1">
                <li>- 단가는 면적 기준으로 산출되며, 최소 면적 기준이 적용됩니다.</li>
                <li>- 특수 규격(3m 초과)은 별도 할증이 적용될 수 있습니다.</li>
                <li>- 설치비 및 운반비는 별도입니다.</li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

// 발주서 다이얼로그 - 스크린샷 기반 업데이트 양식
export const PurchaseOrderDialog = ({ quote, onClose }) => {
  if (!quote) return null;

  // 발주번호 생성 (예: KD-PR-250215-01-01)
  const today = new Date();
  const yy = String(today.getFullYear()).slice(-2);
  const mm = String(today.getMonth() + 1).padStart(2, '0');
  const dd = String(today.getDate()).padStart(2, '0');
  const poNo = `KD-PR-${yy}${mm}${dd}-01-01`;

  // 날짜 포맷팅
  const formatDate = (dateStr) => {
    if (!dateStr) return '-';
    const d = new Date(dateStr);
    return `${d.getFullYear()}년 ${String(d.getMonth() + 1).padStart(2, '0')}월 ${String(d.getDate()).padStart(2, '0')}일`;
  };

  return (
    <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
      <div className="bg-white rounded-xl shadow-2xl w-full max-w-4xl max-h-[90vh] overflow-hidden flex flex-col">
        {/* 헤더 */}
        <div className="flex items-center justify-between p-4 border-b bg-gray-50">
          <div className="flex items-center gap-2">
            <ClipboardList className="w-5 h-5 text-purple-600" />
            <h2 className="text-lg font-bold text-gray-900">발주서</h2>
          </div>
          <div className="flex items-center gap-2">
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Printer className="w-4 h-4" />
            </button>
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Download className="w-4 h-4" />
            </button>
            <button onClick={onClose} className="p-2 hover:bg-gray-200 rounded-lg">
              <X className="w-5 h-5" />
            </button>
          </div>
        </div>

        {/* 발주서 내용 */}
        <div className="flex-1 overflow-y-auto p-6 bg-white">
          <div className="max-w-4xl mx-auto bg-white border border-gray-300 p-8">

            {/* 문서 헤더: 제목 + 로트번호/결재란 */}
            <div className="flex justify-between items-start mb-6">
              {/* 제목 */}
              <h1 className="text-4xl font-bold tracking-widest text-gray-900">발 주 서</h1>

              {/* 로트번호 및 결재란 */}
              <div className="text-sm">
                {/* 로트번호 */}
                <table className="border-collapse border border-gray-400 mb-2">
                  <tbody>
                    <tr>
                      <td className="border border-gray-400 px-3 py-1 bg-gray-100 font-medium text-center">로트번호</td>
                      <td className="border border-gray-400 px-3 py-1 font-mono">{poNo}</td>
                    </tr>
                  </tbody>
                </table>
                {/* 결재란 */}
                <table className="border-collapse border border-gray-400">
                  <tbody>
                    <tr>
                      <td rowSpan={3} className="border border-gray-400 px-2 py-1 bg-gray-100 font-medium text-center w-10 writing-vertical">결<br/>재</td>
                      <td className="border border-gray-400 px-3 py-1 text-center text-xs text-gray-500 w-16">작성</td>
                      <td className="border border-gray-400 px-3 py-1 text-center text-xs text-gray-500 w-16">검토</td>
                      <td className="border border-gray-400 px-3 py-1 text-center text-xs text-gray-500 w-16">승인</td>
                    </tr>
                    <tr>
                      <td className="border border-gray-400 px-3 py-3 text-center text-sm">전진</td>
                      <td className="border border-gray-400 px-3 py-3 text-center"></td>
                      <td className="border border-gray-400 px-3 py-3 text-center"></td>
                    </tr>
                    <tr>
                      <td className="border border-gray-400 px-2 py-1 text-center text-xs text-gray-500">판매/전진</td>
                      <td className="border border-gray-400 px-2 py-1 text-center text-xs text-gray-500">회계</td>
                      <td className="border border-gray-400 px-2 py-1 text-center text-xs text-gray-500">생산</td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>

            {/* 신청업체 섹션 */}
            <table className="w-full border-collapse border border-gray-400 mb-4 text-sm">
              <tbody>
                <tr>
                  <td rowSpan={3} className="border border-gray-400 px-3 py-2 bg-gray-100 font-medium text-center w-24">신청업체</td>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center w-20">발주처</td>
                  <td className="border border-gray-400 px-3 py-2">{quote.customerName || '현대개발(주)'}</td>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center w-20">발주일</td>
                  <td className="border border-gray-400 px-3 py-2">{formatDate(quote.orderDate || today)}</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">담당자</td>
                  <td className="border border-gray-400 px-3 py-2">{quote.manager || '홍길동'}</td>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">연락처</td>
                  <td className="border border-gray-400 px-3 py-2">{quote.contact || '010-1234-5678'}</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">FAX</td>
                  <td className="border border-gray-400 px-3 py-2">{quote.fax || '-'}</td>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">설치개소(총)</td>
                  <td className="border border-gray-400 px-3 py-2">{quote.totalInstallCount || quote.qty || '23'}개소</td>
                </tr>
              </tbody>
            </table>

            {/* 신청내용 섹션 */}
            <table className="w-full border-collapse border border-gray-400 mb-4 text-sm">
              <tbody>
                <tr>
                  <td rowSpan={5} className="border border-gray-400 px-3 py-2 bg-gray-100 font-medium text-center w-24">신청내용</td>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center w-20">현장명</td>
                  <td colSpan={3} className="border border-gray-400 px-3 py-2">{quote.siteName || '연수 오피스텔'}</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">납기요청일</td>
                  <td colSpan={3} className="border border-gray-400 px-3 py-2">{quote.dueDate || '2025-03-15'}</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">출고일</td>
                  <td className="border border-gray-400 px-3 py-2">{formatDate(quote.shipDate || today)}</td>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center w-20">배송방법</td>
                  <td className="border border-gray-400 px-3 py-2">{quote.deliveryMethod || '상차'}</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">납품주소</td>
                  <td colSpan={3} className="border border-gray-400 px-3 py-2">{quote.address || '경기도 안성시 서운면 서운신기 16-180'}</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">수신자</td>
                  <td className="border border-gray-400 px-3 py-2">{quote.receiver || '정제용방'}</td>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center">연락처</td>
                  <td className="border border-gray-400 px-3 py-2">{quote.receiverContact || '010-2293-8700'}</td>
                </tr>
              </tbody>
            </table>

            {/* 누적/금번 발주개소 */}
            <table className="w-full border-collapse border border-gray-400 mb-6 text-sm">
              <tbody>
                <tr>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center w-28">누적발주개소</td>
                  <td className="border border-gray-400 px-3 py-2 text-center">{quote.cumulativeCount || '18'}개소</td>
                  <td className="border border-gray-400 px-3 py-2 bg-gray-50 text-center w-28">금번발주개소</td>
                  <td className="border border-gray-400 px-3 py-2 text-center">{quote.currentCount || quote.qty || '5'}개소</td>
                </tr>
              </tbody>
            </table>

            {/* 인사말 및 안내문구 */}
            <div className="text-sm text-gray-700 mb-4 space-y-1">
              <p>1. 귀사의 일익번영을 기원합니다.</p>
              <p>2. 아래와 같이 주문하오니 품질 및 납기일을 준수하여 주시기 바랍니다.</p>
            </div>

            {/* 부자재 섹션 */}
            <div className="mb-6">
              <h3 className="font-bold text-sm mb-2">■ 부자재</h3>
              <table className="w-full border-collapse border border-gray-400 text-sm">
                <thead>
                  <tr className="bg-gray-100">
                    <th className="border border-gray-400 px-3 py-2 text-center w-16">구분</th>
                    <th className="border border-gray-400 px-3 py-2 text-center w-24">품명</th>
                    <th className="border border-gray-400 px-3 py-2 text-center">규격</th>
                    <th className="border border-gray-400 px-3 py-2 text-center w-24">길이(mm)</th>
                    <th className="border border-gray-400 px-3 py-2 text-center w-20">수량</th>
                    <th className="border border-gray-400 px-3 py-2 text-center w-24">비고</th>
                  </tr>
                </thead>
                <tbody>
                  {quote.items && quote.items.length > 0 ? (
                    quote.items.map((item, idx) => (
                      <tr key={item.id || idx}>
                        <td className="border border-gray-400 px-3 py-2 text-center">{idx + 1}</td>
                        <td className="border border-gray-400 px-3 py-2">{item.productName || item.name}</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">{item.spec || `${item.width || '-'}`}</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">{item.length || item.height || '-'}</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">{item.qty}</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">{item.note || ''}</td>
                      </tr>
                    ))
                  ) : (
                    <>
                      <tr>
                        <td className="border border-gray-400 px-3 py-2 text-center">1</td>
                        <td className="border border-gray-400 px-3 py-2">가이드레일 상판</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">본관 1층</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">100</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">100</td>
                        <td className="border border-gray-400 px-3 py-2 text-center"></td>
                      </tr>
                      <tr>
                        <td className="border border-gray-400 px-3 py-2 text-center">2</td>
                        <td className="border border-gray-400 px-3 py-2">가이드레일 하판</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">본관 1층</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">100</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">100</td>
                        <td className="border border-gray-400 px-3 py-2 text-center"></td>
                      </tr>
                      <tr>
                        <td className="border border-gray-400 px-3 py-2 text-center">3</td>
                        <td className="border border-gray-400 px-3 py-2">셔터 세트</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">별관</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">30</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">30</td>
                        <td className="border border-gray-400 px-3 py-2 text-center"></td>
                      </tr>
                      <tr>
                        <td className="border border-gray-400 px-3 py-2 text-center">4</td>
                        <td className="border border-gray-400 px-3 py-2">알루미늄 프레임</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">지하주차장</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">80</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">80</td>
                        <td className="border border-gray-400 px-3 py-2 text-center"></td>
                      </tr>
                      <tr>
                        <td className="border border-gray-400 px-3 py-2 text-center">5</td>
                        <td className="border border-gray-400 px-3 py-2">DC 모터</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">전동식</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">50</td>
                        <td className="border border-gray-400 px-3 py-2 text-center">50</td>
                        <td className="border border-gray-400 px-3 py-2 text-center"></td>
                      </tr>
                    </>
                  )}
                </tbody>
              </table>
            </div>

            {/* 특이사항 */}
            <div className="bg-gray-50 border border-gray-300 p-4 mb-4 text-sm">
              <h3 className="font-bold mb-2">【특이사항】</h3>
              <p className="text-gray-700">{quote.specialNote || quote.note || '오피스텔 신축 공사'}</p>
            </div>

            {/* 유의사항 */}
            <div className="bg-gray-50 border border-gray-300 p-4 mb-6 text-sm">
              <h3 className="font-bold mb-2">【 유의사항 】</h3>
              <ul className="text-gray-700 space-y-1">
                <li>• 발주서 승인 완료 후 작업을 진행해주시기 바랍니다.</li>
                <li>• 납기 엄수 부탁드리며, 품질 기준에 맞춰 납품해주시기 바랍니다.</li>
                <li>• 기타 문의사항은 담당자에게 연락 부탁드립니다.</li>
              </ul>
            </div>

            {/* 담당자 연락처 */}
            <div className="text-center text-sm text-gray-600">
              <p>문의: {quote.manager || '홍길동'} | {quote.contact || '010-1234-5678'}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

// 납품확인서 다이얼로그 - 스크린샷 기반 엑셀 양식
export const DeliveryConfirmDialog = ({ shipment, onClose }) => {
  if (!shipment) return null;

  // 납품확인서 번호 생성 (예: KD-SA-251218-01)
  const today = new Date();
  const yy = String(today.getFullYear()).slice(-2);
  const mm = String(today.getMonth() + 1).padStart(2, '0');
  const dd = String(today.getDate()).padStart(2, '0');
  const deliveryNo = `KD-SA-${yy}${mm}${dd}-${String(shipment.id || 1).padStart(2, '0')}`;

  // 샘플 자재내역 데이터
  const materialItems = shipment.items || [
    { no: '01', type: '실리카', code: 'A동 FSS-01', openW: 6100, openH: 2900, makeW: 6240, makeH: 3250, guideType: '벽면형(120-70)', shaft: 5, caseSpec: '500×380', bracket: '380×180', motor: 300, finish: 'SUS마감' },
    { no: '02', type: '실리카', code: 'A동 FSS-02', openW: 7820, openH: 2900, makeW: 7960, makeH: 3250, guideType: '벽면형(120-70)', shaft: 5, caseSpec: '500×380', bracket: '380×180', motor: 300, finish: 'SUS마감' },
    { no: '03', type: '실리카', code: 'A동 FSS-03', openW: 3510, openH: 2900, makeW: 3650, makeH: 3250, guideType: '벽면형(120-70)', shaft: 4, caseSpec: '500×380', bracket: '380×180', motor: 150, finish: 'SUS마감' },
    { no: '04', type: '실리카', code: 'A동 FSS-04', openW: 3990, openH: 2900, makeW: 4130, makeH: 3250, guideType: '벽면형(120-70)', shaft: 4, caseSpec: '500×380', bracket: '380×180', motor: 150, finish: 'SUS마감' },
    { no: '05', type: '실리카', code: 'A동 FSS-05', openW: 3990, openH: 2900, makeW: 4130, makeH: 3250, guideType: '벽면형(120-70)', shaft: 4, caseSpec: '500×380', bracket: '380×180', motor: 150, finish: 'SUS마감' },
  ];

  // 절곡내역 데이터
  const bendingItems = [
    { no: '01', code: 'FSS-01', spec: '500×380', case1219: '', case2438: 1, case3000: '', case3500: '', case4000: 1, case4150: '', cover: 6, guideType: '벽면형(120-70)', guide2438: 2, guide3000: '', guide3500: '', guide4000: '', guide4300: '' },
    { no: '02', code: 'FSS-02', spec: '500×380', case1219: '', case2438: '', case3000: '', case3500: '', case4000: 1, case4150: 1, cover: 7, guideType: '벽면형(120-70)', guide2438: 2, guide3000: '', guide3500: '', guide4000: '', guide4300: '' },
    { no: '03', code: 'FSS-03', spec: '500×380', case1219: '', case2438: '', case3000: '', case3500: '', case4000: 1, case4150: '', cover: 4, guideType: '벽면형(120-70)', guide2438: 2, guide3000: '', guide3500: '', guide4000: '', guide4300: '' },
    { no: '04', code: 'FSS-04', spec: '500×380', case1219: 1, case2438: '', case3000: 1, case3500: '', case4000: '', case4150: '', cover: 4, guideType: '벽면형(120-70)', guide2438: 2, guide3000: '', guide3500: '', guide4000: '', guide4300: '' },
    { no: '05', code: 'FSS-05', spec: '500×380', case1219: 1, case2438: '', case3000: '', case3500: '', case4000: '', case4150: '', cover: 4, guideType: '벽면형(120-70)', guide2438: 2, guide3000: '', guide3500: '', guide4000: '', guide4300: '' },
  ];

  return (
    <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
      <div className="bg-white rounded-xl shadow-2xl w-full max-w-6xl max-h-[95vh] overflow-hidden flex flex-col">
        {/* 헤더 */}
        <div className="flex items-center justify-between p-4 border-b bg-gray-50">
          <div className="flex items-center gap-2">
            <ClipboardList className="w-5 h-5 text-blue-600" />
            <h2 className="text-lg font-bold text-gray-900">납품확인서</h2>
          </div>
          <div className="flex items-center gap-2">
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Printer className="w-4 h-4" />
            </button>
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Download className="w-4 h-4" />
            </button>
            <button onClick={onClose} className="p-2 hover:bg-gray-200 rounded-lg">
              <X className="w-5 h-5" />
            </button>
          </div>
        </div>

        {/* 납품확인서 내용 - A4 가로 */}
        <div className="flex-1 overflow-y-auto p-4 bg-gray-100">
          <div className="bg-white mx-auto" style={{ width: '297mm', minHeight: '210mm', padding: '8mm', fontSize: '9px' }}>
            {/* 상단 헤더 */}
            <div className="flex items-start justify-between mb-2">
              {/* 좌측: 로고 + 타이틀 */}
              <div className="flex items-center gap-4">
                <div>
                  <div className="text-2xl font-bold text-blue-800">KD</div>
                  <div className="text-xs text-blue-800">경동기업</div>
                </div>
                <div className="text-center">
                  <h1 className="text-2xl font-bold tracking-widest">납 품 확 인 서</h1>
                  <p className="text-xs text-gray-600 mt-1">전화: 031-983-5130 | 팩스: 02-6911-6315 | 이메일: kd5130@naver.com</p>
                </div>
              </div>

              {/* 우측: 로트번호 + 결재란 */}
              <div className="flex items-start gap-2">
                <table className="border-collapse text-xs">
                  <tbody>
                    <tr>
                      <td className="border border-gray-400 px-2 py-1 bg-gray-100">로트번호</td>
                      <td className="border border-gray-400 px-3 py-1 font-bold text-blue-700">{deliveryNo}</td>
                    </tr>
                    <tr>
                      <td className="border border-gray-400 px-2 py-1 bg-gray-100">결<br/>재</td>
                      <td className="border border-gray-400 px-3 py-1 text-center font-bold">경동기업</td>
                    </tr>
                  </tbody>
                </table>
                <div className="w-12 h-12 border-2 border-red-400 rounded-full flex items-center justify-center">
                  <span className="text-red-500 text-xs font-bold">印</span>
                </div>
              </div>
            </div>

            {/* 상품명 라인 */}
            <table className="w-full border-collapse text-xs mb-2">
              <tbody>
                <tr>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-100 w-20 text-center font-semibold">상 품 명</td>
                  <td className="border border-gray-400 px-2 py-1">{shipment.productName || '국민방화스크린셔터'}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-100 w-16 text-center font-semibold">제품명</td>
                  <td className="border border-gray-400 px-2 py-1">{shipment.productCode || 'KSS02'}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-100 w-16 text-center font-semibold">인정번호</td>
                  <td className="border border-gray-400 px-2 py-1">{shipment.certNo || 'FDS-OTS25-0318-2'}</td>
                </tr>
              </tbody>
            </table>

            {/* 신청업체 + 신청내용 + 납품정보 */}
            <table className="w-full border-collapse text-xs mb-2">
              <tbody>
                <tr>
                  <td colSpan="4" className="border border-gray-400 bg-gray-100 text-center font-semibold py-1">신 청 업 체</td>
                  <td colSpan="4" className="border border-gray-400 bg-gray-100 text-center font-semibold py-1">신 청 내 용</td>
                  <td colSpan="2" className="border border-gray-400 bg-gray-100 text-center font-semibold py-1">납 품 정 보</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50 w-20">발 주 일</td>
                  <td className="border border-gray-400 px-2 py-1" colSpan="3">{shipment.orderDate || '2025년 12월 3일 수요일'}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50 w-20">현 장 명</td>
                  <td className="border border-gray-400 px-2 py-1 text-blue-600 font-semibold" colSpan="3">{shipment.siteName || '은행동 현장 A동'}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">인수담당자</td>
                  <td className="border border-gray-400 px-2 py-1 text-blue-600">{shipment.receiverName || '이양게 소장'}</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">발 주 처</td>
                  <td className="border border-gray-400 px-2 py-1" colSpan="3">{shipment.customerName || '대운기업'}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">납기요청일</td>
                  <td className="border border-gray-400 px-2 py-1 text-blue-600 font-semibold" colSpan="3">{shipment.requestDate || '1900년 1월 1일 일요일'}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">인수자연락처</td>
                  <td className="border border-gray-400 px-2 py-1 text-blue-600">{shipment.receiverPhone || '010-5340-2316'}</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">발주 담당자</td>
                  <td className="border border-gray-400 px-2 py-1" colSpan="3">{shipment.orderManager || '이양게 소장'}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">출 고 일</td>
                  <td className="border border-gray-400 px-2 py-1" colSpan="3">{shipment.shipmentDate || ''}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50" rowSpan="2">배 송 방 법</td>
                  <td className="border border-gray-400 px-2 py-1 text-center" rowSpan="2">
                    <span className="mr-2">상차</span>
                    <span>선불</span>
                  </td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">담당자 연락처</td>
                  <td className="border border-gray-400 px-2 py-1" colSpan="3">{shipment.orderContact || ''}</td>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">셔터총수량</td>
                  <td className="border border-gray-400 px-2 py-1 text-center font-bold" colSpan="2">{shipment.totalQty || 5}</td>
                  <td className="border border-gray-400 px-2 py-1 text-center">개소</td>
                </tr>
                <tr>
                  <td className="border border-gray-400 px-2 py-1 bg-gray-50">배송지 주소</td>
                  <td className="border border-gray-400 px-2 py-1" colSpan="9">{shipment.deliveryAddress || ''}</td>
                </tr>
              </tbody>
            </table>

            {/* 1. 부호별 자재내역 */}
            <div className="mb-2">
              <h3 className="font-bold text-xs mb-1">1. 부호별 자재내역</h3>
              <table className="w-full border-collapse text-xs">
                <thead>
                  <tr className="bg-gray-100">
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-8">일련<br/>번호</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-12">종류</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-20">도면부호</th>
                    <th colSpan="2" className="border border-gray-400 px-1 py-1 bg-yellow-100">오픈사이즈(mm)<br/><span className="text-red-500 text-xs">"가이드레일 너비 120"</span></th>
                    <th colSpan="2" className="border border-gray-400 px-1 py-1">제작사이즈(mm)</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-24">가이드레일<br/>유형</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-12">샤프트<br/>(인치)</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-16">케이스<br/>(규격)</th>
                    <th colSpan="2" className="border border-gray-400 px-1 py-1">모터</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-16">마감유형</th>
                  </tr>
                  <tr className="bg-gray-100">
                    <th className="border border-gray-400 px-1 py-1 bg-yellow-100">가로</th>
                    <th className="border border-gray-400 px-1 py-1 bg-yellow-100">세로</th>
                    <th className="border border-gray-400 px-1 py-1">가로</th>
                    <th className="border border-gray-400 px-1 py-1">세로</th>
                    <th className="border border-gray-400 px-1 py-1">브라켓트</th>
                    <th className="border border-gray-400 px-1 py-1">용량(KG)</th>
                  </tr>
                </thead>
                <tbody>
                  {materialItems.map((item, idx) => (
                    <tr key={idx} className={idx % 2 === 0 ? 'bg-white' : 'bg-gray-50'}>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.no}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.type}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.code}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.openW}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.openH}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.makeW}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.makeH}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.guideType}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.shaft}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.caseSpec}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.bracket}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.motor}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.finish}</td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>

            {/* 2. 부호별 절곡내역 */}
            <div className="mb-2">
              <h3 className="font-bold text-xs mb-1">2. 부호별 절곡내역</h3>
              <table className="w-full border-collapse text-xs">
                <thead>
                  <tr className="bg-gray-100">
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-8">일련<br/>번호</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-16">도면<br/>부호</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-16">규격</th>
                    <th colSpan="6" className="border border-gray-400 px-1 py-1 bg-yellow-50">케이스(셔터박스)</th>
                    <th rowSpan="2" className="border border-gray-400 px-1 py-1 w-12">상부덮개</th>
                    <th colSpan="6" className="border border-gray-400 px-1 py-1">가이드레일</th>
                  </tr>
                  <tr className="bg-gray-100">
                    <th className="border border-gray-400 px-1 py-1 w-10 bg-yellow-50">1219</th>
                    <th className="border border-gray-400 px-1 py-1 w-10 bg-yellow-50">2438</th>
                    <th className="border border-gray-400 px-1 py-1 w-10 bg-yellow-50">3000</th>
                    <th className="border border-gray-400 px-1 py-1 w-10 bg-yellow-50">3500</th>
                    <th className="border border-gray-400 px-1 py-1 w-10 bg-yellow-50">4000</th>
                    <th className="border border-gray-400 px-1 py-1 w-10 bg-yellow-50">4150</th>
                    <th className="border border-gray-400 px-1 py-1 w-20">유형<br/>(1219×380)</th>
                    <th className="border border-gray-400 px-1 py-1 w-10">2438</th>
                    <th className="border border-gray-400 px-1 py-1 w-10">3000</th>
                    <th className="border border-gray-400 px-1 py-1 w-10">3500</th>
                    <th className="border border-gray-400 px-1 py-1 w-10">4000</th>
                    <th className="border border-gray-400 px-1 py-1 w-10">4300</th>
                  </tr>
                </thead>
                <tbody>
                  {bendingItems.map((item, idx) => (
                    <tr key={idx} className={idx % 2 === 0 ? 'bg-white' : 'bg-gray-50'}>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.no}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.code}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.spec}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center bg-yellow-50">{item.case1219}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center bg-yellow-50">{item.case2438}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center bg-yellow-50">{item.case3000}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center bg-yellow-50">{item.case3500}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center bg-yellow-50">{item.case4000}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center bg-yellow-50">{item.case4150}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.cover}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.guideType}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.guide2438}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.guide3000}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.guide3500}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.guide4000}</td>
                      <td className="border border-gray-400 px-1 py-1 text-center">{item.guide4300}</td>
                    </tr>
                  ))}
                </tbody>
              </table>
            </div>

            {/* 별도 추가사항 */}
            <div className="mb-2 text-xs">
              <p className="text-red-600">※ 별도 추가사항</p>
            </div>

            {/* 3. 절곡품 도면 */}
            <div className="mb-2">
              <h3 className="font-bold text-xs mb-1">3. 절곡품 도면</h3>
              <p className="text-xs mb-2">3-1. 가이드레일-EGI 1.55T+ 마감재 EGI 1.15T + 별도마감재 SUS 1.2T</p>

              <div className="flex gap-8">
                {/* 벽면형 도면 */}
                <div className="flex-1">
                  <p className="text-xs font-semibold mb-1 text-center">벽면형 (120-70)</p>
                  <p className="text-xs text-center text-red-500 mb-2">하부BASE (130-80)</p>
                  <div className="border border-gray-300 p-2 h-32 flex items-center justify-center bg-gray-50">
                    <div className="text-center text-gray-500">
                      <p className="text-xs">[KSS02]</p>
                      <p className="text-xs">①마감재 ②가이드레일 ③C형</p>
                    </div>
                  </div>
                </div>

                {/* 측면형 도면 */}
                <div className="flex-1">
                  <p className="text-xs font-semibold mb-1 text-center">측면형 (120-120)</p>
                  <p className="text-xs text-center text-red-500 mb-2">하부BASE (130-130)</p>
                  <div className="border border-gray-300 p-2 h-32 flex items-center justify-center bg-gray-50">
                    <div className="text-center text-gray-500">
                      <p className="text-xs">[KSS02]</p>
                      <p className="text-xs">①②마감재 ③④가이드레일 ⑤C형</p>
                    </div>
                  </div>
                </div>
              </div>
            </div>

            {/* 페이지 표시 */}
            <div className="text-center text-gray-400 text-lg font-bold mt-4">
              1 페이지
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

// 입고증 다이얼로그
export const InboundSlipDialog = ({ inbound, onClose }) => {
  if (!inbound) return null;

  const today = new Date().toISOString().split('T')[0];
  const year = new Date().getFullYear();
  const month = String(new Date().getMonth() + 1).padStart(2, '0');
  const day = String(new Date().getDate()).padStart(2, '0');

  return (
    <div className="fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4">
      <div className="bg-white rounded-xl shadow-2xl w-full max-w-4xl max-h-[90vh] overflow-hidden flex flex-col">
        {/* 헤더 */}
        <div className="flex items-center justify-between p-4 border-b bg-gray-50">
          <div className="flex items-center gap-2">
            <Package className="w-5 h-5 text-green-600" />
            <h2 className="text-lg font-bold text-gray-900">입고증</h2>
          </div>
          <div className="flex items-center gap-2">
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Printer className="w-4 h-4" />
            </button>
            <button className="p-2 hover:bg-gray-200 rounded-lg text-gray-600">
              <Download className="w-4 h-4" />
            </button>
            <button onClick={onClose} className="p-2 hover:bg-gray-200 rounded-lg">
              <X className="w-5 h-5" />
            </button>
          </div>
        </div>

        {/* 입고증 내용 */}
        <div className="flex-1 overflow-y-auto p-6">
          <div className="max-w-3xl mx-auto bg-white border rounded-lg p-8">
            {/* 문서 제목 */}
            <div className="text-center mb-6">
              <h1 className="text-3xl font-bold text-gray-900 mb-2">입 고 증</h1>
              <p className="text-sm text-gray-500">RECEIVING SLIP</p>
            </div>

            {/* 입고 기본정보 */}
            <div className="grid grid-cols-2 gap-6 mb-6">
              <div className="border rounded-lg p-4">
                <h3 className="text-sm font-medium text-gray-500 mb-3 border-b pb-2">입고 정보</h3>
                <div className="space-y-2 text-sm">
                  <div className="flex">
                    <span className="w-24 text-gray-500">입고번호</span>
                    <span className="font-mono font-bold">{inbound.inboundNo || inbound.poNo}</span>
                  </div>
                  <div className="flex">
                    <span className="w-24 text-gray-500">입고일자</span>
                    <span className="font-medium">{inbound.receivedDate || today}</span>
                  </div>
                  <div className="flex">
                    <span className="w-24 text-gray-500">발주번호</span>
                    <span className="font-mono">{inbound.poNo}</span>
                  </div>
                  <div className="flex">
                    <span className="w-24 text-gray-500">입고LOT</span>
                    <span className="font-mono text-blue-600">{inbound.incomingLot || '-'}</span>
                  </div>
                </div>
              </div>

              <div className="border rounded-lg p-4">
                <h3 className="text-sm font-medium text-gray-500 mb-3 border-b pb-2">공급업체 정보</h3>
                <div className="space-y-2 text-sm">
                  <div className="flex">
                    <span className="w-24 text-gray-500">업체명</span>
                    <span className="font-medium">{inbound.vendor}</span>
                  </div>
                  <div className="flex">
                    <span className="w-24 text-gray-500">공급업체LOT</span>
                    <span className="font-mono">{inbound.supplierLot || '-'}</span>
                  </div>
                  <div className="flex">
                    <span className="w-24 text-gray-500">담당자</span>
                    <span>{inbound.vendorContact || '-'}</span>
                  </div>
                  <div className="flex">
                    <span className="w-24 text-gray-500">입고위치</span>
                    <span className="font-medium">{inbound.location || '-'}</span>
                  </div>
                </div>
              </div>
            </div>

            {/* 입고 품목 상세 */}
            <div className="mb-6">
              <h3 className="text-sm font-medium text-gray-700 mb-3">입고 품목 상세</h3>
              <table className="w-full border text-sm">
                <thead className="bg-gray-50">
                  <tr>
                    <th className="border px-3 py-2 text-center">No</th>
                    <th className="border px-3 py-2 text-center">품목코드</th>
                    <th className="border px-3 py-2 text-left">품목명</th>
                    <th className="border px-3 py-2 text-center">규격</th>
                    <th className="border px-3 py-2 text-right">발주수량</th>
                    <th className="border px-3 py-2 text-right">입고수량</th>
                    <th className="border px-3 py-2 text-center">단위</th>
                    <th className="border px-3 py-2 text-left">비고</th>
                  </tr>
                </thead>
                <tbody>
                  {inbound.items ? (
                    inbound.items.map((item, idx) => (
                      <tr key={idx}>
                        <td className="border px-3 py-2 text-center">{idx + 1}</td>
                        <td className="border px-3 py-2 text-center font-mono">{item.code}</td>
                        <td className="border px-3 py-2">{item.name}</td>
                        <td className="border px-3 py-2 text-center">{item.spec || '-'}</td>
                        <td className="border px-3 py-2 text-right">{item.orderQty || item.qty}</td>
                        <td className="border px-3 py-2 text-right font-medium">{item.receivedQty || item.qty}</td>
                        <td className="border px-3 py-2 text-center">{item.unit}</td>
                        <td className="border px-3 py-2 text-xs">{item.note || '-'}</td>
                      </tr>
                    ))
                  ) : (
                    <tr>
                      <td className="border px-3 py-2 text-center">1</td>
                      <td className="border px-3 py-2 text-center font-mono">{inbound.materialCode}</td>
                      <td className="border px-3 py-2">{inbound.materialName}</td>
                      <td className="border px-3 py-2 text-center">{inbound.spec || '-'}</td>
                      <td className="border px-3 py-2 text-right">{inbound.requestQty}</td>
                      <td className="border px-3 py-2 text-right font-medium">{inbound.receivedQty}</td>
                      <td className="border px-3 py-2 text-center">{inbound.unit}</td>
                      <td className="border px-3 py-2 text-xs">{inbound.note || '-'}</td>
                    </tr>
                  )}
                </tbody>
              </table>
            </div>

            {/* 검사 정보 */}
            <div className="mb-6 p-4 bg-yellow-50 border border-yellow-200 rounded-lg">
              <div className="flex items-center gap-2 mb-2">
                <ClipboardList className="w-4 h-4 text-yellow-600" />
                <h3 className="text-sm font-medium text-gray-700">수입검사 안내</h3>
              </div>
              <p className="text-xs text-gray-600">
                본 입고건에 대한 <span className="font-bold text-yellow-700">수입검사(IQC)</span>가 필요합니다.
                <br />
                품질관리 &gt; 수입검사(IQC) 메뉴에서 검사를 진행해주세요.
              </p>
            </div>

            {/* 비고 */}
            {inbound.note && (
              <div className="mb-6">
                <h3 className="text-sm font-medium text-gray-700 mb-2">비고</h3>
                <div className="border rounded-lg p-3 bg-gray-50">
                  <p className="text-sm text-gray-600 whitespace-pre-wrap">{inbound.note}</p>
                </div>
              </div>
            )}

            {/* 서명 영역 */}
            <div className="grid grid-cols-3 gap-4 mb-6">
              <div className="border rounded-lg p-4 text-center">
                <p className="text-xs text-gray-500 mb-6">입고담당</p>
                <div className="border-t pt-2 h-12"></div>
                <p className="text-xs text-gray-400 mt-1">(인)</p>
              </div>
              <div className="border rounded-lg p-4 text-center">
                <p className="text-xs text-gray-500 mb-6">품질검사</p>
                <div className="border-t pt-2 h-12"></div>
                <p className="text-xs text-gray-400 mt-1">(인)</p>
              </div>
              <div className="border rounded-lg p-4 text-center">
                <p className="text-xs text-gray-500 mb-6">창고담당</p>
                <div className="border-t pt-2 h-12"></div>
                <p className="text-xs text-gray-400 mt-1">(인)</p>
              </div>
            </div>

            {/* 발행정보 */}
            <div className="text-right text-xs text-gray-500 border-t pt-4">
              <p>발행일: {year}년 {month}월 {day}일</p>
              <p className="mt-1">(주) 코드빌더스</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

export default { QuoteSheetDialog, CalculationSheetDialog, PurchaseOrderDialog, DeliveryConfirmDialog, InboundSlipDialog };
