import AttachControl from "./components/controls/AttachControl.vue";
import ButtonControl from "./components/controls/ButtonControl.vue";
import CheckControl from "./components/controls/CheckControl.vue";
import CodeControl from "./components/controls/CodeControl.vue";
import CronEditorControl from "@/core/pagetype/form/controls/CronEditor.vue";
import DataControl from "./components/controls/DataControl.vue";
import GeolocationControl from "./components/controls/GeolocationControl.vue";
import ImageControl from "./components/controls/ImageControl.vue";
import JeditorControl from "@/core/pagetype/form/controls/Jeditor.vue";
import LinkControl from "./components/controls/LinkControl.vue";
import RatingControl from "./components/controls/RatingControl.vue";
import SelectControl from "./components/controls/SelectControl.vue";
import SignatureControl from "./components/controls/SignatureControl.vue";
import TableControl from "./components/controls/TableControl.vue";
import TextControl from "./components/controls/TextControl.vue";
import TextEditorControl from "@/core/pagetype/form/controls/TextEditor.vue";

export function registerGlobalComponents(app) {
  // Helper function to safely register component
  const safeRegister = (name, component) => {
    if (!app.component(name)) {
      app.component(name, component);
    }
    return app;
  };

  safeRegister("AttachControl", AttachControl);
  safeRegister("AttachImageControl", AttachControl);
  safeRegister("AutocompleteControl", DataControl);
  safeRegister("BarcodeControl", DataControl);
  safeRegister("ButtonControl", ButtonControl);
  safeRegister("CheckControl", CheckControl);
  safeRegister("CodeControl", CodeControl);
  safeRegister("ColorControl", DataControl);
  safeRegister("CronEditorControl", CronEditorControl);
  safeRegister("CurrencyControl", DataControl);
  safeRegister("DataControl", DataControl);
  safeRegister("DateControl", DataControl);
  safeRegister("DatetimeControl", DataControl);
  safeRegister("DurationControl", DataControl);
  safeRegister("DynamicLinkControl", DataControl);
  safeRegister("FloatControl", DataControl);
  safeRegister("GeolocationControl", GeolocationControl);
  safeRegister("HeadingControl", ButtonControl);
  safeRegister("HTMLControl", DataControl);
  safeRegister("HTMLEditorControl", CodeControl);
  safeRegister("IconControl", DataControl);
  safeRegister("ImageControl", ImageControl);
  safeRegister("IntControl", DataControl);
  safeRegister("JeditorControl", JeditorControl);
  safeRegister("JSONControl", CodeControl);
  safeRegister("LinkControl", LinkControl);
  safeRegister("LongTextControl", TextControl);
  safeRegister("MarkdownEditorControl", CodeControl);
  safeRegister("PasswordControl", DataControl);
  safeRegister("PercentControl", DataControl);
  safeRegister("PhoneControl", DataControl);
  safeRegister("ReadOnlyControl", DataControl);
  safeRegister("RatingControl", RatingControl);
  safeRegister("SelectControl", SelectControl);
  safeRegister("SignatureControl", SignatureControl);
  safeRegister("SmallTextControl", TextControl);
  safeRegister("TableControl", TableControl);
  safeRegister("TableMultiSelectControl", DataControl);
  safeRegister("TextControl", TextControl);
  safeRegister("TextEditorControl", TextEditorControl);
  safeRegister("TimeControl", DataControl);
}

export const controls = {
  AttachControl,
  ButtonControl,
  CheckControl,
  CodeControl,
  CronEditorControl,
  DataControl,
  GeolocationControl,
  ImageControl,
  JeditorControl,
  LinkControl,
  RatingControl,
  SelectControl,
  SignatureControl,
  TableControl,
  TextEditorControl,
};

export default {
  registerGlobalComponents,
  controls,
};
