<?php
$nav = \A7kz\Platform\Modules\Platform\Navigation\Facades\Nav::config();
?>

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

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Qazqar') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}?{{env("CSSJSVERSION")}}"></script>
    <script src="{{ asset('js/editor.js') }}"></script>
    <script src="{{ asset('js/all.js') }}?{{env("CSSJSVERSION")}}"></script>
    <script src="{{ asset('js/tree-diagram.js') }}?{{env("CSSJSVERSION")}}"></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet" />


    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}?{{env("CSSJSVERSION")}}" rel="stylesheet">
    <link href="{{ asset('css/all.css') }}?{{env("CSSJSVERSION")}}" rel="stylesheet">

    @stack('head')
</head>
<body>
<div id="web_content">
    <div id="app"
         @if(isset($_COOKIE['a7platform_open_window']) && $_COOKIE['a7platform_open_window']) class="menu-open" @endif>
        <main class="main-container">
            <header class="navbar">
                <div class="nav-container py-1">
                    <div class="left-cont d-flex">
                        <a class="navbar-brand" href="{{ '/' . app()->getLocale() }}">
                            <img src="{{asset('img/logo.png')}}" alt="logo" class="logo">
                        </a>
                        <div class="item-nav lang">
                            <div class="dropdown">
                                <span class="dropdown-trigger" data-bs-toggle="dropdown">
                                    @if(app()->getLocale() == 'ru')
                                        RU <img src="{{asset('img/ru.png')}}" alt="ru">
                                    @elseif(app()->getLocale() == 'kz')
                                        KZ <img src="{{asset('img/kz.png')}}" alt="kz">
                                    @elseif(app()->getLocale() == 'en')
                                        EN <img src="{{asset('img/en.png')}}" alt="en">
                                    @endif
                                </span>
                                <ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
                                    @if(app()->getLocale() != \A7kz\Platform\Enums\Languages::Ru)
                                        <li><a class="dropdown-item"
                                               href="{{ \A7kz\Platform\Modules\Platform\Translate\Helpers\TranslateHelper::changeUrlLanguage(\A7kz\Platform\Enums\Languages::Ru) }}">RU
                                                <img src="{{asset('img/ru.png')}}" alt="ru"></a>
                                        </li>
                                    @endif
                                    @if(app()->getLocale() != \A7kz\Platform\Enums\Languages::Kz)
                                        <li><a class="dropdown-item"
                                               href="{{ \A7kz\Platform\Modules\Platform\Translate\Helpers\TranslateHelper::changeUrlLanguage(\A7kz\Platform\Enums\Languages::Kz) }}">KZ
                                                <img src="{{asset('img/kz.png')}}" alt="kz"></a>
                                        </li>
                                    @endif
                                    @if(app()->getLocale() != \A7kz\Platform\Enums\Languages::En)
                                        <li><a class="dropdown-item"
                                               href="{{ \A7kz\Platform\Modules\Platform\Translate\Helpers\TranslateHelper::changeUrlLanguage(\A7kz\Platform\Enums\Languages::En) }}">EN
                                                <img src="{{asset('img/en.png')}}" alt="en"></a>
                                        </li>
                                    @endif
                                </ul>
                            </div>
                        </div>
                        <a class="header-phone" href="tel:87763504141"><i class="bi bi-telephone-fill"></i> +7 776 350 41 41</a>
                    </div>
                    <div class="center-cont">
                        @auth
                            @if (auth()->user()->name === 'admin')
                                <div class="sidebar-content">
                                    <ul class="list-group">
                                        @php
                                            $autoNav = $nav->{'pipicar-nav-auto'} ?? null;
                                        @endphp
                                        @if($autoNav)
                                            @if(isset($autoNav->childs))
                                                <li class="list-group-item dropdown">
                                                    <a class="dropdown-toggle text-decoration-none" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                                        {{ $autoNav->label }}
                                                    </a>
                                                    <ul class="dropdown-menu">
                                                        @foreach(collect($autoNav->childs) as $child)
                                                            <li>
                                                                <a class="dropdown-item" href="{{ '/' . app()->getLocale() . '/' . ltrim($child->link ?? '#', '/') }}">
                                                                    {{ $child->label ?? 'Без названия' }}
                                                                </a>
                                                            </li>
                                                            @if (!$loop->last)
                                                                <li><hr class="dropdown-divider"></li>
                                                            @endif
                                                        @endforeach
                                                    </ul>
                                                </li>
                                            @endif
                                        @endif
                                    </ul>
                                </div>
                            @endif
                        @endauth
                    </div>
                    @guest
                        <div class="right-cont d-flex justify-end align-center">
                            @if (Route::has('login'))
                                <a class="item-nav btn btn-primary waves-effect" href="{{ lurl('login') }}">
                                    <i class="bi bi-box-arrow-in-right"></i>
                                    {{ __('Войти') }}
                                </a>
                            @endif
                            @if (Route::has('register'))
                                <a class="item-nav btn btn-outline waves-effect" href="{{ lurl('register') }}">
                                    <i class="bi bi-person-plus-fill"></i>
                                    {{ __('Регистрация') }}
                                </a>
                            @endif
                        </div>
                    @else

                        <div class="right-cont">
                            <div class="dropdown">
                                <a class="item-nav user dropdown-toggle" href="#" role="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                                    <i class="bi bi-person-fill"></i>
                                    {{ Auth::user()->name }}
                                </a>

                                <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                                    @if(config('platform.user_profile.enabled'))
                                        <li>
                                            <a class="dropdown-item" href="{{ \A7kz\Platform\Modules\Platform\Core\Facades\Core::url('user.profile') }}#applications">
                                                @lang('История заказов')
                                            </a>
                                        </li>
                                        <li>
                                            <a class="dropdown-item" href="{{ \A7kz\Platform\Modules\Platform\Core\Facades\Core::url('user.profile') }}#reserves">
                                                @lang('Бронирования')
                                            </a>
                                        </li>
                                    @endif
                                    <li><hr class="dropdown-divider"></li>
                                    <li>
                                        <a class="dropdown-item logout" href="{{ lurl('logout') }}"
                                           onclick="event.preventDefault();document.getElementById('logout-form').submit();">
                                            Выйти
                                        </a>
                                        <form id="logout-form" action="{{ lurl('logout') }}" method="POST" class="d-none">@csrf</form>
                                    </li>
                                </ul>
                            </div>

                        </div>
                    @endguest
                </div>
            </header>
            @yield('content')
        </main>
    </div>
</div>
<div id="print_content"></div>
<div id="loading" style="display:none; opacity: 0.6; position: absolute; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 10000;">
    <div style="margin: 40vh 30vw">
        <div class="text-center">
            <h5>Подождите, идет загрузка данных</h5>
        </div>
        <div class="progress">
            <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>
        </div>
    </div>
</div>
@stack('scripts-bottom')
</body>
<script>
    $.ajaxSetup({headers: {'X-CSRF-TOKEN': '{{csrf_token()}}'}});

    function activateTabFromHash() {
        const hash = window.location.hash;

        if (hash === "#reserves") {
            const tabTrigger = document.querySelector('#reserves-tab');
            if (tabTrigger) {
                new bootstrap.Tab(tabTrigger).show();
                document.getElementById('applicationsTab').scrollIntoView({ behavior: 'smooth' });
            }
        } else if (hash === "#applications") {
            const tabTrigger = document.querySelector('#applications-tab');
            if (tabTrigger) {
                new bootstrap.Tab(tabTrigger).show();
                document.getElementById('applicationsTab').scrollIntoView({ behavior: 'smooth' });
            }
        }
    }

    document.addEventListener("DOMContentLoaded", function () {
        activateTabFromHash();
    });

    window.addEventListener("hashchange", function () {
        activateTabFromHash();
    });
</script>
</html>
