@extends('layouts.app')

@section('title', 'Create Gallery')

@section('content')
<x-app-layout>
    <x-module-hero
        title="Create Gallery"
        description="Set up a new image gallery"
        icon="fa-image">

        <x-slot name="backButton">
            <a href="{{ route('media.galleries.index') }}"
               class="inline-flex items-center gap-2 text-[#475569] hover:text-[#1e293b] text-sm transition">
                <i class="fas fa-arrow-left text-xs"></i> Back to Galleries
            </a>
        </x-slot>
    </x-module-hero>

    <div class="p-6 max-w-3xl">
        {{-- Error Summary --}}
        @if ($errors->any())
        <div class="mb-6 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg">
            <p class="font-semibold flex items-center gap-2">
                <i class="fas fa-exclamation-circle"></i> Please fix the errors below:
            </p>
            <ul class="list-disc list-inside text-sm mt-2">
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
        @endif

        {{-- Create Form --}}
        <form action="{{ route('media.galleries.store') }}" method="POST"
              class="bg-white rounded-lg shadow-sm border border-gray-200 p-8">
            @csrf

            {{-- Gallery Information --}}
            <h3 class="text-lg font-semibold text-gray-800 border-b pb-3 mb-6">Gallery Information</h3>

            {{-- Organization Selection --}}
            <div class="mb-6">
                <label class="block text-sm font-medium text-gray-700 mb-2">
                    Organization <span class="text-red-500">*</span>
                </label>
                <select name="organization_id"
                    class="w-full px-4 py-2 border {{ $errors->has('organization_id') ? 'border-red-500' : 'border-gray-300' }} rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
                    required>
                    <option value="">Select an organization...</option>
                    @foreach($organizations as $org)
                        <option value="{{ $org->id }}" {{ old('organization_id', $selectedOrganization) == $org->id ? 'selected' : '' }}>
                            {{ $org->name }}
                        </option>
                    @endforeach
                </select>
                @error('organization_id')
                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                @enderror
            </div>

            {{-- Gallery Type --}}
            <div class="mb-6">
                <label class="block text-sm font-medium text-gray-700 mb-2">
                    Gallery Type <span class="text-red-500">*</span>
                </label>
                <select name="gallery_type_id"
                    class="w-full px-4 py-2 border {{ $errors->has('gallery_type_id') ? 'border-red-500' : 'border-gray-300' }} rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
                    required>
                    <option value="">Select a gallery type...</option>
                    @foreach($galleryTypes as $type)
                        <option value="{{ $type->id }}" {{ old('gallery_type_id') == $type->id ? 'selected' : '' }}>
                            <i class="fas {{ $type->icon }}"></i> {{ $type->name }}
                        </option>
                    @endforeach
                </select>
                @error('gallery_type_id')
                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                @enderror
            </div>

            {{-- Gallery Title --}}
            <div class="mb-6">
                <label class="block text-sm font-medium text-gray-700 mb-2">
                    Gallery Title <span class="text-red-500">*</span>
                </label>
                <input type="text" name="title"
                       value="{{ old('title') }}"
                       placeholder="e.g., Annual Conference 2024, Team Building Activity"
                       class="w-full px-4 py-2 border {{ $errors->has('title') ? 'border-red-500' : 'border-gray-300' }} rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
                       required>
                @error('title')
                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                @enderror
            </div>

            {{-- Gallery Description --}}
            <div class="mb-6">
                <label class="block text-sm font-medium text-gray-700 mb-2">
                    Description <span class="text-gray-400 text-xs">(optional)</span>
                </label>
                <textarea name="description" rows="4"
                          placeholder="Provide details about this gallery..."
                          class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">{{ old('description') }}</textarea>
                @error('description')
                <p class="mt-1 text-sm text-red-600">{{ $message }}</p>
                @enderror
            </div>

            {{-- Publication Status --}}
            <div class="mb-8 pb-8 border-b border-gray-200">
                <label class="flex items-center gap-3">
                    <input type="checkbox" name="is_published" value="1"
                           {{ old('is_published', true) ? 'checked' : '' }}
                           class="w-5 h-5 text-blue-600 rounded focus:ring-2 focus:ring-blue-500 cursor-pointer">
                    <span class="text-sm font-medium text-gray-700">Publish this gallery immediately</span>
                </label>
                <p class="text-xs text-gray-500 mt-2 ml-8">Gallery will be visible in the media section if published.</p>
            </div>

            {{-- Form Actions --}}
            <div class="flex gap-3">
                <button type="submit"
                    class="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition font-medium flex items-center gap-2">
                    <i class="fas fa-check"></i> Create Gallery
                </button>
                <a href="{{ route('media.galleries.index') }}"
                   class="px-6 py-2 bg-gray-300 text-gray-700 rounded-lg hover:bg-gray-400 transition font-medium flex items-center gap-2">
                    <i class="fas fa-times"></i> Cancel
                </a>
            </div>
        </form>
    </div>
</x-app-layout>
@endsection
