<?php
declare(strict_types=1);

namespace App\Core\Registries;

final class WidgetRegistry
{
    private static array $items = [];

    public static function register(string $key, array $definition): void
    {
        self::$items[$key] = $definition;
    }

    public static function get(string $key): ?array
    {
        return self::$items[$key] ?? null;
    }

    public static function getAll(): array
    {
        $items = self::$items;
        uasort($items, fn($a, $b) => ($a['order'] ?? 999) <=> ($b['order'] ?? 999));
        return $items;
    }

    public static function has(string $key): bool
    {
        return isset(self::$items[$key]);
    }
}