import type { ComponentType } from "react";

export interface GameUIProps {
    state: any;
    myPlayerId: string;
    isSpectator: boolean;
    onAction: (action: unknown) => void;
    players: { discordId: string; username: string }[];
}

export interface GameUIPlugin {
    slug: string;
    name: string;
    icon: string;
    maxPlayers: number;
    component: ComponentType<GameUIProps>;
}

const plugins = new Map<string, GameUIPlugin>();

export const gameUIRegistry = {
    register(plugin: GameUIPlugin) {
        if (plugins.has(plugin.slug)) {
            throw new Error(`Game UI "${plugin.slug}" is already registered`);
        }
        plugins.set(plugin.slug, plugin);
    },
    get(slug: string): GameUIPlugin | undefined {
        return plugins.get(slug);
    },
    list(): GameUIPlugin[] {
        return Array.from(plugins.values());
    },
};
