@include('layouts._partials.error')

<!DOCTYPE html>
<html lang="es">
<head>
    @include('layouts._partials.head')

    {{-- Livewire styles --}}
    @livewireStyles
</head>

<body id="page-top">
<div id="wrapper">

    @include('layouts._partials.menu')

    <div id="content-wrapper" class="d-flex flex-column">
        <div id="content">
            @include('layouts._partials.header')
            @yield('content')
        </div>

        @include('layouts._partials.footer')
    </div>
</div>

{{-- JS base --}}
@include('layouts._partials.scripts')

{{-- Livewire --}}
@livewireScripts

{{-- scripts por vista --}}
@yield('scripts')

@stack('scripts')

<script>
document.addEventListener('livewire:init', () => {

    Livewire.on('swal', (data, ...payload) => {

        // 🔥 compatibilidad Livewire viejo y nuevo
        if (Array.isArray(data)) {
            data = data[0];
        }

        if (!data && payload.length) {
            data = payload[0];
        }

        if (!data || !data.text) {
            console.warn('SweetAlert disparado sin datos', data);
            return;
        }

        Swal.fire({
            icon: data.icon ?? 'info',
            title: data.title ?? 'Aviso',
            text: data.text,
            timer: data.timer ?? null,
            showConfirmButton: data.confirm ?? true,
        });

        if (data.reload) {
            setTimeout(() => location.reload(), data.reload);
        }

        if (data.closeModal) {
            $('#exampleModal').modal('hide');
        }
    });

    Livewire.on('open-prospecto-modal', () => {
        $('#exampleModal').modal('show');
    });

});

window.addEventListener('close-modal', () => {
    const modal = bootstrap.Modal.getInstance(
        document.getElementById('logoutSessionsModal')
    );
    modal?.hide();
});
</script>



</body>
</html>
