<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{{ config('app.name', 'Posture SaaS') }}</title>

    @livewireStyles
    @vite(['resources/css/app.css', 'resources/js/app.js'])
</head>

<body class="bg-[#EDF2F7] font-sans text-[#102A43] antialiased">
    <div class="min-h-screen">
        <aside class="fixed inset-y-0 left-0 z-30 hidden w-72 border-r border-slate-200 bg-white lg:flex lg:flex-col">
            <div class="flex h-16 items-center border-b border-slate-200 px-6">
                <div class="flex h-10 w-10 items-center justify-center rounded-2xl bg-posture-600 text-sm font-bold text-white">
                    GP
                </div>

                <div class="ml-3">
                    <div class="text-sm font-bold text-slate-900">Grupo Posture</div>
                    <div class="text-xs text-[#627D98]">Avaliação Psicossocial</div>
                </div>
            </div>

            <nav class="sidebar-scroll relative flex-1 overflow-y-auto px-4 py-6">
                <div class="space-y-3">

                    <div x-data="{ open: true }">
                        <button type="button" @click="open = !open" class="flex w-full items-center justify-between px-3 py-2">
                            <span class="text-xs font-semibold uppercase tracking-wider text-slate-400">Principal</span>
                            <span class="text-xs text-slate-400" x-text="open ? '−' : '+'"></span>
                        </button>

                        <div x-show="open" x-collapse class="mt-1 space-y-1">
                            <x-app.sidebar-link :href="route('app.dashboard')" :active="request()->routeIs('app.dashboard')">
                                Dashboard
                            </x-app.sidebar-link>
                        </div>
                    </div>

                    <div x-data="{ 
                    open: @js(
                            request()->routeIs('app.empresa') 
                            || request()->routeIs('app.unidades') 
                            || request()->routeIs('app.setores') 
                            || request()->routeIs('app.cargos') 
                            || request()->routeIs('app.dashboard')
                        ) 
                    }">
                        <button type="button" @click="open = !open" class="flex w-full items-center justify-between px-3 py-2">
                            <span class="text-xs font-semibold uppercase tracking-wider text-slate-400">Empresa</span>
                            <span class="text-xs text-slate-400" x-text="open ? '−' : '+'"></span>
                        </button>

                        <div x-show="open" x-collapse class="mt-1 space-y-1">
                            <x-app.sidebar-link :href="route('app.empresa')" :active="request()->routeIs('app.empresa')">
                                Dados da empresa
                            </x-app.sidebar-link>

                            <x-app.sidebar-link :href="route('app.unidades')" :active="request()->routeIs('app.unidades')">
                                Unidades
                            </x-app.sidebar-link>

                            <x-app.sidebar-link :href="route('app.setores')" :active="request()->routeIs('app.setores')">
                                Setores
                            </x-app.sidebar-link>

                            <x-app.sidebar-link :href="route('app.cargos')" :active="request()->routeIs('app.cargos')">
                                Cargos
                            </x-app.sidebar-link>
                        </div>
                    </div>

                    <div x-data="{ open: @js(request()->routeIs('app.colaboradores') || request()->routeIs('app.campanhas') || request()->routeIs('app.campanhas.*') || request()->routeIs('app.relatorios') || request()->routeIs('app.relatorios.*')) }">
                        <button type="button" @click="open = !open" class="flex w-full items-center justify-between px-3 py-2">
                            <span class="text-xs font-semibold uppercase tracking-wider text-slate-400">Operação</span>
                            <span class="text-xs text-slate-400" x-text="open ? '−' : '+'"></span>
                        </button>

                        <div x-show="open" x-collapse class="mt-1 space-y-1">
                            <x-app.sidebar-link :href="route('app.colaboradores')" :active="request()->routeIs('app.colaboradores')">
                                Colaboradores
                            </x-app.sidebar-link>

                            <x-app.sidebar-link :href="route('app.campanhas')" :active="request()->routeIs('app.campanhas') || request()->routeIs('app.campanhas.*')">
                                Campanhas
                            </x-app.sidebar-link>

                            <x-app.sidebar-link :href="route('app.relatorios')" :active="request()->routeIs('app.relatorios') || request()->routeIs('app.relatorios.*')">
                                Relatórios
                            </x-app.sidebar-link>
                        </div>
                    </div>

                    <div x-data="{ open: @js(request()->routeIs('app.billing')) }">
                        <button type="button" @click="open = !open" class="flex w-full items-center justify-between px-3 py-2">
                            <span class="text-xs font-semibold uppercase tracking-wider text-slate-400">Conta</span>
                            <span class="text-xs text-slate-400" x-text="open ? '−' : '+'"></span>
                        </button>

                        <div x-show="open" x-collapse class="mt-1 space-y-1">
                            <x-app.sidebar-link :href="route('app.billing')" :active="request()->routeIs('app.billing')">
                                Plano e cobrança
                            </x-app.sidebar-link>
                        </div>
                    </div>

                    @if(auth()->user()->is_platform_admin)
                        <div x-data="{ open: @js(request()->routeIs('admin.dashboard')) }">
                            <button type="button" @click="open = !open" class="flex w-full items-center justify-between px-3 py-2">
                                <span class="text-xs font-semibold uppercase tracking-wider text-slate-400">Plataforma</span>
                                <span class="text-xs text-slate-400" x-text="open ? '−' : '+'"></span>
                            </button>

                            <div x-show="open" x-collapse class="mt-1 space-y-1">
                                <x-app.sidebar-link :href="route('admin.dashboard')" :active="request()->routeIs('admin.*')">
                                    Admin Posture
                                </x-app.sidebar-link>
                            </div>
                        </div>
                    @endif
                </div>
            </nav>

            <div class="pointer-events-none absolute bottom-0 left-0 right-0 h-16 bg-gradient-to-t from-slate-50 to-transparent"></div>
        </aside>

        <div class="lg:pl-72">
            <header class="sticky top-0 z-20 flex h-16 items-center justify-between border-b border-[#D9E2EC] bg-white/95 px-6 backdrop-blur">
                <div>
                    <div class="text-sm font-semibold text-slate-900">
                        {{ app()->bound('currentTenant') ? app('currentTenant')->company_name : 'Empresa' }}
                    </div>
                    <div class="text-xs text-[#627D98]">
                        Plataforma de Avaliação Psicossocial
                    </div>
                </div>

                <div class="flex items-center gap-4">
                    <div class="hidden text-right sm:block">
                        <div class="text-sm font-medium text-slate-900">{{ auth()->user()->name }}</div>
                        <div class="text-xs text-[#627D98]">{{ auth()->user()->email }}</div>
                    </div>

                    <form method="POST" action="{{ route('logout') }}">
                        @csrf
                        <button class="rounded-xl border border-slate-300 bg-white px-3 py-2 text-sm font-semibold text-slate-700 hover:bg-slate-50">
                            Sair
                        </button>
                    </form>
                </div>
            </header>

            <main class="px-6 py-8">
                {{ $slot ?? '' }}
                @yield('content')
            </main>
        </div>
    </div>

    <div
        x-data="{ show: false, message: '', type: 'success' }"
        x-on:toast.window="
            message = $event.detail.message;
            type = $event.detail.type ?? 'success';
            show = true;
            setTimeout(() => show = false, 5000);
        "
        x-show="show"
        x-transition
        class="fixed right-6 top-6 z-[9999] w-full max-w-sm rounded-2xl border bg-white p-4 shadow-xl"
        style="display: none;"
    >
        <div class="flex gap-3">
            <div
                class="flex h-8 w-8 items-center justify-center rounded-full"
                x-bind:class="type === 'success' ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700'"
            >
                <span x-text="type === 'success' ? '✓' : '!'"></span>
            </div>

            <div>
                <p class="text-sm font-semibold text-slate-900" x-text="type === 'success' ? 'Sucesso' : 'Erro'"></p>
                <p class="mt-1 text-sm text-slate-600" x-text="message"></p>
            </div>
        </div>
    </div>
    @livewireScripts
</body>
</html>