<?php
if (!defined('AYCORE_SKIP_BOTAPI_ROUTER')) define('AYCORE_SKIP_BOTAPI_ROUTER', true);
session_start();
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../lib/panel_capabilities.php';
require_once __DIR__ . '/lib/icons.php';
$q=$pdo->prepare('SELECT * FROM admin WHERE username=:u');$q->execute([':u'=>$_SESSION['user']??'']);
if(!isset($_SESSION['user'])||!$q->fetch(PDO::FETCH_ASSOC)){header('Location: login.php');exit;}
$counts=[];$rows=[];
try{$r=$pdo->query("SELECT type,COUNT(*) c,SUM(status='active') active_count FROM marzban_panel GROUP BY type");foreach(($r?$r->fetchAll(PDO::FETCH_ASSOC):[]) as $x){$counts[(string)$x['type']]=$x;}}catch(Throwable $e){}
$registry=aycore_panel_capabilities();
?>
<!doctype html><html lang="fa" dir="rtl"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Backend Capability Hub | iTzAYDiN-BOT</title><link rel="stylesheet" href="css/theme.css"><link rel="stylesheet" href="css/admin-extra.css"><link rel="stylesheet" href="css/ay-controls.css"><script src="js/theme.js" defer></script><style>.backend-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:14px}.backend-card{border:1px solid var(--border-soft);border-radius:18px;padding:16px;background:var(--surface-2)}.feature-wrap{display:flex;flex-wrap:wrap;gap:6px;margin-top:12px}.feature-wrap .badge{font-size:11px}.backend-top{display:flex;justify-content:space-between;gap:10px;align-items:start}.backend-meta{color:var(--text-muted);font-size:12px}.backend-num{font-size:22px;font-weight:800}</style></head><body><section id="container"><?php include 'header.php';?><section id="main-content"><div class="wrapper"><div class="page-head"><div><div class="page-head__title">🧩 Backend Capability Hub</div><div class="page-head__sub">هر Backend قابلیت خودش را دارد؛ هسته فروش دیگر 3x-ui محور نیست.</div></div><div class="chip-row"><a class="btn btn-primary btn-sm" href="panels.php">افزودن Backend</a><a class="btn btn-outline btn-sm" href="pasarguard.php">PasarGuard Hub</a><a class="btn btn-outline btn-sm" href="rebecca.php">Rebecca Hub</a></div></div><div class="card"><div class="form-group"><input id="backendSearch" class="form-control" type="search" placeholder="جستجو: reseller, inbound, wireguard, reset, marzban..."></div></div><div class="backend-grid" id="backendGrid">
<?php foreach($registry as $type=>$meta):$cnt=$counts[$type]??['c'=>0,'active_count'=>0];$hay=strtolower($type.' '.$meta['label'].' '.$meta['family'].' '.implode(' ',$meta['features']));?>
<div class="backend-card" data-search="<?=htmlspecialchars($hay,ENT_QUOTES)?>"><div class="backend-top"><div><h3 style="margin:0 0 5px"><?=htmlspecialchars($meta['label'])?></h3><div class="backend-meta"><code><?=htmlspecialchars($type)?></code> • <?=htmlspecialchars($meta['family'])?> • <?=htmlspecialchars($meta['generation'])?></div></div><div style="text-align:left"><div class="backend-num"><?=number_format((int)$cnt['active_count'])?> / <?=number_format((int)$cnt['c'])?></div><div class="backend-meta">فعال / کل</div></div></div><div class="feature-wrap"><?php foreach($meta['features'] as $feature):?><span class="badge <?=strpos($feature,'reseller')===0?'badge-warning':'badge-info'?>"><?=htmlspecialchars(aycore_capability_label($feature))?></span><?php endforeach;?></div><?php if($type==='pasarguard'):?><div style="margin-top:12px"><a class="btn btn-sm btn-primary" href="pasarguard.php">بازکردن PasarGuard Hub</a></div><?php elseif($type==='rebecca'):?><div style="margin-top:12px"><a class="btn btn-sm btn-primary" href="rebecca.php">بازکردن Rebecca Hub</a></div><?php elseif($type==='x-ui_single'):?><div style="margin-top:12px"><a class="btn btn-sm btn-primary" href="xui.php">بازکردن 3x-ui Hub</a></div><?php endif;?></div>
<?php endforeach;?></div></div></section></section><script>const s=document.getElementById('backendSearch');s.addEventListener('input',()=>{const q=s.value.trim().toLowerCase();document.querySelectorAll('#backendGrid .backend-card').forEach(c=>c.style.display=!q||c.dataset.search.includes(q)?'block':'none')});</script></body></html>
