<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Dispense Material Details</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px 30px;
            color: #333;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 2px solid #c91761;
            padding-bottom: 12px;
            margin-bottom: 20px;
        }

        .header .title-section h1 {
            margin: 0;
            font-size: 20px;
            color: #c91761;
            text-transform: uppercase;
        }

        .header .title-section p {
            margin: 4px 0 0 0;
            font-size: 11px;
            color: #666;
        }

        .header .logo img {
            height: 45px;
        }

        .info-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 24px;
            font-size: 12px;
        }

        .info-table td {
            padding: 8px 10px;
            border: 1px solid #ccc;
        }

        .info-table .label {
            font-weight: bold;
            background-color: #fff3f8;
            color: #c91761;
            width: 18%;
            white-space: nowrap;
        }

        .info-table .value {
            width: 32%;
        }

        .section-title {
            font-size: 14px;
            font-weight: bold;
            color: #c91761;
            margin: 20px 0 10px 0;
            padding-bottom: 4px;
            border-bottom: 1px solid #eee;
        }

        .material-card {
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-bottom: 16px;
            page-break-inside: avoid;
        }

        .material-card-header {
            background-color: #fff3f8;
            padding: 8px 12px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-bottom: 1px solid #ddd;
        }

        .material-card-header .material-name {
            font-weight: bold;
            font-size: 13px;
            color: #333;
        }

        .material-card-header .material-code {
            font-weight: bold;
            font-size: 12px;
            color: #c91761;
        }

        .extra-granular-badge {
            display: inline-block;
            background-color: #90ee90;
            color: #fff;
            border-radius: 4px;
            padding: 1px 6px;
            font-size: 10px;
            margin-right: 6px;
        }

        .material-card-body {
            padding: 10px 12px;
            font-size: 12px;
        }

        .std-qty {
            margin-bottom: 8px;
            font-size: 12px;
        }

        table.data-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 11px;
            margin-bottom: 10px;
        }

        table.data-table th {
            background-color: #fff3f8;
            color: #c91761;
            font-weight: bold;
            padding: 6px 6px;
            border: 1px solid #ddd;
            text-align: center;
        }

        table.data-table td {
            padding: 5px 6px;
            border: 1px solid #ddd;
            text-align: center;
        }

        table.data-table tbody tr:nth-child(even) {
            background-color: #fafafa;
        }

        .qc-value {
            color: #1890ff;
            font-weight: bold;
        }

        .lots-section {
            margin-top: 8px;
            border-top: 1px solid #eee;
            padding-top: 6px;
        }

        .lots-section b {
            font-size: 12px;
        }

        .lot-row {
            font-size: 11px;
            padding: 2px 0;
        }

        tr {
            page-break-inside: avoid;
        }

        @page {
            margin-top: 20px;
            margin-bottom: 20px;
        }
    </style>
</head>

<body>
    <div class="header">
        <div class="title-section">
            <h1>Dispense Material Details</h1>
            <p>Assay Calculation Summary</p>
        </div>
        <div class="logo">
            <img src="{{logo}}" alt="Company Logo" />
        </div>
    </div>

    <table class="info-table">

          <tr>
        <td class="label">Product Batch #</td>
        <td class="value">{{product_batch_number}}</td>

        {{#if campaign_batch_seq}}
        <td class="label">Campaign Batch Sequence</td>
        <td class="value">{{campaign_batch_seq}}</td>
        {{/if}}
    </tr>

    {{#if process_name}}
    <tr>
        <td class="label">Dispense Process</td>
        <td class="value">{{process_name}}</td>

        <td class="label">Sub Process</td>
        <td class="value">{{#if sub_process_name}}{{sub_process_name}}{{else}}-{{/if}}</td>
    </tr>
    {{/if}}

    </table>

    {{#each materials}}
    <div class="material-card">
        <div class="material-card-header">
            <span class="material-name">
                {{#if this.is_extra}}<span class="extra-granular-badge">Extra-granular</span>{{/if}}
                {{this.material_name}}
            </span>
            <span class="material-code">{{this.material_code}}</span>
        </div>
        <div class="material-card-body">
            <div class="std-qty"><b>Standard Qty:</b> {{this.required_qty}}</div>

            <div class="section-title" style="margin-top:4px;">Available Batches</div>
            <table class="data-table">
                <thead>
                    <tr>
                        <th>Inhouse Batch #</th>
                        <th>BIN #</th>
                        <th>Available Qty</th>
                        {{#if this.has_assay}}
                        <th>Assay</th>
                        <th>LOD / Water Content</th>
                        <th>Solvent (%)</th>
                        {{/if}}
                    </tr>
                </thead>
                <tbody>
                    {{#each this.batches}}
                    <tr>
                        <td>{{this.batch_number}}</td>
                        <td>{{this.bin_location}}</td>
                        <td>{{this.remaining_batch_qty}}</td>
                        {{#if ../has_assay}}
                        <td>{{#if this.assay}}<span class="qc-value">{{this.assay}}</span>{{else}}-{{/if}}</td>
                        <td>{{#if this.lod_water_content}}<span class="qc-value">{{this.lod_water_content}}</span>{{else}}-{{/if}}</td>
                        <td>{{#if this.solvent_percent}}<span class="qc-value">{{this.solvent_percent}}</span>{{else}}-{{/if}}</td>
                        {{/if}}
                    </tr>
                    {{/each}}
                </tbody>
            </table>

            <div class="lots-section">
                <b>Lots / Parts Dispensed:</b>
                {{#each this.dispenseLots}}
                <div class="lot-row">{{this.lot_label}}: <b>{{this.dispensed_qty}}</b></div>
                {{/each}}
            </div>
        </div>
    </div>
    {{/each}}

</body>

</html>
