<?php

namespace App\Http\Controllers\HR;

use App\Http\Controllers\Controller;
use App\Models\HR\Attendance;
use App\Services\HR\AttendanceService;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\Response;

class AttendanceController extends Controller
{
    public function __construct(
        private AttendanceService $attendanceService
    ) {}

    /**
     * 근태현황 목록 페이지 (조회 전용)
     */
    public function index(Request $request): View|Response
    {
        if ($request->header('HX-Request')) {
            return response('', 200)->header('HX-Redirect', route('hr.attendances.index'));
        }

        $stats = $this->attendanceService->getMonthlyStats();
        $departments = $this->attendanceService->getDepartments();
        $statusMap = Attendance::STATUS_MAP;

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

    /**
     * 근태관리 페이지 (등록/수정/삭제/승인)
     */
    public function manage(Request $request): View|Response
    {
        if ($request->header('HX-Request')) {
            return response('', 200)->header('HX-Redirect', route('hr.attendances.manage'));
        }

        $departments = $this->attendanceService->getDepartments();
        $employees = $this->attendanceService->getActiveEmployees();
        $statusMap = Attendance::STATUS_MAP;

        return view('hr.attendances.manage', [
            'departments' => $departments,
            'employees' => $employees,
            'statusMap' => $statusMap,
        ]);
    }
}
