<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>
    </div>

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

    <form wire:submit="save" class="space-y-4 sm:space-y-6">
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 sm:p-6">
            <h2 class="text-base sm:text-lg font-semibold text-gray-700 mb-4">{{ __('بيانات التسوية') }}</h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-3 sm:gap-4">
                {{-- Product --}}
                <div>
                    <label for="product_id" class="block text-sm font-medium text-gray-700 mb-1">{{ __('المنتج') }} *</label>
                    <select id="product_id" wire:model="product_id"
                            class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm @error('product_id') border-red-500 @enderror">
                        <option value="">{{ __('-- اختر المنتج --') }}</option>
                        @foreach($products as $product)
                        <option value="{{ $product->id }}">{{ $product->name_ar }} ({{ $product->sku }})</option>
                        @endforeach
                    </select>
                    @error('product_id') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
                </div>

                {{-- Warehouse --}}
                <div>
                    <label for="warehouse_id" class="block text-sm font-medium text-gray-700 mb-1">{{ __('المستودع') }} *</label>
                    <select id="warehouse_id" wire:model="warehouse_id"
                            class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm @error('warehouse_id') border-red-500 @enderror">
                        <option value="">{{ __('-- اختر المستودع --') }}</option>
                        @foreach($warehouses as $warehouse)
                        <option value="{{ $warehouse->id }}">{{ $warehouse->name_ar }} ({{ $warehouse->code }})</option>
                        @endforeach
                    </select>
                    @error('warehouse_id') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
                </div>

                {{-- Adjustment Type --}}
                <div>
                    <label for="adjustment_type" class="block text-sm font-medium text-gray-700 mb-1">{{ __('نوع التسوية') }} *</label>
                    <select id="adjustment_type" wire:model="adjustment_type"
                            class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm @error('adjustment_type') border-red-500 @enderror">
                        <option value="adjustment_up">{{ __('تسوية بالزيادة (إضافة)') }}</option>
                        <option value="adjustment_down">{{ __('تسوية بالنقص (خصم)') }}</option>
                    </select>
                    @error('adjustment_type') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
                </div>

                {{-- Quantity --}}
                <div>
                    <label for="quantity" class="block text-sm font-medium text-gray-700 mb-1">{{ __('الكمية') }} *</label>
                    <input type="number" id="quantity" wire:model="quantity" min="1" dir="ltr"
                           class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm @error('quantity') border-red-500 @enderror">
                    @error('quantity') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
                </div>

                {{-- Reference Number --}}
                <div>
                    <label for="reference_number" class="block text-sm font-medium text-gray-700 mb-1">{{ __('رقم مرجعي') }}</label>
                    <input type="text" id="reference_number" wire:model="reference_number" dir="ltr"
                           class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm @error('reference_number') border-red-500 @enderror"
                           placeholder="{{ __('اختياري') }}">
                    @error('reference_number') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
                </div>

                {{-- Reason --}}
                <div class="md:col-span-2">
                    <label for="reason" class="block text-sm font-medium text-gray-700 mb-1">{{ __('سبب التسوية') }} *</label>
                    <textarea id="reason" wire:model="reason" rows="3"
                              class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 text-sm @error('reason') border-red-500 @enderror"
                              placeholder="{{ __('أدخل سبب التسوية...') }}"></textarea>
                    @error('reason') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
                </div>
            </div>
        </div>

        {{-- Actions --}}
        <div class="flex flex-col-reverse sm:flex-row gap-3">
            <button type="submit" wire:loading.attr="disabled" wire:target="save"
                    class="w-full sm:w-auto px-6 py-2.5 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 disabled:bg-blue-400 transition-colors text-sm">
                <span wire:loading.remove wire:target="save">{{ __('تنفيذ التسوية') }}</span>
                <span wire:loading wire:target="save">{{ __('جارٍ التنفيذ...') }}</span>
            </button>
        </div>
    </form>
</div>
