@php
    $themeManager = app(\App\Domain\Theme\ThemeManager::class);
    $activeTheme = $themeManager->active();
    $stylevars = \App\Models\Stylevar::query()->visible()->orderBy('id')->get();
@endphp
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
    <title>{{ $seo['title'] ?? ($settings->site_name ?? config('app.name')) }}</title>
    @if(!empty($seo['canonical']))
        <link rel="canonical" href="{{ $seo['canonical'] }}">
    @endif
    @if(!empty($seo['description']))
        <meta name="description" content="{{ $seo['description'] }}">
    @endif
    @foreach(($seo['og'] ?? []) as $property => $content)
        <meta property="{{ $property }}" content="{{ $content }}">
    @endforeach
    @foreach(($seo['twitter'] ?? []) as $name => $content)
        <meta name="{{ $name }}" content="{{ $content }}">
    @endforeach
    @if(!empty($seo['jsonld']))
        <script type="application/ld+json">{!! json_encode($seo['jsonld'], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES) !!}</script>
    @endif
    <link rel="alternate" type="application/rss+xml" href="{{ url('/rss.xml') }}">
    <link rel="stylesheet" href="{{ $themeManager->assetUrl('style.css') }}?v={{ @filemtime(base_path('themes/'.$activeTheme.'/assets/style.css')) }}">
    @stack('head')
    @themeslot('head')
</head>
<body data-theme="{{ $activeTheme }}">
@themeslot('body_start')
<header class="site-header">
    <div class="wrap">
        <a class="brand" href="{{ url('/') }}">{{ $settings->site_name ?? 'LaraBlog' }}</a>
        <p class="tagline">{{ $settings->site_description ?: 'Example 皮肤：另一套排版与配色' }}</p>
        <nav class="nav-bar">
            <a href="{{ url('/') }}">{{ __('frontend.nav.home') }}</a>
            <a href="{{ url('/archives.shtml') }}">{{ __('frontend.nav.archives') }}</a>
            <a href="{{ url('/tagslist.shtml') }}">{{ __('frontend.nav.tags') }}</a>
            <a href="{{ url('/comments.shtml') }}">{{ __('frontend.nav.comments') }}</a>
            <a href="{{ url('/links.shtml') }}">{{ __('frontend.nav.links') }}</a>
            <a href="{{ url('/search.shtml') }}">{{ __('frontend.nav.search') }}</a>
            @auth
                <a href="{{ url('/index.php?action=profile') }}">{{ __('frontend.nav.profile') }}</a>
            @else
                <a href="{{ url('/login.shtml') }}">{{ __('frontend.nav.login') }}</a>
                <a href="{{ url('/reg.shtml') }}">{{ __('frontend.nav.register') }}</a>
            @endauth
        </nav>
        @themeslot('nav_after')
        @if(session('status'))
            <p class="flash">{{ session('status') }}</p>
        @endif
    </div>
</header>
@themeslot('header_after')
<main class="wrap layout">
    <section class="content">
        @themeslot('content_before')
        @yield('content')
        @themeslot('content_after')
    </section>
    <aside class="sidebar">
        @themeslot('sidebar_before')
        <div class="panel">
            <h3>{{ __('frontend.sidebar.categories') }}</h3>
            <ul>
                @foreach(($categories ?? []) as $category)
                    <li>
                        <a href="{{ $category->publicUrl() }}">{{ $category->name }}</a>
                    </li>
                @endforeach
            </ul>
        </div>
        @foreach($stylevars as $stylevar)
            <div class="panel">
                <h3>{{ $stylevar->title }}</h3>
                <p class="meta">{!! nl2br(e($stylevar->value)) !!}</p>
            </div>
        @endforeach
        @php($sidebarInject = trim(\App\Domain\Theme\ThemeSlot::render('sidebar')))
        @if($sidebarInject !== '')
            <div class="panel">{!! $sidebarInject !!}</div>
        @endif
        @php($sidebarAfter = trim(\App\Domain\Theme\ThemeSlot::render('sidebar_after')))
        @if($sidebarAfter !== '')
            <div class="panel">{!! $sidebarAfter !!}</div>
        @endif
    </aside>
</main>
@themeslot('footer_before')
<footer class="site-footer wrap">
    <p>{{ __('frontend.common.theme') }} example · {{ $settings->site_name ?? 'LaraBlog' }}</p>
</footer>
@themeslot('footer_after')
@themeslot('body_end')
</body>
</html>
