<?php
// app/views/layouts/main.php
$__pdo = db();
\App\Core\AppBootstrap::bootLayout($__pdo, !empty($_SESSION['user']));
$config = require __DIR__ . '/../../config.php';
?>
<!doctype html>
<html lang="ar" dir="rtl">
<head>
  <?php require __DIR__ . '/../partials/head.php'; ?>
</head>
<body class="layout-fixed sidebar-expand-lg bg-body-tertiary<?= str_starts_with((string) parse_url((string) ($_SERVER['REQUEST_URI'] ?? ''), PHP_URL_PATH), '/login') ? ' login-page-body' : '' ?>">
<div class="app-wrapper">
  <?php if (!empty($_SESSION['user'])): ?>
    <?php require __DIR__ . '/../partials/navbar.php'; ?>
    <?php require __DIR__ . '/../partials/sidebar.php'; ?>
  <?php endif; ?>

  <main class="app-main">
    <?php if (!empty($_SESSION['user']) && empty($hide_page_header)): ?>
      <?php require __DIR__ . '/../partials/page_header.php'; ?>
    <?php endif; ?>

    <div class="app-content">
      <div class="container-fluid">
        <?php require __DIR__ . '/../partials/flash.php'; ?>
        <?= $content ?? '' ?>
        <?php if (isset($page, $total_pages) && (int)$total_pages > 1): ?>
          <?= render_pagination((int)$page, (int)$total_pages, (int)($total_rows ?? 0), (int)($from_row ?? 0), (int)($to_row ?? 0)) ?>
        <?php endif; ?>
      </div>
    </div>
  </main>

  <footer class="app-footer text-sm">
    <div class="w-100 d-flex justify-content-center align-items-center gap-2 flex-wrap py-1">
      <img src="<?= e(asset('assets/img/techwaves-footer.png')) ?>" alt="Tech Waves" style="height:34px;width:auto;object-fit:contain;">
      <a href="https://Techwaveseg.com" target="_blank" rel="noopener noreferrer" class="text-decoration-none fw-semibold">تم التطوير بواسطه Techwaveseg.com</a>
    </div>
  </footer>
</div>

<?php require __DIR__ . '/../partials/footer.php'; ?>
</body>
</html>
