{{-- Shared Footer for all pages --}}
@php
    $appSettings = \App\Models\AppSetting::getAllCached();
    $siteName = $appSettings['site_name'] ?? config('app.name', 'AskeriPlatform');
    $contactFacebook = $appSettings['contact_facebook'] ?? null;
    $contactTwitter = $appSettings['contact_twitter'] ?? null;
    $contactInstagram = $appSettings['contact_instagram'] ?? null;
    $contactYoutube = $appSettings['contact_youtube'] ?? null;

    // Get Footer settings
    $footerSettings = \App\Models\HeaderFooterSetting::getFooter();
    $showSocialLinks = $footerSettings['show_social_links'] ?? true;
    $showPlatformLinks = $footerSettings['show_platform_links'] ?? true;
    $showToolsLinks = $footerSettings['show_tools_links'] ?? true;
    $showCorporateLinks = $footerSettings['show_corporate_links'] ?? true;
    $footerBrandDesc = $footerSettings['brand_description'] ?? null;
    $footerCustomHtml = $footerSettings['custom_html'] ?? null;
    $footerCopyright = $footerSettings['copyright_text'] ?? null;
    $footerEnabled = $footerSettings['is_enabled'] ?? true;

    // ── Admin-managed footer menu ────────────────────────────────────────────
    try {
        $footerMenu   = \App\Models\Menu::getByLocation('footer');
        $footerItems  = $footerMenu ? $footerMenu->items->where('is_active', true) : collect();
    } catch (\Exception $e) {
        $footerItems = collect();
    }
@endphp

@if($footerEnabled)

<footer class="site-footer">
    <div class="footer-container">
        <div class="footer-grid">
            {{-- Brand --}}
            <div class="footer-brand">
                <div class="footer-brand-title">
                    🎖️ {{ $siteName }}
                </div>
                <p class="footer-brand-desc">
                    {{ $footerBrandDesc ?? "Türkiye'nin lider askeri kariyer platformu. KPSS hazırlığından mülakat pratiklerine, forum tartışmalarından AI asistanına kadar her şey burada." }}
                </p>
                @if($showSocialLinks)
                <div class="footer-social">
                    @if($contactTwitter)<a href="{{ $contactTwitter }}" target="_blank" class="social-link" aria-label="Twitter">𝕏</a>@endif
                    @if($contactInstagram)<a href="{{ $contactInstagram }}" target="_blank" class="social-link" aria-label="Instagram">📷</a>@endif
                    @if($contactFacebook)<a href="{{ $contactFacebook }}" target="_blank" class="social-link" aria-label="Facebook">f</a>@endif
                    @if($contactYoutube)<a href="{{ $contactYoutube }}" target="_blank" class="social-link" aria-label="YouTube">▶</a>@endif
                </div>
                @endif
            </div>

            {{-- Platform Links --}}
            @if($showPlatformLinks)
            <div class="footer-column">
                <h4 class="footer-title">Platform</h4>
                <div class="footer-links">
                    <a href="{{ route('blog.index') }}">Blog</a>
                    <a href="{{ route('forum.index') }}">Forum</a>
                    <a href="{{ route('library.index') }}">Kütüphane</a>
                    <a href="{{ route('interview.index') }}">Mülakat</a>
                </div>
            </div>
            @endif

            {{-- Tools Links --}}
            @if($showToolsLinks)
            <div class="footer-column">
                <h4 class="footer-title">Araçlar</h4>
                <div class="footer-links">
                    <a href="{{ route('interview.index') }}">Mülakat Simülasyonu</a>
                    <a href="{{ route('interview.leaderboard') }}">Lider Tablosu</a>
                    <a href="{{ route('forum.index') }}">Forum Tartışmaları</a>
                    <a href="{{ route('library.index') }}">Kütüphane</a>
                </div>
            </div>
            @endif

            {{-- Corporate Links (from admin Menu system) --}}
            @if($showCorporateLinks)
            <div class="footer-column">
                <h4 class="footer-title">Kurumsal</h4>
                <div class="footer-links">
                    @if($footerItems->isNotEmpty())
                        @foreach($footerItems as $item)
                            <a href="{{ $item->url }}"
                               @if($item->open_in_new_tab) target="_blank" rel="noopener" @endif>
                                {{ $item->label }}
                            </a>
                        @endforeach
                    @else
                        {{-- Fallback to static links --}}
                        <a href="/admin/pages">Hakkımızda</a>
                        <a href="/admin/pages">Gizlilik Politikası</a>
                        <a href="/admin/pages">Sıkça Sorulan Sorular</a>
                        <a href="/contact">İletişim</a>
                    @endif
                </div>
            </div>
            @endif
        </div>

        {{-- Custom HTML --}}
        @if(!empty($footerCustomHtml))
        <div class="footer-custom-html">
            {!! $footerCustomHtml !!}
        </div>
        @endif

        {{-- Bottom Bar --}}
        <div class="footer-bottom">
            <span>&copy; {{ date('Y') }} {{ $siteName }} — {{ $footerCopyright ?? 'Tüm hakları saklıdır.' }}</span>
            <span>Türk Silahlı Kuvvetleri kariyer platformu</span>
        </div>
    </div>
</footer>
@endif

<style>
/* ════════════════════════════════════════════════════════════
   SITE FOOTER  –  Modern Military Platform Design
   ════════════════════════════════════════════════════════════ */
:root {
    --ft-bg: #0f172a;
    --ft-bg-alt: #1e293b;
    --ft-text: #94a3b8;
    --ft-text-light: #cbd5e1;
    --ft-text-white: #ffffff;
    --ft-border: rgba(255, 255, 255, 0.08);
    --ft-accent: #3b82f6;
    --ft-accent-hover: #60a5fa;
    --ft-radius: 10px;
    --ft-transition: 0.2s ease;
}

.site-footer {
    background: var(--ft-bg);
    color: var(--ft-text);
    padding: 72px 24px 32px;
    margin-top: 96px;
    position: relative;
}

.site-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.3), transparent);
}

.footer-container {
    max-width: 1280px;
    margin: 0 auto;
}

.footer-grid {
    display: grid;
    grid-template-columns: 2.2fr repeat(3, 1fr);
    gap: 56px;
    margin-bottom: 56px;
}

/* ── Brand ─────────────────────────────────── */
.footer-brand-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--ft-text-white);
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.3px;
}

.footer-brand-desc {
    font-size: 14px;
    line-height: 1.75;
    color: var(--ft-text);
    margin-bottom: 22px;
    max-width: 280px;
}

.footer-social {
    display: flex;
    gap: 10px;
}

.social-link {
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--ft-border);
    border-radius: var(--ft-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ft-text-light);
    text-decoration: none;
    transition: all var(--ft-transition);
    font-size: 14px;
    font-weight: 600;
}

.social-link:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
    color: var(--ft-accent-hover);
    transform: translateY(-2px);
}

/* ── Columns ───────────────────────────────── */
.footer-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--ft-text-white);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 18px;
}

.footer-links {
    display: flex;
    flex-direction: column;
    gap: 11px;
}

.footer-links a {
    color: var(--ft-text);
    font-size: 14px;
    text-decoration: none;
    transition: all var(--ft-transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.footer-links a:hover {
    color: var(--ft-accent-hover);
    transform: translateX(3px);
}

/* ── Custom HTML ───────────────────────────── */
.footer-custom-html {
    padding: 20px 0;
    border-top: 1px solid var(--ft-border);
    border-bottom: 1px solid var(--ft-border);
    margin-bottom: 24px;
}

/* ── Bottom ────────────────────────────────── */
.footer-bottom {
    border-top: 1px solid var(--ft-border);
    padding-top: 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    font-size: 13px;
    color: var(--ft-text);
}

.footer-bottom span:last-child {
    color: var(--ft-text-light);
}

/* ── Responsive ─────────────────────────────── */
@media (max-width: 1024px) {
    .footer-grid {
        grid-template-columns: 1.5fr repeat(2, 1fr);
        gap: 40px;
    }
}

@media (max-width: 768px) {
    .site-footer {
        padding: 56px 20px 28px;
        margin-top: 72px;
    }
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 36px;
    }
    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 10px;
        padding-top: 24px;
    }
    .footer-brand-desc {
        max-width: 100%;
    }
}
</style>
