<x-layouts.app :title="__('New Ticket')">
    <div class="space-y-6">

        {{-- Header --}}
        <div class="flex items-center gap-3">
            <a href="{{ route('support.index') }}" class="p-1.5 text-muted/60 hover:text-ink rounded-lg hover:bg-surface transition-colors">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
                </svg>
            </a>
            <div>
                <h1 class="text-2xl font-bold text-ink">{{ __('Open a Ticket') }}</h1>
                <p class="mt-0.5 text-sm text-muted">{{ __('Tell us what you need help with. The more detail you share, the faster we can help.') }}</p>
            </div>
        </div>

        <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">

            {{-- Form --}}
            <div class="lg:col-span-2">
                <form method="POST" action="{{ route('support.store') }}"
                      x-data="{ submitting: false }" @submit="submitting = true"
                      class="space-y-5">
                    @csrf

                    <div class="bg-surface-2 rounded-2xl border border-border p-6 space-y-5">
                        <h2 class="text-base font-semibold text-ink">{{ __('Ticket Details') }}</h2>

                        <div>
                            <label for="subject" class="block text-sm font-medium text-ink/80 mb-1.5">{{ __('Subject') }}</label>
                            <input id="subject" type="text" name="subject" value="{{ old('subject') }}" required maxlength="255"
                                   class="input @error('subject') !border-danger !ring-danger/20 @enderror"
                                   placeholder="{{ __('Short summary of the issue') }}">
                            @error('subject') <p class="mt-1 text-xs text-danger">{{ $message }}</p> @enderror
                        </div>

                        <div class="grid sm:grid-cols-2 gap-4">
                            <div>
                                <label for="category" class="block text-sm font-medium text-ink/80 mb-1.5">
                                    {{ __('Category') }}
                                    <span class="text-muted/60 font-normal">({{ __('optional') }})</span>
                                </label>
                                <select id="category" name="category" class="input">
                                    <option value="">{{ __('— Select category —') }}</option>
                                    <option value="billing"   @selected(old('category') === 'billing')>{{ __('Billing') }}</option>
                                    <option value="technical" @selected(old('category') === 'technical')>{{ __('Technical Issue') }}</option>
                                    <option value="account"   @selected(old('category') === 'account')>{{ __('Account / Login') }}</option>
                                    <option value="feature"   @selected(old('category') === 'feature')>{{ __('Feature Request') }}</option>
                                    <option value="other"     @selected(old('category') === 'other')>{{ __('Other') }}</option>
                                </select>
                            </div>
                            <div>
                                <label for="priority" class="block text-sm font-medium text-ink/80 mb-1.5">{{ __('Priority') }}</label>
                                <select id="priority" name="priority" class="input">
                                    <option value="low"    @selected(old('priority') === 'low')>{{ __('Low') }}</option>
                                    <option value="normal" @selected(old('priority', 'normal') === 'normal')>{{ __('Normal') }}</option>
                                    <option value="high"   @selected(old('priority') === 'high')>{{ __('High') }}</option>
                                </select>
                            </div>
                        </div>

                        <div>
                            <label for="body" class="block text-sm font-medium text-ink/80 mb-1.5">{{ __('Describe your issue') }}</label>
                            <textarea id="body" name="body" required rows="8" maxlength="10000"
                                      class="input @error('body') !border-danger !ring-danger/20 @enderror"
                                      placeholder="{{ __('What were you doing, what happened, and what did you expect to happen?') }}">{{ old('body') }}</textarea>
                            @error('body') <p class="mt-1 text-xs text-danger">{{ $message }}</p> @enderror
                        </div>
                    </div>

                    <div class="flex items-center justify-end gap-3">
                        <a href="{{ route('support.index') }}" class="btn-secondary">{{ __('Cancel') }}</a>
                        <button type="submit" :disabled="submitting"
                                class="btn-primary inline-flex items-center gap-2"
                                :class="submitting && 'opacity-75 cursor-not-allowed'">
                            <span x-show="!submitting">{{ __('Submit Ticket') }}</span>
                            <span x-show="submitting" x-cloak class="inline-flex items-center gap-2">
                                <svg class="w-4 h-4 animate-spin" fill="none" viewBox="0 0 24 24">
                                    <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
                                    <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/>
                                </svg>
                                {{ __('Submitting...') }}
                            </span>
                        </button>
                    </div>
                </form>
            </div>

            {{-- Tips sidebar --}}
            <div class="space-y-4">
                <div class="bg-surface-2 rounded-2xl border border-border p-5">
                    <h3 class="text-sm font-semibold text-ink mb-3">{{ __('Tips for a faster reply') }}</h3>
                    <ul class="space-y-2.5">
                        @foreach([
                            __('Be specific about what went wrong'),
                            __('Include steps to reproduce the issue'),
                            __('Select the correct category'),
                            __('One issue per ticket'),
                        ] as $tip)
                        <li class="flex items-start gap-2 text-sm text-muted">
                            <svg class="w-4 h-4 text-success mt-0.5 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                            </svg>
                            {{ $tip }}
                        </li>
                        @endforeach
                    </ul>
                </div>

                <div class="bg-brand/5 border border-brand/20 rounded-2xl p-5">
                    <div class="flex items-center gap-2 mb-1">
                        <svg class="w-4 h-4 text-brand" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
                        </svg>
                        <p class="text-sm font-semibold text-ink">{{ __('Response time') }}</p>
                    </div>
                    <p class="text-xs text-muted">{{ __('We typically reply within one business day.') }}</p>
                </div>
            </div>

        </div>
    </div>
</x-layouts.app>
