/* eslint-disable @typescript-eslint/no-explicit-any */
import React from "react";
import ConfirmationAlert from "../Widgets/ConfirmationAlert";
import { WidgetTypes } from "../constant";
import GridToolBar from "../Widgets/GridToolBar/GridToolBar";
import InformationAlert from "../Widgets/InformationAlert/InformationAlert";
import Menu from "../Widgets/Menu";
import Block from "../Widgets/Block";

class TemplateWidgetFactory {
  private standardWidgetFactory: any = undefined;
  private customWidgetFactory?: any;
  private static factory: TemplateWidgetFactory;
  private widgetMap = new Map<string, React.FC<any>>();

  private constructor() {
    this.createWidgetMap();
  }

  static get(standardWidgetFactory: any, customWidgetFactory: any) {
    if (!standardWidgetFactory && !customWidgetFactory) {
      throw new Error("Widget Factory Not Assigned Error");
    }
    if (!TemplateWidgetFactory.factory) {
      TemplateWidgetFactory.factory = new TemplateWidgetFactory();
    }
    TemplateWidgetFactory.factory.standardWidgetFactory = standardWidgetFactory;
    TemplateWidgetFactory.factory.customWidgetFactory = customWidgetFactory;
    return TemplateWidgetFactory.factory;
  }

  static getStandardFactory = () =>
    TemplateWidgetFactory.factory.standardWidgetFactory;

  static getCustomFactory = () =>
    TemplateWidgetFactory.factory.customWidgetFactory;

  static getTemplateWidgets = () =>
    TemplateWidgetFactory.factory?.widgetMap;

  private createWidgetMap(): void {
    this.widgetMap.set(WidgetTypes.GRIDTOOLBAR, GridToolBar);
    this.widgetMap.set(WidgetTypes.CONFOMATIONALERTBOX, ConfirmationAlert);
    this.widgetMap.set(WidgetTypes.INFOMATIONALERTBOX, InformationAlert);
    this.widgetMap.set(WidgetTypes.MENU, Menu);
    this.widgetMap.set(WidgetTypes.BLOCK, Block);
  }

  getWidgets(): Map<string, React.FC> {
    return this.widgetMap;
  }
}
export default TemplateWidgetFactory;
