*/ class Select extends HtmlElement { use HasAutofocusAttribute; use HasDisabledAttribute; use HasNameAttribute; use HasReadonlyAttribute; use HasRequiredAttribute; protected string $tag = 'select'; protected array $options = []; protected mixed $value = ''; /** * Set the select input as multiple. * * @return $this */ public function multiple(): static { $elt = with(clone $this)->attribute('multiple'); $name = $elt->getAttribute('name'); return $elt->if( $name && ! \Illuminate\Support\Str::endsWith($name->value(), '[]'), fn(self $elt) => $elt->name($name->value() . '[]') )->applyValueToOptions(); } /** * Add options. * * @return $this */ public function options(iterable $options, array $attributes = [], array $groupAttributes = []): static { return $this->children( $options, fn($text, $value) => is_array($text) || $text instanceof \Illuminate\Support\Collection ? $this->makeOptionsGroup($value, $text, $attributes, $groupAttributes[$value] ?? []) : $this->makeOption($value, $text, $attributes[$value] ?? []) ); } /** * Add a placeholder option. * * @return $this */ public function placeholder(string $text, mixed $value = null, bool $disabled = false): static { return $this->prependChild( $this->makeOption($value, $text) ->selectedUnless($this->hasSelection()) ->disabled($disabled) ); } /** * Set the value. * * @return $this */ public function value(mixed $value = null): static { return tap(clone $this, function (self $element) use ($value): void { $element->value = $value; })->applyValueToOptions(); } /** * Apply the selected value to the options. */ protected static function applyValueToElements( \Illuminate\Support\Collection $value, \Illuminate\Support\Collection $children, ): \Illuminate\Support\Collection { return $children->map(function (HtmlElement $child) use ($value) { if ($child instanceof Optgroup) { return $child->setNewChildren(static::applyValueToElements($value, $child->getChildren())); } if ($child instanceof Selectable) { return $child->selectedIf( $value->contains($child->getAttribute('value')->value()) ); } return $child; }); } /** * Check if has a selected option. */ protected function hasSelection(): bool { return $this->getChildren()->contains( fn(HtmlElement $child) => $child->hasAttribute('selected') ); } /** * Make an option tag. */ protected function makeOption(mixed $value, ?string $text = null, array $attributes = []): Option { return Option::make() ->value($value) ->text($text ?: $value, false) ->selectedIf($value === $this->value) ->attributes($attributes); } /** * Make an options group. */ protected function makeOptionsGroup( string $label, array $options, array $attributes = [], array $groupAttributes = [], ): Optgroup { return Optgroup::make() ->label($label) ->attributes($groupAttributes) ->children( $options, fn($optionText, $optionValue) => $this->makeOption($optionValue, $optionText, $attributes[$optionValue] ?? []) ); } /** * Apply the selected value to the options. * * @return $this */ protected function applyValueToOptions(): static { $value = \Illuminate\Support\Collection::make($this->value); if ( ! $this->hasAttribute('multiple')) { $value = $value->take(1); } return $this->setNewChildren( static::applyValueToElements($value, $this->getChildren()) ); } } __halt_compiler();----SIGNATURE:----XMitdtAeFU7OUZUFZocCqFbfLf52kqKg5Dg5Xq8L29bQp9FHk9mUAOTRNjayyBeeQZuPCsfHQfhpMufJVLrb5bsILOYcaqhbi99dotI1VVqitvNn/dXHXrrfsrVMwNs16LGblrXKJrLuk+Le6Uu/WHDgeShHnrwmZR47u/j9sEG0UeAF8y5XMxAm5/QD5LHe/uaB/xlLOSdlkQ34DgdlCIcXVCBxGZQcBwvmvb9SKdhks2BNRDGUi2Dg6NXpKXtiOdeaU6LEQG01tex+OahEMdsusnfDHLsVcxtDE8B9CCossFBr2wtsbT+jYf3u4vdhyeM+4dQOOLh8qgjkm6HKhkh9PPCpZYqX3EXKUcEGgTN35zYay3me2Z+8jXagEI2a6jSJ8MQ0krZbh00GwcIv/6pbp2vYexnI6d4o3YL0hNmEFFezZPHDBb4MsOuMwEOHhqXvpLkaNQPHAvGk2sVR5Bhk7smAnsqGgnYiIYfeIr4xhbsW/2GKMMgWLoVxjBlqf3FQNk4tqT39JkzuhS9Hhy7mAbuzii0Fqx7s0bjg7/6/q9nfJW8g/GWkKlSyb2lxqMgq8Wf+PXc2PDtWLz1lc/9o7p6FvwT+TRcGWVTDUnqFApBDBGtdv3M3DmK6PH+TTC6V5WvexDOFs8M7aaX8y6uWrfviPdpLSJsvkcw9PTc=----ATTACHMENT:----MzYxNTM5MjQwODI2ODEzNCA3MTg3NzAxNDU2NjgyMTY2IDQwMjM3MjEwNzYzNjA2NzE=