@extends('layouts.admin')

@section('title', 'Navigation')

@php
    $breadcrumbs = [['label' => 'Navigation']];
@endphp

@section('content')

    <form method="POST" action="{{ route('admin.navigation.update') }}" data-dirty-form novalidate>
        @csrf
        @method('PATCH')

        <div class="mb-5 flex flex-col gap-1">
            <h1 class="text-xl font-bold text-brand-ink">Navigation et pied de page</h1>
            <p class="text-sm text-brand-muted">Gerez les liens du menu principal, du pied de page et les liens legaux.</p>
        </div>

        <div class="flex flex-col gap-5">
            @foreach (['header' => 'Menu principal', 'footer' => 'Pied de page', 'legal' => 'Liens legaux'] as $location => $title)
                <div class="admin-card p-5">
                    <div class="mb-3 flex items-center justify-between">
                        <h2 class="text-sm font-semibold text-brand-ink">{{ $title }}</h2>
                        <span class="status-badge status-badge--neutral">{{ count($navigation[$location]) }} lien(s)</span>
                    </div>
                    <div data-repeater>
                        <div data-repeater-items class="flex flex-col gap-2">
                            @foreach ($navigation[$location] as $i => $link)
                                <x-admin.repeater-item :index="$i">
                                    <div class="grid grid-cols-1 gap-3 sm:grid-cols-4">
                                        <x-admin.field type="text" data-repeater-name="{{ $location }}[__INDEX__][label]" :name="$location.'['.$i.'][label]'" label="Libelle" :value="$link['label']" />
                                        <x-admin.field type="text" data-repeater-name="{{ $location }}[__INDEX__][url]" :name="$location.'['.$i.'][url]'" label="Route / URL" :value="$link['route_name'] ?: $link['url']" />
                                        <x-admin.field type="select" data-repeater-name="{{ $location }}[__INDEX__][target]" :name="$location.'['.$i.'][target]'" label="Cible" :options="['_self' => 'Meme onglet', '_blank' => 'Nouvel onglet']" :value="$link['target'] ?? '_self'" />
                                        <x-admin.field type="switch" data-repeater-name="{{ $location }}[__INDEX__][is_active]" :name="$location.'['.$i.'][is_active]'" label="Actif" :checked="$link['is_active']" />
                                    </div>
                                </x-admin.repeater-item>
                            @endforeach
                        </div>
                        <button type="button" data-repeater-add class="btn btn-secondary btn-sm mt-3"><x-icon name="plus" class="h-4 w-4" /> Ajouter un lien</button>
                        <template data-repeater-template>
                            <x-admin.repeater-item>
                                <div class="grid grid-cols-1 gap-3 sm:grid-cols-4">
                                    <x-admin.field type="text" data-repeater-name="{{ $location }}[__INDEX__][label]" :name="$location.'[__NEW__][label]'" label="Libelle" />
                                    <x-admin.field type="text" data-repeater-name="{{ $location }}[__INDEX__][url]" :name="$location.'[__NEW__][url]'" label="Route / URL" />
                                    <x-admin.field type="select" data-repeater-name="{{ $location }}[__INDEX__][target]" :name="$location.'[__NEW__][target]'" label="Cible" :options="['_self' => 'Meme onglet', '_blank' => 'Nouvel onglet']" />
                                    <x-admin.field type="switch" data-repeater-name="{{ $location }}[__INDEX__][is_active]" :name="$location.'[__NEW__][is_active]'" label="Actif" :checked="true" />
                                </div>
                            </x-admin.repeater-item>
                        </template>
                    </div>
                </div>
            @endforeach

            <div class="admin-card flex flex-col gap-4 p-5">
                <h2 class="text-sm font-semibold text-brand-ink">Contenu du pied de page</h2>
                <x-admin.field type="textarea" name="footer_content[about_text]" label="Courte presentation" :rows="3" :value="$footerContent['about_text'] ?? ''" />
                <x-admin.field type="text" name="footer_content[admin_link_label]" label="Libelle du lien vers l'espace administrateur" :value="$footerContent['admin_link_label'] ?? ''" />
                <p class="text-xs text-brand-muted">Les services affiches et les coordonnees du pied de page reprennent les modules Services et Parametres.</p>
            </div>
        </div>

        <x-admin.action-bar :preview-href="route('home')" status="published" />
    </form>

@endsection
