import _Select from "@alifd/next/es/select";
import _extends from "@babel/runtime/helpers/extends";
import React, { useEffect, useState } from "react";
import BoxSlotComponent from "../../_components/boxSlotComponent";
import { OperateEnumType, getComOpenActiveList } from "../config";
import { TelegramType, OperationType } from "../type";
import { DialogComponent } from "./dialogComponent";
import { ToLinkComponent } from "./toLinkComponent";
import { TipComponent } from "./tipComponent";
import { GroupComponent } from "./groupComponent";
import { VideoComponent } from "./videoComponent";
import { RotateWheelComponent } from "./rotateWheelComponent";
import { t } from "../../../../src/locale";
import { TelegramComponent } from "./telegramComponent";
import { GroupDataSourceType } from "../../cGroupManage-setter/type";
import { BehaviorType } from "../../../../src/utils/CLowCodeService/type";
import { AnimationComponent } from "./animationComponent";
import { CarouselComponent } from "./carouselComponent";
export var OpenComponent = function OpenComponent(props) {
  var value = props.value,
    onChange = props.onChange;
  var _useState = useState(value || {
      operateType: OperateEnumType.Dialog,
      modelName: [],
      modelTreeData: [],
      apiParams: []
    }),
    openPageObj = _useState[0],
    setOpenPageObj = _useState[1];
  useEffect(function () {
    onChange(openPageObj);
  }, [openPageObj]);
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BoxSlotComponent, {
    title: t("setter.controls")
  }, /*#__PURE__*/React.createElement(_Select, {
    placeholder: t("setter.selectPlaceHolder"),
    notFoundContent: t('setter.notFoundContent'),
    showSearch: true,
    value: openPageObj.operateType,
    dataSource: getComOpenActiveList(),
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        modelName: [],
        modelTreeData: [],
        operateType: e
      }));
    }
  })), openPageObj.operateType === OperateEnumType.Dialog && /*#__PURE__*/React.createElement(DialogComponent, {
    title: t("setter.bindWindow"),
    value: {
      modelName: openPageObj.modelName,
      modelTreeData: openPageObj.modelTreeData,
      apiParams: openPageObj.apiParams
    },
    maxList: 1,
    isParams: true,
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, e));
    }
  }), openPageObj.operateType === OperateEnumType.ToLink && /*#__PURE__*/React.createElement(ToLinkComponent, {
    value: openPageObj.linkParams || '',
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        linkParams: e
      }));
    }
  }), openPageObj.operateType === OperateEnumType.Tip && /*#__PURE__*/React.createElement(TipComponent, {
    value: openPageObj.messageConfig,
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        messageConfig: Object.assign({}, e)
      }));
    }
  }), openPageObj.operateType === OperateEnumType.Group && /*#__PURE__*/React.createElement(GroupComponent, {
    originNode: BehaviorType.openBehavior,
    value: openPageObj.groupParams || {
      groupId: '',
      groupIndex: '',
      groupIndexSelectType: GroupDataSourceType["default"],
      groupStateSelectType: GroupDataSourceType["default"],
      groupFollowStateSelectType: GroupDataSourceType["default"]
    },
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        groupParams: Object.assign({}, e)
      }));
    }
  }), openPageObj.operateType === OperateEnumType.Video && /*#__PURE__*/React.createElement(VideoComponent, {
    value: openPageObj.videoParams || {
      videoComponentKey: '',
      videoGroupId: '',
      videoDataSourceType: GroupDataSourceType["default"]
    },
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        videoParams: Object.assign({}, e)
      }));
    }
  }), openPageObj.operateType === OperateEnumType.Telegram && /*#__PURE__*/React.createElement(TelegramComponent, {
    value: openPageObj.telegramParams || {
      type: TelegramType.link,
      data: {}
    },
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        telegramParams: Object.assign({}, e)
      }));
    }
  }), openPageObj.operateType === OperateEnumType.RotateWheel && /*#__PURE__*/React.createElement(RotateWheelComponent, {
    type: OperationType.start,
    value: openPageObj.rotateWheelParams,
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        rotateWheelParams: Object.assign({}, e)
      }));
    }
  }), openPageObj.operateType === OperateEnumType.Animation && /*#__PURE__*/React.createElement(AnimationComponent, {
    type: OperationType.start,
    value: openPageObj.animationParams,
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        animationParams: e
      }));
    }
  }), openPageObj.operateType === OperateEnumType.Carousel && /*#__PURE__*/React.createElement(CarouselComponent, {
    type: OperationType.start,
    value: openPageObj.carouselParams,
    onChange: function onChange(e) {
      setOpenPageObj(_extends({}, openPageObj, {
        carouselParams: Object.assign({}, e)
      }));
    }
  }));
};