<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Panel - SLHD Provinsi DKI Jakarta</title>
    <!-- Tailwind CSS CDN -->
    <link rel="apple-touch-icon" sizes="180x180" href="{{asset('assets/logo3.png')}}">
    <link rel="icon" type="image/png" sizes="32x32" href="{{asset('assets/logo3.png')}}">
    <link rel="mask-icon" href="{{asset('assets/logo3.png')}}" color="#5bbad5">
    <script src="{{ asset('assets/js/tailwind.js') }}"></script>
    <!-- Google Fonts -->
    <link href="{{ asset('assets/css/font.css') }}" rel="stylesheet">
    <!-- Lucide Icons -->
    <script src="{{ asset('assets/js/lucide.js') }}"></script>
    <link rel="stylesheet" href="{{asset('assets/css/bootstrap-table.min.css')}}">
    <link rel="stylesheet" media="screen, print" href="{{asset('assets/css/datatables/datatables.bundle.css')}}">
    <link rel="stylesheet" href="{{asset('assets/css/sweetalert.min.css')}}">
    <link rel="stylesheet" href="{{asset('assets/css/toast.min.css')}}">
    <link rel="stylesheet" href="{{asset('assets/css/select2/select2.bundle.css')}}">
    <link href="{{asset('assets/css/icons.min.css')}}" rel="stylesheet" type="text/css">
    @yield('css')
    <style>
        .dropdown-menu > .dropdown-item{ display: inline; text-align: center;}
        .bootstrap-table .dropdown-menu {
            z-index: 9999 !important;
        }
        .bootstrap-table .fixed-table-container .table td, .bootstrap-table .fixed-table-container .table th{
            vertical-align: top!important;
            font-size: 12px!important;
        }
        .bootstrap-table .fixed-table-container .table td{
            text-align: left!important;
            padding:10px;
            font-weight: 500!important;

        }

        .bootstrap-table .fixed-table-container .table td.tengah{
            text-align: center!important;
            padding:10px;
            vertical-align: middle!important;
            font-weight: 500!important;

        }
        body { font-family: 'Plus Jakarta Sans', sans-serif; }
        
        /* Sidebar Transitions */
        #sidebar {
            transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        
        #sidebar.collapsed {
            width: 80px;
        }

        #sidebar.collapsed .sidebar-text, 
        #sidebar.collapsed .sidebar-header-text,
        #sidebar.collapsed .sidebar-dropdown-icon {
            display: none;
        }

        #sidebar.collapsed .sidebar-section-label {
            text-align: center;
            font-size: 8px;
            padding-left: 0;
            padding-right: 0;
        }

        .sidebar-item-active {
            background: rgba(59, 130, 246, 0.1);
            color: #2563eb;
            border-right: 4px solid #2563eb;
        }

        /* Nested Menu Style */
        .submenu {
            display: none;
            background: #f8fafc;
        }
        
        #sidebar.collapsed .submenu {
            display: none !important;
        }

        .custom-scrollbar::-webkit-scrollbar {
            width: 4px;
        }
        .custom-scrollbar::-webkit-scrollbar-thumb {
            background: #e2e8f0;
            border-radius: 10px;
        }
    </style>
</head>
<body class="bg-slate-50 text-slate-900 overflow-hidden">

    <div class="flex h-screen overflow-hidden">
        
        <!-- Sidebar -->
        <aside id="sidebar" class="w-64 bg-white border-r border-slate-200 flex flex-col hidden md:flex z-30">
            <!-- Logo & Toggle Container -->
            <div class="p-6 border-b border-slate-50 flex items-center justify-between">
                <div class="flex items-center space-x-3 overflow-hidden">
                    {{-- <div class="bg-white p-2 rounded-lg text-white shrink-0"> --}}
                        <img src="{{asset('assets/logo3.png')}}" width="40" alt="">
                    {{-- </div> --}}
                    <div class="sidebar-header-text">
                        <h1 class="font-bold text-lg tracking-tight text-slate-900 leading-none">SLHD</h1>
                        <p class="text-[6px] mt-2 uppercase tracking-widest text-slate-600 font-bold">Status Lingkungan Hidup Daerah</p>
                    </div>
                </div>
                <!-- Desktop Toggle Button -->
                <button id="toggle-sidebar" class="text-slate-400 hover:text-blue-600 transition-colors">
                    <i data-lucide="chevron-left" id="toggle-icon" class="w-5 h-5"></i>
                </button>
            </div>

            <!-- Navigation -->
            <nav class="flex-1 overflow-y-auto py-4 custom-scrollbar">
                <div class="sidebar-section-label px-4 mb-2 text-[10px] font-bold text-slate-400 uppercase tracking-widest transition-all">Menu Utama</div>

                <a href="{{ url('dashboard') }}" class="flex items-center px-6 py-3 transition-all group text-slate-500">
                    <i data-lucide="layout-dashboard" class="w-5 h-5 shrink-0"></i>
                    <span class="sidebar-text font-medium text-slate-500 text-sm ml-3">Dashboard</span>
                </a>

                {!! renderMenu() !!}
                
                {{-- 

                <!-- Nested Menu: Manajemen Data -->
                <div class="menu-dropdown">
                    <button class="w-full flex items-center justify-between px-6 py-3 text-slate-500 hover:text-blue-600 hover:bg-slate-50 transition-all dropdown-trigger group">
                        <div class="flex items-center">
                            <i data-lucide="database" class="w-5 h-5 shrink-0"></i>
                            <span class="sidebar-text font-semibold text-sm ml-3">Manajemen Data</span>
                        </div>
                        <i data-lucide="chevron-down" class="sidebar-dropdown-icon w-4 h-4 transition-transform duration-200"></i>
                    </button>
                    <div class="submenu">
                        <a href="#" class="flex items-center pl-14 pr-6 py-2.5 text-xs font-medium text-slate-500 hover:text-blue-600 transition-colors">Data Air</a>
                        <a href="#" class="flex items-center pl-14 pr-6 py-2.5 text-xs font-medium text-slate-500 hover:text-blue-600 transition-colors">Data Udara</a>
                        <a href="#" class="flex items-center pl-14 pr-6 py-2.5 text-xs font-medium text-slate-500 hover:text-blue-600 transition-colors">Data Sampah</a>
                    </div>
                </div>

                <a href="#" class="flex items-center px-6 py-3 text-slate-500 hover:text-blue-600 hover:bg-slate-50 transition-all group">
                    <i data-lucide="file-text" class="w-5 h-5 shrink-0"></i>
                    <span class="sidebar-text font-semibold text-sm ml-3">Laporan Publikasi</span>
                </a>
                
                <div class="menu-dropdown">
                    <button class="w-full flex items-center justify-between px-6 py-3 text-slate-500 hover:text-blue-600 hover:bg-slate-50 transition-all dropdown-trigger group">
                        <div class="flex items-center">
                            <i data-lucide="bar-chart-3" class="w-5 h-5 shrink-0"></i>
                            <span class="sidebar-text font-semibold text-sm ml-3">Visualisasi</span>
                        </div>
                        <i data-lucide="chevron-down" class="sidebar-dropdown-icon w-4 h-4"></i>
                    </button>
                    <div class="submenu">
                        <a href="#" class="flex items-center pl-14 pr-6 py-2.5 text-xs font-medium text-slate-500 hover:text-blue-600 transition-colors">Peta Interaktif</a>
                        <a href="#" class="flex items-center pl-14 pr-6 py-2.5 text-xs font-medium text-slate-500 hover:text-blue-600 transition-colors">Grafik Tahunan</a>
                    </div>
                </div>

                <div class="sidebar-section-label px-4 mt-8 mb-2 text-[10px] font-bold text-slate-400 uppercase tracking-widest transition-all">Sistem</div>
                
                <a href="#" class="flex items-center px-6 py-3 text-slate-500 hover:text-blue-600 hover:bg-slate-50 transition-all group">
                    <i data-lucide="users" class="w-5 h-5 shrink-0"></i>
                    <span class="sidebar-text font-semibold text-sm ml-3">Manajemen User</span>
                </a>
                <a href="#" class="flex items-center px-6 py-3 text-slate-500 hover:text-blue-600 hover:bg-slate-50 transition-all group">
                    <i data-lucide="settings" class="w-5 h-5 shrink-0"></i>
                    <span class="sidebar-text font-semibold text-sm ml-3">Pengaturan</span>
                </a> --}}
            </nav>

            <!-- Bottom Profile -->
            <div class="p-4 border-t border-slate-100">
                <div class="flex items-center p-3 bg-slate-100 border-slate-150 rounded-xl overflow-hidden">
                    <div class="w-10 h-10 rounded-full bg-blue-100 flex items-center justify-center text-blue-600 font-bold border border-blue-200 shrink-0">
                        <i data-lucide="user" class="w-5 h-5 shrink-0"></i> 
                    </div>
                    <div class="sidebar-text ml-3 overflow-hidden">
                        <p class="text-sm font-bold text-slate-900 truncate">{{ auth()->user()->name }}</p>
                        <p class="text-[10px] text-slate-500 truncate">{{ session('group_name') }}</p>
                    </div>
                    <a href="{{ url('logout') }}" class="sidebar-text ml-auto text-slate-400 hover:text-red-500 transition-colors">
                        <i data-lucide="log-out" class="w-4 h-4"></i>
                    </a>
                </div>
            </div>
        </aside>

        <!-- Main Content Area -->
        <main class="flex-1 flex flex-col overflow-hidden">
            <header class="h-20 bg-white border-b border-slate-200 flex items-center justify-between px-8 shrink-0">
                <div class="flex items-center">
                    <button id="mobile-toggle" class="p-2 text-slate-600 md:hidden">
                        <i data-lucide="menu" class="w-6 h-6"></i>
                    </button>
                    <div class="hidden md:block">
                        <h2 class="text-xl font-bold text-slate-900">{{ @$title }}</h2>
                        {{-- <p class="text-xs text-slate-500">Ringkasan Sistem SLHD Provinsi DKI Jakarta</p> --}}
                    </div>
                </div>
                
                <div class="flex items-center space-x-4">
                    {{-- <div class="relative hidden sm:block">
                        <i data-lucide="search" class="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"></i>
                        <input type="text" placeholder="Cari fitur..." class="pl-10 pr-4 py-2 bg-slate-50 border border-slate-200 rounded-xl text-sm outline-none focus:ring-2 focus:ring-blue-500 w-48 lg:w-64">
                    </div>
                    <button class="relative p-2 text-slate-400 hover:text-blue-600 transition-colors">
                        <i data-lucide="bell" class="w-5 h-5"></i>
                        <span class="absolute top-2 right-2 w-2 h-2 bg-red-500 rounded-full border-2 border-white"></span>
                    </button> --}}
                    <div class="h-8 w-px bg-slate-200 mx-2"></div>
                    <a href="{{ asset('assets/manualbook.pdf') }}" class="bg-blue-600 text-white px-4 py-2 rounded-lg text-sm font-bold hover:bg-blue-700 transition-all flex items-center shadow-lg shadow-blue-100">
                        <i data-lucide="download" class="w-4 h-4 mr-2"></i> Download Manual Book
                    </a>
                </div>
            </header>
            
            @yield('content')
        </main>
    </div>

    <!-- jQuery CDN -->
    <script src="{{ asset('assets/js/jquery.min.js') }}"></script>
    <script src="{{asset('assets/js/bootstrap-table.min.js')}}"></script>
    <script src="{{ asset('assets/js/sweetalert.min.js') }}"></script>
    <script src="{{asset('assets/js/toast.min.js')}}"></script>
    <script src="{{asset('assets/js/select2/select2.bundle.js')}}"></script>
    @yield('js')
    <script>
        $(document).ready(function() {
            lucide.createIcons();

            $('.select2').select2();
                $('.numberInput').on('input', function() {
                    this.value = this.value.replace(/[^0-9]/g, ''); // Hanya angka 0-9
                });
            
            @if (Session::get('type')=='error')
                  toastr.error("{{ Session::get('message') }}", 'Error!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
              @endif
              @if (Session::get('type')=='success')
                  toastr.success("{{ Session::get('message') }}", 'Berhasil!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
              @endif
              @if (Session::get('type')=='warning')
                  toastr.warning("{{ Session::get('message') }}", 'Whoopss!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
              @endif
              @if (Session::get('type')=='info')
                  toastr.info("{{ Session::get('message') }}", 'Info!', {positionClass: 'toast-bottom-right', containerId: 'toast-bottom-right'});
              @endif

            // 1. Sidebar Collapse Logic
            $('#toggle-sidebar').click(function() {
                const sidebar = $('#sidebar');
                const icon = $('#toggle-icon');
                
                sidebar.toggleClass('collapsed');
                
                // Change icon direction
                if (sidebar.hasClass('collapsed')) {
                    icon.attr('data-lucide', 'chevron-right');
                } else {
                    icon.attr('data-lucide', 'chevron-left');
                }
                
                // Re-init icons to apply changes
                lucide.createIcons();
            });

            // 2. Nested Menu / Dropdown Logic
            $('.dropdown-trigger').click(function() {
                // If sidebar is collapsed, don't allow open dropdown (or expand it first)
                if($('#sidebar').hasClass('collapsed')) {
                    $('#sidebar').removeClass('collapsed');
                    $('#toggle-icon').attr('data-lucide', 'chevron-left');
                    lucide.createIcons();
                }

                const submenu = $(this).next('.submenu');
                const icon = $(this).find('.sidebar-dropdown-icon');
                
                // Toggle Submenu
                submenu.slideToggle(300);
                
                // Rotate Icon
                icon.toggleClass('rotate-180');
                
                // Optional: Close other open dropdowns
                $('.submenu').not(submenu).slideUp(300);
                $('.sidebar-dropdown-icon').not(icon).removeClass('rotate-180');
            });

            // Mobile Menu Toggle
            $('#mobile-toggle').click(function() {
                $('#sidebar').toggleClass('hidden').toggleClass('fixed inset-0 w-full');
            });
        });

        $(document).on('click', '.dropdown-toggle', function () {
            // alert('klik');
            $('.dropdown-menu').removeClass('hidden');
            $('.dropdown-menu').toggle();
        });

        // $('.bootstrap-table .dropdown-menu').removeClass('hidden');
    </script>
</body>
</html>