<?php

namespace Modules\Booking\Filament\Widgets;

use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Modules\Booking\Enums\BookingStatus;
use Modules\Booking\Models\Booking;

/**
 * Dispatch-facing snapshot of today's trips — "today" means travel_date, not
 * created_at, since this is what staff care about when assigning
 * drivers/vehicles (domain.md §5a), not how many bookings were made today.
 */
class BookingsTodayWidget extends BaseWidget
{
    protected function getStats(): array
    {
        $today = Booking::query()->whereDate('travel_date', today());

        $confirmedToday = (clone $today)->where('status', BookingStatus::Confirmed)->count();
        $pendingToday = (clone $today)->where('status', BookingStatus::PendingPayment)->count();

        return [
            Stat::make('Trips Today', (clone $today)->count())
                ->description('Bookings scheduled for today')
                ->color('primary'),
            Stat::make('Confirmed', $confirmedToday)
                ->description('Paid & ready for driver assignment')
                ->color('success'),
            Stat::make('Awaiting Payment', $pendingToday)
                ->description('Still pending_payment')
                ->color($pendingToday > 0 ? 'warning' : 'gray'),
        ];
    }
}
