@extends('layouts.app')

@section('content')
<div class="max-w-2xl mx-auto p-6 bg-white shadow-md rounded-md">
  <h2 class="text-2xl font-semibold text-gray-800 mb-6">Créer un nouveau groupe</h2>

  {{-- Affichage des erreurs globales --}}
  @if($errors->any())
    <div class="mb-4 p-4 bg-red-50 border border-red-200 text-red-800 rounded">
      <h3 class="font-semibold">Veuillez corriger les erreurs suivantes :</h3>
      <ul class="mt-2 list-disc list-inside text-sm">
        @foreach($errors->all() as $error)
          <li>{{ $error }}</li>
        @endforeach
      </ul>
    </div>
  @endif

  <form action="{{ route('groups.store') }}" method="POST" class="space-y-6">
    @csrf

    {{-- Nom du groupe --}}
    <div>
      <label for="name" class="block text-sm font-medium text-gray-700">Nom du groupe <span class="text-red-500">*</span></label>
      <input
        id="name"
        name="name"
        type="text"
        value="{{ old('name') }}"
        placeholder="Ex: Campagne Printemps 2025"
        class="mt-1 block w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-indigo-500 focus:border-indigo-500"
        required
      >
      @error('name')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
    </div>

    {{-- Description --}}
    <div>
      <label for="description" class="block text-sm font-medium text-gray-700">Description (optionnel)</label>
      <textarea
        id="description"
        name="description"
        rows="3"
        placeholder="Quelques mots pour qualifier ce groupe"
        class="mt-1 block w-full border border-gray-300 rounded-md px-3 py-2 focus:ring-indigo-500 focus:border-indigo-500"
      >{{ old('description') }}</textarea>
      @error('description')<p class="mt-1 text-sm text-red-600">{{ $message }}</p>@enderror
    </div>

    {{-- Boutons d'action --}}
    <div class="flex justify-end space-x-3">
      <a href="{{ route('groups.index') }}" class="px-4 py-2 bg-gray-200 text-gray-700 rounded hover:bg-gray-300">Annuler</a>
      <button
        type="submit"
        class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700 transition"
      >
        Enregistrer
      </button>
    </div>
  </form>
</div>
@endsection
