<?php

declare(strict_types=1);

namespace App\Filament\Components\Form;

use Filament\Forms\Components\Select;

class ParentSelect extends Select
{
    public static function create($model): static
    {
        return parent::make('parent_id')
            ->label('والد')
            ->options(function () use ($model) {
                $options = [];
                foreach ($model::all() as $item) {
                    if ($item->name) {
                        $options[$item->id] = $item->name;
                    } elseif ($item->title) {
                        $options[$item->id] = $item->title;
                    }
                }

                return $options;
            })
            ->searchable()
            ->preload()
            ->columnSpan(6);
    }
}
