<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <title>{{ config('app.name', 'Laravel') }} - Admin</title>

        <!-- Fonturi -->
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" />

        <!-- Script-uri -->
        @vite(['resources/css/app.css', 'resources/js/app.js'])
    </head>
    <body class="font-sans antialiased">
        <div class="flex h-screen bg-gray-50 dark:bg-gray-900 overflow-hidden">
            <!-- Bara Laterală -->
            @include('layouts.sidebar')

            <!-- Zona de Conținut Principal -->
            <div class="flex-1 flex flex-col overflow-hidden">
                <!-- Header Superior -->
                @include('layouts.header')

                <!-- Titlu Pagină -->
                @if (isset($header))
                    <header class="bg-white dark:bg-gray-800 shadow-sm border-b border-gray-200 dark:border-gray-700">
                        <div class="py-4 px-6 lg:px-8">
                            {{ $header }}
                        </div>
                    </header>
                @endif

                <!-- Mesaje Flash Toast -->
                @if (session('success') || session('error') || session('info'))
                    <div id="alert-toast" class="fixed z-[9999] animate-slideIn" style="top: 5rem; right: 1rem;">
                        <div class="bg-white dark:bg-gray-800 rounded-lg shadow-lg border {{ session('success') ? 'border-green-200 dark:border-green-800' : (session('error') ? 'border-red-200 dark:border-red-800' : 'border-blue-200 dark:border-blue-800') }} w-96">
                            <div class="p-4">
                                <div class="flex items-start">
                                    <!-- Icoană -->
                                    <div class="flex-shrink-0">
                                        @if (session('success'))
                                            <div class="flex items-center justify-center h-10 w-10 rounded-full bg-green-100 dark:bg-green-900/30">
                                                <i class="fas fa-check text-green-600 dark:text-green-400"></i>
                                            </div>
                                        @elseif (session('error'))
                                            <div class="flex items-center justify-center h-10 w-10 rounded-full bg-red-100 dark:bg-red-900/30">
                                                <i class="fas fa-times text-red-600 dark:text-red-400"></i>
                                            </div>
                                        @elseif (session('info'))
                                            <div class="flex items-center justify-center h-10 w-10 rounded-full bg-blue-100 dark:bg-blue-900/30">
                                                <i class="fas fa-info text-blue-600 dark:text-blue-400"></i>
                                            </div>
                                        @endif
                                    </div>

                                    <!-- Conținut -->
                                    <div class="ml-3 flex-1">
                                        <p class="text-sm font-medium text-gray-900 dark:text-gray-100">
                                            @if (session('success'))
                                                Succes
                                            @elseif (session('error'))
                                                Eroare
                                            @elseif (session('info'))
                                                Informație
                                            @endif
                                        </p>
                                        <p class="mt-1 text-sm text-gray-600 dark:text-gray-300">
                                            {{ session('success') ?? session('error') ?? session('info') }}
                                        </p>
                                    </div>

                                    <!-- Buton închidere -->
                                    <button onclick="closeToast()" class="ml-4 flex-shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-gray-300">
                                        <i class="fas fa-times text-sm"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <script>
                        // Închide automat toast-ul după 5 secunde
                        setTimeout(() => {
                            const toast = document.getElementById('alert-toast');
                            if (toast) {
                                toast.style.animation = 'slideOut 0.3s ease-out forwards';
                                setTimeout(() => toast.remove(), 300);
                            }
                        }, 5000);

                        function closeToast() {
                            const toast = document.getElementById('alert-toast');
                            if (toast) {
                                toast.style.animation = 'slideOut 0.3s ease-out forwards';
                                setTimeout(() => toast.remove(), 300);
                            }
                        }
                    </script>
                @endif

                <!-- Conținut Pagină -->
                <main class="flex-1 overflow-y-auto bg-gray-50 dark:bg-gray-900">
                    <!-- Mesaje Flash -->
                    @if (session('warning'))
                        <div class="mx-6 mt-6 p-4 bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 rounded" role="alert">
                            <div class="flex items-center">
                                <i class="fas fa-exclamation-triangle mr-2"></i>
                                <div>
                                    <p class="font-bold">Atenție</p>
                                    <p>{{ session('warning') }}</p>
                                </div>
                            </div>
                        </div>
                    @endif

                    @if (session('error'))
                        <div class="mx-6 mt-6 p-4 bg-red-100 border-l-4 border-red-500 text-red-700 rounded" role="alert">
                            <div class="flex items-center">
                                <i class="fas fa-times-circle mr-2"></i>
                                <div>
                                    <p class="font-bold">Eroare</p>
                                    <p>{{ session('error') }}</p>
                                </div>
                            </div>
                        </div>
                    @endif

                    @isset($slot)
                        {{ $slot }}
                    @else
                        @yield('content')
                    @endisset
                </main>
            </div>
        </div>

        <!-- Chart.js -->
        <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>

        <!-- Script-uri Personalizate -->
        @stack('scripts')
    </body>
</html>
