<x-app-layout>
<x-module-hero title="New Ticket" description="Submit a new support request" icon="fa-plus-circle">
    <x-slot name="backButton">
        <a href="{{ route('tickets.index') }}" class="inline-flex items-center gap-1 text-sm text-[#475569] hover:text-[#1e293b] transition-colors">
            <i class="fas fa-arrow-left text-xs"></i> Back to Tickets
        </a>
    </x-slot>
    <x-slot name="tabs">
        @can('view tickets')
        <a href="{{ route('tickets.index') }}"
           class="module-hero-tab {{ request()->routeIs('tickets.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-list text-sm"></i> All Tickets
        </a>
        @endcan
        @can('create tickets')
        <a href="{{ route('tickets.create') }}"
           class="module-hero-tab {{ request()->routeIs('tickets.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> New Ticket
        </a>
        @endcan
    </x-slot>
</x-module-hero>

<div class="p-6">
    @if(session('error'))
        <div class="mb-4 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg flex items-center gap-2">
            <i class="fas fa-exclamation-circle"></i> {{ session('error') }}
        </div>
    @endif

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <div class="lg:col-span-2">
            <form action="{{ route('tickets.store') }}" method="POST">
                @csrf

                {{-- Section: Ticket Details --}}
                <div class="mb-6">
                    <h3 class="text-lg font-semibold text-gray-800 border-b pb-2 mb-4">Ticket Details</h3>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                        <div class="md:col-span-2">
                            <label for="title" class="block text-sm font-medium text-gray-700 mb-1">
                                Subject <span class="text-red-500">*</span>
                            </label>
                            <input type="text" id="title" name="title"
                                value="{{ old('title') }}"
                                required
                                placeholder="Brief description of your issue"
                                class="w-full px-4 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-green-500 @error('title') border-red-400 @enderror">
                            @error('title')<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
                        </div>

                        <div>
                            <label for="priority" class="block text-sm font-medium text-gray-700 mb-1">
                                Priority <span class="text-red-500">*</span>
                            </label>
                            <select id="priority" name="priority" required
                                class="w-full px-4 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-green-500 @error('priority') border-red-400 @enderror">
                                <option value="">Select Priority</option>
                                <option value="low" {{ old('priority') == 'low' ? 'selected' : '' }}>Low — General inquiry</option>
                                <option value="medium" {{ old('priority') == 'medium' ? 'selected' : '' }}>Medium — Normal issue</option>
                                <option value="high" {{ old('priority') == 'high' ? 'selected' : '' }}>High — Urgent issue</option>
                                <option value="urgent" {{ old('priority') == 'urgent' ? 'selected' : '' }}>Urgent — Critical / System down</option>
                            </select>
                            @error('priority')<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
                        </div>

                        <div>
                            <label for="category" class="block text-sm font-medium text-gray-700 mb-1">
                                Category <span class="text-gray-400 text-xs">(optional)</span>
                            </label>
                            <input type="text" id="category" name="category"
                                value="{{ old('category') }}"
                                placeholder="e.g. Technical, Billing, General"
                                class="w-full px-4 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-green-500">
                        </div>
                    </div>
                </div>

                {{-- Section: Description --}}
                <div class="mb-6">
                    <h3 class="text-lg font-semibold text-gray-800 border-b pb-2 mb-4">Description</h3>
                    <div>
                        <label for="description" class="block text-sm font-medium text-gray-700 mb-1">
                            Detailed Description <span class="text-red-500">*</span>
                        </label>
                        <textarea id="description" name="description" rows="6" required
                            placeholder="Provide detailed information about your issue, including steps to reproduce if applicable..."
                            class="w-full px-4 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-green-500 @error('description') border-red-400 @enderror">{{ old('description') }}</textarea>
                        @error('description')<p class="mt-1 text-xs text-red-600">{{ $message }}</p>@enderror
                    </div>
                </div>

                <div class="flex items-center justify-end gap-3 pt-4 border-t border-gray-200">
                    <a href="{{ route('tickets.index') }}"
                       class="px-4 py-2 border border-gray-300 rounded-lg text-sm text-gray-700 hover:bg-gray-50 transition">
                        <i class="fas fa-times mr-1"></i> Cancel
                    </a>
                    <button type="submit"
                        class="px-6 py-2 bg-[#1e293b] text-white text-sm font-semibold rounded-lg hover:bg-[#334155] transition">
                        <i class="fas fa-paper-plane mr-1"></i> Submit Ticket
                    </button>
                </div>
            </form>
        </div>

        {{-- Help Sidebar --}}
        <div>
            <div class="bg-blue-50 border border-blue-200 rounded-lg p-5">
                <h4 class="font-semibold text-blue-800 mb-3 flex items-center gap-2">
                    <i class="fas fa-info-circle"></i> Before You Submit
                </h4>
                <ul class="space-y-2 text-sm text-blue-700">
                    <li class="flex items-start gap-2">
                        <i class="fas fa-check text-blue-500 mt-0.5 flex-shrink-0"></i>
                        Provide a clear, descriptive subject line
                    </li>
                    <li class="flex items-start gap-2">
                        <i class="fas fa-check text-blue-500 mt-0.5 flex-shrink-0"></i>
                        Include steps to reproduce any issues
                    </li>
                    <li class="flex items-start gap-2">
                        <i class="fas fa-check text-blue-500 mt-0.5 flex-shrink-0"></i>
                        Provide relevant details or screenshots in the description
                    </li>
                    <li class="flex items-start gap-2">
                        <i class="fas fa-check text-blue-500 mt-0.5 flex-shrink-0"></i>
                        Select the appropriate priority level
                    </li>
                </ul>
            </div>

            <div class="mt-4 bg-white border border-gray-200 rounded-lg p-5">
                <h4 class="font-semibold text-gray-800 mb-3">Priority Guide</h4>
                <div class="space-y-2 text-sm">
                    <div class="flex items-center gap-2">
                        <span class="px-2 py-0.5 bg-gray-100 text-gray-700 rounded text-xs font-semibold">Low</span>
                        <span class="text-gray-600">General questions, non-urgent</span>
                    </div>
                    <div class="flex items-center gap-2">
                        <span class="px-2 py-0.5 bg-blue-100 text-blue-700 rounded text-xs font-semibold">Medium</span>
                        <span class="text-gray-600">Normal issues affecting work</span>
                    </div>
                    <div class="flex items-center gap-2">
                        <span class="px-2 py-0.5 bg-orange-100 text-orange-700 rounded text-xs font-semibold">High</span>
                        <span class="text-gray-600">Urgent issues, significant impact</span>
                    </div>
                    <div class="flex items-center gap-2">
                        <span class="px-2 py-0.5 bg-red-100 text-red-700 rounded text-xs font-semibold">Urgent</span>
                        <span class="text-gray-600">Critical failure, system down</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</x-app-layout>
