{{-- Condition inputs, driven entirely by ConditionSchema::kind() --}}
@php
    use App\Domain\Pricing\Support\ConditionSchema;
@endphp

@if($kind === ConditionSchema::KIND_RANGE)
    <div class="grid grid-cols-2 gap-3">
        <div>
            <label class="block text-xs text-gray-500 mb-1">
                {{ __('من') }} @if($unit)<span class="text-gray-400">({{ $unit }})</span>@endif
            </label>
            <input type="number" min="0" dir="ltr" wire:model.live.debounce.400ms="conditions.min"
                   class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500">
            @error('conditions.min') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
        </div>
        <div>
            <label class="block text-xs text-gray-500 mb-1">
                {{ __('إلى') }} @if($unit)<span class="text-gray-400">({{ $unit }})</span>@endif
            </label>
            <input type="number" min="0" dir="ltr" wire:model.live.debounce.400ms="conditions.max"
                   class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500">
            @error('conditions.max') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror
        </div>
    </div>

@elseif($kind === ConditionSchema::KIND_LIST)
    @php
        $options = match($ruleType) {
            'gender' => collect(ConditionSchema::GENDERS)->mapWithKeys(fn($g) => [$g => $g === 'male' ? __('ذكور') : __('إناث')]),
            'classification' => collect(ConditionSchema::CLASSIFICATIONS)->mapWithKeys(fn($c) => [$c => ConditionSchema::classificationLabel($c)]),
            default => $branches->mapWithKeys(fn($b) => [(string) $b->id => $b->name_ar]),
        };
    @endphp
    <div class="flex flex-wrap gap-2">
        @foreach($options as $value => $label)
            <label class="cursor-pointer">
                <input type="checkbox" value="{{ $value }}" wire:model.live="conditions.values" class="peer sr-only">
                <span class="inline-block px-3 py-1.5 rounded-full border-2 text-sm font-medium
                             border-gray-200 text-gray-600
                             peer-checked:border-emerald-500 peer-checked:bg-emerald-50 peer-checked:text-emerald-700">
                    {{ $label }}
                </span>
            </label>
        @endforeach
    </div>
    @error('conditions.values') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror

@elseif($kind === ConditionSchema::KIND_MONTHS)
    <div class="flex flex-wrap gap-2">
        @for($m = 1; $m <= 12; $m++)
            <label class="cursor-pointer">
                <input type="checkbox" value="{{ $m }}" wire:model.live="conditions.months" class="peer sr-only">
                <span class="inline-block px-3 py-1.5 rounded-full border-2 text-sm font-medium
                             border-gray-200 text-gray-600
                             peer-checked:border-emerald-500 peer-checked:bg-emerald-50 peer-checked:text-emerald-700">
                    {{ ConditionSchema::monthLabel($m) }}
                </span>
            </label>
        @endfor
    </div>
    @error('conditions.months') <p class="text-red-500 text-xs mt-1">{{ $message }}</p> @enderror

@elseif($kind === ConditionSchema::KIND_SCHED)
    <div class="space-y-3">
        <div class="flex flex-wrap gap-2">
            @foreach(ConditionSchema::WEEKDAYS as $day)
                <label class="cursor-pointer">
                    <input type="checkbox" value="{{ $day }}" wire:model.live="conditions.days" class="peer sr-only">
                    <span class="inline-block px-3 py-1.5 rounded-full border-2 text-sm font-medium
                                 border-gray-200 text-gray-600
                                 peer-checked:border-emerald-500 peer-checked:bg-emerald-50 peer-checked:text-emerald-700">
                        {{ ConditionSchema::dayLabel($day) }}
                    </span>
                </label>
            @endforeach
        </div>
        <div class="grid grid-cols-2 gap-3">
            <div>
                <label class="block text-xs text-gray-500 mb-1">{{ __('بعد الساعة') }}</label>
                <input type="number" min="0" max="23" dir="ltr" wire:model.live.debounce.400ms="conditions.after_hour"
                       class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500">
            </div>
            <div>
                <label class="block text-xs text-gray-500 mb-1">{{ __('قبل الساعة') }}</label>
                <input type="number" min="0" max="23" dir="ltr" wire:model.live.debounce.400ms="conditions.before_hour"
                       class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500">
            </div>
        </div>
    </div>

@elseif($kind === ConditionSchema::KIND_TIMING)
    <div class="grid grid-cols-1 sm:grid-cols-3 gap-3">
        <div>
            <label class="block text-xs text-gray-500 mb-1">{{ __('قبل البداية بـ (يوم)') }}</label>
            <input type="number" min="1" max="365" dir="ltr" wire:model.live.debounce.400ms="conditions.days_before_start"
                   class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500">
        </div>
        <div>
            <label class="block text-xs text-gray-500 mb-1">{{ __('يبدأ من') }}</label>
            <input type="date" dir="ltr" wire:model.live="conditions.after_date"
                   class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500">
        </div>
        <div>
            <label class="block text-xs text-gray-500 mb-1">{{ __('ينتهي في') }}</label>
            <input type="date" dir="ltr" wire:model.live="conditions.before_date"
                   class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-emerald-500">
        </div>
    </div>

@else
    <div class="p-3 bg-amber-50 border border-amber-200 rounded-lg text-sm text-amber-800">
        {{ __('خصم يدوي — لا يُطبق تلقائياً، يُختار من قائمة الخصومات عند الدفع') }}
    </div>
@endif
