<div>
    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4 sm:mb-6">
        <h1 class="text-xl sm:text-2xl font-bold text-gray-800">{{ __('تسجيل مصروف') }}</h1>
        <a href="{{ route('expenses.list') }}" wire:navigate
           class="inline-flex items-center gap-1 text-sm text-gray-600 hover:text-gray-800">
            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 17l-5-5m0 0l5-5m-5 5h12"/></svg>
            {{ __('سجل المصروفات') }}
        </a>
    </div>

    @if(session('error'))
    <div class="mb-4 p-3 bg-red-50 border border-red-200 rounded-lg text-red-700 text-sm">{{ session('error') }}</div>
    @endif

    <form wire:submit="save" class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
        <div class="grid grid-cols-1 md:grid-cols-2 gap-4 sm:gap-6">
            {{-- Category --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('فئة المصروف') }} <span class="text-red-500">*</span></label>
                <select wire:model="category" class="w-full rounded-lg border-gray-300 text-sm py-2.5">
                    <option value="">{{ __('اختر الفئة') }}</option>
                    @foreach($categories as $cat)
                    <option value="{{ $cat->value }}">{{ $cat->label() }}</option>
                    @endforeach
                </select>
                @error('category') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Amount --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('المبلغ (ج.م)') }} <span class="text-red-500">*</span></label>
                <input type="number" wire:model="amount_display" dir="ltr" step="0.01" min="0"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5" placeholder="0.00">
                @error('amount_display') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Description --}}
            <div class="md:col-span-2">
                <label class="block text-sm text-gray-600 mb-1">{{ __('الوصف') }} <span class="text-red-500">*</span></label>
                <input type="text" wire:model="description"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5"
                       placeholder="{{ __('مثال: شراء أدوات تدريب للفريق الأول') }}">
                @error('description') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Recipient --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('المستلم / راحت لمين') }}</label>
                <input type="text" wire:model="recipient_name"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5"
                       placeholder="{{ __('اسم الشخص أو المحل') }}">
                @error('recipient_name') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Payment Source --}}
            <div class="md:col-span-2">
                <label class="block text-sm text-gray-600 mb-2">{{ __('الفلوس طلعت منين؟') }} <span class="text-red-500">*</span></label>
                <div class="grid grid-cols-2 sm:grid-cols-5 gap-2" x-data="{ method: @entangle('payment_method') }">
                    <label class="relative cursor-pointer">
                        <input type="radio" wire:model="payment_method" value="cash" class="peer sr-only">
                        <div class="peer-checked:ring-2 peer-checked:ring-green-500 peer-checked:border-green-500 peer-checked:bg-green-50 flex flex-col items-center gap-1.5 p-3 rounded-xl border-2 border-gray-200 hover:border-green-300 transition-all">
                            <svg class="w-7 h-7 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 9V7a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2m2 4h10a2 2 0 002-2v-6a2 2 0 00-2-2H9a2 2 0 00-2 2v6a2 2 0 002 2zm7-5a2 2 0 11-4 0 2 2 0 014 0z"/>
                            </svg>
                            <span class="text-xs font-medium text-gray-700">{{ __('من الخزنة (كاش)') }}</span>
                        </div>
                    </label>
                    <label class="relative cursor-pointer">
                        <input type="radio" wire:model="payment_method" value="card" class="peer sr-only">
                        <div class="peer-checked:ring-2 peer-checked:ring-blue-500 peer-checked:border-blue-500 peer-checked:bg-blue-50 flex flex-col items-center gap-1.5 p-3 rounded-xl border-2 border-gray-200 hover:border-blue-300 transition-all">
                            <svg class="w-7 h-7 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"/>
                            </svg>
                            <span class="text-xs font-medium text-gray-700">{{ __('فيزا / بطاقة') }}</span>
                        </div>
                    </label>
                    <label class="relative cursor-pointer">
                        <input type="radio" wire:model="payment_method" value="bank_transfer" class="peer sr-only">
                        <div class="peer-checked:ring-2 peer-checked:ring-purple-500 peer-checked:border-purple-500 peer-checked:bg-purple-50 flex flex-col items-center gap-1.5 p-3 rounded-xl border-2 border-gray-200 hover:border-purple-300 transition-all">
                            <svg class="w-7 h-7 text-purple-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 14v3m4-3v3m4-3v3M3 21h18M3 10h18M3 7l9-4 9 4M4 10h16v11H4V10z"/>
                            </svg>
                            <span class="text-xs font-medium text-gray-700">{{ __('تحويل بنكي') }}</span>
                        </div>
                    </label>
                    <label class="relative cursor-pointer">
                        <input type="radio" wire:model="payment_method" value="cheque" class="peer sr-only">
                        <div class="peer-checked:ring-2 peer-checked:ring-amber-500 peer-checked:border-amber-500 peer-checked:bg-amber-50 flex flex-col items-center gap-1.5 p-3 rounded-xl border-2 border-gray-200 hover:border-amber-300 transition-all">
                            <svg class="w-7 h-7 text-amber-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                            </svg>
                            <span class="text-xs font-medium text-gray-700">{{ __('شيك') }}</span>
                        </div>
                    </label>
                    <label class="relative cursor-pointer">
                        <input type="radio" wire:model="payment_method" value="other" class="peer sr-only">
                        <div class="peer-checked:ring-2 peer-checked:ring-gray-500 peer-checked:border-gray-500 peer-checked:bg-gray-50 flex flex-col items-center gap-1.5 p-3 rounded-xl border-2 border-gray-200 hover:border-gray-300 transition-all">
                            <svg class="w-7 h-7 text-gray-600" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h.01M12 12h.01M19 12h.01M6 12a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0zm7 0a1 1 0 11-2 0 1 1 0 012 0z"/>
                            </svg>
                            <span class="text-xs font-medium text-gray-700">{{ __('أخرى') }}</span>
                        </div>
                    </label>
                </div>
                @error('payment_method') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Receipt Reference --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('رقم الإيصال') }}</label>
                <input type="text" wire:model="receipt_reference" dir="ltr"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5">
                @error('receipt_reference') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Date --}}
            <div>
                <label class="block text-sm text-gray-600 mb-1">{{ __('تاريخ المصروف') }} <span class="text-red-500">*</span></label>
                <input type="date" wire:model="expense_date" dir="ltr"
                       class="w-full rounded-lg border-gray-300 text-sm py-2.5">
                @error('expense_date') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>

            {{-- Notes --}}
            <div class="md:col-span-2">
                <label class="block text-sm text-gray-600 mb-1">{{ __('ملاحظات') }}</label>
                <textarea wire:model="notes" rows="2"
                          class="w-full rounded-lg border-gray-300 text-sm py-2.5"></textarea>
            </div>

            {{-- Attachment --}}
            <div class="md:col-span-2">
                <label class="block text-sm text-gray-600 mb-1">{{ __('مرفق (إيصال / إثبات)') }}</label>
                @if($attachment && method_exists($attachment, 'getClientOriginalName'))
                <div class="flex items-center gap-3 p-3 bg-green-50 border border-green-200 rounded-lg mb-2">
                    <svg class="w-5 h-5 text-green-600 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                    </svg>
                    <span class="text-sm text-green-700 truncate">{{ $attachment->getClientOriginalName() }}</span>
                    <button type="button" wire:click="removeAttachment" class="ms-auto text-red-500 hover:text-red-700 text-xs">
                        {{ __('إزالة') }}
                    </button>
                </div>
                @endif
                <label class="flex flex-col items-center justify-center w-full h-28 border-2 border-dashed border-gray-300 rounded-lg cursor-pointer hover:border-amber-400 hover:bg-amber-50/50 transition-colors">
                    <div class="flex flex-col items-center">
                        <svg class="w-8 h-8 text-gray-400 mb-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/>
                        </svg>
                        <span class="text-xs text-gray-500">{{ __('اضغط لرفع صورة أو ملف PDF (حد أقصى :mb ميجابايت)', ['mb' => intdiv((int) config('uploads.max_kb'), 1024)]) }}</span>
                    </div>
                    {{-- image/* rather than an extension list: an extension list
                         greys out the camera roll on iOS and hides HEIC photos. --}}
                    <input type="file" wire:model="attachment" class="hidden" accept="image/*,.heic,.heif,application/pdf">
                </label>
                <div wire:loading wire:target="attachment" class="mt-1 text-xs text-amber-600">{{ __('جارٍ رفع الملف...') }}</div>
                @error('attachment') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
            </div>
        </div>

        {{-- Submit --}}
        <div class="mt-6 flex justify-end">
            <button type="submit" wire:loading.attr="disabled" wire:target="save"
                    class="inline-flex items-center gap-2 px-6 py-2.5 bg-emerald-600 text-white rounded-lg hover:bg-emerald-700 transition text-sm font-medium disabled:opacity-50">
                <span wire:loading.remove wire:target="save">{{ __('تسجيل المصروف') }}</span>
                <span wire:loading wire:target="save">{{ __('جارٍ الحفظ...') }}</span>
            </button>
        </div>
    </form>
</div>
