<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\System\DashboardService;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class DashboardController extends Controller
{
    public function __construct(
        private readonly DashboardService $dashboardService,
    ) {}

    public function index(Request $request): Response
    {
        $user = $request->user();

        return Inertia::render('admin/Dashboard', [
            'attendance' => $this->dashboardService->getAttendance(),
            'cashOverview' => $this->dashboardService->getCashOverview(),
            'revenueSummary' => $this->dashboardService->getRevenueSummary(),
            'expenseSummary' => $this->dashboardService->getExpenseSummary(),

            'orderStats' => $this->dashboardService->getOrderStats(),

            'todayAttendance' => $user
                ? $this->dashboardService->getTodayAttendanceForUser($user)
                : null,
            'isOnLeave' => $user
                ? $this->dashboardService->isOnLeaveTodayForUser($user)
                : false,
            'canCheckIn' => $user
                ? $this->dashboardService->canCheckInForUser($user)
                : false,
        ]);
    }
}
