<?php

declare(strict_types=1);

namespace App\Filament\Components\Form;

use Filament\Forms\Components\Select;

class AddressSelect extends Select
{
    public static function create(): static
    {
        return parent::make('address_id')
            ->label('آدرس')
            ->relationship('address', 'address')
            ->getOptionLabelFromRecordUsing(
                fn ($record) => (isset($record->first_name) || isset($record->last_name)
                    ? trim($record->first_name . ' ' . $record->last_name) . ' | '
                    : '') .
                $record->phone . ' | ' .
                (isset($record->county->province) && $record->county?->province?->name ? $record->county->province->name . ' | ' : '') .
                (isset($record->county) && $record->county?->name ? $record->county->name . ' | ' : '') .
                $record->address . ' | ' .
                $record->postal_code
            )
            ->searchable(['address', 'phone'])
            ->preload()
            ->allowHtml()
            ->columnSpan(12);
    }
}
