<?php
declare(strict_types=1);require __DIR__.'/_bootstrap.php';
$user=admin_user();$isEditor=($user['role']??'')==='editor';
$counts=[];
$counts['services']=(int)db()->query("SELECT COUNT(*) FROM services WHERE is_active=1")->fetchColumn();
$counts['posts']=(int)db()->query("SELECT COUNT(*) FROM posts WHERE status='published'")->fetchColumn();
$counts['drafts']=(int)db()->query("SELECT COUNT(*) FROM posts WHERE status='draft'")->fetchColumn();
$counts['pages']=(int)db()->query("SELECT COUNT(*) FROM pages WHERE status='published'")->fetchColumn();
$upcoming=[];
if(!$isEditor){
 $counts['today']=(int)db()->query("SELECT COUNT(*) FROM reservations WHERE reservation_date=CURDATE() AND status NOT IN ('cancelled','rejected')")->fetchColumn();
 $counts['pending']=(int)db()->query("SELECT COUNT(*) FROM reservations WHERE status='pending'")->fetchColumn();
 $upcoming=db()->query("SELECT r.*,s.name service_name FROM reservations r JOIN services s ON s.id=r.service_id WHERE r.reservation_date>=CURDATE() AND r.status NOT IN ('cancelled','rejected') ORDER BY r.reservation_date,r.start_time LIMIT 12")->fetchAll();
}
admin_header('Genel Bakış');?>
<?php if($isEditor):?>
<div class="cards"><div class="stat"><span>Aktif Hizmet</span><b><?=$counts['services']?></b></div><div class="stat"><span>Yayındaki Makale</span><b><?=$counts['posts']?></b></div><div class="stat"><span>Makale Taslağı</span><b><?=$counts['drafts']?></b></div><div class="stat"><span>Kurumsal Sayfa</span><b><?=$counts['pages']?></b></div></div>
<div class="panel"><div class="panel-head"><h2>İçerik işlemleri</h2></div><div class="panel-body actions"><a class="button" href="<?=url('/admin/content-edit.php?type=post')?>">Yeni Makale</a><a class="button secondary" href="<?=url('/admin/services.php')?>">Hizmetleri Yönet</a><a class="button secondary" href="<?=url('/admin/automation.php')?>">Yapay Zekâ Merkezi</a></div></div>
<?php else:?>
<div class="cards"><div class="stat"><span>Bugünkü Rezervasyon</span><b><?=$counts['today']?></b></div><div class="stat"><span>Onay Bekleyen</span><b><?=$counts['pending']?></b></div><div class="stat"><span>Aktif Hizmet</span><b><?=$counts['services']?></b></div><div class="stat"><span>Yayındaki Makale</span><b><?=$counts['posts']?></b></div></div>
<div class="panel"><div class="panel-head"><h2>Yaklaşan rezervasyonlar</h2><a class="button" href="<?=url('/admin/reservations.php')?>">Tümünü Gör</a></div><div class="panel-body calendar-list"><?php if(!$upcoming):?><p class="muted">Yaklaşan rezervasyon bulunmuyor.</p><?php endif;?><?php foreach($upcoming as $r):?><a class="reservation-mini" href="<?=url('/admin/reservations.php?view='.$r['id'])?>"><time><?=e(date('d.m',strtotime($r['reservation_date'])))?><br><?=e(substr($r['start_time'],0,5))?></time><div><b><?=e($r['guest_name'])?></b><div class="muted"><?=e($r['service_name'])?> · <?=e($r['reservation_code'])?></div></div><?=admin_status($r['status'])?></a><?php endforeach;?></div></div>
<?php endif;?>
<?php admin_footer();?>
