<?php

namespace App\Filament\Resources\UserResource\Pages;

use App\Filament\Resources\Pages\AuditedEditRecord;
use App\Filament\Resources\UserResource;
use App\Services\Audit\SuperAdminAuditLogger;
use Filament\Actions;
use Illuminate\Support\Facades\Hash;

class EditUser extends AuditedEditRecord
{
    protected static string $resource = UserResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\DeleteAction::make()
                ->after(fn ($record) => app(SuperAdminAuditLogger::class)->recordModelMutation(
                    'deleted',
                    $record,
                    source: static::class
                )),
        ];
    }

    protected function mutateFormDataBeforeSave(array $data): array
    {
        if (isset($data['password'])) {
            $data['password'] = Hash::make($data['password']);
        }

        return $data;
    }
}
