<?php
$page_title = 'لوحة أندرويد';
$UA_FORCE_DESIGN_V2 = true;
$UA_PAGE_CSS = ['assets/css/android_dashboard.css'];
if (!defined('UA_HIDE_FOOTER')) define('UA_HIDE_FOOTER', true);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/header.php';

$androidCompanyName = trim((string)($companyName ?? ''));
if ($androidCompanyName === '') $androidCompanyName = 'مركز إدارة الشبكة';
$androidDashboardJs = @filemtime(__DIR__ . '/assets/js/android_dashboard.js') ?: time();
$androidCan = static function (string $permission): bool {
  return !function_exists('has_perm') || has_perm($permission);
};
$androidShowStats = $androidCan('can_view_dashboard_stats');
$androidShowTraffic = $androidCan('can_view_dashboard_traffic');
$androidShowSecurity = $androidCan('can_view_dashboard_security');
$androidQuickPermissions = [
  'subscribers' => $androidCan('can_view_subscribers'),
  'subscriber_add' => $androidCan('can_add_subscriber'),
  'invoices' => $androidCan('can_view_invoices'),
  'network' => $androidCan('can_mikrotik'),
  'messages' => $androidCan('can_manage_messages') || $androidCan('can_messages'),
  'links' => $androidCan('can_settings') || $androidCan('can_system_settings'),
];
?>
<div class="content-wrapper ua-android-dashboard" data-android-dashboard>
  <main class="ad-main">
    <header class="ad-top-card">
      <div class="ad-top-actions">
        <button type="button" class="ad-icon-button" data-ad-open-menu data-ua-mobile-menu aria-controls="uaSb3" aria-label="فتح قائمة البرنامج">
          <i class="fa fa-bars" aria-hidden="true"></i>
        </button>
        <button type="button" class="ad-icon-button" data-ad-refresh aria-label="تحديث لوحة التحكم">
          <i class="fa fa-refresh" aria-hidden="true"></i>
        </button>
      </div>
      <div class="ad-brand">
        <span class="ad-brand-kicker">النسخة الفرعية</span>
        <h1><?= h($androidCompanyName) ?></h1>
        <div class="ad-live-state"><i></i><span data-ad-system-label>جارِ فحص النظام</span></div>
      </div>
      <div class="ad-brand-mark" aria-hidden="true"><i class="fa fa-sitemap"></i></div>
    </header>

    <?php if($androidShowStats): ?><section class="ad-section" aria-labelledby="adOverviewTitle">
      <div class="ad-section-head">
        <div><span>نظرة سريعة</span><h2 id="adOverviewTitle">حالة المشتركين</h2></div>
        <?php if($androidQuickPermissions['subscribers']): ?><a href="subscribers.php">عرض الكل <i class="fa fa-angle-left"></i></a><?php endif; ?>
      </div>
      <div class="ad-stat-grid">
        <article class="ad-stat ad-stat--primary"><i class="fa fa-users"></i><strong data-ad-total>—</strong><span>إجمالي المشتركين</span></article>
        <article class="ad-stat ad-stat--online"><i class="fa fa-wifi"></i><strong data-ad-online>—</strong><span>متصل الآن</span></article>
        <article class="ad-stat ad-stat--offline"><i class="fa fa-user-times"></i><strong data-ad-offline>—</strong><span>غير متصل</span></article>
        <article class="ad-stat ad-stat--disabled"><i class="fa fa-ban"></i><strong data-ad-disabled>—</strong><span>مفصول</span></article>
      </div>
    </section><?php endif; ?>

    <?php if($androidShowTraffic): ?><section class="ad-card ad-traffic-card" aria-labelledby="adTrafficTitle">
      <div class="ad-card-head">
        <div><span>مباشر</span><h2 id="adTrafficTitle">حركة الإنترنت</h2></div>
        <i class="fa fa-exchange ad-card-icon"></i>
      </div>
      <div class="ad-traffic-total"><strong data-ad-traffic-total>—</strong><span>الاستهلاك اللحظي الكلي</span></div>
      <div class="ad-traffic-split">
        <div><i class="fa fa-arrow-up"></i><span>الرفع</span><strong data-ad-traffic-up>—</strong></div>
        <div><i class="fa fa-arrow-down"></i><span>التحميل</span><strong data-ad-traffic-down>—</strong></div>
      </div>
      <div class="ad-traffic-source">
        <div><span>المصدر</span><strong data-ad-traffic-source>بانتظار البيانات</strong></div>
        <button type="button" class="ad-traffic-toggle" data-ad-traffic-toggle aria-expanded="false" aria-controls="adTrafficDetails">
          <span>التفاصيل</span><i class="fa fa-angle-down" aria-hidden="true"></i>
        </button>
      </div>
      <div class="ad-traffic-details" id="adTrafficDetails" data-ad-traffic-details hidden>
        <div class="ad-traffic-details-head"><strong>تفاصيل مصادر الترافيك</strong><span data-ad-traffic-count>0 مصدر</span></div>
        <div class="ad-traffic-sources" data-ad-traffic-sources></div>
      </div>
    </section><?php endif; ?>

    <?php if($androidShowSecurity): ?><section class="ad-card ad-security-card" aria-labelledby="adSecurityTitle">
      <div class="ad-card-head">
        <div><span>أحداث اليوم</span><h2 id="adSecurityTitle">مراقب الشبكة</h2></div>
        <i class="fa fa-shield ad-card-icon"></i>
      </div>
      <div class="ad-security-grid">
        <div><span>تعرف اليوم</span><strong data-ad-identifying>—</strong></div>
        <div><span>اشتباه اليوم</span><strong data-ad-suspect>—</strong></div>
        <div><span>PPPoE اليوم</span><strong data-ad-pppoe>—</strong></div>
        <div><span>مؤكد اليوم</span><strong data-ad-confirmed>—</strong></div>
      </div>
      <a class="ad-card-link" href="security_monitor.php">فتح مركز المراقبة <i class="fa fa-angle-left"></i></a>
    </section><?php endif; ?>

    <?php if(in_array(true, $androidQuickPermissions, true)): ?><section class="ad-section" aria-labelledby="adQuickTitle">
      <div class="ad-section-head"><div><span>وصول مباشر</span><h2 id="adQuickTitle">الإجراءات السريعة</h2></div></div>
      <nav class="ad-quick-grid">
        <?php if($androidQuickPermissions['subscribers']): ?><a href="subscribers.php"><i class="fa fa-users"></i><span>المشتركون</span></a><?php endif; ?>
        <?php if($androidQuickPermissions['subscriber_add']): ?><a href="subscribers_add.php"><i class="fa fa-user-plus"></i><span>إضافة مشترك</span></a><?php endif; ?>
        <?php if($androidQuickPermissions['invoices']): ?><a href="invoices.php"><i class="fa fa-file-text-o"></i><span>الفواتير</span></a><?php endif; ?>
        <?php if($androidQuickPermissions['network']): ?><a href="network_map.php"><i class="fa fa-sitemap"></i><span>الشبكة</span></a><?php endif; ?>
        <?php if($androidQuickPermissions['messages']): ?><a href="messages.php"><i class="fa fa-comments-o"></i><span>الرسائل</span></a><?php endif; ?>
        <?php if($androidQuickPermissions['links']): ?><a href="server_links.php"><i class="fa fa-sitemap"></i><span>الربط الشبكي</span></a><?php endif; ?>
      </nav>
    </section><?php endif; ?>

    <p class="ad-last-update">آخر تحديث: <time data-ad-updated>—</time></p>
  </main>
</div>
<script src="assets/js/android_dashboard.js?v=<?= (int)$androidDashboardJs ?>" defer></script>
<?php require_once __DIR__ . '/footer.php'; ?>
