<?php

declare(strict_types=1);

namespace Apexl\Io\Display\ComponentFactories;

use Apexl\Io\Component\Factories\GenericComponentFactory;
use Apexl\Io\Display\Components\Menu;

final readonly class MenuComponentFactory
{
    public function __construct(private GenericComponentFactory $componentFactory) {}

    public function make(array $menuItems = [], string $title = '', string $menuClass = Menu::class, bool $collapsable = false): Menu
    {
        \Apexl\Io\assertInstanceOf($menuClass, Menu::class);

        /** @var Menu $menu */
        $menu = $this->componentFactory->make($menuClass);

        $menu->setCollapsable($collapsable);

        if ($menuItems) {
            $menu->addMenuItems($menuItems);
        }

        if ($title) {
            $menu->setTitle($title);
        }

        return $menu;
    }
}
