<?php

namespace App\Filament\Admin\Resources\PackageCategories\Schemas;

use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class PackageCategoryForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Section::make('Basic Information')
                    ->schema([
                        Grid::make(2)
                            ->schema([
                                TextInput::make('en_name')
                                    ->required()
                                    ->live(onBlur: true)
                                    ->afterStateUpdated(function (string $state, callable $set, $record) {
                                        if ($record) {
                                            return;
                                        }

                                        $set('slug', str($state)->slug());
                                    }),

                                TextInput::make('slug')
                                    ->required()
                                    ->unique(ignoreRecord: true)
                                    ->disabled()
                                    ->dehydrated(),
                                TextInput::make('fa_name')
                                    ->required(),

                            ]),
                    ]),
                                    Section::make('Media & Status')
                    ->schema([
                        Grid::make(2)
                            ->schema([
                                FileUpload::make('thumbnail')
                                    ->image()
                                    ->imageEditor()
                                    ->multiple()
                                    ->disk('public')
                                    ->directory('package-categories/thumbnails')

                                    ->columnSpanFull(),

                                Toggle::make('is_active')
                                    ->required()
                                    ->default(true),
                            ]),
                    ]),

                Section::make('Descriptions')
                    ->schema([
                        Grid::make(1)
                            ->schema([
                                RichEditor::make('en_description')
                                    ->columnSpanFull(),

                                RichEditor::make('fa_description')
                                    ->columnSpanFull(),

                            ]),
                    ])
                    ->columnSpanFull(),


            ]);
    }
}
