<?php

declare(strict_types=1);

use Builder\Core\Foundation\Definition\MenuItem;
use Builder\Core\Foundation\Registry;

it('registers an "advanced" top-level menu group', function (): void {
    $registry = app(Registry::class);

    $advanced = collect($registry->menuItems())->first(
        fn (MenuItem $item): bool => $item->getKey() === 'advanced',
    );

    expect($advanced)->not->toBeNull()
        ->and($advanced->getLabel())->toBe('Advanced')
        ->and($advanced->getIcon())->toBe('Wrench');
});

it('places the health item under "advanced", not under "settings"', function (): void {
    $registry = app(Registry::class);

    $items = collect($registry->menuItems());

    $settings = $items->first(fn (MenuItem $item): bool => $item->getKey() === 'settings');
    $advanced = $items->first(fn (MenuItem $item): bool => $item->getKey() === 'advanced');

    $settingsChildKeys = array_map(fn (MenuItem $c): string => $c->getKey(), $settings->getChildren());
    $advancedChildKeys = array_map(fn (MenuItem $c): string => $c->getKey(), $advanced->getChildren());

    expect($settingsChildKeys)->not->toContain('health')
        ->and($advancedChildKeys)->toContain('health');
});

it('exposes "advanced" group after "settings" by priority', function (): void {
    $registry = app(Registry::class);

    $items = collect($registry->menuItems());

    $settings = $items->first(fn (MenuItem $item): bool => $item->getKey() === 'settings');
    $advanced = $items->first(fn (MenuItem $item): bool => $item->getKey() === 'advanced');

    expect($advanced->getPriority())->toBeGreaterThan($settings->getPriority());
});
