<?php

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

use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Select;
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\Components\Utilities\Set;
use Filament\Schemas\Schema;
use Illuminate\Support\Str;
class ProductForm
{
    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 (Set $set, ?string $state) {
                                    $set('slug', Str::slug($state));
                                }),

                            TextInput::make('fa_name')
                                ->required(),

                            TextInput::make('slug')
                                ->required()
                                ->disabled()
                                ->dehydrated(),

                            Select::make('product_category_id')
                                ->relationship('productCategory', 'en_name')
                                ->required(),
                        ]),
                    ]),

                Section::make('Media')
                    ->schema([
                        Grid::make(2)->schema([

                            FileUpload::make('thumbnail')
                                ->directory('products/thumbnails')
                                ->image()
                                ->imageEditor()
                                ->disk('public')
                                ->columnSpanFull(),
                            FileUpload::make('media')
                            ->image()
                            ->imageEditor()
                                ->multiple()
                                ->disk('public')
                                ->directory('products/media')
                                ->columnSpanFull(),
                        ]),
                    ]),

                Section::make('Descriptions')
                    ->schema([
                        Textarea::make('en_description')
                            ->columnSpanFull(),

                        Textarea::make('fa_description')
                            ->columnSpanFull(),
                    ]),

                Section::make('Pricing')
                    ->schema([
                        Grid::make(2)->schema([
                            TextInput::make('price')
                                ->required()
                                ->numeric()
                                ->prefix('$'),

                            TextInput::make('discount')
                                ->required()
                                ->numeric(),
                        ]),
                    ]),

                Section::make('Status')
                    ->schema([
                        Grid::make(2)->schema([
                            Toggle::make('is_featured')
                                ->required(),

                            Toggle::make('is_active')
                                ->required(),
                        ]),
                    ])
            ]);
    }
}
