/* eslint-disable @typescript-eslint/no-explicit-any */

import { fixedContainerComponent } from "./fixComponentsUtils/container"
import { fixedLikeInputComponentDefaultValue } from "./fixComponentsUtils/likeInput"

export const fixedComponentsToNewComponents = (
  componentsTree: any,
) => {
  const newComponentsTree = componentsTree ?? {}
  if (Array.isArray(newComponentsTree.childrenNode)) {
    newComponentsTree.childrenNode =
      newComponentsTree.childrenNode?.map((component) => {
        switch (component.type) {
          case "CONTAINER_WIDGET":
            return fixedContainerComponent(component)
          case "JSON_EDITOR_WIDGET":
          case "SLIDER_WIDGET":
          case "TEXTAREA_INPUT_WIDGET":
          case "EDITABLE_TEXT_WIDGET":
          case "NUMBER_INPUT_WIDGET":
          case "INPUT_WIDGET": {
            return fixedLikeInputComponentDefaultValue(component)
          }
          default: {
            return fixedComponentsToNewComponents(component)
          }
        }
      }) || []
  }

  return newComponentsTree
}
