<?php

namespace App\Http\Controllers\HR;

use App\Http\Controllers\Controller;
use App\Models\HR\Payroll;
use App\Services\HR\PayrollService;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class PayrollController extends Controller
{
    public function __construct(
        private PayrollService $payrollService
    ) {}

    /**
     * 급여관리 페이지
     */
    public function index(Request $request): View|Response
    {
        if ($request->header('HX-Request')) {
            return response('', 200)->header('HX-Redirect', route('hr.payrolls.index'));
        }

        $stats = $this->payrollService->getMonthlyStats();
        $departments = $this->payrollService->getDepartments();
        $employees = $this->payrollService->getActiveEmployees();
        $settings = $this->payrollService->getSettings();
        $statusMap = Payroll::STATUS_MAP;

        return view('hr.payrolls.index', [
            'stats' => $stats,
            'departments' => $departments,
            'employees' => $employees,
            'settings' => $settings,
            'statusMap' => $statusMap,
        ]);
    }
}
