import { widgetRegistryMetas as clockMetas } from 'widgets/Clock';
import { widgetRegistryMetas as weatherMetas } from 'widgets/Weather';
import { widgetRegistryMetas as pomodoroMetas } from 'widgets/Pomodoro';
import { widgetRegistryMetas as dailyGoalsMetas } from 'widgets/DailyGoals';
import { widgetRegistryMetas as quickNotesMetas } from 'widgets/QuickNotes';
import { widgetRegistryMetas as musicPlayerMetas } from 'widgets/MusicPlayer';
import type { QueryClient } from '@tanstack/react-query';
import { globalQueryKey } from 'hooks/useGlobal';
import type { WidgetRegistry as WidgetRegistryMap } from './types';
import type { WidgetRegistryMeta } from './useWidgetRegistry';

const widgets = [
  ...clockMetas,
  ...weatherMetas,
  ...pomodoroMetas,
  ...dailyGoalsMetas,
  ...quickNotesMetas,
  ...musicPlayerMetas,
];

const metasToRegistry = (metas: WidgetRegistryMeta[]): WidgetRegistryMap =>
  Object.fromEntries(metas.map(({ key, ...entry }) => [key, entry]));

/** Same shape, and the same reasoning, as `seedAppRegistry`. */
export const seedWidgetRegistry = (queryClient: QueryClient) => {
  queryClient.setQueryData(globalQueryKey('WIDGET_REGISTRY'), metasToRegistry(widgets));
};
