<?php
declare(strict_types=1);

namespace WP_AUX\Entities\AuxFramework\Partials;

use WHOOP\Entities\Elements\A;
use WHOOP\Entities\Elements\Li;
use WHOOP\Entities\Elements\Ul;
use WP_AUX\Services\AuxFramework\ElementClassesService;
use WP_AUX\Services\HtmlService;

class DismissibleTagCollectionEntity extends TagCollectionEntity
{
  protected bool $hasContainer = true;
  protected ?string $tagType = 'dismissible';

  public function __toString(): string
  {
    if (empty($this->items)) {
      return '';
    }

    $list = $this->getList();

    $headingContent = HtmlService::formattedValue(
      $this->heading,
      '<span class="dismissible-tag-collection__heading">%s</span>'
    );

    $collection = sprintf(
      '<div class="dismissible-tag-collection__container">%s</div>',
      $list
    );

    $collection = sprintf(
      '<div class="dismissible-tag-collection">%s%s</div>',
      $headingContent,
      $collection,
    );

    return $collection;
  }

  public static function create(?string $heading = null): static
  {
    $collection = (new static())
      ->setHasContainer(true)
      ->setHeading($heading);

    return $collection;
  }
}
