<!DOCTYPE html>
<html lang="ms">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>@yield('title', 'Panel Pentadbir') - e-Sijil</title>
    @vite(['resources/js/app.js'])
    @stack('styles')
</head>
<body class="admin-body">
    <div class="admin-wrapper d-flex">
        {{-- Sidebar Desktop --}}
        <aside class="admin-sidebar d-none d-lg-flex flex-column flex-shrink-0">
            <div class="admin-sidebar-brand">
                <div class="admin-sidebar-logo">e-S</div>
                <div>
                    <h5 class="mb-0">e-Sijil Admin</h5>
                    <small class="text-white-50">{{ auth()->user()->name }}</small>
                </div>
            </div>

            <nav class="admin-sidebar-nav flex-grow-1">
                <ul class="nav flex-column">
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.dashboard') ? 'active' : '' }}" href="{{ route('admin.dashboard') }}">
                            <span class="nav-icon">&#9632;</span> Dashboard
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.participants.index') || request()->routeIs('admin.participants.create') || request()->routeIs('admin.participants.edit') || request()->routeIs('admin.participants.show') ? 'active' : '' }}" href="{{ route('admin.participants.index') }}">
                            <span class="nav-icon">&#9786;</span> Peserta
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.participants.import.*') ? 'active' : '' }}" href="{{ route('admin.participants.import.index') }}">
                            <span class="nav-icon">&#8682;</span> Import Peserta
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.certificate-templates.*') ? 'active' : '' }}" href="{{ route('admin.certificate-templates.index') }}">
                            <span class="nav-icon">&#128196;</span> Template Sijil
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.reports.*') ? 'active' : '' }}" href="{{ route('admin.reports.index') }}">
                            <span class="nav-icon">&#128202;</span> Laporan
                        </a>
                    </li>
                    @if(auth()->user()->isSuperAdmin())
                    <li class="nav-item mt-2">
                        <small class="nav-section-label">PENTADBIRAN</small>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.users.*') ? 'active' : '' }}" href="{{ route('admin.users.index') }}">
                            <span class="nav-icon">&#128101;</span> Pengguna Admin
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.settings.*') ? 'active' : '' }}" href="{{ route('admin.settings.index') }}">
                            <span class="nav-icon">&#9881;</span> Tetapan Sistem
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {{ request()->routeIs('admin.activity-logs.*') ? 'active' : '' }}" href="{{ route('admin.activity-logs.index') }}">
                            <span class="nav-icon">&#128221;</span> Log Aktiviti
                        </a>
                    </li>
                    @endif
                </ul>
            </nav>

            <div class="admin-sidebar-footer">
                <a href="{{ route('certificate.index') }}" class="btn btn-outline-light btn-sm w-100 mb-2" target="_blank">Halaman Awam</a>
                <form action="{{ route('admin.logout') }}" method="POST">
                    @csrf
                    <button type="submit" class="btn btn-danger btn-sm w-100">Log Keluar</button>
                </form>
            </div>
        </aside>

        {{-- Main Content --}}
        <div class="admin-main flex-grow-1 d-flex flex-column min-vh-100">
            {{-- Top Navbar Mobile/Tablet --}}
            <header class="admin-topbar d-lg-none">
                <button class="btn btn-outline-secondary btn-sm" type="button" data-bs-toggle="offcanvas" data-bs-target="#adminSidebarMobile">
                    &#9776; Menu
                </button>
                <span class="fw-semibold">e-Sijil Admin</span>
                <small class="text-muted">{{ auth()->user()->name }}</small>
            </header>

            {{-- Mobile Sidebar Offcanvas --}}
            <div class="offcanvas offcanvas-start admin-sidebar-offcanvas" tabindex="-1" id="adminSidebarMobile">
                <div class="offcanvas-header border-bottom border-secondary">
                    <h5 class="offcanvas-title text-white">e-Sijil Admin</h5>
                    <button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas"></button>
                </div>
                <div class="offcanvas-body p-0">
                    <nav class="admin-sidebar-nav">
                        <ul class="nav flex-column">
                            <li class="nav-item"><a class="nav-link" href="{{ route('admin.dashboard') }}">Dashboard</a></li>
                            <li class="nav-item"><a class="nav-link" href="{{ route('admin.participants.index') }}">Peserta</a></li>
                            <li class="nav-item"><a class="nav-link" href="{{ route('admin.participants.import.index') }}">Import Peserta</a></li>
                            <li class="nav-item"><a class="nav-link" href="{{ route('admin.certificate-templates.index') }}">Template Sijil</a></li>
                            <li class="nav-item"><a class="nav-link" href="{{ route('admin.reports.index') }}">Laporan</a></li>
                            @if(auth()->user()->isSuperAdmin())
                            <li class="nav-item"><a class="nav-link" href="{{ route('admin.users.index') }}">Pengguna Admin</a></li>
                            <li class="nav-item"><a class="nav-link" href="{{ route('admin.settings.index') }}">Tetapan Sistem</a></li>
                            <li class="nav-item"><a class="nav-link" href="{{ route('admin.activity-logs.index') }}">Log Aktiviti</a></li>
                            @endif
                        </ul>
                    </nav>
                    <div class="p-3 border-top border-secondary">
                        <form action="{{ route('admin.logout') }}" method="POST">
                            @csrf
                            <button type="submit" class="btn btn-danger btn-sm w-100">Log Keluar</button>
                        </form>
                    </div>
                </div>
            </div>

            <main class="admin-content flex-grow-1">
                @if(session('success'))
                    <div class="alert alert-success alert-dismissible fade show">{{ session('success') }}<button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>
                @endif
                @if(session('error'))
                    <div class="alert alert-danger alert-dismissible fade show">{{ session('error') }}<button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>
                @endif

                @yield('content')
            </main>
        </div>
    </div>
    @stack('scripts')
</body>
</html>
