<?php
namespace PHPFUI;
abstract class Bar extends \PHPFUI\HTML5Element
{
protected array $left = [];
protected array $right = [];
private string $className;
private bool $started = false;
public function __construct(string $className)
{
parent::__construct('div');
$this->className = $className . '-bar';
$this->addClass($this->className);
}
public function addLeft(mixed $item) : static
{
$this->left[] = $item;
return $this;
}
public function addRight(mixed $item) : static
{
$this->right[] = $item;
return $this;
}
public function pushLeft(mixed $item) : static
{
$this->left[] = $item;
return $this;
}
public function pushRight(mixed $item) : static
{
$this->right[] = $item;
return $this;
}
protected function getStart() : string
{
if (! $this->started)
{
$this->started = true;
$this->add($this->getSection($this->left, 'left'));
$this->add($this->getSection($this->right, 'right'));
}
return parent::getStart();
}
private function getSection(array $items, string $class) : ?HTML5Element
{
$element = null;
if ($items)
{
$element = new \PHPFUI\HTML5Element('div');
$element->addClass($this->className . '-' . $class);
foreach ($items as $item)
{
$element->add($item);
}
}
return $element;
}
}