<div>
    @if($submitted)
        {{-- Success --}}
        <div class="bg-green-50 border border-green-200 rounded-2xl p-8 text-center">
            <div class="w-16 h-16 mx-auto bg-green-100 rounded-full flex items-center justify-center mb-4">
                <svg class="w-8 h-8 text-green-600" 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>
            </div>
            <h3 class="text-xl font-bold text-green-800 mb-2">{{ __('تم التسجيل بنجاح!') }}</h3>
            <p class="text-green-700 mb-4">{{ __('رقم التسجيل الخاص بك:') }}</p>
            <div class="inline-block bg-white border-2 border-green-300 rounded-xl px-6 py-3">
                <span class="text-2xl font-mono font-bold text-green-800" dir="ltr">{{ $registrationNumber }}</span>
            </div>
            <p class="text-sm text-green-600 mt-4">{{ __('يرجى الاحتفاظ بهذا الرقم للمتابعة') }}</p>
        </div>
    @else
        {{-- Registration Form --}}
        <form wire:submit="submit" class="space-y-5">
            @error('form')
                <div class="p-4 bg-red-50 border border-red-200 rounded-xl text-red-700 text-sm">{{ $message }}</div>
            @enderror

            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                @foreach($event->form_fields as $field)
                    <div class="{{ $field['width'] === 'full' ? 'md:col-span-2' : '' }}">
                        <label class="block text-sm font-medium text-gray-700 mb-1">
                            {{ $field['label'] }}
                            @if($field['is_required']) <span class="text-red-500">*</span> @endif
                        </label>

                        @switch($field['type'])
                            @case('text')
                            @case('email')
                            @case('phone')
                            @case('number')
                                <input type="{{ $field['type'] === 'phone' ? 'tel' : $field['type'] }}"
                                       wire:model="fields.{{ $field['key'] }}"
                                       placeholder="{{ $field['placeholder'] ?? '' }}"
                                       @if(in_array($field['type'], ['email', 'phone', 'number'])) dir="ltr" @endif
                                       class="w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 @error('fields.'.$field['key']) border-red-500 @enderror">
                                @break

                            @case('textarea')
                                <textarea wire:model="fields.{{ $field['key'] }}" rows="3"
                                          placeholder="{{ $field['placeholder'] ?? '' }}"
                                          class="w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 @error('fields.'.$field['key']) border-red-500 @enderror"></textarea>
                                @break

                            @case('date')
                                <input type="date" wire:model="fields.{{ $field['key'] }}" dir="ltr"
                                       class="w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 @error('fields.'.$field['key']) border-red-500 @enderror">
                                @break

                            @case('select')
                                <select wire:model="fields.{{ $field['key'] }}"
                                        class="w-full px-4 py-3 border border-gray-300 rounded-xl text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 @error('fields.'.$field['key']) border-red-500 @enderror">
                                    <option value="">{{ $field['placeholder'] ?? __('اختر...') }}</option>
                                    @foreach($field['options'] ?? [] as $option)
                                        <option value="{{ $option['value'] }}">{{ $option['label'] }}</option>
                                    @endforeach
                                </select>
                                @break

                            @case('multi_select')
                                <div class="space-y-2 border border-gray-300 rounded-xl p-3 @error('fields.'.$field['key']) border-red-500 @enderror">
                                    @foreach($field['options'] ?? [] as $option)
                                        <label class="flex items-center gap-2 cursor-pointer">
                                            <input type="checkbox" wire:model="fields.{{ $field['key'] }}" value="{{ $option['value'] }}" class="rounded text-blue-600 focus:ring-blue-500">
                                            <span class="text-sm text-gray-700">{{ $option['label'] }}</span>
                                        </label>
                                    @endforeach
                                </div>
                                @break

                            @case('checkbox')
                                <label class="flex items-center gap-2 cursor-pointer">
                                    <input type="checkbox" wire:model="fields.{{ $field['key'] }}" class="rounded text-blue-600 focus:ring-blue-500">
                                    <span class="text-sm text-gray-700">{{ $field['placeholder'] ?? $field['label'] }}</span>
                                </label>
                                @break
                        @endswitch

                        @error('fields.'.$field['key']) <p class="mt-1 text-xs text-red-600">{{ $message }}</p> @enderror
                    </div>
                @endforeach
            </div>

            <button type="submit" wire:loading.attr="disabled" wire:target="submit"
                    class="w-full py-3.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 transition-colors disabled:opacity-50">
                <span wire:loading.remove wire:target="submit">{{ __('تسجيل') }}</span>
                <span wire:loading wire:target="submit">{{ __('جارٍ التسجيل...') }}</span>
            </button>
        </form>
    @endif
</div>
