<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title><?= esc($title ?? 'Repositori Digital') ?> — STT El-Shadday</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link href="https://fonts.googleapis.com/css2?family=Kreon:wght@400;600;700&display=swap" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
  <link rel="icon" type="image/gif" href="<?= base_url('assets/img/logo.gif') ?>">
  <link rel="stylesheet" href="<?= base_url('assets/css/custom.css') ?>">
</head>
<body>

<!-- Navbar -->
<nav class="navbar navbar-expand-lg stt-navbar">
  <div class="container">
    <a class="navbar-brand d-flex align-items-center gap-2" href="<?= base_url('/') ?>">
      <img src="<?= base_url('assets/img/logo.gif') ?>" alt="Logo STT El-Shadday" height="42">
      <span class="fw-semibold text-white d-none d-sm-inline">Repositori STT El-Shadday</span>
    </a>
    <button class="navbar-toggler border-0" type="button" data-bs-toggle="collapse" data-bs-target="#mainNav">
      <i class="bi bi-list text-white fs-4"></i>
    </button>
    <div class="collapse navbar-collapse" id="mainNav">
      <ul class="navbar-nav me-auto">
        <li class="nav-item">
          <a class="nav-link <?= uri_string() === '' || uri_string() === 'documents' ? 'active' : '' ?>"
             href="<?= base_url('/') ?>">
            <i class="bi bi-collection me-1"></i>Repositori
          </a>
        </li>
        <?php if (auth()->loggedIn() && (auth()->user()->inGroup('student') || auth()->user()->inGroup('lecturer'))): ?>
        <li class="nav-item">
          <a class="nav-link <?= str_starts_with(uri_string(), 'my-works') ? 'active' : '' ?>"
             href="<?= base_url('my-works') ?>">
            <i class="bi bi-journal-text me-1"></i>Karya Saya
          </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="<?= base_url('submit') ?>">
            <i class="bi bi-cloud-upload me-1"></i>Unggah Karya
          </a>
        </li>
        <?php endif; ?>
      </ul>
      <ul class="navbar-nav ms-auto align-items-lg-center">
        <?php if (auth()->loggedIn()): ?>
          <?php if (auth()->user()->inGroup('admin') || auth()->user()->inGroup('super_admin')): ?>
          <li class="nav-item">
            <a class="nav-link" href="<?= base_url('admin') ?>">
              <i class="bi bi-speedometer2 me-1"></i>Admin
            </a>
          </li>
          <?php endif; ?>
          <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">
              <i class="bi bi-person-circle me-1"></i>
              <?= esc(session()->get('user_name') ?? auth()->user()->username) ?>
            </a>
            <ul class="dropdown-menu dropdown-menu-end">
              <li><a class="dropdown-item" href="<?= base_url('logout') ?>">
                <i class="bi bi-box-arrow-right me-2"></i>Keluar
              </a></li>
            </ul>
          </li>
        <?php else: ?>
          <li class="nav-item">
            <a class="nav-link" href="<?= base_url('login') ?>">
              <i class="bi bi-box-arrow-in-right me-1"></i>Masuk
            </a>
          </li>
        <?php endif; ?>
      </ul>
    </div>
  </div>
</nav>

<!-- Flash messages -->
<div class="container mt-3">
  <?php if (session()->has('success')): ?>
    <div class="alert alert-success alert-dismissible fade show py-2" role="alert">
      <i class="bi bi-check-circle me-2"></i><?= esc(session('success')) ?>
      <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
  <?php endif; ?>
  <?php if (session()->has('error')): ?>
    <div class="alert alert-danger alert-dismissible fade show py-2" role="alert">
      <i class="bi bi-exclamation-circle me-2"></i><?= esc(session('error')) ?>
      <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
  <?php endif; ?>
</div>

<!-- Main content -->
<main class="container py-4">
  <?= $this->renderSection('content') ?>
</main>

<!-- Footer -->
<footer class="stt-footer mt-5 py-4">
  <div class="container text-center">
    <p class="mb-1 fw-semibold text-white">Repositori Digital STT El-Shadday</p>
    <p class="mb-0 small" style="color:#5b646b;">
      &copy; <?= date('Y') ?> Sekolah Tinggi Teologi El-Shadday.
      <a href="https://stt-elshadday.ac.id" target="_blank" rel="noopener">stt-elshadday.ac.id</a>
    </p>
  </div>
</footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
<?= $this->renderSection('scripts') ?>
</body>
</html>
