{{-- Favicon : version carrée générée à partir du logo (ratio conservé, fond transparent) --}}
@if($logo ?? null)
    <link rel="icon" href="{{ route('site.favicon') }}" type="image/png" sizes="64x64">
@else
    <link rel="icon" href="{{ asset('favicon.ico') }}" type="image/x-icon">
@endif

{{-- SEO --}}
@if(!empty($meta_description ?? ''))
    <meta name="description" content="{{ $meta_description }}">
@endif
@if(!empty($meta_keywords ?? ''))
    <meta name="keywords" content="{{ $meta_keywords }}">
@endif

{{-- Open Graph / réseaux sociaux --}}
@php
    $pageTitle = optional($page ?? null)->title ?? $site_name ?? 'Mon Site';
@endphp
<meta property="og:type" content="website">
<meta property="og:title" content="{{ $pageTitle }}">
@if(!empty($meta_description ?? ''))
    <meta property="og:description" content="{{ $meta_description }}">
@endif
@php
    $ogImage = $og_image ?? ($logo ?? null);
    $ogImageUrl = $ogImage ? (str_starts_with($ogImage, 'http') || str_starts_with($ogImage, '/') ? $ogImage : asset('storage/'.$ogImage)) : null;
@endphp
@if($ogImageUrl)
    <meta property="og:image" content="{{ $ogImageUrl }}">
@endif
<meta property="og:url" content="{{ url()->current() }}">
<meta property="og:site_name" content="{{ $site_name ?? 'Mon Site' }}">

@include('partials.google-analytics')

@if(config('app.debug') && ($multilang_enabled ?? false))
{{-- Debug Multilang : visible dans la console du navigateur (F12) --}}
<script>
(function(){
    var d = {
        locale: "{{ app()->getLocale() }}",
        session_locale: "{{ session('locale', '') }}",
        multilang_current: "{{ $multilang_current ?? '' }}",
        multilang_default: "{{ $multilang_default ?? 'fr' }}",
        multilang_enabled: {{ ($multilang_enabled ?? false) ? 'true' : 'false' }},
        languages: @json($multilang_languages ?? [])
    };
    console.log('[Multilang Debug]', d);
    if (d.locale !== d.session_locale && d.session_locale) {
        console.warn('[Multilang] Incohérence: app locale=' + d.locale + ' mais session=' + d.session_locale);
    }
})();
</script>
@endif
