import { WidgetsIndex as RemoteWidgets } from '@win2win/shared-ui';
import { Component } from 'vue';
import LocalWidgets from './index';

const WIDGET_LIB_CODE = '@shared/';
export function getWidget(code?: string): Component | null {
  if (!code) return null;
  let widgetComponent: Component | null = null;
  if (code.startsWith(WIDGET_LIB_CODE)) {
    const [_, widgetCode] = code.split(WIDGET_LIB_CODE);
    widgetComponent = RemoteWidgets[widgetCode];
  } else {
    widgetComponent = LocalWidgets[code];
  }
  return widgetComponent?.component || null;
}
