<?php
declare(strict_types=1);require __DIR__.'/_bootstrap.php';
if(request_is_post()&&isset($_POST['toggle'])){verify_csrf();$id=(int)$_POST['toggle'];db()->prepare('UPDATE services SET is_active=1-is_active,updated_at=NOW() WHERE id=?')->execute([$id]);audit_log('toggle','services',$id);flash('success','Hizmet durumu değiştirildi.');redirect('/admin/services.php');}
$services=db()->query('SELECT s.*,(SELECT COUNT(*) FROM service_durations d WHERE d.service_id=s.id AND d.is_active=1) duration_count FROM services s ORDER BY s.sort_order,s.id')->fetchAll();
admin_header('Hizmetler');?>
<div class="panel"><div class="panel-head"><h2>Wellness hizmetleri</h2><a class="button" href="<?=url('/admin/service-edit.php')?>">Yeni Hizmet</a></div><div class="table-wrap"><table><thead><tr><th>Sıra</th><th>Hizmet</th><th>Kategori</th><th>Süre</th><th>Durum</th><th></th></tr></thead><tbody><?php foreach($services as $s):?><tr><td><?=$s['sort_order']?></td><td><b><?=e($s['name'])?></b><br><span class="muted">/hizmet/<?=e($s['slug'])?></span></td><td><?=e($s['category'])?></td><td><?=$s['duration_count']?> seçenek</td><td><?=admin_status($s['is_active']?'active':'inactive')?></td><td><div class="actions"><a class="button small secondary" href="<?=url('/admin/service-edit.php?id='.$s['id'])?>">Düzenle</a><form method="post"><?=csrf_field()?><button class="button small" name="toggle" value="<?=$s['id']?>" type="submit"><?=$s['is_active']?'Kapat':'Aç'?></button></form></div></td></tr><?php endforeach;?></tbody></table></div></div>
<?php admin_footer();?>
