"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.DialogComponent = void 0;
var _cascaderSelect = _interopRequireDefault(require("@alifd/next/lib/cascader-select"));
var _react = _interopRequireWildcard(require("react"));
var _boxSlotComponent = _interopRequireDefault(require("../../_components/boxSlotComponent"));
var _behaviorService = require("../../../_utils/behaviorService");
var _config = require("../config");
var _utils = require("../../../_utils/utils");
var _ = require("../..");
var _commonFn = require("../../cDataSourceList-setter/commonFn");
var _utils2 = require("../config/utils");
var _locale = require("../../../../src/locale");
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
var DialogComponent = exports.DialogComponent = function DialogComponent(props) {
  var _props$value, _props$value2, _props$value3;
  var behaviorService = new _behaviorService.BehaviorService();
  var _useState = (0, _react.useState)([]),
    dataSource = _useState[0],
    setDataSource = _useState[1];
  var _useState2 = (0, _react.useState)(((_props$value = props.value) === null || _props$value === void 0 ? void 0 : _props$value.modelName) || []),
    modelName = _useState2[0],
    setModelName = _useState2[1];
  var _useState3 = (0, _react.useState)(((_props$value2 = props.value) === null || _props$value2 === void 0 ? void 0 : _props$value2.modelTreeData) || []),
    modelTreeData = _useState3[0],
    setModelTreeData = _useState3[1];
  var _useState4 = (0, _react.useState)(((_props$value3 = props.value) === null || _props$value3 === void 0 ? void 0 : _props$value3.apiParams) || []),
    apiParams = _useState4[0],
    setApiParams = _useState4[1];
  (0, _react.useEffect)(function () {
    var data = behaviorService.getModalList();
    setDataSource(data);
  }, []);
  (0, _react.useEffect)(function () {
    var obj = {
      operateType: _config.OperateEnumType.Dialog,
      modelName: modelName,
      modelTreeData: modelTreeData
    };
    if (props.isParams && props.maxList === 1) {
      obj.apiParams = apiParams;
    }
    props.onChange(obj);
  }, [modelName, modelTreeData, apiParams]);
  function onChangeFn(v, treeData) {
    var num = (0, _utils2.getTreeDataNum)(treeData);
    if (props.maxList && num > props.maxList) {
      return;
    }
    setModelName(v ? v : []);
    setModelTreeData((0, _utils.filter_source)(treeData ? treeData : []));
    if (props.isParams && props.maxList === 1) {
      var data = (0, _utils2.getDialogParamsByTreeData)(treeData);
      data = (0, _commonFn.getApiParams)(data);
      setApiParams(data);
    }
  }
  return /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      marginBottom: "10px"
    }
  }, /*#__PURE__*/_react["default"].createElement(_boxSlotComponent["default"], {
    title: props.title
  }, /*#__PURE__*/_react["default"].createElement(_cascaderSelect["default"], {
    multiple: true,
    className: "itemOne_select",
    popupClassName: "itemOne-Select-popup",
    listClassName: "itemOne-Select-list",
    style: {
      width: 100 + "%",
      minWidth: 0
    },
    dataSource: dataSource,
    value: modelName,
    onChange: function onChange(v, treeData) {
      onChangeFn(v, treeData);
    },
    placeholder: (0, _locale.t)('setter.selectPlaceHolder')
  })), props.isParams && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "dataSourceTitle"
  }, (0, _locale.t)('setter.requestParams')), /*#__PURE__*/_react["default"].createElement("div", {
    className: "pramsBox requireBody"
  }, /*#__PURE__*/_react["default"].createElement(_.CTreeDataRelationSetter, {
    key: (0, _utils2.getNewKeyByApiParams)(apiParams),
    value: apiParams || [],
    disabledInput: true,
    maxAddNum: -1,
    onChange: function onChange(e) {
      setApiParams(e ? e : []);
    }
  }))));
};