"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.messageBehaviorAction = void 0;
var _input = _interopRequireDefault(require("@alifd/next/lib/input"));
var _select = _interopRequireDefault(require("@alifd/next/lib/select"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _box = _interopRequireDefault(require("@alifd/next/lib/box"));
var React = _interopRequireWildcard(require("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; }
function fillDefaultValue(value) {
  if (typeof value !== 'object') {
    console.warn('value passed to fillDefaultValue should be an object');
    return;
  }
  if (!value.type) {
    value.type = 'notice';
  }
}
var MessageActionContent = function MessageActionContent(_ref) {
  var _ref$value = _ref.value,
    value = _ref$value === void 0 ? {} : _ref$value,
    _onChange = _ref.onChange,
    options = _ref.options;
  fillDefaultValue(value);
  var types = options.types;
  return /*#__PURE__*/React.createElement(_box["default"], null, /*#__PURE__*/React.createElement(_box["default"], {
    direction: "row",
    align: "center",
    className: "behavior-item"
  }, /*#__PURE__*/React.createElement(_box["default"], {
    style: {
      width: 70
    }
  }, "\u901A\u77E5\u7C7B\u578B"), /*#__PURE__*/React.createElement(_box["default"], {
    className: "behavior-radio"
  }, /*#__PURE__*/React.createElement(_select["default"], {
    size: "small",
    dataSource: types,
    defaultValue: "notice",
    value: (value === null || value === void 0 ? void 0 : value.type) || 'notice',
    onChange: function onChange(val) {
      _onChange((0, _extends2["default"])({}, value, {
        type: val
      }));
    }
  }))), /*#__PURE__*/React.createElement(_box["default"], {
    direction: "row",
    align: "center",
    className: "behavior-item"
  }, /*#__PURE__*/React.createElement(_box["default"], {
    style: {
      width: 70
    }
  }, "\u901A\u77E5\u5185\u5BB9"), /*#__PURE__*/React.createElement(_box["default"], {
    className: "behavior-radio"
  }, /*#__PURE__*/React.createElement(_input["default"].TextArea, {
    size: "small",
    placeholder: "\u8BF7\u8F93\u5165\u5185\u5BB9",
    value: value.content,
    onChange: function onChange(content) {
      _onChange((0, _extends2["default"])({}, value, {
        content: content
      }));
    }
  }))));
};
var messageBehaviorAction = exports.messageBehaviorAction = {
  name: 'message',
  title: '提示',
  render: function render(props) {
    return /*#__PURE__*/React.createElement(MessageActionContent, props);
  },
  toActionValue: function toActionValue(value, options) {
    var library = options.library,
      component = options.component,
      defaultType = options.defaultType;
    return {
      type: 'JSExpression',
      value: "function() {" + library + "." + component + "." + (value.type || defaultType) + "('" + value.content + "')}"
    };
  }
};