<?php $this->start('body');
    $scrub    = $this->data['scrub'];
    $prj      = $this->data['project'] ?? [];
    $po       = $this->data['client_po'] ?? [];
    $lines    = $this->data['lines']   ?? [];
    $pillars  = $this->data['pillars'] ?? [];
    $canEdit  = !empty($this->data['can_edit']);

    // Warm/faded palette per pillar (matches rsflow.dspera pattern)
    $pillarChip = [
        'PRELIMINARIES' => ['#EDE7DC', '#5B4F3C'],
        'MANPOWER'      => ['#E4DEF0', '#4A3D6B'],
        'MATERIALS'     => ['#E1EBDF', '#3D5B44'],
        'EQUIPMENT'     => ['#F0E1D9', '#6B3F2A'],
        'TOOLS'         => ['#EAE7DA', '#5B5738'],
        'SUBCONTRACTS'  => ['#DDE4E9', '#3D4E5B'],
        'OVERHEADS'     => ['#F1DDDD', '#6B3F3F'],
    ];
    $pillarIcon = [
        'PRELIMINARIES' => 'fas fa-tools',
        'MANPOWER'      => 'fas fa-users',
        'MATERIALS'     => 'fas fa-boxes',
        'EQUIPMENT'     => 'fas fa-truck-monster',
        'TOOLS'         => 'fas fa-hammer',
        'SUBCONTRACTS'  => 'fas fa-handshake',
        'OVERHEADS'     => 'fas fa-shield-alt',
    ];
    $statusPill = [
        'DRAFT'     => ['#f59e0b', 'Draft'],
        'COMPLETE'  => ['#22c55e', 'Complete'],
        'CANCELLED' => ['#dc2626', 'Cancelled'],
    ];
    $sp = $statusPill[$scrub['status']] ?? ['#94a3b8', $scrub['status']];
?>

<div class="d-flex align-items-center justify-content-between mb-3">
    <div>
        <h5 class="mb-0" style="font-weight:600;">
            <i class="fas fa-clipboard-list me-1 text-muted"></i>
            <code style="font-size:.85rem;color:#334155;background:#F1F5F9;padding:2px 6px;border-radius:3px;"><?= htmlspecialchars($scrub['scrub_no']); ?></code>
            · PC Scrub · 7 pillars
            <span class="badge ms-2" style="background:<?= $sp[0]; ?>;color:#fff;text-transform:capitalize;"><?= htmlspecialchars($sp[1]); ?></span>
        </h5>
        <div class="text-muted" style="font-size:.72rem;">
            Project <?= htmlspecialchars($prj['project_no'] ?? '?'); ?> · Client PO <?= htmlspecialchars($po['client_po_no'] ?? '?'); ?>
            · customer <?= htmlspecialchars($prj['project_customer'] ?? '?'); ?>
        </div>
    </div>
    <div>
        <?php if ($canEdit): ?>
            <button type="button" id="btn_complete" class="btn btn-sm btn-primary" style="background:#3D5B44;border-color:#3D5B44;">
                <i class="fas fa-check me-1"></i> Mark scrub complete
            </button>
        <?php endif; ?>
        <a href="<?= PROOT; ?>Projects/view/<?= (int)$scrub['project_id']; ?>" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-left me-1"></i> Project</a>
    </div>
</div>

<!-- ── Pillar totals bar ──────────────────────────────────────────────── -->
<div class="card border-0 shadow-sm mb-3">
    <div class="card-body p-3">
        <div class="row g-2 text-center">
            <?php foreach ($pillars as $p => $meta):
                $ch = $pillarChip[$p]; $ic = $pillarIcon[$p];
                $val = (float)($scrub[$meta['total_col']] ?? 0);
            ?>
                <div class="col-md">
                    <div class="text-muted small" style="text-transform:uppercase;letter-spacing:.4px;font-size:.6rem;">
                        <i class="<?= $ic; ?>" style="color:<?= $ch[1]; ?>;"></i> <?= strtolower(str_replace('_',' ', $p)); ?>
                    </div>
                    <div style="color:#334155;font-weight:700;font-size:.95rem;"><?= number_format($val); ?></div>
                </div>
            <?php endforeach; ?>
            <div class="col-md" style="background:#F1F5F9;border-radius:4px;padding:4px;">
                <div class="text-muted small" style="text-transform:uppercase;letter-spacing:.4px;font-size:.6rem;">Scrub total (COG est.)</div>
                <div style="color:#166534;font-weight:800;font-size:1.05rem;"><?= number_format((float)$scrub['grand_total']); ?></div>
            </div>
            <div class="col-md" style="background:#F1F5F9;border-radius:4px;padding:4px;">
                <div class="text-muted small" style="text-transform:uppercase;letter-spacing:.4px;font-size:.6rem;">Customer PO (sell)</div>
                <div style="color:#3D5B44;font-weight:800;font-size:1.05rem;"><?= number_format((float)($po['subtotal_sell'] ?? 0)); ?></div>
            </div>
        </div>
    </div>
</div>

<?php if (!$canEdit): ?>
<div class="alert py-2 mb-3" style="background:#EAF2E8;border:1px solid #7A9E7E;color:#3D5B44;">
    <i class="fas fa-check-circle me-1"></i>
    Scrub is <strong>COMPLETE</strong> — Procurement can now open RFQs against the materials pillar.
    <?php if (!empty($scrub['completed_by_name'])): ?>Completed by <?= htmlspecialchars($scrub['completed_by_name']); ?> on <?= htmlspecialchars(substr((string)$scrub['completed_on'], 0, 10)); ?>.<?php endif; ?>
</div>
<?php endif; ?>

<!-- ── PILLAR 1 · MATERIALS (seeded from Client PO + PC/Proc estimates) ─ -->
<?php $pillar = 'MATERIALS'; $ch = $pillarChip[$pillar]; ?>
<div class="card border-0 shadow-sm mb-3">
    <div class="card-header bg-white d-flex justify-content-between align-items-center">
        <div>
            <span class="badge me-1" style="background:<?= $ch[0]; ?>;color:<?= $ch[1]; ?>;font-weight:600;text-transform:capitalize;">materials</span>
            <strong>Items · seeded from Client PO · Procurement fills unit_cost</strong>
            <span class="text-muted small ms-1"><?= count($lines['MATERIALS'] ?? []); ?> line<?= count($lines['MATERIALS'] ?? []) === 1 ? '' : 's'; ?></span>
        </div>
    </div>
    <div class="card-body p-0">
        <?php if (empty($lines['MATERIALS'])): ?>
            <div class="p-3 text-muted small">No materials yet.</div>
        <?php else: ?>
        <table class="table table-sm mb-0 align-middle">
            <thead class="table-light">
                <tr>
                    <th style="width:32px;"></th>
                    <th>Item</th>
                    <th style="width:100px;">Brand</th>
                    <th style="width:70px;">Src</th>
                    <th class="text-end" style="width:80px;">Qty</th>
                    <th style="width:60px;">Unit</th>
                    <th style="width:140px;">Unit cost (COG)</th>
                    <th class="text-end" style="width:130px;">Line total</th>
                    <?php if ($canEdit): ?><th style="width:40px;"></th><?php endif; ?>
                </tr>
            </thead>
            <tbody>
            <?php foreach ($lines['MATERIALS'] as $l):
                $srcPill = ['LOCAL'=>['#EAF2E8','#3D5B44','Local'],'IMPORT'=>['#F3E5D9','#6B3F2A','Import'],'ANY'=>['#EDE7DC','#5B4F3C','Any']][$l['source_pref']] ?? ['#e5e7eb','#374151','?'];
                $isSeeded = (int)$l['client_po_item_id'] > 0;
            ?>
            <tr data-line-id="<?= (int)$l['c0d']; ?>">
                <td class="text-muted small"><?= (int)$l['line_no']; ?></td>
                <td class="small">
                    <?= htmlspecialchars($l['description']); ?>
                    <?php if ($isSeeded): ?><i class="fas fa-link ms-1 text-muted" title="Seeded from Client PO item"></i><?php endif; ?>
                </td>
                <td class="small text-muted"><?= htmlspecialchars($l['brand'] ?: '—'); ?></td>
                <td><span class="badge" style="background:<?= $srcPill[0]; ?>;color:<?= $srcPill[1]; ?>;font-size:.65rem;"><?= $srcPill[2]; ?></span></td>
                <td class="text-end small"><?= rtrim(rtrim(number_format((float)$l['qty'], 4), '0'), '.'); ?></td>
                <td class="small text-muted"><?= htmlspecialchars($l['unit']); ?></td>
                <td>
                    <?php if ($canEdit): ?>
                        <input type="number" step="0.01" min="0" class="form-control form-control-sm mat-unit-cost" value="<?= htmlspecialchars((string)$l['unit_cost']); ?>">
                    <?php else: ?>
                        <span class="small"><?= number_format((float)$l['unit_cost']); ?></span>
                    <?php endif; ?>
                </td>
                <td class="text-end"><strong><?= number_format((float)$l['total']); ?></strong></td>
                <?php if ($canEdit): ?>
                <td class="text-end">
                    <?php if (!$isSeeded): // only ad-hoc lines can be removed; seeded lines stay in sync with PO ?>
                        <button class="btn btn-sm btn-outline-secondary btn-line-del" data-pillar="MATERIALS" data-id="<?= (int)$l['c0d']; ?>"><i class="fas fa-times"></i></button>
                    <?php endif; ?>
                </td>
                <?php endif; ?>
            </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
        <?php endif; ?>
    </div>
    <?php if ($canEdit): ?>
    <div class="card-footer bg-white">
        <div class="row g-2 align-items-end">
            <div class="col-md-4">
                <label class="form-label" style="font-size:.78rem;">Ad-hoc material (not on Client PO)</label>
                <input id="mat_desc" class="form-control form-control-sm" placeholder="e.g. packing tape">
            </div>
            <div class="col-md-2"><input id="mat_brand" class="form-control form-control-sm" placeholder="brand"></div>
            <div class="col-md-1">
                <select id="mat_src" class="form-select form-select-sm">
                    <option value="ANY">Any</option><option value="LOCAL">Local</option><option value="IMPORT">Import</option>
                </select>
            </div>
            <div class="col-md-1"><input type="number" step="0.01" id="mat_qty" class="form-control form-control-sm" placeholder="qty"></div>
            <div class="col-md-1"><input id="mat_unit" class="form-control form-control-sm" placeholder="unit"></div>
            <div class="col-md-2"><input type="number" step="0.01" id="mat_cost" class="form-control form-control-sm" placeholder="unit cost"></div>
            <div class="col-md-1 text-end">
                <button type="button" class="btn btn-sm btn-primary btn-pillar-add" data-pillar="MATERIALS" style="background:#3D5B44;border-color:#3D5B44;">
                    <i class="fas fa-plus"></i>
                </button>
            </div>
        </div>
    </div>
    <?php endif; ?>
</div>

<!-- ── PILLAR 2 · MANPOWER ──────────────────────────────────────────── -->
<?php $pillar = 'MANPOWER'; $ch = $pillarChip[$pillar]; ?>
<div class="card border-0 shadow-sm mb-3">
    <div class="card-header bg-white d-flex justify-content-between align-items-center">
        <div>
            <span class="badge me-1" style="background:<?= $ch[0]; ?>;color:<?= $ch[1]; ?>;font-weight:600;text-transform:capitalize;">manpower</span>
            <strong>Roles × persons × days × rate</strong>
            <span class="text-muted small ms-1"><?= count($lines['MANPOWER'] ?? []); ?></span>
        </div>
    </div>
    <?php if (!empty($lines['MANPOWER'])): ?>
    <div class="card-body p-0">
        <table class="table table-sm mb-0 align-middle">
            <thead class="table-light"><tr><th>Role</th><th class="text-end">Persons</th><th class="text-end">Days</th><th class="text-end">Rate</th><th class="text-end">Total</th><?php if ($canEdit): ?><th style="width:40px;"></th><?php endif; ?></tr></thead>
            <tbody>
            <?php foreach ($lines['MANPOWER'] as $l): ?>
            <tr>
                <td class="small"><?= htmlspecialchars($l['role']); ?></td>
                <td class="text-end small"><?= (int)$l['persons']; ?></td>
                <td class="text-end small"><?= (float)$l['days']; ?></td>
                <td class="text-end small"><?= number_format((float)$l['rate']); ?></td>
                <td class="text-end"><strong><?= number_format((float)$l['total']); ?></strong></td>
                <?php if ($canEdit): ?><td class="text-end"><button class="btn btn-sm btn-outline-secondary btn-line-del" data-pillar="MANPOWER" data-id="<?= (int)$l['c0d']; ?>"><i class="fas fa-times"></i></button></td><?php endif; ?>
            </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
    <?php if ($canEdit): ?>
    <div class="card-footer bg-white">
        <div class="row g-2 align-items-end">
            <div class="col-md-4"><input id="mp_role" class="form-control form-control-sm" placeholder="role (loader, driver)"></div>
            <div class="col-md-2"><input type="number" step="1" id="mp_pers" class="form-control form-control-sm" placeholder="persons" value="1"></div>
            <div class="col-md-2"><input type="number" step="0.5" id="mp_days" class="form-control form-control-sm" placeholder="days" value="1"></div>
            <div class="col-md-3"><input type="number" step="0.01" id="mp_rate" class="form-control form-control-sm" placeholder="daily rate"></div>
            <div class="col-md-1 text-end"><button type="button" class="btn btn-sm btn-primary btn-pillar-add" data-pillar="MANPOWER" style="background:#4A3D6B;border-color:#4A3D6B;"><i class="fas fa-plus"></i></button></div>
        </div>
    </div>
    <?php endif; ?>
</div>

<?php $pillar = 'EQUIPMENT'; $ch = $pillarChip[$pillar]; ?>
<div class="card border-0 shadow-sm mb-3">
    <div class="card-header bg-white">
        <span class="badge me-1" style="background:<?= $ch[0]; ?>;color:<?= $ch[1]; ?>;font-weight:600;text-transform:capitalize;">equipment</span>
        <strong>Transport / handling equipment (hours × rate)</strong>
        <span class="text-muted small ms-1"><?= count($lines['EQUIPMENT'] ?? []); ?></span>
    </div>
    <?php if (!empty($lines['EQUIPMENT'])): ?>
    <div class="card-body p-0">
        <table class="table table-sm mb-0 align-middle">
            <thead class="table-light"><tr><th>Description</th><th style="width:80px;">In-house?</th><th class="text-end">Hours</th><th class="text-end">Rate</th><th class="text-end">Total</th><?php if ($canEdit): ?><th style="width:40px;"></th><?php endif; ?></tr></thead>
            <tbody>
            <?php foreach ($lines['EQUIPMENT'] as $l): ?>
            <tr>
                <td class="small"><?= htmlspecialchars($l['description']); ?></td>
                <td><span class="badge <?= (int)$l['in_house_flag']===1 ? 'bg-success' : 'bg-warning text-dark'; ?>"><?= (int)$l['in_house_flag']===1 ? 'Yes' : 'Rented'; ?></span></td>
                <td class="text-end small"><?= (float)$l['hours']; ?></td>
                <td class="text-end small"><?= number_format((float)$l['rate']); ?></td>
                <td class="text-end"><strong><?= number_format((float)$l['total']); ?></strong></td>
                <?php if ($canEdit): ?><td class="text-end"><button class="btn btn-sm btn-outline-secondary btn-line-del" data-pillar="EQUIPMENT" data-id="<?= (int)$l['c0d']; ?>"><i class="fas fa-times"></i></button></td><?php endif; ?>
            </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
    <?php if ($canEdit): ?>
    <div class="card-footer bg-white">
        <div class="row g-2 align-items-end">
            <div class="col-md-4"><input id="eq_desc" class="form-control form-control-sm" placeholder="e.g. Delivery truck"></div>
            <div class="col-md-2">
                <select id="eq_ih" class="form-select form-select-sm">
                    <option value="1">In-house</option><option value="0">Rented</option>
                </select>
            </div>
            <div class="col-md-2"><input type="number" step="0.5" id="eq_hrs" class="form-control form-control-sm" placeholder="hours"></div>
            <div class="col-md-3"><input type="number" step="0.01" id="eq_rate" class="form-control form-control-sm" placeholder="hourly rate"></div>
            <div class="col-md-1 text-end"><button type="button" class="btn btn-sm btn-primary btn-pillar-add" data-pillar="EQUIPMENT" style="background:#6B3F2A;border-color:#6B3F2A;"><i class="fas fa-plus"></i></button></div>
        </div>
    </div>
    <?php endif; ?>
</div>

<?php foreach ([
    'PRELIMINARIES' => ['label' => 'Preliminaries (site setup, permits, insurance)', 'inputs' => [['id'=>'prel_desc','placeholder'=>'description','col'=>7],['id'=>'prel_amt','type'=>'number','placeholder'=>'amount','col'=>3]]],
    'TOOLS'         => ['label' => 'Tools (small consumables for delivery)', 'inputs' => [['id'=>'tool_desc','placeholder'=>'description','col'=>4],['id'=>'tool_qty','type'=>'number','placeholder'=>'qty','col'=>2],['id'=>'tool_unit','placeholder'=>'unit','col'=>2],['id'=>'tool_cost','type'=>'number','placeholder'=>'unit cost','col'=>2]]],
    'SUBCONTRACTS'  => ['label' => 'Subcontracts (lump sum outsourced work)', 'inputs' => [['id'=>'sub_name','placeholder'=>'subcontractor','col'=>4],['id'=>'sub_scope','placeholder'=>'scope','col'=>4],['id'=>'sub_ls','type'=>'number','placeholder'=>'lump sum','col'=>2]]],
    'OVERHEADS'     => ['label' => 'Overheads (HSE, insurance, admin, other)', 'inputs' => [['id'=>'ovh_cat','placeholder'=>'category','col'=>2],['id'=>'ovh_desc','placeholder'=>'description','col'=>5],['id'=>'ovh_amt','type'=>'number','placeholder'=>'amount','col'=>3]]],
] as $pillar => $cfg):
    $ch = $pillarChip[$pillar];
?>
<div class="card border-0 shadow-sm mb-3">
    <div class="card-header bg-white">
        <span class="badge me-1" style="background:<?= $ch[0]; ?>;color:<?= $ch[1]; ?>;font-weight:600;text-transform:capitalize;"><?= strtolower(str_replace('_',' ',$pillar)); ?></span>
        <strong><?= htmlspecialchars($cfg['label']); ?></strong>
        <span class="text-muted small ms-1"><?= count($lines[$pillar] ?? []); ?></span>
    </div>
    <?php if (!empty($lines[$pillar])): ?>
    <div class="card-body p-0">
        <table class="table table-sm mb-0 align-middle">
            <thead class="table-light"><tr><th>Line</th><th class="text-end">Amount / Total</th><?php if ($canEdit): ?><th style="width:40px;"></th><?php endif; ?></tr></thead>
            <tbody>
            <?php foreach ($lines[$pillar] as $l):
                $desc = $pillar === 'SUBCONTRACTS' ? ($l['subcontractor_name'] . ' · ' . $l['scope'])
                     : ($pillar === 'OVERHEADS'    ? ($l['category'] . ' · ' . $l['description'])
                     : $l['description']);
                $amt  = $pillar === 'SUBCONTRACTS' ? (float)$l['lump_sum']
                     : ($pillar === 'TOOLS'         ? (float)$l['total']
                     : (float)$l['amount']);
            ?>
            <tr>
                <td class="small"><?= htmlspecialchars($desc); ?></td>
                <td class="text-end"><strong><?= number_format($amt); ?></strong></td>
                <?php if ($canEdit): ?><td class="text-end"><button class="btn btn-sm btn-outline-secondary btn-line-del" data-pillar="<?= $pillar; ?>" data-id="<?= (int)$l['c0d']; ?>"><i class="fas fa-times"></i></button></td><?php endif; ?>
            </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <?php endif; ?>
    <?php if ($canEdit): ?>
    <div class="card-footer bg-white">
        <div class="row g-2 align-items-end">
            <?php foreach ($cfg['inputs'] as $inp): ?>
                <div class="col-md-<?= (int)$inp['col']; ?>">
                    <input type="<?= $inp['type'] ?? 'text'; ?>" step="0.01" id="<?= htmlspecialchars($inp['id']); ?>" class="form-control form-control-sm" placeholder="<?= htmlspecialchars($inp['placeholder']); ?>">
                </div>
            <?php endforeach; ?>
            <div class="col-md text-end">
                <button type="button" class="btn btn-sm btn-primary btn-pillar-add" data-pillar="<?= $pillar; ?>" style="background:<?= $ch[1]; ?>;border-color:<?= $ch[1]; ?>;"><i class="fas fa-plus"></i></button>
            </div>
        </div>
    </div>
    <?php endif; ?>
</div>
<?php endforeach; ?>

<?php $this->end(); ?>

<?php $this->start('section_js'); ?>
<script>
const SCRUB_ID = <?= (int)$scrub['c0d']; ?>;

$('.mat-unit-cost').on('change', function () {
    var lid = $(this).closest('tr').data('line-id');
    var uc  = parseFloat($(this).val() || '0');
    $.post('<?= PROOT; ?>GoodsScrubPack/setMaterialsUnitCostAj', { scrub_id: SCRUB_ID, line_id: lid, unit_cost: uc }, 'json')
        .done(function (r) { if (r && r.ok) location.reload(); else rsToast('Failed: ' + (r.msg || 'unknown'), 'error'); });
});

$('.btn-line-del').on('click', function () {
    var lid    = $(this).data('id');
    var pillar = $(this).data('pillar');
    $.confirm({ title: 'Remove this line?', content: '', boxWidth: '360px', useBootstrap: false, buttons: {
        confirm: { text: 'Remove', btnClass: 'btn-danger', action: function () {
            $.post('<?= PROOT; ?>GoodsScrubPack/removeLineAj', { scrub_id: SCRUB_ID, pillar: pillar, line_id: lid }, 'json')
                .done(function (r) { if (r && r.ok) location.reload(); else rsToast('Failed: ' + (r.msg || 'unknown'), 'error'); });
        }},
        cancel: { text: 'Cancel' }
    }});
});

$('.btn-pillar-add').on('click', function () {
    var pillar = $(this).data('pillar');
    var payload = { scrub_id: SCRUB_ID, pillar: pillar };
    if (pillar === 'MATERIALS') {
        payload.description = $('#mat_desc').val().trim();
        payload.brand       = $('#mat_brand').val();
        payload.source_pref = $('#mat_src').val();
        payload.qty         = $('#mat_qty').val();
        payload.unit        = $('#mat_unit').val();
        payload.unit_cost   = $('#mat_cost').val();
    } else if (pillar === 'MANPOWER') {
        payload.role = $('#mp_role').val().trim(); payload.persons = $('#mp_pers').val(); payload.days = $('#mp_days').val(); payload.rate = $('#mp_rate').val();
    } else if (pillar === 'EQUIPMENT') {
        payload.description = $('#eq_desc').val().trim(); payload.in_house_flag = $('#eq_ih').val(); payload.hours = $('#eq_hrs').val(); payload.rate = $('#eq_rate').val();
    } else if (pillar === 'PRELIMINARIES') {
        payload.description = $('#prel_desc').val().trim(); payload.amount = $('#prel_amt').val();
    } else if (pillar === 'TOOLS') {
        payload.description = $('#tool_desc').val().trim(); payload.qty = $('#tool_qty').val(); payload.unit = $('#tool_unit').val(); payload.unit_cost = $('#tool_cost').val();
    } else if (pillar === 'SUBCONTRACTS') {
        payload.subcontractor_name = $('#sub_name').val().trim(); payload.scope = $('#sub_scope').val(); payload.lump_sum = $('#sub_ls').val();
    } else if (pillar === 'OVERHEADS') {
        payload.category = $('#ovh_cat').val(); payload.description = $('#ovh_desc').val().trim(); payload.amount = $('#ovh_amt').val();
    }
    $.post('<?= PROOT; ?>GoodsScrubPack/addLineAj', payload, 'json')
        .done(function (r) { if (r && r.ok) location.reload(); else rsToast('Failed: ' + (r.msg || 'unknown'), 'error'); });
});

$('#btn_complete').on('click', function () {
    $.confirm({ title: 'Mark scrub complete?', content: '<p style="font-size:.85rem;color:#5B4F3C;">All MATERIALS lines must have unit_cost > 0. Procurement can start RFQs once complete.</p>', boxWidth: '440px', useBootstrap: false, buttons: {
        confirm: { text: 'Mark complete', btnClass: 'btn-success', action: function () {
            $.post('<?= PROOT; ?>GoodsScrubPack/markCompleteAj', { scrub_id: SCRUB_ID }, 'json')
                .done(function (r) { if (r && r.ok) { rsToast('Complete.', 'success'); location.reload(); } else rsToast('Failed: ' + (r.msg || 'unknown'), 'error'); });
        }},
        cancel: { text: 'Cancel' }
    }});
});
</script>
<?php $this->end(); ?>
