"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.dialogBehaviorAction = void 0;
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var _box = _interopRequireDefault(require("@alifd/next/lib/box"));
var _react = _interopRequireWildcard(require("react"));
var React = _react;
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 getDialogList = function getDialogList(field) {
  var _nodeDocument$modalNo, _nodeDocument$modalNo2;
  var node = field.getNode();
  var nodeDocument = node.document || node.page;
  var nodeList = nodeDocument === null || nodeDocument === void 0 ? void 0 : (_nodeDocument$modalNo = nodeDocument.modalNodesManager) === null || _nodeDocument$modalNo === void 0 ? void 0 : (_nodeDocument$modalNo2 = _nodeDocument$modalNo.getModalNodes) === null || _nodeDocument$modalNo2 === void 0 ? void 0 : _nodeDocument$modalNo2.call(_nodeDocument$modalNo);
  if (!nodeList || !nodeList.length) {
    var _nodeDocument$modalNo3, _nodeDocument$modalNo4, _nodeDocument$modalNo5, _nodeDocument$modalNo6;
    nodeDocument === null || nodeDocument === void 0 ? void 0 : (_nodeDocument$modalNo3 = nodeDocument.modalNodesManager) === null || _nodeDocument$modalNo3 === void 0 ? void 0 : (_nodeDocument$modalNo4 = _nodeDocument$modalNo3.setNodes) === null || _nodeDocument$modalNo4 === void 0 ? void 0 : _nodeDocument$modalNo4.call(_nodeDocument$modalNo3);
    nodeList = nodeDocument === null || nodeDocument === void 0 ? void 0 : (_nodeDocument$modalNo5 = nodeDocument.modalNodesManager) === null || _nodeDocument$modalNo5 === void 0 ? void 0 : (_nodeDocument$modalNo6 = _nodeDocument$modalNo5.getModalNodes) === null || _nodeDocument$modalNo6 === void 0 ? void 0 : _nodeDocument$modalNo6.call(_nodeDocument$modalNo5);
  }
  return (nodeList || []).filter(function (x) {
    return x && x.propsData;
  }).map(function (x) {
    return {
      label: x.propsData && x.propsData.title ? x.propsData.title + "(" + x.id + ")" : x.id + "(" + x.componentName + ")",
      value: x.propsData.ref
    };
  });
};
var DialogContent = function DialogContent(_ref) {
  var _ref$value = _ref.value,
    value = _ref$value === void 0 ? {} : _ref$value,
    _onChange = _ref.onChange,
    field = _ref.field;
  var _useState = (0, _react.useState)([]),
    dialogList = _useState[0],
    setDialogList = _useState[1];
  (0, _react.useEffect)(function () {
    setDialogList(getDialogList(field));
  }, [field]);
  return /*#__PURE__*/React.createElement(_box["default"], {
    direction: "row",
    align: "center",
    className: "behavior-item"
  }, /*#__PURE__*/React.createElement(_box["default"], {
    style: {
      width: 70
    }
  }, "\u7ED1\u5B9A\u5F39\u7A97"), /*#__PURE__*/React.createElement(_box["default"], {
    className: "behavior-radio"
  }, /*#__PURE__*/React.createElement(_select["default"], {
    size: "small",
    hasClear: true,
    value: value.id,
    onChange: function onChange(val) {
      return _onChange({
        id: val
      });
    },
    dataSource: dialogList,
    style: {
      width: '100%',
      marginRight: 8
    }
  })));
};
var dialogBehaviorAction = exports.dialogBehaviorAction = {
  name: 'dialog',
  title: '弹窗',
  render: function render(props) {
    return /*#__PURE__*/React.createElement(DialogContent, props);
  },
  toActionValue: function toActionValue(value) {
    return value.id ? {
      type: 'JSExpression',
      value: "function() {\n      const dialog = this.$('" + value.id + "');\n      dialog.show();\n    }"
    } : null;
  }
};