<?php

namespace App\Filament\Widgets;

use App\Models\Consultation;
use App\Models\Inquiry;
use App\Support\AdminDashboard;
use Filament\Widgets\Widget;

class WelcomeBanner extends Widget
{
    protected string $view = 'filament.widgets.welcome-banner';

    protected int|string|array $columnSpan = 'full';

    protected static ?int $sort = -6;

    protected static bool $isLazy = false;

    public function getViewData(): array
    {
        $user = auth()->user();
        $hour = (int) now()->format('H');
        $greeting = $hour < 12 ? 'Good morning' : ($hour < 17 ? 'Good afternoon' : 'Good evening');

        $dashboard = app(AdminDashboard::class)->snapshot();

        return [
            'greeting' => $greeting,
            'name' => $user?->name ?? 'there',
            'today' => now()->format('l, j F Y'),
            'openConsultations' => Consultation::where('status', 'new')->count(),
            'openInquiries' => Inquiry::where('status', 'new')->count(),
            'checkoutConversion' => $dashboard['checkoutConversion'],
            'revenueKes' => $dashboard['revenueKes'],
            'readiness' => $dashboard['readiness'],
        ];
    }
}
