<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="apple-mobile-web-app-title" content="{{ config('meta_application_name') }}"/>
    @if($metaViewport = config('meta_viewport'))
        <meta name="viewport" content="{{ $metaViewport }}"/>
    @else
        <meta name="viewport" content="width=device-width, initial-scale=1"/>
    @endif
    @if($metaRobots = config('meta_robots'))
        <meta name="robots" content="{{ $metaRobots }}"/>
    @endif
    @if($metaAuthor = config('meta_author'))
        <meta name="author" content="{{ $metaAuthor }}"/>
    @endif
    @if($metaKeywords = config('meta_keywords'))
        <meta name="keywords" content="{{ $metaKeywords }}"/>
    @endif
    @if($metaDescription = config('meta_description'))
        <meta name="description" content="{{ $metaDescription }}"/>
    @endif
    {!! config('meta_adds_info') !!}

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

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

    @if($siteFavicon = config('site_favicon'))
        <link rel="icon" type="image/x-icon" href="{{ asset($siteFavicon) }}"/>
        <link rel="shortcut icon" type="image/x-icon" href="{{ asset($siteFavicon) }}"/>
    @endif

    @vite(['resources/sass/app.scss', 'resources/js/app.js'])
    <link rel="stylesheet" href="{{ asset('css/desktop/layout.css') }}"/>
    @stack('styles')

    <script>
        // 자바스크립트에서 사용하는 전역변수 선언
        var BASE_URL = "{{ BASE_URL }}";
        var FULL_URL = "{{ FULL_URL }}";
        var ADMIN_URL = "{{ ADMIN_URL }}";
        var CHARSET = "{{ CHARSET }}";
        var DATE = "{{ DATE }}";
        var DATETIME = "{{ DATETIME }}";
        var IP_ADDRESS = "{{ IP_ADDRESS }}";
        var REFERER = "{{ REFERER }}";
        var USER_AGENT = "{{ USER_AGENT }}";
        var DEVICE = "{{ DEVICE }}";
        var PLATFORM = "{{ PLATFORM }}";
        var BROWSER = "{{ BROWSER }}";
        var IS_USER = {{ IS_USER }};
        var IS_ADMIN = {{ IS_ADMIN }};
        var IS_FRONT = 1;
        var CSRF = "{{ csrf_token() }}";
    </script>

    <!--[if lt IE 9]>
    <script src="{{ asset('js/common/html5shiv.min.js') }}" defer></script>
    <script src="{{ asset('js/common/respond.min.js') }}" defer></script>
    <script src="{{ asset('js/common/ie8-responsive-file-warning.js') }}" defer></script>
    <![endif]-->

    <script src="{{ asset('/js/common/common.js') }}" defer></script>
    <script src="{{ asset('/js/common/jquery.validate.extension.js') }}" defer></script>
    <script src="{{ asset('/js/front.js') }}" defer></script>

    <!-- Google tag (gtag.js) -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-E4M2FCM7HR"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'G-E4M2FCM7HR');
    </script>
</head>
<body id="app">
    {{-- 상단 --}}
    <header id="header" class="container-fluid">
        {{-- 로고 --}}
        <article>
            <a href="/" type="text/html" rel="noreferrer" referrerpolicy="no-referrer">
                {{ strtoupper(config('app.name')) }}
            </a>
        </article>

        {{-- 검색 --}}
        <article>
            <ul class="nav">
                <li class="nav-item">
                    <a href="/" class="nav-link @if(!$isTab) active @endif">
                        게시글
                    </a>
                </li>
                <li class="nav-item">
                    <a href="{{ route('tag.index') }}" class="nav-link @if($isTab) active @endif">
                        태그
                    </a>
                </li>
            </ul>
        </article>

        {{-- 로그인, 회원가입 --}}
        <article>
            <ul class="nav">
                @guest
                    @if (Route::has('login'))
                    <li class="nav-item">
                        <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                    </li>
                    @endif
                    <li><span class="vr"></span></li>
                    @if (Route::has('register'))
                    <li class="nav-item">
                        <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                    </li>
                    @endif
                @else
                    <li class="nav-item">
                        <div class="dropdown">
                            <a href="#" id="account" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-bs-offset="-5,1">
                                {{ $user->nickname }}님 <span class="caret"></span>
                            </a>
                            <div class="dropdown-menu dropdown-menu-right">
                                @admin
                                <a href="{{ route('admin.index') }}" class="dropdown-item" target="_blank">관리자</a>
                                @endadmin
                                <a href="{{ route('account.profile') }}" class="dropdown-item">내 정보</a>
                                <div class="dropdown-divider"></div>
                                <a href="{{ route('logout') }}" class="dropdown-item">{{ __('Logout') }}</a>
                                <form id="logoutForm" class="hide" action="{{ route('logout') }}" method="POST">@csrf</form>
                            </div>
                        </div>
                    </li>
                @endguest
            </ul>
        </article>
    </header>

    <main id="main">
        {{-- 좌측 메뉴 --}}
        <nav id="nav">
            <div class="nav flex-column mb-auto">
                <a href="/recently" class="nav-link">최신글 보기</a>
                @if($topMenu)
                    @php
                        $buildSubMenu = function ($categories) use (&$buildSubMenu, $subMenu) {
                            $html = '<ul>';
                            foreach ($categories as $cate) {
                                $meta = $subMenu[$cate->id];
                                $hasClass = "";
                                if($meta->hasChildren) {
                                    $hasClass = 'class="has-children"';
                                }
                                $html .= sprintf('<li %s><a href="%s" class="dropdown-item" target="%s" %s>%s</a>', $hasClass, $meta->url, $meta->target, $meta->custom, $meta->name);
                                $html .= $buildSubMenu($cate->children);
                                $html .= '</li>';
                            }
                            $html .= '</ul>';
                            return $html;
                        };
                    @endphp
                    @foreach($topMenu[0] as $row)
                        <a href="{{ $row->url }}" target="{{ $row->target }}" {{ $row->custom }} class="nav-link @if(!$row->isLeaf) dropdown-toggle @endif"
                            @if(!$row->isLeaf) data-bs-toggle="dropdown" role="button" aria-expanded="false" data-bs-offset="10,-5" @endif>
                            {{ $row->name }}
                        </a>
                        @if($row->hasChildren)
                            <ul class="dropdown-menu">
                                @foreach($row->children as $mn)
                                    @php $meta = $subMenu[$mn->id]; @endphp
                                    <li @if($meta->hasChildren) class="has-children" @endif>
                                        <a href="{{ $meta->url }}" class="dropdown-item" target="{{ $meta->target }}" {{ $meta->custom }}>{{ $meta->name }}</a>
                                        @if($meta->hasChildren)
                                        @php echo $buildSubMenu($mn->children) @endphp
                                        @endif
                                    </li>
                                @endforeach
                            </ul>
                        @endif
                    @endforeach
                @endif
            </div>

            <div class="ad-coupang">
                <iframe src="https://coupa.ng/cdLzPn" width="100%" height="75" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
                <iframe src="https://ads-partners.coupang.com/widgets.html?id=630891&template=carousel&trackingCode=AF0305179&subId=&width=200&height=150" width="100%" height="150" frameborder="0" scrolling="no" referrerpolicy="unsafe-url"></iframe>
                <small>
                    쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
                </small>
            </div>

            <table>
                <caption>방문자 수</caption>
                <tr>
                    <th>오늘</th>
                    <td>{{ $visitorTodayCount }}</td>
                </tr>
                <tr>
                    <th>어제</th>
                    <td>{{ $visitorYesterdayCount }}</td>
                </tr>
                <tr>
                    <th>누적</th>
                    <td>{{ $visitorTotalCount }}</td>
                </tr>
            </table>
            <address>&copy; Copyright 2022 {{ config('company_name') }}</address>
        </nav>

        {{-- 컨텐츠 --}}
        <aside id="aside">
            <article>
                @yield('content')
            </article>

            <footer>
                <div class="row align-items-center">
                    <div class="col">
                        <ul>
                            <li>
                                <a href="{{ route('document', 'privacy') }}">개인정보처리방침</a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="{{ route('document', 'refusal') }}">이메일주소무단수집거부</a>
                            </li>
                            <li class="divider"></li>
                            <li>
                                <a href="{{ route('document', 'proposal') }}">제휴 문의</a>
                            </li>
                        </ul>
                    </div>
                    <div class="col text-end">
                        <a href="https://ccl.cckorea.org/" title="https://ccl.cckorea.org/" target="_blank">
                            <img src="/images/cc-license.png" alt="BY NC ND EU"/>
                        </a>
                    </div>
                </div>
            </footer>
        </aside>
    </main>

    @stack('scripts')

    @include('component.loading')
    @include('component.popup')
    @include('component.alert')
</body>
</html>
