{{--
    The accent band that closes the page: copyright on the leading edge, a
    "powered by" lock-up of partner logos on the trailing edge.

    Rendered only when website_settings.footer_powered_by holds something, so a
    site that never configures it keeps the plain bottom bar it has today.

    Shape:
      {
        "label":     {"ar": "بدعم من", "en": "Powered By"},
        "copyright": {"ar": "...",     "en": "..."},
        "logos":     [{"src": "...", "name": "...", "url": "..."}]
      }
--}}
@php
    $poweredBy = $settings->footer_powered_by ?? null;
    $logos = collect(data_get($poweredBy, 'logos') ?: [])
        ->filter(fn ($l) => filled(data_get($l, 'src')))
        ->values();

    $pick = function ($value) {
        if (! is_array($value)) {
            return $value;
        }
        $primary = app()->getLocale() === 'ar' ? 'ar' : 'en';
        $fallback = $primary === 'ar' ? 'en' : 'ar';

        return filled($value[$primary] ?? null) ? $value[$primary] : ($value[$fallback] ?? null);
    };

    $label = $pick(data_get($poweredBy, 'label'));
    $copyright = $pick(data_get($poweredBy, 'copyright')) ?: $settings->footer_bottom_text;
@endphp

@if ($poweredBy && ($logos->isNotEmpty() || filled($copyright)))
    <div class="ec-powered-bar" style="background: var(--site-accent)">
        <div class="max-w-7xl mx-auto flex flex-col items-center justify-between gap-4 px-4 py-4 sm:flex-row sm:px-6 lg:px-8">
            @if (filled($copyright))
                <p class="text-sm font-medium" style="color: var(--site-primary)">{{ $copyright }}</p>
            @endif

            @if ($logos->isNotEmpty())
                <div class="flex flex-wrap items-center justify-center gap-4 sm:gap-6">
                    @if (filled($label))
                        <span class="text-sm font-bold" style="color: var(--site-primary)">{{ $label }}</span>
                    @endif

                    @foreach ($logos as $logo)
                        @php $logoUrl = safe_url(data_get($logo, 'url')); @endphp
                        <{{ $logoUrl ? 'a' : 'span' }}
                            @if ($logoUrl) href="{{ $logoUrl }}" target="_blank" rel="noopener noreferrer" @endif
                            class="inline-flex items-center">
                            <img src="{{ data_get($logo, 'src') }}"
                                 alt="{{ data_get($logo, 'name') ?: '' }}"
                                 loading="lazy"
                                 class="h-8 w-auto max-w-[7rem] object-contain">
                        </{{ $logoUrl ? 'a' : 'span' }}>
                    @endforeach
                </div>
            @endif
        </div>
    </div>
@endif
