<?php $e=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8'); ?>
<section class="page-header"><div><p class="eyebrow">Billing · Service catalogue</p><h1>Services</h1><p><?= $e($pageDescription??'') ?></p></div><a class="btn btn-primary" href="/crm/public/services/create">+ New Service</a></section>
<?php if($message=\App\Core\Session::pull('service_message')): ?><div class="alert alert-success"><?= $e($message) ?></div><?php endif; ?>
<?php if($error=\App\Core\Session::pull('service_error')): ?><div class="alert alert-error"><?= $e($error) ?></div><?php endif; ?>
<section class="card"><form method="get" class="filters"><label class="form-field"><span>Search</span><input type="search" name="search" value="<?= $e($filters['search']??'') ?>" placeholder="Service name or description"></label><label class="form-field"><span>Status</span><select name="status"><option value="">All statuses</option><option value="active" <?= ($filters['status']??'')==='active'?'selected':'' ?>>Active</option><option value="inactive" <?= ($filters['status']??'')==='inactive'?'selected':'' ?>>Inactive</option></select></label><div class="form-actions"><button class="btn btn-secondary" type="submit">Filter</button><a class="btn btn-secondary" href="/crm/public/services">Reset</a></div></form></section>
<section class="card"><div class="card-header"><div><h2>Service catalogue</h2><p><?= (int)$services['total'] ?> service(s)</p></div></div><?php if(empty($services['items'])): ?><div class="empty-state"><h3>No services found</h3><p>Create your first therapy service.</p></div><?php else: ?><div class="table-wrap"><table class="data-table"><thead><tr><th>Service</th><th>Description</th><th>Price</th><th>Status</th><th>Updated</th><th>Actions</th></tr></thead><tbody><?php foreach($services['items'] as $s): ?><tr><td><strong><?= $e($s['name']) ?></strong></td><td><?= $e($s['description']??'—') ?></td><td><strong>KSh <?= number_format((float)$s['price'],2) ?></strong></td><td><span class="badge badge-muted"><?= $e(ucfirst($s['status'])) ?></span></td><td><?= $e($s['updated_at']??'') ?></td><td><a class="btn btn-small btn-secondary" href="/crm/public/services/<?= (int)$s['id'] ?>/edit">Edit</a></td></tr><?php endforeach; ?></tbody></table></div><?php if(($services['pages']??1)>1): ?><div class="pagination"><?php for($i=1;$i<=$services['pages'];$i++): ?><a class="<?= $i===$services['page']?'active':'' ?>" href="?page=<?= $i ?>&search=<?= urlencode((string)($filters['search']??'')) ?>&status=<?= urlencode((string)($filters['status']??'')) ?>"><?= $i ?></a><?php endfor; ?></div><?php endif; ?><?php endif; ?></section>
