<?php

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

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 OrderPackageForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Grid::make()->schema([

                    /*
                |--------------------------------------------------------------------------
                | Order Settings
                |--------------------------------------------------------------------------
                */
                    Section::make('Order Active')->schema([
                        Toggle::make('is_paid')
                            ->label('Paid')
                            ->helperText('Mark if this order has been paid.')
                            ->required(),
                    ])->columnSpanFull(),

                    Section::make('Order Settings')
                        ->description('Configure order payment and type details.')
                        ->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([



                            Select::make('status')
                                ->label('Status')
                                ->options([
                                    'pending' => 'Pending',
                                    'completed' => 'Completed',
                                    'failed' => 'Failed',
                                ])->default('pending')
                                ->required(),

                            Select::make('pm_type')
                                ->label('Payment Method')
                                ->options([
                                    'wallet' => 'Wallet',
                                    'stripe' => 'Stripe',
                                ])->default('wallet')
                                ->required(),
                            TextInput::make('username')
                                ->label('Username')
                                ->helperText('The username associated with this order.')
                                ->required(),
                        ])
                        ->columns(3)
                        ->columnSpanFull(),

                    /*
                |--------------------------------------------------------------------------
                | Relationships
                |--------------------------------------------------------------------------
                */
                    Section::make('Relations')
                        ->description('Select related package, user, and coupon.')
                        ->extraAttributes([
                            'style' => 'background-color:#ffffff;padding:12px;border-radius:6px;border:1px solid #e5e7eb;'
                        ])
                        ->schema([

                            Select::make('package_id')
                                ->label('Package')
                                ->relationship('package', 'en_name') // assuming en_name is the display field
                                ->searchable()
                                ->preload()
                                ->native(false)
                                ->required(),

                            Select::make('user_id')
                                ->label('User')
                                ->relationship('user', 'name')
                                ->searchable()
                                ->preload()
                                ->native(false)
                                ->required(),

                            Select::make('coupon_id')
                                ->label('Coupon')
                                ->relationship('coupon', 'code')
                                ->searchable()
                                ->preload()
                                ->native(false)
                                ->nullable(), // coupon might not be required

                        ])
                        ->columns(3)
                        ->columnSpanFull(),

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