<?php

namespace App\Filament\Resources\Payments\Schemas;

use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;

class PaymentForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema->components([
            Section::make('Transaction')
                ->description('Provider-confirmed transaction data. Payments are read-only in admin to protect automated fulfilment.')
                ->columns(2)
                ->schema([
                    TextInput::make('reference')->disabled(),
                    TextInput::make('gateway_reference')->label('Provider reference')->disabled(),
                    Select::make('status')->options([
                        'pending' => 'Pending',
                        'paid' => 'Paid',
                        'failed' => 'Failed',
                        'cancelled' => 'Cancelled',
                    ])->disabled(),
                    TextInput::make('gateway')->disabled(),
                    TextInput::make('currency')->disabled(),
                    TextInput::make('amount')
                        ->formatStateUsing(fn ($state) => number_format(((int) $state) / 100, 2))
                        ->disabled(),
                    TextInput::make('email')->disabled(),
                    TextInput::make('phone')->disabled(),
                    TextInput::make('purpose')->disabled()->columnSpanFull(),
                    Textarea::make('failure_reason')->disabled()->columnSpanFull(),
                ]),
            Section::make('Customer & product')
                ->columns(2)
                ->schema([
                    Select::make('user_id')->relationship('user', 'name')->disabled(),
                    Select::make('course_id')->relationship('course', 'title')->disabled(),
                    TextInput::make('created_at')->disabled(),
                    TextInput::make('paid_at')->disabled(),
                ]),
        ]);
    }
}
