<?php

namespace App\Filament\Resources\Finance\Payrolls\Pages;

use App\Enums\SalaryAdjustmentType;
use App\Filament\Resources\Finance\Payrolls\Actions\AddAdjustmentAction;
use App\Filament\Resources\Finance\Payrolls\Actions\DeleteAdjustmentAction;
use App\Filament\Resources\Finance\Payrolls\Actions\EditAdjustmentAction;
use App\Filament\Resources\Finance\Payrolls\PayrollResource;
use Filament\Actions\Action;
use Filament\Resources\Pages\ManageRecords;

class ManagePayrolls extends ManageRecords
{
    protected static string $resource = PayrollResource::class;

    protected static ?string $title = 'Penggajian';

    protected string $view = 'filament.resources.finance.payrolls.list-payrolls';

    protected function getViewData(): array
    {
        return [
            'currentMonthPayrolls' => $this->getResource()::getModel()::with(['user', 'adjustments'])
                ->where('period_month', now()->format('Y-m'))
                ->notPaid()
                ->get(),
        ];
    }

    public function addAdjustmentAction(): Action
    {
        return AddAdjustmentAction::make()
            ->mountUsing(function ($form, $arguments) {

                $form->fill([
                    'payroll_id' => $arguments['payroll_id'],
                    'type' => SalaryAdjustmentType::BONUS->value,
                ]);
            });
    }

    public function editAdjustmentAction(): Action
    {
        return EditAdjustmentAction::make();
    }

    public function deleteAdjustmentAction(): Action
    {
        return DeleteAdjustmentAction::make();
    }
}
