<?php $e=static fn($v)=>htmlspecialchars((string)$v,ENT_QUOTES,'UTF-8'); $isEdit=is_array($service); $v=static function($key,$default='') use ($form,$service){return $form[$key]??($service[$key]??$default);}; ?>
<section class="page-header"><div><p class="eyebrow">Billing · Service catalogue</p><h1><?= $isEdit?'Edit Service':'New Service' ?></h1><p><?= $e($pageDescription??'') ?></p></div><a class="btn btn-secondary" href="/crm/public/services">Back to Services</a></section>
<?php if($message): ?><div class="alert alert-success"><?= $e($message) ?></div><?php endif; ?><?php if($error): ?><div class="alert alert-error"><?= $e($error) ?></div><?php endif; ?>
<section class="card"><form method="post" action="<?= $isEdit?'/crm/public/services/'.(int)$service['id'].'/edit':'/crm/public/services/create' ?>" class="form-grid"><input type="hidden" name="_csrf" value="<?= $e($csrf) ?>"><label class="form-field"><span>Service name *</span><input required maxlength="190" name="name" value="<?= $e($v('name')) ?>"></label><label class="form-field"><span>Price (KSh) *</span><input required inputmode="decimal" name="price" value="<?= $e($v('price','0.00')) ?>"></label><label class="form-field form-field-full"><span>Description</span><textarea name="description" rows="5"><?= $e($v('description')) ?></textarea></label><label class="form-field"><span>Status</span><select name="status"><option value="active" <?= $v('status','active')==='active'?'selected':'' ?>>Active</option><option value="inactive" <?= $v('status','active')==='inactive'?'selected':'' ?>>Inactive</option></select></label><div class="form-actions form-field-full"><button class="btn btn-primary" type="submit"><?= $isEdit?'Save Changes':'Create Service' ?></button><a class="btn btn-secondary" href="/crm/public/services">Cancel</a></div></form><?php if($isEdit): ?><form method="post" action="/crm/public/services/<?= (int)$service['id'] ?>/delete" onsubmit="return confirm('Delete this service? If it has been used in sessions, it cannot be deleted.');" style="margin-top:1rem"><input type="hidden" name="_csrf" value="<?= $e($csrf) ?>"><button class="btn btn-danger" type="submit">Delete Service</button></form><?php endif; ?></section>
