<?php
session_start();
include 'koneksi.php';

// Cek login
if (!isset($_SESSION['user_id'])) {
    $current_page = basename($_SERVER['PHP_SELF']);
    if ($current_page != 'login.php' && $current_page != 'register.php') {
        header("Location: login.php");
        exit;
    }
}

// Halaman aktif
$active_page = basename($_SERVER['PHP_SELF']);
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>Manajemen Perpustakaan</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- CSS utama -->
    <link rel="stylesheet" href="style.css?v=1.0">


    <!-- Font Awesome (IKON) -->
    <link rel="stylesheet"
          href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">

    <style>
        .sidebar-menu i {
            width: 20px;
            margin-right: 8px;
            text-align: center;
        }
    </style>
</head>
<body>

<?php if (isset($_SESSION['user_id'])): ?>
<header class="header">
    <div class="header-title">Manajemen Perpustakaan</div>
    <a href="logout.php" class="header-logout">Logout</a>
</header>

<div class="container">
    <aside class="sidebar">
    <img src="assets/Logo.png" alt="Logo Perpustakaan" class="sidebar-logo">


        <ul class="sidebar-menu">

            <li>
                <a href="index.php"
                   class="<?= ($active_page == 'index.php') ? 'active' : '' ?>">
                    <i class="fa-solid fa-gauge"></i> Dashboard
                </a>
            </li>

            <li>
                <a href="buku_data.php"
                   class="<?= (strpos($active_page,'buku_') !== false) ? 'active' : '' ?>">
                    <i class="fa-solid fa-book"></i> Data Buku
                </a>
            </li>

            <li>
                <a href="pinjam_data.php"
                   class="<?= (strpos($active_page,'pinjam_') !== false) ? 'active' : '' ?>">
                    <i class="fa-solid fa-book-reader"></i> Data Peminjaman
                </a>
            </li>

            <li>
                <a href="kembali_data.php"
                   class="<?= ($active_page == 'kembali_data.php') ? 'active' : '' ?>">
                    <i class="fa-solid fa-rotate-left"></i> Data Pengembalian
                </a>
            </li>

            <!-- MENU LAPORAN -->
            <li>
                <a href="laporan_peminjaman.php"
                   class="<?= ($active_page == 'laporan_peminjaman.php') ? 'active' : '' ?>">
                    <i class="fa-solid fa-file-lines"></i> Laporan Peminjaman
                </a>
            </li>

            <li>
                <a href="laporan_pengembalian.php"
                   class="<?= ($active_page == 'laporan_pengembalian.php') ? 'active' : '' ?>">
                    <i class="fa-solid fa-file-circle-check"></i> Laporan Pengembalian
                </a>
            </li>

        </ul>
    </aside>

    <main class="content">

<?php endif; ?>
