<?php

declare(strict_types=1);

use Builder\Core\Foundation\Account\AccountTab;
use Illuminate\Http\Request;

it('make creates AccountTab with key and component', function (): void {
    $tab = AccountTab::make('profile', 'ProfileComponent');

    expect($tab)->toBeInstanceOf(AccountTab::class)
        ->and($tab->getKey())->toBe('profile')
        ->and($tab->getComponent())->toBe('ProfileComponent');
});

it('label defaults to key', function (): void {
    expect(AccountTab::make('profile', 'ProfileComponent')->getLabel())->toBe('profile');
});

it('label() sets the label', function (): void {
    expect(AccountTab::make('profile', 'ProfileComponent')->label('My Profile')->getLabel())->toBe('My Profile');
});

it('order defaults to 50', function (): void {
    expect(AccountTab::make('profile', 'ProfileComponent')->getOrder())->toBe(50);
});

it('order() sets the order', function (): void {
    expect(AccountTab::make('profile', 'ProfileComponent')->order(10)->getOrder())->toBe(10);
});

it('getData returns empty array when no closure is set', function (): void {
    $request = Request::create('/');

    expect(AccountTab::make('profile', 'ProfileComponent')->getData($request))->toBe([]);
});

it('getData returns result of closure when set', function (): void {
    $request = Request::create('/');
    $tab = AccountTab::make('profile', 'ProfileComponent')
        ->data(fn (Request $r): array => ['key' => 'value']);

    expect($tab->getData($request))->toBe(['key' => 'value']);
});

it('toArray returns correct structure with data closure', function (): void {
    $request = Request::create('/');
    $tab = AccountTab::make('profile', 'ProfileComponent')
        ->label('My Profile')
        ->order(10)
        ->data(fn (Request $r): array => ['user_data' => 'info']);

    $arr = $tab->toArray($request);

    expect($arr)->toHaveKey('key', 'profile')
        ->toHaveKey('label', 'My Profile')
        ->toHaveKey('component', 'ProfileComponent')
        ->toHaveKey('order', 10)
        ->toHaveKey('data', ['user_data' => 'info']);
});
