<?php

namespace App\Http\Controllers\Company\Payroll;

use App\Http\Controllers\Controller;
use App\Models\Setting;

class PayrollModuleController extends Controller
{
    protected function ensurePayrollModule(): void
    {
        if (Setting::get(auth()->user()->company_id, 'use_payroll_module', '0') !== '1') {
            abort(404);
        }
    }

    protected function gate(string $action = 'view'): void
    {
        if (!auth()->user()->hasPermission('payroll', $action)) {
            abort(403);
        }
    }

    protected function page(string $title, string $icon, string $subtitle): \Illuminate\View\View
    {
        $this->ensurePayrollModule();
        $this->gate();

        return view('payroll.placeholder', compact('title', 'icon', 'subtitle'));
    }

    public function payrollSheet()
    {
        return $this->page('Payroll Sheet', 'bi-table', 'Prepare and review monthly payroll for all employees.');
    }

    public function journal()
    {
        return $this->page('Payroll Journal', 'bi-journal-text', 'View payroll journal entries posted to the general ledger.');
    }

    public function paySlip()
    {
        return $this->page('Pay Slip', 'bi-receipt', 'Generate and print employee pay slips.');
    }

    public function bankTransferLetter()
    {
        return $this->page('Bank Transfer Letter', 'bi-envelope-paper', 'Generate salary transfer letters for bank disbursement.');
    }
}
