<?php

declare(strict_types=1);

namespace App\Filament\Widgets;

use App\Enums\ApprovalStatus;
use App\Enums\EmploymentStatus;
use App\Models\Employee;
use App\Models\SickLeave;
use App\Models\Vacation;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;

class HrStatsOverviewWidget extends StatsOverviewWidget
{
    public function getHeading(): ?string
    {
        return __('hr.widgets.hr_overview');
    }

    protected function getStats(): array
    {
        $today = now()->toDateString();

        $onVacationToday = Vacation::query()
            ->where('status', ApprovalStatus::Approved)
            ->whereDate('start_date', '<=', $today)
            ->whereDate('end_date', '>=', $today)
            ->count();

        $onSickLeaveToday = SickLeave::query()
            ->whereDate('start_date', '<=', $today)
            ->whereDate('end_date', '>=', $today)
            ->count();

        $pendingRequests = Vacation::query()
            ->where('status', ApprovalStatus::Pending)
            ->count();

        return [
            Stat::make(__('hr.stats.total_employees'), Employee::query()->count())
                ->description(__('hr.stats.total_employees_desc'))
                ->descriptionIcon('heroicon-o-users')
                ->color('primary'),
            Stat::make(__('hr.stats.active'), Employee::query()->where('employment_status', EmploymentStatus::Active)->count())
                ->description(__('hr.stats.active_desc'))
                ->descriptionIcon('heroicon-o-check-circle')
                ->color('success'),
            Stat::make(__('hr.stats.inactive'), Employee::query()->where('employment_status', EmploymentStatus::Inactive)->count())
                ->description(__('hr.stats.inactive_desc'))
                ->descriptionIcon('heroicon-o-pause-circle')
                ->color('gray'),
            Stat::make(__('hr.stats.on_vacation_today'), $onVacationToday)
                ->description(__('hr.stats.on_vacation_today_desc'))
                ->descriptionIcon('heroicon-o-sun')
                ->color('warning'),
            Stat::make(__('hr.stats.on_sick_leave_today'), $onSickLeaveToday)
                ->description(__('hr.stats.on_sick_leave_today_desc'))
                ->descriptionIcon('heroicon-o-heart')
                ->color('danger'),
            Stat::make(__('hr.stats.pending_requests'), $pendingRequests)
                ->description(__('hr.stats.pending_requests_desc'))
                ->descriptionIcon('heroicon-o-clock')
                ->color('info'),
        ];
    }
}
