<?php

namespace App\Modules\HR\Dashboard\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\HR\Dashboard\Services\HrDashboardService;
use Illuminate\View\View;

class HrDashboardPageController extends Controller
{
    public function __construct(
        private readonly HrDashboardService $service,
    ) {}

    public function index(): View
    {
        $user = auth()->user();
        abort_unless(
            $user !== null && ($user->can('employees.view') || $user->can('attendance.view')),
            403,
        );

        $tenantId = (int) $user->tenant_id;
        abort_if($tenantId < 1, 403);

        return view('pages.hr.dashboard.index', [
            'kpis' => $this->service->kpis($tenantId),
        ]);
    }
}
