<?php

namespace App\Filament\Resources\Master\Users\Pages;

use App\Filament\Actions\Cheerful\CreateAction;
use App\Filament\Resources\Master\Users\UserResource;
use Filament\Resources\Pages\ManageRecords;
use Filament\Support\Enums\Width;

class ManageUsers extends ManageRecords
{
    protected static string $resource = UserResource::class;

    protected static ?string $title = 'Pengguna';

    protected function getHeaderActions(): array
    {
        return [
            CreateAction::make()
                ->label('Tambah')
                ->modalHeading('Tambah Pengguna')
                ->modalSubmitActionLabel('Simpan')
                ->modalCancelActionLabel('Batal')
                ->extraModalFooterActions(fn (CreateAction $action): array => [
                    $action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
                        ->label('Simpan dan Tambah Lagi'),
                ])
                ->modalWidth(Width::Large)
                ->after(function (CreateAction $action): void {
                    $user = $action->getRecord();

                    $user->update([
                        'email_verified_at' => now(),
                    ]);
                }),
        ];
    }
}
