<?php

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

use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\RichEditor;
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\Schema;

class CouponForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Grid::make()->schema([

                    /*
                |--------------------------------------------------------------------------
                | Coupon Settings
                |--------------------------------------------------------------------------
                */
                    Section::make('Coupon Setting')->schema([
                        Toggle::make('is_active')
                            ->label('Active')
                                ->default(true)

                            ->helperText('Enable or disable the coupon.')
                            ->required(),
                    ])->columnSpanFull(),
                    Section::make('Coupon Details')
                        ->description('Configure coupon details and visibility.')
                        ->extraAttributes([
                            'style' => 'background-color:#ffffff;padding:15px;border-radius:8px;border:1px solid #e5e7eb;box-shadow:0 1px 3px rgba(0,0,0,0.05);'
                        ])
                        ->schema([

                            TextInput::make('code')
                                ->label('Coupon Code')
                                ->placeholder('Enter unique coupon code')
                                ->unique('coupons', 'code')

                                ->regex('/^[A-Z0-9]+$/')
                                ->required(),

                            Select::make('type')
                                ->label('Type')
                                ->placeholder('Select Ones')
                                ->options([
                                    "percentage" => 'percentage',
                                    'fixed' => 'fixed',
                                ]),

                            TextInput::make('value')
                                ->label('Value')
                                ->placeholder('Enter the value of coupon')
                                ->numeric()
                                ->required()
                                ->columnSpanFull(),
                        ])
                        ->columns(2)
                        ->columnSpanFull(),

                    /*
                |--------------------------------------------------------------------------
                | Titles & Description (Multilingual)
                |--------------------------------------------------------------------------
                */
                    Section::make('Descriptions (Multilingual)')
                        ->description('Enter the description for English and Persian.')
                        ->collapsible()
                        ->schema([
                            Grid::make()->schema([

                                // English Section
                                Section::make('English')
                                    ->collapsible()
                                    ->collapsed()
                                    ->extraAttributes([
                                        'style' => 'background-color:#f9fafb;padding:12px;border-radius:6px;border:1px solid #d1d5db;'
                                    ])
                                    ->schema([
                                        RichEditor::make('en_description')
                                            ->label('English Description')
                                            ->placeholder('Enter description in English')
                                            ->columnSpanFull(),
                                    ])
                                    ->columnSpanFull(),

                                // Persian Section (RTL)
                                Section::make('فارسی')
                                    ->collapsible()
                                    ->collapsed()
                                    ->extraAttributes([
                                        'dir' => 'rtl',
                                        'class' => 'text-right',
                                        'style' => 'background-color:#f9fafb;padding:12px;border-radius:6px;border:1px solid #d1d5db;'
                                    ])
                                    ->schema([
                                        RichEditor::make('fa_description')
                                            ->label('توضیحات فارسی')
                                            ->extraAttributes(['dir' => 'rtl', 'class' => 'text-right'])
                                            ->placeholder('توضیح را وارد کنید')
                                            ->columnSpanFull(),
                                    ])
                                    ->columnSpanFull(),

                            ]),
                        ])
                        ->columnSpanFull(),

                    /*
                |--------------------------------------------------------------------------
                | Validity Dates
                |--------------------------------------------------------------------------
                */
                    Section::make('Validity')
                        ->description('Set the start and end date for this coupon.')
                        ->extraAttributes([
                            'style' => 'background-color:#ffffff;padding:12px;border-radius:6px;border:1px solid #e5e7eb;'
                        ])
                        ->schema([
                            DateTimePicker::make('valid_from')
                                ->label('Valid From')
                                ->required(),

                            DateTimePicker::make('valid_to')
                                ->label('Valid To')
                                ->required(),
                        ])
                        ->columns(2)
                        ->columnSpanFull(),

                    /*
                |--------------------------------------------------------------------------
                | Slug
                |--------------------------------------------------------------------------
                */


                    /*
                |--------------------------------------------------------------------------
                | Author
                |--------------------------------------------------------------------------
                */
                    Section::make('Author')
                        ->extraAttributes([
                            'style' => 'background-color:#ffffff;padding:12px;border-radius:6px;border:1px solid #e5e7eb;'
                        ])
                        ->schema([
                    Select::make('user_id')
                                ->label('Author')
                                ->relationship('user', 'name')
                                ->default(fn() => auth()->id())
                                ->disabled()
                                ->dehydrated()
                                ->required()
                                ->native(false),
                        ])
                        ->columnSpanFull(),

                ])->columnSpanFull(),
            ]);
    }
}
