<?php

namespace Apexl\Io\Display\Components;

use Apexl\Io\Component\Collections\ComponentCollection;
use Apexl\Io\Component\Collections\ComponentPropertyCollection;
use Apexl\Io\Component\Components\Component;
use Apexl\Io\Component\Factories\ComponentPropertyFactory;
use Arrayy\Type\StringCollection;

readonly class CardTile extends Component
{
    public function __construct(
        ComponentPropertyFactory $propertyFactory,
        ComponentPropertyCollection $props,
        ComponentCollection $components,
        StringCollection $classes,
        ?string $componentId = null
    ) {
        parent::__construct($propertyFactory, $props, $components, $classes, $componentId);
    }

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

    public function addHeaderModal($modalTitle, $contentComponents, $icon = 'circle-question')
    {
        $modal = (new Modal())->setButtonContent('<i class="fa-regular fa-circle-question"></i>')->addComponents(
            $contentComponents
        )->setTitle($modalTitle)->addClass('modal-help');
        $this->addSupportComponent($modal);
        return $this;
    }

    public function addDataSrc($src, $allowRefresh = true)
    {
        $this->setProperty('contentSrc', $src);
        if ($allowRefresh) {
            $this->setProperty('refreshButton', '<i class="fa-light fa-arrows-rotate"></i>');
        }
        return $this;
    }

}
