<?php

declare(strict_types=1);

namespace KupShop\ComponentsBundle\Utils;

class ComponentsLocator
{
    public function __construct(
        protected array $components,
        protected array $unusedComponents,
    ) {
    }

    public function getComponents(): array
    {
        return $this->components;
    }

    public function getComponent(string $class): ?array
    {
        return $this->components[$class] ?? null;
    }

    public function findComponentByName($name): ?array
    {
        foreach ($this->components as $component) {
            if ($component['name'] === $name) {
                return $component;
            }
        }

        return null;
    }

    public function getUnusedComponents(): array
    {
        return $this->unusedComponents;
    }

    public function findUnusedComponentByName($name): ?array
    {
        foreach ($this->unusedComponents as $component) {
            if ($component['name'] === $name) {
                return $component;
            }
        }

        return null;
    }
}
