<?php

declare(strict_types=1);

namespace App\Filament\Resources\MediaCategories\Schemas;

use App\Filament\Support\SelectOptionLabels;

use App\Models\MediaCategory;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class MediaCategoryForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema->components([
            Section::make('دسته‌بندی')
                ->schema([
                    TextInput::make('name')->label('نام')->required()->maxLength(255),
                    Select::make('parent_id')
                        ->label('شاخه اصلی')
                        ->relationship('parent', 'name')
                        ->getOptionLabelFromRecordUsing(fn ($record) => SelectOptionLabels::generic($record, 'name', 'دسته'))
                        ->searchable()
                        ->preload()
                        ->placeholder('— بدون والد'),
                    Select::make('type')
                        ->label('نوع')
                        ->options(MediaCategory::typeOptions())
                        ->default(MediaCategory::TYPE_GALLERY)
                        ->required(),
                    TextInput::make('sort_order')->label('ترتیب')->numeric()->default(0),
                ])
                ->columns(2),
        ]);
    }
}
