<div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="fw-bold mb-0"><i class="fas fa-clipboard-check me-2 text-primary"></i>Work Orders (read-only)</h5>
    <a href="<?= url('/ClientPortal') ?>" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-left me-1"></i>Portal</a>
</div>

<form method="get" action="<?= url('/ClientPortal/workOrders') ?>" class="rs-card p-2 mb-3">
    <div class="row g-2 align-items-end">
        <div class="col-md-3"><select name="priority" class="form-select form-select-sm"><option value="">Any priority</option><?php foreach (['low','medium','high','urgent'] as $p): ?><option value="<?= $p ?>" <?= ($filters['priority'] ?? '') === $p ? 'selected' : '' ?>><?= $p ?></option><?php endforeach; ?></select></div>
        <div class="col-md-3"><select name="status" class="form-select form-select-sm"><option value="">Any status</option><?php foreach (['draft','assigned','in_progress','on_hold','completed','cancelled'] as $s): ?><option value="<?= $s ?>" <?= ($filters['status'] ?? '') === $s ? 'selected' : '' ?>><?= $s ?></option><?php endforeach; ?></select></div>
        <div class="col-md-2"><button type="submit" class="btn btn-sm btn-outline-primary w-100"><i class="fas fa-filter me-1"></i>Filter</button></div>
    </div>
</form>

<div class="rs-card p-3">
<?php if (empty($orders)): ?><p class="text-muted small mb-0">No work orders found.</p><?php else: ?>
    <table class="table table-sm table-hover mb-0">
        <thead><tr><th>Code</th><th>Title</th><th>Type</th><th>Priority</th><th>Status</th><th>Due</th><th class="text-end">Tasks</th></tr></thead>
        <tbody><?php foreach ($orders as $w): ?><tr>
            <td class="small"><?= e($w['code'] ?? '#' . $w['work_order_id']) ?></td>
            <td><?= e($w['title']) ?></td>
            <td class="small"><span class="badge bg-secondary text-uppercase"><?= e($w['wo_type']) ?></span></td>
            <td><span class="badge bg-secondary text-uppercase"><?= e($w['priority']) ?></span></td>
            <td><span class="badge bg-secondary text-uppercase"><?= e($w['status']) ?></span></td>
            <td class="small text-muted"><?= e($w['due_at'] ?? '—') ?></td>
            <td class="text-end"><?= (int) $w['task_done'] ?>/<?= (int) $w['task_total'] ?></td>
        </tr><?php endforeach; ?></tbody>
    </table>
<?php endif; ?>
</div>
