<?php
/*
    * Created by VahabDev in Aparat Live
    * Website: https://pourfi.ir
    * Aparat Live: https://www.aparat.com/vahabdev/live
    * Aparat Channel: https://www.aparat.com/vahabdev
    * Rubika Channel: https://rubika.ir/vahabdev
    * Donate: https://reymit.ir/vahabdev
    * Telegram: https://t.me/vahabdev
*/


namespace App\Filament\Resources\ProductCategories\Schemas;

use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Components\Utilities\Set;
use Filament\Schemas\Schema;

class ProductCategorieForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('اطلاعات دسته‌بندی محصول')
                    ->schema([
                        TextInput::make('name')
                            ->required()
                            ->maxLength(255)
                            ->label('نام دسته‌بندی')
                            ->live(onBlur: true)
                            ->afterStateUpdated(function (Set $set, $state) {
                                $set('slug', \Str::slug($state));
                            }),

                        TextInput::make('slug')
                            ->required()
                            ->maxLength(255)
                            ->unique(ignoreRecord: true)
                            ->label('اسلاگ'),

                        Textarea::make('description')
                            ->label('توضیحات')
                            ->columnSpanFull(),

                        Select::make('parent_id')
                            ->label('والد')
                            ->relationship(
                                name: 'parent',
                                titleAttribute: 'name'
                            )
                            ->columnSpanFull()
                            ->searchable()
                            ->preload()
                            ->nullable(),
                    ])
                    ->columnSpanFull()
                    ->columns(2),
            ]);
    }
}
