<x-app-layout>

    <x-module-hero
        title="Edit Hero Card"
        :description="$heroCard->title"
        icon="fa-edit"
    >
        <x-slot name="backButton">
            <a href="{{ route('admin.hero-cards.index') }}"
               class="inline-flex items-center gap-2 text-[#475569] hover:text-[#1e293b] text-sm transition">
                <i class="fas fa-arrow-left"></i> Back to Hero Cards
            </a>
        </x-slot>
        <x-slot name="tabs">
            @role('Manager|Super Manager')
            <a href="{{ route('admin.sliders.index') }}"
               class="module-hero-tab {{ request()->routeIs('admin.sliders.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                      inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                      md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                <i class="fas fa-images text-sm"></i> Hero Slider
            </a>
            <a href="{{ route('admin.hero-cards.index') }}"
               class="module-hero-tab {{ request()->routeIs('admin.hero-cards.index') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                      inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                      md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                <i class="fas fa-th-large text-sm"></i> All Cards
            </a>
            <a href="{{ route('admin.hero-cards.create') }}"
               class="module-hero-tab {{ request()->routeIs('admin.hero-cards.create') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                      inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                      md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                <i class="fas fa-plus text-sm"></i> Add Card
            </a>
            @endrole
            @can('manage what we do images')
            <a href="{{ route('admin.what-we-do-images.index') }}"
               class="module-hero-tab {{ request()->routeIs('admin.what-we-do-images.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                      inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                      md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                <i class="fas fa-image text-sm"></i> What We Do Images
            </a>
            @endcan
            @can('view pages')
            <a href="{{ route('admin.pages.index') }}"
               class="module-hero-tab {{ request()->routeIs('admin.pages.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                      inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                      md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                <i class="fas fa-file-alt text-sm"></i> Pages
            </a>
            @endcan
        </x-slot>
    </x-module-hero>

    <div class="p-6">

        @if($errors->any())
            <div class="mb-6 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg">
                <div class="flex items-center gap-2 mb-2">
                    <i class="fas fa-exclamation-circle"></i>
                    <strong>Please fix the following errors:</strong>
                </div>
                <ul class="list-disc list-inside space-y-1 text-sm">
                    @foreach($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-6 max-w-3xl">
            <form action="{{ route('admin.hero-cards.update', $heroCard) }}" method="POST">
                @csrf
                @method('PUT')

                <div class="mb-6">
                    <h3 class="text-base font-semibold text-gray-800 border-b border-gray-200 pb-3 mb-4">
                        <i class="fas fa-th-large mr-2 text-teal-600"></i> Card Details
                    </h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-5">
                        {{-- Title --}}
                        <div class="md:col-span-2">
                            <label for="title" class="block text-sm font-medium text-gray-700 mb-1">
                                Card Title <span class="text-red-500">*</span>
                            </label>
                            <input type="text" id="title" name="title"
                                   value="{{ old('title', $heroCard->title) }}"
                                   maxlength="191"
                                   class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-teal-500 focus:border-transparent @error('title') border-red-400 @enderror">
                            @error('title')<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
                        </div>

                        {{-- Content --}}
                        <div class="md:col-span-2">
                            <label for="content" class="block text-sm font-medium text-gray-700 mb-1">
                                Card Content / Subtitle <span class="text-red-500">*</span>
                            </label>
                            <textarea id="content" name="content" rows="3" maxlength="2000"
                                      class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-teal-500 focus:border-transparent @error('content') border-red-400 @enderror">{{ old('content', $heroCard->content) }}</textarea>
                            @error('content')<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
                        </div>

                        {{-- Background Color --}}
                        <div class="md:col-span-2" x-data="{ color: '{{ old('background_color', $heroCard->background_color) }}' }">
                            <label for="background_color" class="block text-sm font-medium text-gray-700 mb-1">
                                Background Color <span class="text-red-500">*</span>
                            </label>
                            <div class="flex items-center gap-3">
                                <input type="text" id="background_color" name="background_color"
                                       value="{{ old('background_color', $heroCard->background_color) }}"
                                       maxlength="50" placeholder="bg-red-600"
                                       x-model="color"
                                       class="flex-1 px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-teal-500 focus:border-transparent @error('background_color') border-red-400 @enderror">
                                <div class="w-12 h-10 rounded-lg border border-gray-200 shadow-sm flex-shrink-0"
                                     :class="color"></div>
                            </div>
                            @error('background_color')<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
                            <p class="mt-1 text-xs text-gray-400">
                                Use a Tailwind CSS class, e.g.
                                <code class="bg-gray-100 px-1 rounded">bg-red-600</code>,
                                <code class="bg-gray-100 px-1 rounded">bg-green-600</code>,
                                <code class="bg-gray-100 px-1 rounded">bg-blue-900</code>
                            </p>
                        </div>

                        {{-- Order --}}
                        <div>
                            <label for="order" class="block text-sm font-medium text-gray-700 mb-1">
                                Display Order
                            </label>
                            <input type="number" id="order" name="order"
                                   value="{{ old('order', $heroCard->order) }}" min="0"
                                   class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-teal-500 focus:border-transparent @error('order') border-red-400 @enderror">
                            @error('order')<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
                            <p class="mt-1 text-xs text-gray-400">Lower numbers appear first (left to right).</p>
                        </div>

                        {{-- Is Active --}}
                        <div class="flex flex-col justify-center">
                            <label class="block text-sm font-medium text-gray-700 mb-3">Visibility</label>
                            <label class="inline-flex items-center gap-3 cursor-pointer">
                                <input type="checkbox" name="is_active" value="1"
                                       {{ old('is_active', $heroCard->is_active) ? 'checked' : '' }}
                                       class="h-4 w-4 text-teal-600 rounded focus:ring-teal-500">
                                <span class="text-sm text-gray-700">Active (visible on homepage)</span>
                            </label>
                        </div>
                    </div>
                </div>

                <div class="flex items-center justify-between pt-4 border-t border-gray-100">
                    {{-- Delete --}}
                    <form action="{{ route('admin.hero-cards.destroy', $heroCard) }}" method="POST"
                          onsubmit="return confirm('Delete this hero card? This cannot be undone.')">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="btn-action-delete">
                            <i class="fas fa-trash"></i> Delete
                        </button>
                    </form>

                    <div class="flex items-center gap-3">
                        <a href="{{ route('admin.hero-cards.index') }}"
                           class="px-5 py-2.5 bg-gray-100 text-gray-700 font-medium rounded-lg hover:bg-gray-200 transition">
                            Cancel
                        </a>
                        <button type="submit"
                                class="px-5 py-2.5 bg-[#1a4731] text-white font-semibold rounded-lg hover:bg-[#276749] transition">
                            <i class="fas fa-save mr-2"></i> Update Card
                        </button>
                    </div>
                </div>
            </form>
        </div>

    </div>
</x-app-layout>
