@php
    use Filament\Support\Enums\Width;

    $livewire ??= null;

    $renderHookScopes = $livewire?->getRenderHookScopes();
    $maxContentWidth ??= (filament()->getSimplePageMaxContentWidth() ?? Width::Large);

    if (is_string($maxContentWidth)) {
        $maxContentWidth = Width::tryFrom($maxContentWidth) ?? $maxContentWidth;
    }

    $isGuest = ! filament()->auth()->check();
    $dberpBranding = app(\App\Support\DberpProductBranding::class);
    $productName = $dberpBranding->displayName();
    $showOfficialLoginFooter = $dberpBranding->showsOfficialLoginFooterBranding();
@endphp

<x-filament-panels::layout.base :livewire="$livewire">
    @props([
        'after' => null,
        'heading' => null,
        'subheading' => null,
    ])

    <div @class(['fi-simple-layout', 'dberp-auth-layout' => $isGuest])>
        {{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::SIMPLE_LAYOUT_START, scopes: $renderHookScopes) }}

        @if ($isGuest)
            {{-- 移动端品牌头部（仅小屏可见） --}}
            <div class="dberp-auth-mobile-header">
                <div class="dberp-auth-mobile-logo-wrap">
                    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="dberp-auth-mobile-icon">
                        <path d="M12.378 1.602a.75.75 0 0 0-.756 0L3 6.632l9 5.25 9-5.25-8.622-5.03ZM21.75 7.93l-9 5.25v9l8.628-5.032a.75.75 0 0 0 .372-.648V7.93ZM11.25 22.18v-9l-9-5.25v8.57a.75.75 0 0 0 .372.648l8.628 5.033Z"/>
                    </svg>
                </div>
                <span class="dberp-auth-mobile-name">{{ $productName }}</span>
            </div>

            {{-- 左侧品牌面板（仅访客/登录页、桌面端可见） --}}
            <div class="dberp-auth-brand-panel" aria-hidden="true">
                <div class="dberp-auth-brand-inner">
                    <div class="dberp-auth-brand-logo">
                        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="dberp-auth-brand-icon">
                            <path d="M12.378 1.602a.75.75 0 0 0-.756 0L3 6.632l9 5.25 9-5.25-8.622-5.03ZM21.75 7.93l-9 5.25v9l8.628-5.032a.75.75 0 0 0 .372-.648V7.93ZM11.25 22.18v-9l-9-5.25v8.57a.75.75 0 0 0 .372.648l8.628 5.033Z"/>
                        </svg>
                    </div>
                    <h1 class="dberp-auth-brand-name">{{ $productName }}</h1>
                    <p class="dberp-auth-brand-slogan">高效管理 · 精准决策 · 业务提速</p>
                    <hr class="dberp-auth-brand-divider">
                    <ul class="dberp-auth-brand-features">
                        <li class="dberp-auth-brand-feature">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="dberp-auth-feature-check">
                                <path fill-rule="evenodd" d="M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z" clip-rule="evenodd"/>
                            </svg>
                            <span>采购 · 销售 · 仓库一体化管理</span>
                        </li>
                        <li class="dberp-auth-brand-feature">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="dberp-auth-feature-check">
                                <path fill-rule="evenodd" d="M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z" clip-rule="evenodd"/>
                            </svg>
                            <span>往来结算 · 多维报表实时分析</span>
                        </li>
                        <li class="dberp-auth-brand-feature">
                            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" class="dberp-auth-feature-check">
                                <path fill-rule="evenodd" d="M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z" clip-rule="evenodd"/>
                            </svg>
                            <span>多角色权限精细管控</span>
                        </li>
                    </ul>
                </div>
@php
    $dberpProductVersion = app(\App\Support\DberpProductVersion::class);
@endphp
                <p class="dberp-auth-brand-footer">
                    © {{ date('Y') }}
                    @if ($showOfficialLoginFooter)
                        <a href="https://www.dberp.com.cn" target="_blank" rel="noopener noreferrer nofollow" class="dberp-auth-brand-footer-link">{{ $productName }}</a>
                        · v{{ $dberpProductVersion->displayVersion() }}
                    @else
                        {{ $productName }}
                    @endif
                </p>
                <span class="dberp-auth-deco dberp-auth-deco-1"></span>
                <span class="dberp-auth-deco dberp-auth-deco-2"></span>
                <span class="dberp-auth-deco dberp-auth-deco-3"></span>
            </div>
        @endif

        @if (($hasTopbar ?? true) && filament()->auth()->check())
            <div class="fi-simple-layout-header">
                @if (filament()->hasDatabaseNotifications())
                    @livewire(filament()->getDatabaseNotificationsLivewireComponent(), [
                        'lazy' => filament()->hasLazyLoadedDatabaseNotifications(),
                        'position' => \Filament\Enums\DatabaseNotificationsPosition::Topbar,
                    ])
                @endif

                @if (filament()->hasUserMenu())
                    @livewire(Filament\Livewire\SimpleUserMenu::class)
                @endif
            </div>
        @endif

        <div class="fi-simple-main-ctn">
            <main
                @class([
                    'fi-simple-main',
                    ($maxContentWidth instanceof Width) ? "fi-width-{$maxContentWidth->value}" : $maxContentWidth,
                ])
            >
                {{ $slot }}
            </main>
            @if ($isGuest)
                @include('filament.hooks.login-filing-footer')
            @endif
        </div>

        {{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::FOOTER, scopes: $renderHookScopes) }}

        {{ \Filament\Support\Facades\FilamentView::renderHook(\Filament\View\PanelsRenderHook::SIMPLE_LAYOUT_END, scopes: $renderHookScopes) }}
    </div>
</x-filament-panels::layout.base>
