<?php

declare(strict_types=1);

namespace CliqThemes\UI;

use CliqThemes\UI\Contracts\DataRepository;
use CliqThemes\UI\Data\OptionRepository;

/**
 * Static accessor for framework services shared with host plugins — the PHP-side
 * counterpart of the JS `window.cliqUI` registry. Hosts reach reusable, framework-
 * owned data through it, e.g.:
 *
 *     CliqUI::dataRepo()->get('font_family')
 *
 * keeping that data defined once in cliq-ui rather than copied into each plugin.
 */
final class CliqUI
{
    private static ?DataRepository $dataRepo = null;

    /** The shared option/data repository (font families, …). */
    public static function dataRepo(): DataRepository
    {
        if (self::$dataRepo === null) {
            self::$dataRepo = new OptionRepository();
        }

        return self::$dataRepo;
    }

    /** Swap the repository — for host customisation or tests. */
    public static function setDataRepo(DataRepository $repo): void
    {
        self::$dataRepo = $repo;
    }
}
