"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _tooltip = _interopRequireDefault(require("../../tooltip"));

var _userSelector = _interopRequireDefault(require("../../user-selector"));

var _style = require("../style");

var _emotionsSelector = _interopRequireDefault(require("../../emotions-selector"));

var _RangeSelectorPop = _interopRequireDefault(require("../../range-selector-pop/RangeSelectorPop"));

var _requestV = require("../../../utils/request-v1");

var _bsGlobal = require("../../../utils/bs-global");

var _context = _interopRequireDefault(require("../context"));

var _ConfirmPop = _interopRequireDefault(require("./ConfirmPop"));

var _upload = _interopRequireDefault(require("../../upload"));

var _getLocale = require("../../../utils/getLocale");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

var visibilityMap = function visibilityMap() {
  return {
    1: (0, _getLocale.getLocale)('OKR_MyO_Pubiic'),
    2: (0, _getLocale.getLocale)('OKR_MyO_Private'),
    3: (0, _getLocale.getLocale)('OKR_MyO_E_Departmentvisible')
  };
};

var MblogAction = /*#__PURE__*/function (_PureComponent) {
  _inherits(MblogAction, _PureComponent);

  var _super = _createSuper(MblogAction);

  function MblogAction() {
    var _this;

    _classCallCheck(this, MblogAction);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _possibleConstructorReturn(_this, (_this = _super.call.apply(_super, [this].concat(args)), _this.state = {
      isSendSms: false,
      // 是否短信通知
      isShowConfirmPop: false
    }, _this._sentMsgClickHandler = function () {
      var isSendSms = _this.state.isSendSms;
      isSendSms = !isSendSms;

      if (isSendSms) {
        var url = (0, _requestV.getApiUrl)("SMS/Check?to_user_id=".concat((0, _bsGlobal.getUserInfo)().Id));
        (0, _requestV.taker)(url, 'GET').then(function (res) {
          if (res.Code == 2 || res.Code == 4) {
            // 目前您企业的短信已超出许可量，请联系超管进行短信充值
            _this.setState({
              isSendSms: false,
              isShowConfirmPop: true
            });
          } else {
            _this.setState({
              isSendSms: true
            });

            _this.props.onActionsTextChange('allowSendSMS');
          }
        });
      } else {
        _this.setState({
          isSendSms: false
        });
      }
    }, _this.onOpenAtSelector = function () {
      _this.refs.atSelector.open(); // 输入@弹出选人组件

    }, _assertThisInitialized(_this)));
  }

  _createClass(MblogAction, [{
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps, prevState) {
      var isInputAt = this.props.isInputAt;

      if (isInputAt) {
        // @ts-ignore
        this.refs.atSelector.open(); // 输入@弹出选人组件
      }
    } // componentWillReceiveProps(newProps: Props) {
    //   if (newProps.isInputEnterSubmit && newProps.isAllowSubmit) {
    //     this.props.onActionSubmit('submit')
    //   }
    // }
    // 短信通知

  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$state = this.state,
          isSendSms = _this$state.isSendSms,
          isShowConfirmPop = _this$state.isShowConfirmPop;
      var _this$props = this.props,
          onActionSubmit = _this$props.onActionSubmit,
          onActionsTextChange = _this$props.onActionsTextChange,
          onActionsAttachmentChange = _this$props.onActionsAttachmentChange,
          submitStatus = _this$props.submitStatus,
          localStroageKey = _this$props.localStroageKey,
          atAllValue = _this$props.atAllValue,
          className = _this$props.className,
          fileNumLimit = _this$props.fileNumLimit,
          fileSizeLimit = _this$props.fileSizeLimit,
          attachmentPreviewBox = _this$props.attachmentPreviewBox,
          userSelectorPopAlign = _this$props.userSelectorPopAlign,
          emotionsSelectorPopAlign = _this$props.emotionsSelectorPopAlign,
          visibility = _this$props.visibility,
          onActionsSelectedUserChange = _this$props.onActionsSelectedUserChange,
          onActionsAllMembersChange = _this$props.onActionsAllMembersChange,
          onActionsEmotionChange = _this$props.onActionsEmotionChange,
          dragFilesList = _this$props.dragFilesList,
          _this$props$disableRa = _this$props.disableRangeSelect,
          disableRangeSelect = _this$props$disableRa === void 0 ? true : _this$props$disableRa,
          _this$props$useMouseD = _this$props.useMouseDown,
          useMouseDown = _this$props$useMouseD === void 0 ? false : _this$props$useMouseD;
      return /*#__PURE__*/_react["default"].createElement(_style.MblogActionWrapper, {
        className: className
      }, /*#__PURE__*/_react["default"].createElement(_style.LeftBtnGroupWrapper, {
        className: "action__left"
      }, this.props.isShowAttachment && /*#__PURE__*/_react["default"].createElement(_style.LeftBtn, {
        key: this.props.attachmentText
      }, /*#__PURE__*/_react["default"].createElement(_upload["default"], {
        fileNumLimit: fileNumLimit,
        fileSizeLimit: fileSizeLimit,
        dragFilesList: dragFilesList,
        attachmentTipText: this.props.attachmentTipText,
        attachmentPreviewBox: attachmentPreviewBox,
        submitStatus: submitStatus,
        localStroageKey: localStroageKey,
        onSubmit: function onSubmit(uploadSuccessFilesPath) {
          return onActionsAttachmentChange(uploadSuccessFilesPath);
        }
      }, /*#__PURE__*/_react["default"].createElement(_style.IconSpan, {
        className: "tu-icon-cus-fujian"
      }), /*#__PURE__*/_react["default"].createElement("span", {
        className: "upload_fujian_text"
      }, this.props.attachmentText))), this.props.isShowAt && /*#__PURE__*/_react["default"].createElement(_style.LeftBtn, {
        key: this.props.atText,
        tips: this.props.atTipText
      }, /*#__PURE__*/_react["default"].createElement(_userSelector["default"], {
        popupAlign: {
          offset: [-550, -100],
          overflow: {
            adjustX: true,
            adjustY: true
          },
          targetOffset: [0, 0]
        },
        ref: "atSelector",
        multiple: true,
        onOk: onActionsSelectedUserChange,
        position: "centerRight",
        autoClear: true // selectNodes={visiableLimitState || {}}

      }, /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
        container: function container() {
          return document.body;
        },
        overlay: this.props.atTipText
      }, /*#__PURE__*/_react["default"].createElement("div", {
        onClick: useMouseDown ? undefined : this.onOpenAtSelector,
        onMouseDown: useMouseDown ? this.onOpenAtSelector : undefined
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "btn-txt"
      }, this.props.atText))))), this.props.isShowAtAll && /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
        container: function container() {
          return document.body;
        },
        overlay: this.props.atAllTipText
      }, /*#__PURE__*/_react["default"].createElement(_style.LeftBtn, {
        key: this.props.atAllText,
        tips: this.props.atAllTipText,
        onMouseDown: onActionsAllMembersChange
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: "btn-txt"
      }, this.props.atAllText))), this.props.isShowEmotion && /*#__PURE__*/_react["default"].createElement(_style.LeftBtn, {
        key: this.props.emotionText
      }, /*#__PURE__*/_react["default"].createElement(_emotionsSelector["default"], {
        align: emotionsSelectorPopAlign,
        popExtraClassName: "pull-screen-ignore",
        container: this.context.popContainer,
        onSubmit: function onSubmit(emotionName, emotion) {
          return onActionsEmotionChange(emotion);
        }
      }, /*#__PURE__*/_react["default"].createElement(_style.IconSpan, {
        className: "tu-icon-emoji"
      }), /*#__PURE__*/_react["default"].createElement("span", {
        className: "btn-txt"
      }, this.props.emotionText)))), /*#__PURE__*/_react["default"].createElement(_style.RightBtnGroupWrapper, {
        className: "action__right"
      }, this.props.isShowRange && /*#__PURE__*/_react["default"].createElement(_style.BtnPrivate, {
        id: "1",
        "data-name": "range",
        className: disableRangeSelect ? 'disabled' : '',
        disabled: disableRangeSelect
      }, /*#__PURE__*/_react["default"].createElement(_RangeSelectorPop["default"], {
        align: "bottom left",
        isDisabled: disableRangeSelect,
        container: this.context.popContainer,
        onSubmit: function onSubmit(visibility) {
          return onActionsTextChange(visibility);
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "mblog-visiblity-range"
      }, /*#__PURE__*/_react["default"].createElement("span", {
        "data-name": "range-cont"
      }, visibilityMap()[visibility || 1]), this.props.isShowRangeDropDown && /*#__PURE__*/_react["default"].createElement("i", {
        className: "tu-icon-caret-down range-cont-icon",
        "data-name": "range-caret"
      })))), this.props.isShowBtnCancel && /*#__PURE__*/_react["default"].createElement(_style.BtnCancel, {
        onMouseDown: function onMouseDown() {
          return onActionSubmit('cancel');
        }
      }, (0, _getLocale.getLocale)('Mod_Cancel')), /*#__PURE__*/_react["default"].createElement(_style.BtnConfirm, {
        disabled: !this.props.isAllowSubmit,
        className: !this.props.isAllowSubmit || this.props.submitStatus === 2 ? 'disabled' : '',
        onMouseDown: function onMouseDown() {
          return onActionSubmit('submit');
        }
      }, this.props.submitStatus !== 2 ? this.props.submitText : "".concat(this.props.submitText, "\u4E2D..."))), isShowConfirmPop && /*#__PURE__*/_react["default"].createElement(_ConfirmPop["default"], {
        onSubmit: function onSubmit() {
          _this2.setState({
            isShowConfirmPop: false
          });
        }
      }));
    }
  }]);

  return MblogAction;
}(_react.PureComponent);

exports["default"] = MblogAction;
MblogAction.contextType = _context["default"];
MblogAction.defaultProps = {
  userSelectorPopAlign: 'top left',
  emotionsSelectorPopAlign: 'top center'
};