<?php declare(strict_types=1);
$ab = assets_base();
$links = cfg('links', []);
?>
<!DOCTYPE html>
<html lang="en" data-theme="dark">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title><?= h($pageTitle ?? 'Builder') ?> — <?= h(cfg('app_name')) ?></title>
  <script>
    (function () {
      var t = localStorage.getItem('crash_console_theme');
      if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t);
      var l = localStorage.getItem('crash_console_lang');
      if (l === 'en' || l === 'ru') document.documentElement.setAttribute('lang', l);
    })();
  </script>
  <link rel="stylesheet" href="<?= h($ab) ?>/assets/css/app.css">
  <script src="<?= h($ab) ?>/assets/js/i18n.js" defer></script>
  <script src="<?= h(Auth::basePath()) ?>/assets/js/builder.js" defer></script>
</head>
<body data-base-path="<?= h(Auth::basePath()) ?>"
      data-view="<?= h($view ?? 'home') ?>"
      <?= (($view ?? '') === 'build' && !empty($build['id'])) ? ' data-build-id="' . (int) $build['id'] . '"' : '' ?>
      <?= (($view ?? '') === 'build' && !empty($build['status'])) ? ' data-build-status="' . h((string) $build['status']) . '"' : '' ?>>
  <div class="shell">
    <nav class="nav-pane" id="nav-pane" aria-label="Builder navigation">
      <button type="button" class="nav-handle" id="nav-handle" aria-label="Toggle navigation">
        <span class="nav-icon nav-icon--menu" aria-hidden="true"></span>
      </button>
      <ul class="nav-list">
        <li><a href="<?= h(Auth::basePath()) ?>/" class="nav-link <?= ($view ?? '') === 'home' ? 'active' : '' ?>"><span class="nav-icon nav-icon--home"></span><span class="nav-label">Builder</span></a></li>
        <li><a href="<?= h($links['crashes'] ?? '') ?>?view=reports" class="nav-link"><span class="nav-icon nav-icon--reports"></span><span class="nav-label">Crashes</span></a></li>
        <li><a href="<?= h($links['tickets'] ?? '') ?>" class="nav-link"><span class="nav-icon nav-icon--tickets"></span><span class="nav-label">Tickets</span></a></li>
        <li><a href="<?= h($links['git'] ?? '') ?>" class="nav-link"><span class="nav-icon nav-icon--git"></span><span class="nav-label">Git</span></a></li>
        <li><a href="<?= h($links['hub'] ?? '') ?>" class="nav-link"><span class="nav-icon nav-icon--home"></span><span class="nav-label">Hub</span></a></li>
      </ul>
      <div class="nav-locale">
        <label class="toolbar-select"><span>Theme</span>
          <select id="theme-select" aria-label="UI theme"><option value="dark">Dark</option><option value="light">Light</option></select>
        </label>
      </div>
      <div class="nav-user">
        <span class="nav-user-name"><?= h(Auth::user()['username'] ?? '') ?></span>
        <a href="<?= h(Auth::basePath()) ?>/logout" class="nav-link nav-link--logout">Logout</a>
      </div>
    </nav>
    <main class="main-pane">
      <?php if (($view ?? '') === 'build' && !empty($build)): ?>
        <?php require __DIR__ . '/build_detail.php'; ?>
      <?php else: ?>
        <?php require __DIR__ . '/home.php'; ?>
      <?php endif; ?>
    </main>
  </div>
  <?php platform_render_footer(); ?>
</body>
</html>
