<?php

namespace App\Filament\Admin\Resources\TopUps\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;
use Illuminate\Support\Facades\Auth;

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

                    /*
                |--------------------------------------------------------------------------
                | Payment Settings
                |--------------------------------------------------------------------------
                */
                    Section::make('Payment Paid')->schema([

                        Toggle::make('is_paid')
                            ->label('Paid')
                            ->helperText('Mark if the top-up is completed.')
                            ->required()
                            ->disabled(fn() => auth()->user()?->role !== 'admin')
                            ->dehydrated(),

                    ])->columnSpanFull(),

                    Section::make('Payment Settings')
                        ->description('Configure the payment status, amount, and method.')
                        ->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('amount')
                                ->label('Amount')
                                ->numeric()
                                ->required()
                                ->prefix('Afs'),

                            Select::make('pm_type')
                                ->label('Payment Method')
                                ->options([
                                    'wallet' => 'Wallet',
                                    // 'stripe' => 'Stripe',
                                ])->default('wallet')
                                ->required(),

                            \Filament\Forms\Components\Placeholder::make('wallet_balance')
                                ->label('Wallet Balance')
                                ->content(fn () => '$' . number_format(Auth::user()?->wallet_balance ?? 0, 2))
                                ->visible(fn ($get) => $get('pm_type') === 'wallet'),

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


                            TextInput::make('phone')
                                ->label('Phone Number')
                             
                                ->required()
                                ->rules(['digits:10', 'starts_with:07'])
                                ->minLength(10)
                                ->maxLength(10)
                                ->placeholder('07XXXXXXXX'),

                            Select::make('user_id')
                                ->label('User')
                                ->relationship('user', 'name')
                                ->default(fn() => Auth::id())
                                ->disabled()
                                ->dehydrated(true) // VERY IMPORTANT
                                ->required()
                                ->native(false),
                        ])
                        ->columns(2)
                        ->columnSpanFull(),

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