<?php

namespace apexl\Io\modules\display\components;

use apexl\Io\includes\Entity;
use apexl\Io\modules\component\Collections\ComponentCollection;
use apexl\Io\modules\component\Collections\ComponentPropertyCollection;
use apexl\Io\modules\component\Factories\ComponentPropertyFactory;
use apexl\Io\modules\component\Factories\GenericComponentFactory;
use Arrayy\Type\StringCollection;

/**
 * @deprecated Builder-pattern component incompatible with the readonly Component contract — mutating methods (setEntity()/setFilters(), inherited from EntityFilteredDisplayTable/EntityDisplayTable) fatal at runtime on write-once properties. Superseded by tabulator-based components: io-tabulator (Tabulator / EntityTabulator / AggregateTabulator); user/role admin screens via apexl/io-user-tabulator. Do not use in new code; removal planned once the legacy io-user userDisplay routes are gone.
 */
readonly class CardEntityFilteredDisplayTable extends EntityFilteredDisplayTable
{
    // setName() is part of the io-component 3.1.7 compatibility shim (slated
    // for reversal) and doesn't exist on the strict base. Both the strict and
    // shimmed Component constructors resolve the component name from a `NAME`
    // class constant when present, so declare it instead of calling setName().
    // This overrides EntityDisplayTable::NAME ('DataTable') via late static
    // binding.
    public const string NAME = 'CardDataTable';

    public function __construct(
        GenericComponentFactory $componentFactory,
        ComponentPropertyFactory $propertyFactory,
        ComponentPropertyCollection $props,
        ComponentCollection $components,
        StringCollection $classes,
        ?string $componentId = null,
        ?Entity $entity = null,
        $replacements = [],
        $withButtons = true,
        $buttonFormat = 'buttons'
    ) {
        parent::__construct(
            $componentFactory,
            $propertyFactory,
            $props,
            $components,
            $classes,
            $componentId,
            $entity,
            $replacements,
            $withButtons
        );
        $this->setProperty('supportComponentLocation', 'header');
    }

    public function addTitle($title)
    {
        $this->setProperty('title', $title);
        return $this;
    }

    public function setFilterFormLocation($location)
    {
        if (in_array($location, ['header', 'body'])) {
            $this->setProperty('filterFormLocation', $location);
        }
        return $this;
    }

}
