<?php

namespace App\Filament\Resources\Bookings\Schemas;

use App\Models\Trip;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
use Illuminate\Support\HtmlString;

class BookingForm
{
    public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Select::make('trip_id')
                    ->label('Trip')
                    ->options(
                        Trip::with('fromCity', 'toCity')
                            ->orderByDesc('departure_at')
                            ->limit(200)
                            ->get()
                            ->mapWithKeys(fn($t) => [
                                $t->id => "{$t->fromCity?->name_en} → {$t->toCity?->name_en}  |  "
                                    . $t->departure_at->format('d M Y H:i')
                                    . "  |  TZS {$t->price_per_seat}",
                            ])
                    )
                    ->searchable()
                    ->required(),

                Select::make('rider_id')
                    ->label('Rider')
                    ->relationship('rider', 'name')
                    ->searchable()
                    ->preload()
                    ->required(),

                TextInput::make('seats_booked')
                    ->label('Seats Booked')
                    ->required()
                    ->numeric()
                    ->minValue(1)
                    ->maxValue(4)
                    ->default(1),

                Select::make('status')
                    ->label('Booking Status')
                    ->options([
                        'pending'   => 'Pending (awaiting driver)',
                        'confirmed' => 'Confirmed',
                        'cancelled' => 'Cancelled',
                        'completed' => 'Completed',
                        'no_show'   => 'No-show',
                    ])
                    ->default('pending')
                    ->required(),

                DateTimePicker::make('confirmed_at')
                    ->label('Confirmed At')
                    ->seconds(false),

                DateTimePicker::make('cancelled_at')
                    ->label('Cancelled At')
                    ->seconds(false),

                TextInput::make('cancellation_reason')
                    ->label('Cancellation Reason')
                    ->placeholder('e.g. rider_cancelled, driver_declined')
                    ->default(null),
            ]);
    }
}
