<?php

declare(strict_types=1);

use Builder\Core\Foundation\Tables\BulkAction;

it('make creates a BulkAction instance', function (): void {
    expect(BulkAction::make('delete'))->toBeInstanceOf(BulkAction::class);
});

it('key defaults as label', function (): void {
    expect(BulkAction::make('delete')->getLabel())->toBe('delete');
});

it('label() sets label', function (): void {
    expect(BulkAction::make('delete')->label('Delete Selected')->getLabel())->toBe('Delete Selected');
});

it('icon defaults to null', function (): void {
    expect(BulkAction::make('delete')->getIcon())->toBeNull();
});

it('icon() sets icon', function (): void {
    expect(BulkAction::make('delete')->icon('trash')->getIcon())->toBe('trash');
});

it('confirm defaults to null', function (): void {
    expect(BulkAction::make('delete')->getConfirm())->toBeNull();
});

it('confirm() sets confirmation message', function (): void {
    expect(BulkAction::make('delete')->confirm('Are you sure?')->getConfirm())->toBe('Are you sure?');
});

it('permission defaults to null', function (): void {
    expect(BulkAction::make('delete')->getPermission())->toBeNull();
});

it('permission() sets permission', function (): void {
    expect(BulkAction::make('delete')->permission('delete-users')->getPermission())->toBe('delete-users');
});

it('handle() sets handle closure', function (): void {
    $fn = function (mixed $records): void {};
    $action = BulkAction::make('delete')->handle($fn);

    expect($action->getHandle())->toBe($fn);
});

it('handle is null by default', function (): void {
    expect(BulkAction::make('delete')->getHandle())->toBeNull();
});

it('getKey() returns the key', function (): void {
    expect(BulkAction::make('delete')->getKey())->toBe('delete');
});

it('toArray() excludes handle closure', function (): void {
    $action = BulkAction::make('delete')
        ->label('Delete')
        ->icon('trash')
        ->confirm('Are you sure?')
        ->permission('delete-users')
        ->handle(function (mixed $r): void {});

    $array = $action->toArray();

    expect($array)->toBe([
        'key' => 'delete',
        'label' => 'Delete',
        'icon' => 'trash',
        'confirm' => 'Are you sure?',
        'permission' => 'delete-users',
    ])->and($array)->not->toHaveKey('handle');
});
