<?php

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

use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

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

                    /*
                |--------------------------------------------------------------------------
                | CreditCoupon Settings
                |--------------------------------------------------------------------------
                */
                    Section::make('Coupon Active')->schema([
                        Toggle::make('is_active')
                            ->label('Active')
                            ->default(true)
                            ->helperText('Enable or disable this credit coupon.')
                            ->required(),

                    ])->columnSpanFull(),
                    Section::make('Credit Coupon Settings')
                        ->description('Configure the credit 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')
                                ->required(),

                            TextInput::make('amount')
                                ->label('Amount')
                                ->placeholder('Enter credit amount')
                                ->numeric()
                                ->required(),
                        ])
                        ->columns(2)
                        ->columnSpanFull(),

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

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

                    /*
                |--------------------------------------------------------------------------
                | 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(),
            ]);
    }
}
