<?php

namespace App\Modules\HR\Reports\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Modules\PLATFORM\Settings\Models\Branch;
use App\Modules\HR\Core\Models\Department;

class ReportController extends Controller
{
    public function index(Request $request)
    {
        $reportName = $request->route()->getName();
        $branches = Branch::where('status', 1)->get();
        $departments = Department::where('status', 1)->get();

        // Map route names to readable titles if needed, or pass the route name directly
        $reportTitle = $this->getReportTitle($reportName);

        return view('HR::Reports.index', compact('reportName', 'branches', 'departments', 'reportTitle'));
    }

    public function generate(Request $request)
    {
        // Placeholder for report generation logic
        // logic to handle PDF, Excel, CSV, DAT based on $request->format
        
        return "Generating report: " . $request->report_name . " in format: " . $request->format;
    }

    private function getReportTitle($routeName)
    {
        $titles = [
            'hr.reports.employee-details' => 'Employee Details',
            'hr.reports.employee-photo' => 'Employee Photo',
            'hr.reports.employee-birthday' => 'Employee Birthday',
             // Add other mappings here as needed, or derivation logic
        ];

        return $titles[$routeName] ?? ucwords(str_replace(['hr.reports.', '-'], ['',' '], $routeName));
    }
}
