<?php use App\Shared\Support\RoutePaths; ?>
<?php
$current = basename($_SERVER['SCRIPT_NAME'] ?? '');
$requestUri = (string) parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH);
$baseUri = rtrim(base_uri(), '/');
$requestPath = $requestUri;
if ($baseUri !== '' && $baseUri !== '/' && str_starts_with($requestUri, $baseUri)) {
    $requestPath = substr($requestUri, strlen($baseUri));
}
$requestPath = '/' . ltrim((string)$requestPath, '/');

$isPath = static function (string $path) use ($requestPath): bool {
    return $requestPath === $path || str_starts_with($requestPath, $path . '/');
};

$dashboardPages = ['/', '/index.php', '/dashboard', '/admin/dashboard', '/alerts'];
$dashboardOpen = in_array($current, $dashboardPages, true) || $isPath('/dashboard') || $isPath('/admin/dashboard');

$partiesPages = [
      ];
$partiesOpen = in_array($current, $partiesPages, true) || $isPath('/parties');

$inventoryPages = [
  '/inventory/stock-voucher',
  'inventory/opening-stock','/reports/inventory/item-balance',
];
$inventoryOpen = in_array($current, $inventoryPages, true) || $isPath('/inventory');

$salesPages = [
];
$salesOpen = in_array($current, $salesPages, true) || $isPath('/sales');

$purchasesPages = [
];
$purchasesOpen = in_array($current, $purchasesPages, true) || $isPath('/purchases');

$treasuryPages = [
  '','','','',
  
  
  
];
$treasuryOpen = in_array($current, $treasuryPages, true) || $isPath('/finance');

$checkPages = [
];
$checkOpen = in_array($current, $checkPages, true) || $isPath('/finance/checks');

$expensePages = [
  '/finance/expenses/categories','/finance/expenses/categories/form',
  '/finance/expenses/items','/finance/expenses/items/form',
];
$expenseOpen = in_array($current, $expensePages, true);

$employeePages = [];
$employeeOpen = in_array($current, $employeePages, true);

$reportsPages = [
      '/reports/inventory/item-balance',
  '',
  
];
$reportsOpen = in_array($current, $reportsPages, true) || $isPath('/reports');

$adminPages = [
  '/admin/audit-logs','/admin/label-definitions','/admin/import-data','/admin/backups','/admin/backups/restore','/admin/wipe-data','/admin/company-profile','/admin/communication-settings',
];
$adminOpen = in_array($current, $adminPages, true);

$printPages = [
  '/admin/print-settings',
  '/admin/print-settings/general',
  '/admin/print-settings/quotation',
  '/admin/print-settings/sales-invoice',
  '/admin/print-settings/purchase-invoice',
  '/admin/print-settings/sales-return',
  '/admin/print-settings/purchase-return',
  '/admin/print-settings/customer-receipt',
  '/admin/print-settings/cash-payment',
  '/admin/print-settings/supplier-payment',
  '/admin/print-settings/party-statement',
];
$printOpen = in_array($current, $printPages, true) || $isPath('/admin/print-settings');

$alertsCounts = ['total'=>0];
try { $alertsCounts = alerts_dashboard_counts(db(), 7, 30); } catch (\Throwable $e) { $alertsCounts = ['total'=>0]; }

$navActive = function(string $file) use ($current): string { return $current === $file ? ' active' : ''; };
?>
<?php $sidebarCompany = company_profile(db()); ?>
<aside class="app-sidebar bg-body-secondary shadow" data-bs-theme="dark">
  <div class="sidebar-brand border-bottom border-secondary-subtle">
    <a href="<?= e(url('/admin/dashboard')) ?>" class="brand-link d-flex align-items-center gap-2 px-3 py-2 text-decoration-none">
      <?php if (!empty($sidebarCompany['logo_path'])): ?>
        <?php $sidebarLogo = ltrim((string)$sidebarCompany['logo_path'], '/'); ?>
        <img src="<?= e(asset($sidebarLogo)) ?>" alt="Company Logo" style="width:38px;height:38px;border-radius:10px;object-fit:cover;border:1px solid rgba(255,255,255,.15);background:#fff;">
      <?php else: ?>
        <div class="d-inline-flex align-items-center justify-content-center" style="width:38px;height:38px;border-radius:10px;background:rgba(255,255,255,.08);border:1px solid rgba(255,255,255,.1);">
          <i class="fa-solid fa-building text-light"></i>
        </div>
      <?php endif; ?>
      <div class="flex-grow-1 overflow-hidden">
        <div class="brand-text fw-semibold text-truncate" style="line-height:1.15;"><?= e($sidebarCompany['name'] ?? (($config['app']['name'] ?? 'اسم الشركة'))) ?></div>
        <?php if (!empty($sidebarCompany['subtitle'])): ?>
          <div class="small text-white-50 text-truncate" style="font-size:.72rem;"><?= e($sidebarCompany['subtitle']) ?></div>
        <?php endif; ?>
      </div>
    </a>
  </div>

  <div class="sidebar-wrapper">
    <div class="sidebar-search px-3 pt-3">
      <div class="sidebar-search-box">
        <i class="fa-solid fa-magnifying-glass"></i>
        <input type="search" id="sidebarMenuSearch" class="form-control form-control-sm" placeholder="ابحث داخل القائمة" autocomplete="off">
        <button type="button" class="sidebar-search-shortcut" data-sidebar-search-shortcut title="/">/</button>
      </div>
    </div>
    <nav class="mt-2">
      <ul class="nav sidebar-menu flex-column" role="menu" id="sidebarMenuList">

        <li class="nav-header mt-2 text-muted small px-3">لوحة التحكم</li>
        <li class="nav-item">
          <a href="<?= e(url('/admin/dashboard')) ?>" class="nav-link<?= $navActive('/admin/dashboard') ?>">
            <i class="nav-icon fa-solid fa-gauge-high"></i>
            <p>الرئيسية</p>
          </a>
        </li>
        <?php if (can('alerts.view')): ?>
        <li class="nav-item">
          <a href="<?= e(url('/alerts')) ?>" class="nav-link<?= ($isPath('/alerts')) ? ' active' : '' ?>">
            <i class="nav-icon fa-solid fa-bell"></i>
            <p>التنبيهات<?php if ((int)($alertsCounts['total'] ?? 0) > 0): ?> <span class="badge text-bg-danger ms-2"><?= (int)$alertsCounts['total'] ?></span><?php endif; ?></p>
          </a>
        </li>
        <?php endif; ?>

        <?php if (can_view_parties() || can('sales.statement.view') || can('suppliers.statement.view') || can('suppliers.aging.view')): ?>
        <li class="nav-header mt-3 text-muted small px-3">الأطراف</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $partiesOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-parties" role="button" aria-expanded="<?= $partiesOpen ? 'true' : 'false' ?>" aria-controls="menu-parties">
            <i class="nav-icon fa-solid fa-users"></i>
            <p class="mb-0 flex-grow-1">الأطراف</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $partiesOpen ? ' show' : '' ?>" id="menu-parties">
            <ul class="nav flex-column ms-3 mt-1">
              <?php if (can_view_parties()): ?>
              <li class="nav-item"><a href="<?= e(url('/parties')) ?>" data-search="كل الأطراف اطراف عملاء موردون parties" class="nav-link<?= ($isPath('/parties') && !$isPath('/parties/customers') && !$isPath('/parties/suppliers')) || $isPath('/parties/view') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-address-book"></i><p>كل الأطراف</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/parties/customers')) ?>" data-search="العملاء عملاء customers" class="nav-link<?= $isPath('/parties/customers') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-user-group"></i><p>العملاء</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/parties/suppliers')) ?>" data-search="الموردون موردون suppliers" class="nav-link<?= $isPath('/parties/suppliers') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-truck-field"></i><p>الموردون</p></a></li>
              <?php endif; ?>
            </ul>
          </div>
        </li>
        <?php endif; ?>

        <li class="nav-header mt-3 text-muted small px-3">المخزون</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $inventoryOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-inventory" role="button" aria-expanded="<?= $inventoryOpen ? 'true' : 'false' ?>" aria-controls="menu-inventory">
            <i class="nav-icon fa-solid fa-warehouse"></i>
            <p class="mb-0 flex-grow-1">المخزون</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $inventoryOpen ? ' show' : '' ?>" id="menu-inventory">
            <ul class="nav flex-column ms-3 mt-1">
              <li class="nav-item"><a href="<?= e(url('/inventory/items/create')) ?>" data-search="إضافة صنف صنف جديد" class="nav-link<?= $isPath('/inventory/items/create') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-plus"></i><p>إضافة صنف</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/inventory/items')) ?>" data-search="الأصناف اصناف items منتجات بحث عن صنف" class="nav-link<?= $isPath('/inventory/items') && !$isPath('/inventory/items/create') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-box"></i><p>بحث عن صنف</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/inventory/categories')) ?>" data-search="فئات الأصناف " class="nav-link<?= $isPath('/inventory/categories') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-tags"></i><p>فئات الأصناف</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/inventory/units')) ?>" data-search="الوحدات " class="nav-link<?= $isPath('/inventory/units') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-ruler-combined"></i><p>الوحدات</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/inventory/warehouses')) ?>" data-search="المخازن " class="nav-link<?= $isPath('/inventory/warehouses') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-warehouse"></i><p>المخازن</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/inventory/opening-stock')) ?>" data-search="افتتاحيات المخزون " class="nav-link<?= $navActive('inventory/opening-stock') ?>"><i class="nav-icon fa-solid fa-box-open"></i><p>افتتاحيات المخزون</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/inventory/stock-voucher')) ?>" data-search="أذون المخازن " class="nav-link<?= $isPath('/inventory/stock-voucher') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-file-circle-plus"></i><p>أذون المخازن</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/inventory/warehouse-docs')) ?>" data-search="استعلام أذونات المخازن " class="nav-link<?= $isPath('/inventory/warehouse-docs') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-folder-open"></i><p>استعلام أذونات المخازن</p></a></li>
              <?php if (can('inventory.barcode.print')): ?><li class="nav-item"><a href="<?= e(url('/inventory/barcode-print')) ?>" data-search="طباعة باركود باركود اصناف labels barcode print" class="nav-link<?= $isPath('/inventory/barcode-print') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-barcode"></i><p>طباعة باركود</p></a></li><?php endif; ?>
            </ul>
          </div>
        </li>

        <?php if (can('sales.invoices.view') || can('sales.invoices.create') || can('sales_returns.view')): ?>
        <li class="nav-header mt-3 text-muted small px-3">المبيعات</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $salesOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-sales" role="button" aria-expanded="<?= $salesOpen ? 'true' : 'false' ?>" aria-controls="menu-sales">
            <i class="nav-icon fa-solid fa-chart-line"></i>
            <p class="mb-0 flex-grow-1">المبيعات</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $salesOpen ? ' show' : '' ?>" id="menu-sales">
            <ul class="nav flex-column ms-3 mt-1">
              <li class="nav-item"><a href="<?= e(url('/sales')) ?>" data-search="لوحة المبيعات " class="nav-link<?= $isPath('/sales') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-gauge"></i><p>لوحة المبيعات</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/sales/invoices')) ?>" data-search="فواتير المبيعات مبيعات فواتير بيع sales invoices" class="nav-link<?= $isPath('/sales/invoices') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-file-invoice"></i><p>فواتير المبيعات</p></a></li>
              <?php if (can('sales_returns.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/sales/returns')) ?>" data-search="مرتجعات البيع مرتجع بيع sales returns" class="nav-link<?= $isPath('/sales/returns') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-rotate-left"></i><p>مرتجعات البيع</p></a></li>
              <?php endif; ?>
              <?php if (can('quotations.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/sales/quotations')) ?>" data-search="عروض الأسعار عروض اسعار quotations" class="nav-link<?= $isPath('/sales/quotations') ? ' active' : ($isPath('/sales/quotations') ? ' active' : '') ?>"><i class="nav-icon fa-solid fa-file-signature"></i><p>عروض الأسعار</p></a></li>
              <?php endif; ?>
              <?php if (can('sales.invoices.view') || can('sales.invoices.create')): ?>
              <li class="nav-item"><a href="<?= e(url('/pos')) ?>" data-search="نقطة البيع POS نقطة بيع كاشير pos" class="nav-link<?= $isPath('/pos') && !$isPath('/pos/suspended') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-cart-shopping"></i><p>نقطة البيع POS</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/pos/suspended')) ?>" data-search="السلال المعلقة " class="nav-link<?= $isPath('/pos/suspended') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-layer-group"></i><p>السلال المعلقة</p></a></li>
              <?php endif; ?>
            </ul>
          </div>
        </li>
        <?php endif; ?>

        <?php if (can('suppliers.view')): ?>
        <li class="nav-header mt-3 text-muted small px-3">المشتريات</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $purchasesOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-purchases" role="button" aria-expanded="<?= $purchasesOpen ? 'true' : 'false' ?>" aria-controls="menu-purchases">
            <i class="nav-icon fa-solid fa-truck"></i>
            <p class="mb-0 flex-grow-1">المشتريات</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $purchasesOpen ? ' show' : '' ?>" id="menu-purchases">
            <ul class="nav flex-column ms-3 mt-1">
              <li class="nav-item"><a href="<?= e(url('/purchases/invoices')) ?>" data-search="فواتير الشراء شراء فواتير purchase invoices" class="nav-link<?= $isPath('/purchases/invoices') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-file-invoice-dollar"></i><p>فواتير الشراء</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/purchases/returns')) ?>" data-search="مرتجعات الشراء مرتجع شراء purchase returns" class="nav-link<?= $isPath('/purchases/returns') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-rotate-left"></i><p>مرتجعات الشراء</p></a></li>
            </ul>
          </div>
        </li>
        <?php endif; ?>

        <?php if (can('cashboxes.view') || can('cashboxes.txn.create') || can('cashboxes.report.view') || can('sales.receipts.view') || can('sales.receipts.create') || can('cash.payments.view') || can('cash.payments.create') || can('banks.accounts.view') || can('banks.txns.view')): ?>
        <li class="nav-header mt-3 text-muted small px-3">الخزن والبنوك</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $treasuryOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-treasury" role="button" aria-expanded="<?= $treasuryOpen ? 'true' : 'false' ?>" aria-controls="menu-treasury">
            <i class="nav-icon fa-solid fa-building-columns"></i>
            <p class="mb-0 flex-grow-1">الخزن والبنوك</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $treasuryOpen ? ' show' : '' ?>" id="menu-treasury">
            <ul class="nav flex-column ms-3 mt-1">
              <?php if (can('cashboxes.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/cashboxes')) ?>" data-search="الخزن خزن خزائن cashboxes" class="nav-link<?= $isPath('/finance/cashboxes') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-cash-register"></i><p>الخزن</p></a></li>
              <?php endif; ?>
              <?php if (can('cashboxes.txn.create')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/cashboxes/txn-form')) ?>" data-search="حركة خزنة " class="nav-link<?= $isPath('/finance/cashboxes/txn-form') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-right-left"></i><p>حركة خزنة</p></a></li>
              <?php endif; ?>
              <?php if (can('sales.receipts.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/sales/receipts')) ?>" data-search="سندات القبض سند قبض قبض receipt" class="nav-link<?= $isPath('/sales/receipts') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-money-bill-wave"></i><p>سندات القبض</p></a></li>
              <?php endif; ?>
              <?php if (can('cash.payments.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/cash-payments')) ?>" data-search="سندات الصرف سند صرف صرف payment" class="nav-link<?= $isPath('/finance/cash-payments') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-hand-holding-dollar"></i><p>سندات الصرف</p></a></li>
              <?php endif; ?>
              <?php if (can('banks.accounts.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/bank-accounts')) ?>" data-search="الحسابات البنكية بنوك حسابات bank accounts" class="nav-link<?= $isPath('/finance/bank-accounts') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-building-columns"></i><p>الحسابات البنكية</p></a></li>
              <?php endif; ?>
              <?php if (can('banks.txns.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/bank-transactions')) ?>" data-search="حركات البنوك حركة بنك bank transactions" class="nav-link<?= $isPath('/finance/bank-transactions') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-money-check-dollar"></i><p>حركات البنوك</p></a></li>
              <?php endif; ?>
            </ul>
          </div>
        </li>
        <?php endif; ?>

        
<?php if (can('checks.view') || can('checks.create') || can('checks.endorse') || can('checks.return') || can('checks.settle') || can('checks.replace')): ?>
        <li class="nav-header mt-3 text-muted small px-3">الشيكات</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $checkOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-checks" role="button" aria-expanded="<?= $checkOpen ? 'true' : 'false' ?>" aria-controls="menu-checks">
            <i class="nav-icon fa-solid fa-money-check"></i>
            <p class="mb-0 flex-grow-1">الشيكات</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $checkOpen ? ' show' : '' ?>" id="menu-checks">
            <ul class="nav flex-column ms-3 mt-1">
              <?php if (can('checks.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/checks')) ?>" data-search="سجل الشيكات شيكات checks" class="nav-link<?= $isPath('/finance/checks') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-list-check"></i><p>سجل الشيكات</p></a></li>
              <?php endif; ?>
              <?php if (can('checks.create')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/checks/receive')) ?>" data-search="استلام شيك استلام شيك receive check" class="nav-link<?= $isPath('/finance/checks/receive') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-file-circle-plus"></i><p>استلام شيك</p></a></li>
              <?php endif; ?>
            </ul>
          </div>
        </li>
        <?php endif; ?>

<?php if (can('expenses.categories.view') || can('expenses.categories.create') || can('expenses.items.view') || can('expenses.items.create') || can('expenses.report.view')): ?>
        <li class="nav-header mt-3 text-muted small px-3">المصاريف</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $expenseOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-expenses" role="button" aria-expanded="<?= $expenseOpen ? 'true' : 'false' ?>" aria-controls="menu-expenses">
            <i class="nav-icon fa-solid fa-receipt"></i>
            <p class="mb-0 flex-grow-1">موديول المصروفات</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $expenseOpen ? ' show' : '' ?>" id="menu-expenses">
            <ul class="nav flex-column ms-3 mt-1">
              <?php if (can('expenses.categories.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/expenses/categories')) ?>" data-search="مجموعات المصروفات " class="nav-link<?= ($isPath('/finance/expenses/categories') || $isPath('/finance/expenses/categories/form')) ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-folder-tree"></i><p>مجموعات المصروفات</p></a></li>
              <?php endif; ?>
              <?php if (can('expenses.items.view')): ?>
              <li class="nav-item"><a href="<?= e(url('/finance/expenses/items')) ?>" data-search="بنود المصروفات " class="nav-link<?= ($isPath('/finance/expenses/items') || $isPath('/finance/expenses/items/form')) ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-list"></i><p>بنود المصروفات</p></a></li>
              <?php endif; ?>
            </ul>
          </div>
        </li>
        <?php endif; ?>

        <?php if (can('sales.statement.view') || can('suppliers.statement.view') || can('suppliers.aging.view') || can('cashboxes.report.view') || can('banks.accounts.view') || can('banks.txns.view') || can('expenses.report.view') || can('purchases.reports.view') || can('sales.invoices.view')): ?>
        <li class="nav-header mt-3 text-muted small px-3">التقارير</li>
        <li class="nav-item">
          <a href="<?= e(url('/reports')) ?>" data-search="مركز التقارير تقارير reports hub" class="nav-link<?= $isPath('/reports') ? ' active' : '' ?>">
            <i class="nav-icon fa-solid fa-table-cells-large"></i>
            <p>مركز التقارير</p>
          </a>
        </li>
        <?php endif; ?>

        <?php
          $showAdmin = can('roles.view') || can('users.view') || can('admin.logs.view') || can('admin.backup.create') || can('admin.backup.restore') || can('admin.data.wipe') || can('admin.company.edit') || can('admin.comms.edit') || can('admin.label_definitions.edit') || can('admin.import_data');
$showPrintModule = can('admin.print_settings.edit');
        ?>
        <?php if ($showAdmin): ?>
        <li class="nav-header mt-3 text-muted small px-3">الإدارة</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $adminOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-admin" role="button" aria-expanded="<?= $adminOpen ? 'true' : 'false' ?>" aria-controls="menu-admin">
            <i class="nav-icon fa-solid fa-user-shield"></i>
            <p class="mb-0 flex-grow-1">موديول الإدارة</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $adminOpen ? ' show' : '' ?>" id="menu-admin">
            <ul class="nav flex-column ms-3 mt-1">
              <?php if (can('users.view')): ?><li class="nav-item"><a href="<?= e(url('/admin/users')) ?>" data-search="المستخدمون " class="nav-link<?= $isPath('/admin/users') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-users"></i><p>المستخدمون</p></a></li><?php endif; ?>
              <?php if (can('roles.view')): ?><li class="nav-item"><a href="<?= e(url('/admin/roles')) ?>" data-search="الأدوار والصلاحيات " class="nav-link<?= $isPath('/admin/roles') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-shield-halved"></i><p>الأدوار والصلاحيات</p></a></li><?php endif; ?>
              <?php if (can('admin.logs.view')): ?><li class="nav-item"><a href="<?= e(url('/admin/audit-logs')) ?>" data-search="سجلات النظام " class="nav-link<?= $navActive('/admin/audit-logs') ?>"><i class="nav-icon fa-solid fa-clipboard-list"></i><p>سجلات النظام</p></a></li><?php endif; ?>
              <?php if (can('admin.label_definitions.edit')): ?><li class="nav-item"><a href="<?= e(url('/admin/label-definitions')) ?>" data-search="تعريفات الاختصارات تعريب الأكواد labels shortcuts" class="nav-link<?= $navActive('/admin/label-definitions') ?>"><i class="nav-icon fa-solid fa-language"></i><p>تعريفات الاختصارات</p></a></li><?php endif; ?>
              <?php if (can('admin.import_data')): ?><li class="nav-item"><a href="<?= e(url('/admin/import-data')) ?>" data-search="استيراد البيانات bulk import excel أصناف عملاء موردين" class="nav-link<?= $navActive('/admin/import-data') ?>"><i class="nav-icon fa-solid fa-file-excel"></i><p>استيراد البيانات</p></a></li><?php endif; ?>
              <?php if (can('admin.backup.create')): ?><li class="nav-item"><a href="<?= e(url('/admin/backups')) ?>" data-search="نسخ احتياطي " class="nav-link<?= $navActive('/admin/backups') ?>"><i class="nav-icon fa-solid fa-database"></i><p>نسخ احتياطي</p></a></li><?php endif; ?>
              <?php if (can('admin.backup.restore')): ?><li class="nav-item"><a href="<?= e(url('/admin/backups/restore')) ?>" data-search="استرجاع نسخة " class="nav-link<?= $navActive('/admin/backups/restore') ?>"><i class="nav-icon fa-solid fa-rotate"></i><p>استرجاع نسخة</p></a></li><?php endif; ?>
              <?php if (can('admin.data.wipe')): ?><li class="nav-item"><a href="<?= e(url('/admin/wipe-data')) ?>" data-search="تفريغ البيانات " class="nav-link<?= $navActive('/admin/wipe-data') ?>"><i class="nav-icon fa-solid fa-trash-can"></i><p>تفريغ البيانات</p></a></li><?php endif; ?>
              <?php if (can('admin.company.edit')): ?><li class="nav-item"><a href="<?= e(url('/admin/company-profile')) ?>" data-search="تعريف الشركة " class="nav-link<?= $navActive('/admin/company-profile') ?>"><i class="nav-icon fa-solid fa-building"></i><p>تعريف الشركة</p></a></li><?php endif; ?>
              <?php if (can('admin.comms.edit')): ?><li class="nav-item"><a href="<?= e(url('/admin/communication-settings')) ?>" data-search="إعدادات البريد والواتساب واتساب whatsapp communication settings" class="nav-link<?= $navActive('/admin/communication-settings') ?>"><i class="nav-icon fa-solid fa-comments"></i><p>إعدادات البريد والواتساب</p></a></li><?php endif; ?>
                          </ul>
          </div>
        </li>
        <?php endif; ?>

        <?php if ($showPrintModule): ?>
        <li class="nav-header mt-3 text-muted small px-3">الطباعة</li>
        <li class="nav-item">
          <a class="nav-link d-flex align-items-center<?= $printOpen ? ' active' : '' ?>" data-bs-toggle="collapse" href="#menu-print-settings" role="button" aria-expanded="<?= $printOpen ? 'true' : 'false' ?>" aria-controls="menu-print-settings">
            <i class="nav-icon fa-solid fa-print"></i>
            <p class="mb-0 flex-grow-1">موديول الطباعة</p>
            <i class="fa-solid fa-angle-left ms-2 submenu-caret"></i>
          </a>
          <div class="collapse<?= $printOpen ? ' show' : '' ?>" id="menu-print-settings">
            <ul class="nav flex-column ms-3 mt-1">
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings')) ?>" data-search="موديول الطباعة overview print module" class="nav-link<?= $requestPath === '/admin/print-settings' ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-table-cells-large"></i><p>نظرة عامة</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/general')) ?>" data-search="الإعدادات العامة للطباعة pos barcode print settings" class="nav-link<?= $isPath('/admin/print-settings/general') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-sliders"></i><p>الإعدادات العامة</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/quotation')) ?>" data-search="عرض السعر quotation print" class="nav-link<?= $isPath('/admin/print-settings/quotation') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-file-signature"></i><p>عرض السعر</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/sales-invoice')) ?>" data-search="فاتورة البيع sales invoice print" class="nav-link<?= $isPath('/admin/print-settings/sales-invoice') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-file-invoice-dollar"></i><p>فاتورة البيع</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/purchase-invoice')) ?>" data-search="فاتورة الشراء purchase invoice print" class="nav-link<?= $isPath('/admin/print-settings/purchase-invoice') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-file-invoice-dollar"></i><p>فاتورة الشراء</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/sales-return')) ?>" data-search="مرتجع البيع sales return print" class="nav-link<?= $isPath('/admin/print-settings/sales-return') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-rotate-left"></i><p>مرتجع البيع</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/purchase-return')) ?>" data-search="مرتجع الشراء purchase return print" class="nav-link<?= $isPath('/admin/print-settings/purchase-return') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-rotate-left"></i><p>مرتجع الشراء</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/customer-receipt')) ?>" data-search="سند القبض customer receipt print" class="nav-link<?= $isPath('/admin/print-settings/customer-receipt') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-money-bill-wave"></i><p>سند القبض</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/cash-payment')) ?>" data-search="سند الصرف cash payment print" class="nav-link<?= $isPath('/admin/print-settings/cash-payment') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-money-bill-wave"></i><p>سند الصرف</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/supplier-payment')) ?>" data-search="سند سداد المورد supplier payment print" class="nav-link<?= $isPath('/admin/print-settings/supplier-payment') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-money-bill-wave"></i><p>سند سداد المورد</p></a></li>
              <li class="nav-item"><a href="<?= e(url('/admin/print-settings/party-statement')) ?>" data-search="كشف الحساب statement print" class="nav-link<?= $isPath('/admin/print-settings/party-statement') ? ' active' : '' ?>"><i class="nav-icon fa-solid fa-file-lines"></i><p>كشف الحساب</p></a></li>
            </ul>
          </div>
        </li>
        <?php endif; ?>

        <li class="nav-header mt-3 text-muted small px-3">حساب</li>
        <li class="nav-item">
          <a href="<?= e(url('/logout')) ?>" class="nav-link">
            <i class="nav-icon fa-solid fa-right-from-bracket"></i>
            <p>تسجيل الخروج</p>
          </a>
        </li>
      </ul>
    </nav>
  </div>
</aside>
