@props([
    'compact' => false,
])

@php
    use App\Models\ContentPage;
    use App\Support\NavigationLinks;

    $footerLinks = NavigationLinks::parse(setting('navigation.footer_links'), [
        ['label' => 'Terms', 'href' => '/pages/terms-and-conditions'],
        ['label' => 'Privacy Policy', 'href' => '/pages/privacy-policy'],
        ['label' => 'Refund Policy', 'href' => '/pages/refund-policy'],
        ['label' => 'Contact', 'href' => 'mailto:'.(setting('general.support_email', 'support@example.com') ?: 'support@example.com')],
    ]);

    $socialLinks = NavigationLinks::parse(setting('navigation.social_links'), []);

    $footerPages = collect();

    try {
        $footerPages = ContentPage::query()
            ->published()
            ->where('show_in_footer', true)
            ->orderBy('footer_sort')
            ->orderBy('title')
            ->get(['title', 'slug', 'footer_label']);
    } catch (Throwable) {
        $footerPages = collect();
    }

    $brandName = setting('general.application_name', 'RemoteMatch');
    $description = setting('branding.footer_description', 'AI-powered remote job matching with resume insights, ATS scoring, role previews, and tracked job discovery after completion.');
    $supportEmail = setting('general.support_email');
    $copyright = setting('general.footer_copyright_text', '(c) '.date('Y').' RemoteMatch. All rights reserved.');
@endphp

<footer {{ $attributes->merge(['class' => ($compact ? 'mt-10 ' : '').'overflow-hidden rounded-[2rem] border border-slate-200 bg-white shadow-sm shadow-slate-900/[0.04]']) }}>
    <div class="bg-[linear-gradient(135deg,#F8FAFC_0%,#ECFDF5_48%,#EFF6FF_100%)] px-5 py-8 sm:px-8">
        <div class="grid gap-8 lg:grid-cols-[1.3fr_0.7fr_0.7fr]">
            <div>
                <div class="flex items-center gap-3">
                    <x-brand-logo mark-class="flex size-11 items-center justify-center rounded-2xl bg-teal-700 text-sm font-semibold text-white shadow-lg shadow-teal-700/15" image-class="block object-contain" />
                </div>
                <p class="mt-4 max-w-xl text-sm leading-6 text-slate-600">{{ $description }}</p>
                <p class="mt-4 max-w-2xl text-xs leading-5 text-slate-500">
                    Job listings are sourced from third-party platforms and original employers. Application outcomes are not guaranteed.
                </p>

                @if ($socialLinks !== [])
                    <div class="mt-5 flex flex-wrap gap-2">
                        @foreach ($socialLinks as $link)
                            <a href="{{ $link['href'] }}" @if ($link['external']) target="_blank" rel="noopener noreferrer" @endif class="inline-flex size-11 items-center justify-center rounded-full border border-slate-200 bg-white text-slate-600 shadow-sm shadow-slate-900/[0.04] transition hover:-translate-y-0.5 hover:border-teal-200 hover:text-teal-700" aria-label="{{ $link['label'] }}">
                                <x-landing.icon :name="$link['icon']" class="size-5" />
                            </a>
                        @endforeach
                    </div>
                @endif
            </div>

            <div>
                <h3 class="text-sm font-semibold uppercase tracking-[0.16em] text-slate-400">Footer links</h3>
                <div class="mt-4 grid gap-3">
                    @foreach ($footerLinks as $link)
                        <a href="{{ $link['href'] }}" @if ($link['external']) target="_blank" rel="noopener noreferrer" @endif class="text-sm font-medium text-slate-600 transition hover:text-teal-700">
                            {{ $link['label'] }}
                        </a>
                    @endforeach
                    @if ($supportEmail)
                        <a href="mailto:{{ $supportEmail }}" class="text-sm font-medium text-slate-600 transition hover:text-teal-700">Support</a>
                    @endif
                </div>
            </div>

            @if ($footerPages->isNotEmpty())
                <div>
                    <h3 class="text-sm font-semibold uppercase tracking-[0.16em] text-slate-400">Content pages</h3>
                    <div class="mt-4 grid gap-3">
                        @foreach ($footerPages as $page)
                            <a href="{{ $page->publicPath() }}" class="text-sm font-medium text-slate-600 transition hover:text-teal-700">
                                {{ $page->displayFooterLabel() }}
                            </a>
                        @endforeach
                    </div>
                </div>
            @endif
        </div>
    </div>

    <div class="flex flex-col gap-3 border-t border-slate-200 bg-white px-5 py-4 text-xs font-medium text-slate-500 sm:flex-row sm:items-center sm:justify-between sm:px-8">
        <span>{{ $copyright }}</span>
        <span>AI suggestions are advisory. Hiring decisions are made by employers.</span>
    </div>
</footer>
