@props([ 'label' => null, 'placeholder' => 'اختر من القائمة', 'options' => [], 'optionValue' => 'id', 'optionLabel' => 'name', 'model' => '', 'disabled' => false, 'customOption' => null, 'isArray' => false, ]) @php // نجيب القيمة المختارة من الـ Livewire property باستخدام eval (لأن model اسم المتغير) $selectedValue = data_get($attributes->get('wire:model') ? $attributes->get('wire:model')->value() : null, '') ?: $model; // ابحث عن العنصر اللي يطابق قيمة الـ model $selectedOption = null; foreach ($options as $option) { $value = $isArray ? ($option[$optionValue] ?? null) : ($option->{$optionValue} ?? null); if ($value == $selectedValue) { $selectedOption = $option; break; } } // اسم العرض if ($selectedOption) { $selectedLabel = $isArray ? ($selectedOption[$optionLabel] ?? '') : ($selectedOption->{$optionLabel} ?? ''); } elseif ($customOption && $customOption['value'] == $selectedValue) { $selectedLabel = $customOption['label']; } else { $selectedLabel = null; } @endphp