@component('admin/layouts/main')
  @slot('main')
    <h1 class="text-2xl font-bold mb-6">{{ music ? 'Modifier la musique' : 'Nouvelle musique' }}</h1>
    <form action="{{ music ? `/admin/music/${music.id}` : '/admin/music' }}?_method={{ music ? 'PUT' : 'POST' }}" method="post" enctype="multipart/form-data" class="bg-white p-6 rounded shadow max-w-xl">
      {{{ csrfField() }}}
      <div class="space-y-4">
        <div>
          <label for="name" class="block text-sm font-medium text-gray-700 mb-1">Nom</label>
          <input type="text" name="name" id="name" value="{{ music?.name || '' }}" required
            class="w-full px-3 py-2 border rounded" />
        </div>
        <div>
          <label for="file" class="block text-sm font-medium text-gray-700 mb-1">Fichier Audio (MP3)</label>
          @if(music && music.url)
            <div class="mb-2 text-sm text-gray-600">
                Fichier actuel: <a href="{{ music.url }}" target="_blank" class="text-blue-600 hover:underline">{{ music.url }}</a>
                <audio controls src="{{ music.url }}" class="mt-2 w-full"></audio>
            </div>
          @endif
          <input type="file" name="file" id="file" accept=".mp3,.wav,.ogg" {{ music ? '' : 'required' }}
            class="w-full px-3 py-2 border rounded" />
        </div>
        <button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">
          Enregistrer
        </button>
      </div>
    </form>
  @endslot
@end
