<!doctype html>
<html lang="id">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title><?= esc($title ?? 'Modular CRUD') ?></title>

    <!-- Bootstrap 4 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">

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

    <!-- DataTables -->
    <link rel="stylesheet" href="https://cdn.datatables.net/1.13.5/css/jquery.dataTables.min.css">

    <!-- JS -->
    <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <script src="https://cdn.datatables.net/1.13.5/js/jquery.dataTables.min.js"></script>
    <!-- main.php head -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">




    <!-- Script dan CSS -->
    <link rel="stylesheet" href="<?= base_url('css/sidebar.css') ?>">
    <script src="<?= base_url('js/sidebar.js') ?>"></script>
    <!-- Di bagian <head> atau tepat sebelum script utama JS -->

    <style>
        /* Pastikan header berwarna kontras */
        .table-primary {
            background-color: #007bff !important;
            /* Biru Primer Bootstrap */
            border-color: #007bff !important;
        }

        /* Gaya Umum DataTables */
        .dataTable-custom-style {
            border-collapse: separate;
            border-spacing: 0 5px;
            /* Sedikit spasi antar baris */
        }

        .dataTable-custom-style td {
            vertical-align: middle !important;
            padding-top: 5px !important;
            padding-bottom: 5px !important;
        }

        /* KODE BARU UNTUK KOLOM BERUKURAN KECIL */
        .column-fit {
            /* Mencegah teks melompat ke baris baru */
            white-space: nowrap;
            /* Mengatur lebar kolom agar hanya selebar konten */
            width: 1%;
        }
    </style>


</head>

<body>
    <div class="container-fluid">
        <div class="layout-wrapper">
            <!-- Tombol Hamburger (pojok kanan atas) -->
            <!-- <button class="btn btn-outline-secondary position-fixed top-0 end-0 m-3 d-md-none" id="toggleSidebar">
                <i class="fas fa-bars"></i>
            </button> -->


            <button id="toggleSidebar" class="d-md-none">
                <i class="fas fa-bars"></i>
            </button>



            <div class="row h-100 m-0">
                <!-- Sidebar -->
                <aside class="sidebar col-md-2 bg-light py-3" id="sidebar">
                    <?= $this->renderSection('sidebar') ?>
                </aside>

                <!-- Konten -->
                <main class="content-area col-md-10 p-4" id="content-area">
                    <?= $this->renderSection('content') ?>
                </main>
            </div>
        </div>
    </div>

    <script>
        const CRUD = {
            baseUrl: '<?= site_url() ?>'
        };
    </script>

    <script>
        // Ambil nilai activeViewTable dari session PHP
        //   const activeViewTable = ?= json_encode(session()->get('activeViewTable')) ?>;
        // === Auto-detect baseUrl untuk CRUD ===
        // ===================================================================
        window.CRUD = window.CRUD || {};
        (function() {
            if (!CRUD.baseUrl) {
                // Ambil protocol + host + optional path root
                const loc = window.location;
                CRUD.baseUrl = loc.origin; // https://domain.com

                // Jika aplikasi ada di subfolder, tambahkan path folder
                // Misal: https://domain.com/app/ → baseUrl = https://domain.com/app
                const pathName = loc.pathname.split('/');
                if (pathName.length > 1 && pathName[1] !== '') {
                    CRUD.baseUrl += '/' + pathName[1];
                }

                // Optional: hapus trailing slash
                CRUD.baseUrl = CRUD.baseUrl.replace(/\/$/, '');
            }
            console.log('CRUD.baseUrl =', CRUD.baseUrl);
        })();
    </script>
    <!-- ✅ Notifikasi Active View (hanya tampil saat aktif) -->
    <!-- Di bagian bawah halaman, load JS Active View -->
    <script src="<?= base_url('js/crud.js') ?>"></script>
</body>

</html>