@php
    $header = $snapshot->header();
    $logoUrl = $agency->logo ? asset('storage/' . $agency->logo) : null;

    // Önizlemede public route'lar 404 verir; nav linkleri preview route'una çevrilir
    $navHref = function (array $p) use ($agency, $preview) {
        if ($preview) {
            return match ($p['type']) {
                'home' => route('agency.site.preview', 'home'),
                'contact' => route('agency.site.preview', 'contact'),
                'custom' => route('agency.site.preview', $p['slug']),
                default => '#',
            };
        }

        return match ($p['type']) {
            'home' => route('customer.agency.show', $agency->slug),
            'contact' => route('customer.agency.contact', $agency->slug),
            'tours' => route('customer.agency.tours.index', $agency->slug),
            'custom' => route('customer.agency.page', ['agency' => $agency->slug, 'pageSlug' => $p['slug']]),
            default => '#',
        };
    };
    $currentType = $page['type'] ?? null;
    $ctaHref = $preview ? route('agency.site.preview', 'contact') : route('customer.agency.contact', $agency->slug);
@endphp
<header class="v-header{{ ($header['sticky'] ?? true) ? ' is-sticky' : '' }}" id="vHeader">
    <div class="v-container v-header__inner">
        <a href="{{ $navHref(['type' => 'home']) }}" class="v-header__brand">
            @if($logoUrl)
                <img src="{{ $logoUrl }}" alt="{{ $agency->name }}" class="v-header__logo">
            @else
                <span class="v-header__wordmark">{{ $agency->name }}</span>
            @endif
        </a>

        <nav class="v-header__nav" id="vNav" aria-label="Ana menü">
            @foreach($snapshot->navPages() as $navPage)
                <a href="{{ $navHref($navPage) }}"
                   class="v-header__link{{ $currentType === $navPage['type'] ? ' is-active' : '' }}">
                    {{ $navPage['nav_label'] }}
                </a>
            @endforeach
            @foreach(($header['extra_links'] ?? []) as $link)
                <a href="{{ $link['url'] ?? '#' }}" class="v-header__link">{{ $link['label'] ?? '' }}</a>
            @endforeach
        </nav>

        <div class="v-header__actions">
            @if(($header['show_phone'] ?? true) && $agency->contact_phone)
                <a href="tel:{{ preg_replace('/\s+/', '', $agency->contact_phone) }}" class="v-header__phone">
                    <x-voyage.icon name="phone" />
                    <span>{{ $agency->contact_phone }}</span>
                </a>
            @endif
            <a href="{{ $ctaHref }}" class="v-btn v-btn--primary v-header__cta">{{ $header['cta_text'] ?? 'Bize Ulaşın' }}</a>
            <button type="button" class="v-header__burger" id="vBurger" aria-label="Menüyü aç">
                <x-voyage.icon name="menu" />
            </button>
        </div>
    </div>

    <div class="v-mobile-nav" id="vMobileNav">
        @foreach($snapshot->navPages() as $navPage)
            <a href="{{ $navHref($navPage) }}" class="v-mobile-nav__link">{{ $navPage['nav_label'] }}</a>
        @endforeach
        @if($agency->contact_phone)
            <a href="tel:{{ preg_replace('/\s+/', '', $agency->contact_phone) }}" class="v-mobile-nav__link v-mobile-nav__phone">
                <x-voyage.icon name="phone" /> {{ $agency->contact_phone }}
            </a>
        @endif
    </div>
</header>
