<?php $PAGE_TITLE='Dashboard'; require __DIR__.'/_layout.php';
$uid=$U['id'];
$stats=[
  'orders'=>$pdo->query("SELECT COUNT(*) c FROM orders WHERE user_id=$uid")->fetch()['c'],
  'today' =>$pdo->query("SELECT COUNT(*) c FROM orders WHERE user_id=$uid AND DATE(created_at)=CURDATE()")->fetch()['c'],
  'recharge_count'=>$pdo->query("SELECT COUNT(*) c FROM recharges WHERE user_id=$uid AND status='approved'")->fetch()['c'],
];
$notice=$pdo->query("SELECT * FROM notices WHERE active=1 ORDER BY id DESC LIMIT 1")->fetch();

// Custom services list (same as user/services.php) — shown inline on dashboard
$dash_services = $pdo->query("SELECT * FROM services
                              WHERE kind='custom' AND status IN ('open','closed')
                              ORDER BY pinned DESC, position, id DESC")->fetchAll();
?>
<style>
.quick-actions{background:linear-gradient(135deg,#6366f1,#8b5cf6);padding:18px;border-radius:14px;color:#fff;box-shadow:0 8px 20px rgba(99,102,241,.25)}
.quick-actions h3{color:#fff;margin:0 0 12px;font-size:17px;display:flex;align-items:center;gap:8px}
.quick-actions .qa-row{display:flex;gap:10px;flex-wrap:wrap}
.quick-actions .qa-btn{flex:1;min-width:130px;padding:12px 14px;background:rgba(255,255,255,.15);color:#fff;border-radius:10px;text-decoration:none;font-weight:600;text-align:center;border:1px solid rgba(255,255,255,.2);transition:all .15s ease;font-size:14px}
.quick-actions .qa-btn:hover{background:rgba(255,255,255,.28);transform:translateY(-1px)}

.dash-services-title{margin:18px 0 12px;font-size:18px;color:#0f172a;font-weight:700;display:flex;align-items:center;gap:8px}
.svc-card{background:#fff;border:1px solid #e2e8f0;border-radius:14px;padding:14px;box-shadow:0 4px 12px rgba(15,23,42,.04);position:relative;display:flex;gap:12px;align-items:flex-start}
.svc-card .svc-thumb{flex:0 0 auto;width:64px;height:64px;border-radius:10px;overflow:hidden;border:1px solid #e2e8f0;background:#f8fafc;display:flex;align-items:center;justify-content:center}
.svc-card .svc-thumb img{width:100%;height:100%;object-fit:cover;display:block}
.svc-card .svc-body{flex:1;min-width:0}
.svc-card h3{font-size:15px;margin:0 0 4px;color:#0f172a;line-height:1.3}
.svc-card p{color:#64748b;font-size:12px;margin:0 0 8px;line-height:1.4}
.svc-card .svc-price{font-size:18px;font-weight:700;color:#6366f1;margin-bottom:8px}
.svc-card .svc-pin{position:absolute;top:8px;right:10px;background:#fef3c7;color:#92400e;font-size:10px;font-weight:700;padding:2px 7px;border-radius:999px}
.svc-card .btn{padding:7px 12px;font-size:13px}
</style>

<?php if($notice):?><div class="alert info" style="margin-bottom:14px"><b>📢 <?=e($notice['title'])?>:</b> <?=e($notice['body'])?></div><?php endif;?>

<div class="quick-actions">
  <h3>⚡ দ্রুত অ্যাকশন</h3>
  <div class="qa-row">
    <a class="qa-btn" href="search.php">🔍 অটো সার্ভার কপি</a>
    <a class="qa-btn" href="auto_nid.php">🪪 অটো NID মেক</a>
    <a class="qa-btn" href="recharge.php">💰 রিচার্জ করুন</a>
    <a class="qa-btn" href="history.php">📜 হিস্টোরি</a>
  </div>
</div>

<div class="dash-services-title">🎯 সকল সার্ভিস</div>
<?php if(!$dash_services): ?>
  <p style="color:#64748b">এখনো কোন সার্ভিস যোগ করা হয়নি।</p>
<?php else: ?>
<div class="grid g2">
<?php foreach($dash_services as $s):
  $closed = ($s['status']==='closed');
?>
<div class="svc-card">
  <?php if(!empty($s['pinned'])): ?><span class="svc-pin">📌</span><?php endif; ?>
  <?php if(!empty($s['image'])): ?>
    <div class="svc-thumb"><img src="../uploads/services/<?=e($s['image'])?>" alt="<?=e($s['name'])?>"></div>
  <?php else: ?>
    <div class="svc-thumb" style="font-size:24px;color:#94a3b8">🎯</div>
  <?php endif; ?>
  <div class="svc-body">
    <h3><?=e($s['name'])?></h3>
    <?php if(!empty($s['description'])): ?><p><?=e($s['description'])?></p><?php endif; ?>
    <div class="svc-price"><?=money($s['price'])?></div>
    <?php if($closed): ?>
      <button class="btn" disabled style="background:#94a3b8;cursor:not-allowed">🚫 বন্ধ</button>
    <?php else: ?>
      <a class="btn" href="service_order.php?id=<?=$s['id']?>">🛒 অর্ডার করুন</a>
    <?php endif; ?>
  </div>
</div>
<?php endforeach;?>
</div>
<?php endif; ?>

<?php require __DIR__.'/_footer.php';
