<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>@yield('title', 'Admin | CineCatalog')</title>

    <link rel="stylesheet" href="{{ asset('assets/css/admin.css') }}">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
    @stack('head')
</head>
<body>
    <aside class="admin-sidebar">
        <a class="admin-brand" href="{{ route('admin.dashboard') }}">
            <span aria-hidden="true">🎬</span>
            <span>CineCatalog</span>
        </a>

        <nav class="admin-nav">
            @php
                $menuItems = [
                    ['route' => 'admin.dashboard', 'match' => 'admin.dashboard', 'label' => 'Dashboard', 'icon' => 'fa-gauge'],
                    ['route' => 'admin.movies.index', 'match' => 'admin.movies.*', 'label' => 'Movies', 'icon' => 'fa-film'],
                    ['route' => 'admin.shows.index', 'match' => 'admin.shows.*', 'label' => 'TV Shows', 'icon' => 'fa-tv'],
                    ['route' => 'admin.tmdb-bulk.index', 'match' => 'admin.tmdb-bulk.*', 'label' => 'TMDB Bulk Import', 'icon' => 'fa-cloud-arrow-down'],
                    ['route' => 'admin.seasons', 'match' => 'admin.seasons*', 'label' => 'Seasons', 'icon' => 'fa-layer-group'],
                    ['route' => 'admin.episodes', 'match' => 'admin.episodes*', 'label' => 'Episodes', 'icon' => 'fa-list'],
                    ['route' => 'admin.genres', 'match' => 'admin.genres*', 'label' => 'Genres', 'icon' => 'fa-tags'],
                    ['route' => 'admin.ads', 'match' => 'admin.ads*', 'label' => 'Website Ads', 'icon' => 'fa-rectangle-ad'],
                    ['route' => 'admin.pages', 'match' => 'admin.pages*', 'label' => 'Pages', 'icon' => 'fa-file-lines'],
                    ['route' => 'admin.storage', 'match' => 'admin.storage*', 'label' => 'Storage', 'icon' => 'fa-cloud-arrow-up'],
                    ['route' => 'admin.settings', 'match' => 'admin.settings*', 'label' => 'Settings & API', 'icon' => 'fa-gear'],
                ];
            @endphp

            @foreach ($menuItems as $item)
                <a
                    class="{{ request()->routeIs($item['match']) ? 'active' : '' }}"
                    href="{{ route($item['route']) }}"
                >
                    <i class="fa-solid {{ $item['icon'] }}" aria-hidden="true"></i>
                    <span>{{ $item['label'] }}</span>
                </a>
            @endforeach
        </nav>

        <form method="POST" action="{{ route('admin.logout') }}" class="admin-logout">
            @csrf
            <button type="submit">
                <i class="fa-solid fa-right-from-bracket" aria-hidden="true"></i>
                <span>Logout</span>
            </button>
        </form>
    </aside>

    <main class="admin-main">
        <header class="admin-header">
            <button class="sidebar-toggle" type="button" aria-label="Toggle sidebar">☰</button>
            <strong>@yield('heading', 'Admin Panel')</strong>
        </header>

        <section class="content">
            @if (session('ok'))
                <div class="alert" role="status">{{ session('ok') }}</div>
            @endif

            @if ($errors->any())
                <div class="error" role="alert">{{ $errors->first() }}</div>
            @endif

            @yield('content')
        </section>
    </main>

    <script src="{{ asset('assets/js/admin.js') }}"></script>
    @stack('scripts')
</body>
</html>
