import type { WidgetRegistry, WidgetRegistryEntry } from './types';
import { useGlobal } from 'hooks/useGlobal';

export type WidgetRegistryMeta = { key: string } & WidgetRegistryEntry;

const EMPTY_REGISTRY: WidgetRegistry = {};

/** Read the widget registry. Written once by `seedWidgetRegistry`; see `useAppRegistry` for the reasoning. */
export function useWidgetRegistry() {
  const [registry] = useGlobal<WidgetRegistry>('WIDGET_REGISTRY', EMPTY_REGISTRY);
  return { registry };
}
