<?php

namespace Plainwork\Ui\Component;

class TabMenu extends AbstractTag
{
    private array $items = [];
    private $currentItemId;
    private ?string $currentRoute = null;

    public function __construct(...$items)
    {
        if ((1 === count($items)) && is_array(current($items))){
            $items = current($items);
        }
        foreach ($items as $id => $item) {
            $this->add($id, $item);
        }
    }

    public function setActive(string $id): self
    {
        return $this->setCurrent($id);
    }

    public function setCurrent($id): self
    {
        $this->currentItemId = $id;

        return $this;
    }

    public function getCurrent()
    {
        return $this->currentItemId ?? 0;
    }

    public function add($id, $item): self
    {
        $this->items[$id] = $item;

        return $this;
    }

    public function addWithOrder($item, int $weight): self
    {
        $this->items[] = [$weight, $item];

        return $this;
    }

    public function hasItems(): bool
    {
        return $this->items ? true : false;
    }

    public function getItems(): array
    {
        return $this->items;
    }
}
