@extends('layouts.admin')

@section('title', $partner ? "Modifier - {$partner['name']}" : 'Ajouter un partenaire')

@php
    $breadcrumbs = [['label' => 'Partenaires', 'route' => 'admin.partners.index'], ['label' => $partner ? $partner['name'] : 'Ajouter']];
@endphp

@section('content')

    <form method="POST" action="{{ $partner ? route('admin.partners.update', $partner) : route('admin.partners.store') }}" data-dirty-form novalidate>
        @csrf
        @if ($partner)
            @method('PATCH')
        @endif

        <div class="mb-5 flex flex-col gap-1">
            <h1 class="text-xl font-bold text-brand-ink">{{ $partner ? 'Modifier le partenaire' : 'Ajouter un partenaire' }}</h1>
        </div>

        <div class="grid grid-cols-1 gap-6 lg:grid-cols-3">
            <div class="admin-card flex flex-col gap-4 p-5 lg:col-span-2">
                <x-admin.field type="text" name="name" label="Nom" required :value="old('name', $partner['name'] ?? '')" placeholder="Nom du partenaire" :error="$errors->first('name')" />
                <x-admin.media-picker name="logo" label="Logo" alt-name="logo_alt" :value="old('logo', $partner['media_id'] ?? null)" :preview-url="$partner['logo'] ?? null" :alt="old('logo_alt', $partner['logo_alt'] ?? '')" help="Le logo est affiche tel quel : couleurs et proportions conservees." />
                <x-admin.field type="url" name="website_url" label="Site web" :value="old('website_url', $partner['website_url'] ?? '')" placeholder="https://" :error="$errors->first('website_url')" />
            </div>

            <div class="admin-card flex flex-col gap-4 p-5">
                <x-admin.field type="number" name="sort_order" label="Ordre d'affichage" :value="old('sort_order', $partner['sort_order'] ?? 0)" />
                <x-admin.field type="select" name="status" label="Statut" :options="['published' => 'Publie', 'draft' => 'Brouillon', 'archived' => 'Archive']" :value="old('status', $partner['status'] ?? 'draft')" />
                <x-admin.field type="switch" name="is_active" label="Actif (visible publiquement)" :checked="old('is_active', $partner['is_active'] ?? false)" />
            </div>
        </div>

        <x-admin.action-bar :preview-href="route('home') . '#partenaires'" :status="$partner['status'] ?? 'draft'" />
    </form>

@endsection
