"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 _styledComponents = _interopRequireDefault(require("styled-components"));

var _popup = _interopRequireDefault(require("../../../../../../popup"));

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

var _i18nFrontTranslate = require("../../../../../../../utils/i18n-front-translate");

var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;

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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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); }

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var Wrapper = _styledComponents["default"].div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n  min-width: 343px;\n  background: #FFFFFF;\n  box-shadow: 0 2px 4px 0 rgba(0,0,0,0.21);\n  border-radius: 4px;\n  display: flex;\n  flex-direction: column;\n  align-items: stretch; \n"])));

var Header = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n  background-image: linear-gradient(90deg, #1D86F0 6%, #5CADFF 94%);\n  height: 32px;\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n  box-sizing: border-box;\n  padding: 0 16px;\n  border-top-left-radius: 4px;\n  border-top-right-radius: 4px;\n"])));

var Body = _styledComponents["default"].div(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n  padding: 13px 13px 15px 18px;\n"])));

var Title = _styledComponents["default"].span(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n  font-size: 14px;\n  color: #FFF;\n  user-select: none;\n"])));

var Icon = _styledComponents["default"].a(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n  font-size: 12px;\n  color: #FFF;\n  &:hover {\n    color: #FFF;\n  }\n"])));

var Line = _styledComponents["default"].div(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n  display: flex;\n  height: 23px;\n  align-items: center;\n  margin-bottom: 2px;\n"])));

var InputName = _styledComponents["default"].span(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n  font-family: OPPOSans, Arial, Verdana, Helvetica Neue, Helvetica, PingFang SC, Microsoft YaHei, sans-serif;\n  font-size: 14px;\n  color: #83898F;\n  margin-right: 4px;\n"])));

var LineInputWrapper = _styledComponents["default"].div(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n  display: flex;\n  align-items: center;\n  justify-content: stretch;\n  flex: 1;\n  box-sizing: border-box;\n  border: 1px solid #E6E8EB;\n  border-radius: 4px;\n  height: 28px;\n  line-height: 23px;\n  font-size: 14px;\n  color: #33383D;\n  padding: 0 8px;\n"])));

var BtnWrapper = _styledComponents["default"].div(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n  display: flex;\n  justify-content: flex-end;\n"])));

var CancelBtn = _styledComponents["default"].a(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n  width: 55px;\n  height: 26px;\n  text-align: center;\n  line-height: 26px;\n  background: #FAFBFC;\n  box-shadow: 0 0 2px 0 rgba(0,0,0,0.21);\n  border-radius: 2px;\n  font-size: 12px;\n  color: #565E66;\n  margin-right: 15px;\n  &:hover {\n    color: #565E66;\n  }\n"])));

var ErrorWrapper = _styledComponents["default"].div(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\nfont-size: 12px;\ncolor: #D0021B;\nheight: 20px;\n"])));

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

  var _super = _createSuper(EditPop);

  function EditPop() {
    var _this;

    _classCallCheck(this, EditPop);

    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 = {
      value: _this.props.value,
      showError: false,
      errMsg: "",
      disable: false,
      visiable: false
    }, _this.handleCancel = function () {
      _this.setState({
        visiable: false
      });
    }, _this.handleClick = function (e) {
      e.stopPropagation();
      e.nativeEvent.stopImmediatePropagation();
      var onShow = _this.props.onShow;
      onShow && onShow();

      _this.setState({
        value: _this.props.value,
        errMsg: "",
        showError: false
      }); // // @ts-ignore
      // this.refs.pop.open() //this.refs.trigger


      _this.setState({
        visiable: true
      });
    }, _this.handleConfirm = function () {
      var _this$props = _this.props,
          onConfirm = _this$props.onConfirm,
          isValueValid = _this$props.isValueValid;
      var value = _this.state.value;
      var error = onConfirm(value);
      var disable = _this.props.disable;

      if (error) {
        _this.setState({
          showError: true,
          errMsg: error,
          disable: !!disable
        });

        return;
      }

      if (isValueValid != void 0 && !isValueValid) return;
      if (_this.state.showError) return; // // @ts-ignore
      // this.refs.pop.close();

      _this.setState({
        visiable: false
      });
    }, _this.handleChange = function (e) {
      var maxLength = _this.props.maxLength;
      var value = e.target.value;
      var disable = _this.props.disable;

      _this.setState({
        value: value,
        showError: maxLength && value.length > maxLength,
        errMsg: (0, _i18nFrontTranslate.inputWordTrans)(value.length, maxLength),
        disable: !!(maxLength && value.length > maxLength && disable)
      });
    }, _assertThisInitialized(_this)));
  }

  _createClass(EditPop, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props2 = this.props,
          isValueValid = _this$props2.isValueValid,
          title = _this$props2.title,
          inputName = _this$props2.inputName,
          type = _this$props2.type,
          placeHolder = _this$props2.placeHolder,
          information = _this$props2.information,
          extra = _this$props2.extra,
          style = _this$props2.style,
          container = _this$props2.container;
      var _this$state = this.state,
          showError = _this$state.showError,
          errMsg = _this$state.errMsg,
          disable = _this$state.disable,
          visiable = _this$state.visiable;

      var SureBtn = _styledComponents["default"].a(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n      width: 55px;\n      height: 26px;\n      text-align: center;\n      line-height: 26px;\n      background: #1D86F0;\n      box-shadow: 0 0 2px 0 rgba(0,0,0,0.21);\n      border-radius: 2px;\n      font-size: 12px;\n      color: #FFFFFF;\n      &:hover {\n        color: ", ";\n      }\n    "])), isValueValid ? "#FFF" : "#565E66");

      var sureButtonStyleForScoreInfo = isValueValid ? {} : {
        backgroundColor: "rgb(231, 238, 243)",
        color: "rgb(173, 184, 192)"
      }; // 这个样式只针对修改评分说明, 需要判断是否提供了isValueValid

      var sureBtnStyle2 = isValueValid != void 0 ? sureButtonStyleForScoreInfo : {};
      var sureBtnStyle1 = disable ? {
        "default": "default",
        color: "#ADB8C0",
        backgroundColor: "#E7EEF3"
      } : {};

      var popupLayer = /*#__PURE__*/_react["default"].createElement(Wrapper, {
        onClick: function onClick(e) {
          e.stopPropagation();
          e.nativeEvent.stopImmediatePropagation();
        }
      }, /*#__PURE__*/_react["default"].createElement(Header, null, /*#__PURE__*/_react["default"].createElement(Title, null, title), /*#__PURE__*/_react["default"].createElement(Icon, {
        className: "tu-icon-canceled",
        onClick: this.handleCancel
      })), /*#__PURE__*/_react["default"].createElement(Body, null, /*#__PURE__*/_react["default"].createElement(Line, null, /*#__PURE__*/_react["default"].createElement(InputName, {
        style: type == "line" ? {
          width: _getLocale.isEn ? "75px" : "30px"
        } : {
          position: "relative",
          top: "3px",
          width: _getLocale.isEn ? "75px" : "30px"
        }
      }, inputName), type == "line" && /*#__PURE__*/_react["default"].createElement(LineInputWrapper, {
        style: showError ? {
          borderColor: "#D0021B"
        } : undefined
      }, /*#__PURE__*/_react["default"].createElement("input", {
        style: {
          border: "none",
          outline: "none",
          width: "100%"
        },
        placeholder: placeHolder,
        value: this.state.value,
        onChange: this.handleChange
      }))), type != "line" && /*#__PURE__*/_react["default"].createElement("textarea", {
        style: {
          width: "100%",
          height: "44px",
          lineHeight: "22px",
          border: "1px solid ".concat(showError ? "#D0021B" : "#E6E8EB"),
          borderRadius: "4px",
          display: "block"
        },
        value: this.state.value,
        placeholder: placeHolder,
        onChange: this.handleChange
      }), /*#__PURE__*/_react["default"].createElement(ErrorWrapper, {
        style: {
          paddingLeft: type == "line" ? 30 : 0
        }
      }, showError && errMsg), information, extra, /*#__PURE__*/_react["default"].createElement(BtnWrapper, null, /*#__PURE__*/_react["default"].createElement(CancelBtn, {
        onClick: this.handleCancel
      }, (0, _getLocale.getLocale)("Mod_Cancel")), /*#__PURE__*/_react["default"].createElement(SureBtn, {
        onClick: this.handleConfirm,
        style: _objectSpread(_objectSpread({}, sureBtnStyle1), sureBtnStyle2)
      }, (0, _getLocale.getLocale)("OKR_MyO_Butt_Determine")))));

      return /*#__PURE__*/_react["default"].createElement(_popup["default"], {
        popupVisible: visiable,
        popup: popupLayer,
        onPopupVisibleChange: function onPopupVisibleChange(v) {
          return _this2.setState({
            visiable: v
          });
        },
        destroyPopupOnHide: true
      }, this.props.children);
    }
  }]);

  return EditPop;
}(_react.PureComponent);

exports["default"] = EditPop;
EditPop.defaultProps = {
  value: ""
};