<?php

namespace Plainwork\Ui\Component;

final class BlockList extends AbstractTag
{
    public bool $asTable = false;
    private array $items = [];
    private int $spacing = 2;

    public function __construct(...$items)
    {
        if ((1 === count($items)) && is_array(current($items))){
            $items = current($items);
        }
        $this->items = $items;
    }

    public function asTable(bool $v = true): self
    {
        $this->asTable = $v;

        return $this;
    }

    public function smallSpacing(): self
    {
        return $this->setSpacing(1);
    }

    public function largeSpacing(): self
    {
        return $this->setSpacing(3);
    }

    public function noSpacing(): self
    {
        return $this->setSpacing(0);
    }

    public function setSpacing(int $v): self
    {
        if ($v < 0) {
            $v = 0;
        }
        if ($v > 3) {
            $v = 3;
        }
        $this->spacing = $v;

        return $this;
    }

    public function getSpacing(): int
    {
        return $this->spacing;
    }

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

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

        return $this;
    }
}
