import{a as g}from"./storage-leases-DIh1SO1g.js";import{c0 as h}from"./bootstrap-Bqxdt4iG.js";const b=Object.fromEntries(g.map(e=>[e.value,e.label])),a=e=>e?new Date(e).toLocaleDateString("en-GB",{day:"2-digit",month:"2-digit",year:"numeric"}):"-",o=e=>e==null?"-":String(e).replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;"),f=e=>{var i;const{lease:t,periods:r,locationCodes:n}=e,d=a((i=new Date().toISOString().split("T")[0])!=null?i:""),c=r.map(s=>{var l;const p=(l=b[s.action])!=null?l:s.action;return`
        <tr>
          <td class="center">${o(p)}</td>
          <td class="center">${a(s.startDate)}</td>
          <td class="center">${a(s.endDate)}</td>
          <td class="right">${s.duration} Days</td>
          <td class="center">${s.insured?"Yes":"No"}</td>
          <td class="right">${s.insured&&s.sumInsured>0?`RM ${s.sumInsured.toFixed(2)}`:"-"}</td>
          <td>${o(s.remarks)||"-"}</td>
        </tr>
      `}).join(""),m=r.some(s=>s.insured);return`
    <!-- Header -->
    <div class="header">
      <div class="logo">
        <span class="td-logo">TD</span>
        <span class="warehouse-text">WAREHOUSE</span>
      </div>
      <div class="warehouse-code">${o(t.warehouseCode)}</div>
    </div>

    <h2 class="title">Storage Lease Agreement</h2>

    <div class="info-row">
      <div><strong>Client:</strong> ${o(t.customerName)}</div>
      <div><strong>Date:</strong> ${d}</div>
    </div>
    <div class="info-row">
      <div><strong>Lease No:</strong> ${o(t.code)}</div>
      <div><strong>Status:</strong> ${o(t.status.toUpperCase())}</div>
    </div>

    <!-- Lease Info Table -->
    <table>
      <tbody>
        <tr>
          <td class="label-cell" style="width:25%">Warehouse</td>
          <td style="width:25%">${o(t.warehouseCode)}${t.warehouseName?` - ${o(t.warehouseName)}`:""}</td>
          <td class="label-cell" style="width:25%">Assigned Storage</td>
          <td style="width:25%">${n.length>0?o(n.join(", ")):"-"}</td>
        </tr>
        <tr>
          <td class="label-cell">Salesman</td>
          <td>${o(t.salesmanName)}</td>
          <td class="label-cell">Overall Period</td>
          <td>${a(t.startDate)} — ${a(t.endDate)}</td>
        </tr>
      </tbody>
    </table>

    <!-- Lease Terms -->
    <h3 class="section-title">Lease Terms</h3>
    <table>
      <thead>
        <tr>
          <th class="center">Action</th>
          <th class="center">Start Date</th>
          <th class="center">End Date</th>
          <th class="center">Duration</th>
          <th class="center">Insured</th>
          <th class="center">Sum Insured</th>
          <th class="center">Remarks</th>
        </tr>
      </thead>
      <tbody>
        ${c||'<tr><td colspan="7" class="center">No terms</td></tr>'}
      </tbody>
    </table>

    <!-- Terms & Conditions -->
    <div class="terms">
      <strong>Terms &amp; Conditions</strong>
      <ol>
        <li>The Lessor agrees to lease the above storage area(s) to the Lessee for the periods stated.</li>
        <li>The Lessee shall use the storage area solely for warehousing purposes and shall not store any hazardous, illegal, or prohibited materials.</li>
        <li>Rental charges shall be as per the agreed costing sheet and are payable monthly in advance.</li>
        <li>The Lessee shall maintain the storage area in good condition and shall be responsible for any damage beyond normal wear and tear.</li>
        <li>${m?"Insured periods are covered by the insurance cover noted. The Lessee shall maintain valid insurance for those periods.":"The stored goods are NOT covered by insurance. The Lessee bears all risk of loss or damage."}</li>
        <li>Either party may terminate this agreement with 30 days written notice.</li>
        <li>Upon termination, the Lessee shall remove all goods and return the storage area in its original condition.</li>
      </ol>
    </div>

    <!-- Sign-off Section -->
    <table class="sign-off-table">
      <tr>
        <td class="sign-cell">
          <strong>Lessor (Company)</strong>
          <div class="sign-content"></div>
          <div class="date-line"><strong>Date :</strong></div>
        </td>
        <td class="sign-cell">
          <strong>Lessee (Client)</strong>
          <div class="sign-content"></div>
          <div class="date-line"><strong>Date :</strong></div>
        </td>
      </tr>
    </table>
  `},u=()=>`
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  body {
    font-family: Arial, sans-serif;
    font-size: 9pt;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    padding: 10mm;
  }

  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 3mm;
    border-bottom: 1px solid #333;
    margin-bottom: 3mm;
  }

  .logo {
    display: flex;
    align-items: center;
    gap: 2mm;
  }

  .td-logo {
    font-size: 14pt;
    font-weight: bold;
    color: #000;
    background: #f0f0f0;
    padding: 1mm 2mm;
    border: 2px solid #333;
  }

  .warehouse-text {
    font-size: 10pt;
    font-weight: bold;
    letter-spacing: 1px;
  }

  .warehouse-code {
    font-size: 10pt;
    font-weight: bold;
    color: #333;
  }

  .title {
    text-align: center;
    font-size: 14pt;
    margin: 4mm 0;
  }

  .section-title {
    font-size: 10pt;
    margin: 4mm 0 2mm;
    text-transform: uppercase;
    letter-spacing: 1px;
  }

  .info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2mm;
    font-size: 10pt;
  }

  table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 4mm;
  }

  th, td {
    border: 1px solid #333;
    padding: 2mm 3mm;
    font-size: 8pt;
  }

  th {
    background: #f0f0f0;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 7pt;
  }

  .center { text-align: center; }
  .right { text-align: right; }

  .label-cell {
    background: #f9f9f9;
    font-weight: bold;
  }

  .terms {
    margin: 4mm 0;
    font-size: 8pt;
  }

  .terms strong {
    display: block;
    margin-bottom: 2mm;
    font-size: 9pt;
    text-transform: uppercase;
  }

  .terms ol {
    padding-left: 5mm;
    line-height: 1.8;
  }

  .sign-off-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6mm;
  }

  .sign-off-table td {
    border: 1px solid #333;
    padding: 3mm 4mm;
    vertical-align: top;
    font-size: 9pt;
    width: 50%;
  }

  .sign-content {
    min-height: 20mm;
  }

  .date-line {
    margin-top: 3mm;
    padding-top: 2mm;
  }

  body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  .content-wrapper {
    flex: 1;
  }

  .footer {
    text-align: center;
    font-size: 8pt;
    color: #666;
    padding: 2mm 0;
    border-top: 1px solid #999;
  }

  @media print {
    .no-print {
      display: none !important;
    }
  }
`,y=e=>{const t=f(e),r=`
    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title>Storage Lease Agreement - ${o(e.lease.code)}</title>
        <style>
          ${u()}
          .preview-controls {
            position: fixed;
            top: 10px;
            right: 10px;
            z-index: 1000;
            display: flex;
            gap: 10px;
          }
          .preview-btn {
            padding: 10px 20px;
            font-size: 14px;
            cursor: pointer;
            border: none;
            border-radius: 4px;
          }
          .print-btn {
            background: #1890ff;
            color: white;
          }
          .print-btn:hover {
            background: #40a9ff;
          }
          .close-btn {
            background: #f5f5f5;
            color: #333;
          }
          .close-btn:hover {
            background: #e8e8e8;
          }
        </style>
      </head>
      <body>
        <div class="preview-controls no-print">
          <button class="preview-btn print-btn" onclick="window.print()">Print</button>
          <button class="preview-btn close-btn" onclick="window.close()">Close</button>
        </div>
        <div class="content-wrapper">
          ${t}
        </div>
        <div class="footer">www.tdexpress.co</div>
      </body>
    </html>
  `,n=window.open("","_blank","width=900,height=700");return n?(n.document.write(r),n.document.close(),n):(h.warning("Please allow pop-ups to print"),null)};export{y as p};
