"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 _rangePickerPop = _interopRequireDefault(require("../range-picker-pop"));

var _ReviewItem = _interopRequireDefault(require("./components/ReviewItem"));

var _platform = require("../../utils/platform");

var _Portals = _interopRequireDefault(require("../../components-v1/portals/Portals"));

var _ReviewPop = _interopRequireDefault(require("./ReviewPop"));

var _transition = _interopRequireDefault(require("../../components-v1/transition"));

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

var _common = require("./common");

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

var _openData = require("../../utils/open-data");

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 Review = /*#__PURE__*/function (_PureComponent) {
  _inherits(Review, _PureComponent);

  var _super = _createSuper(Review);

  function Review(props) {
    var _this;

    _classCallCheck(this, Review);

    _this = _super.call(this, props);

    _this.getReviewList = function (startDate, endDate) {
      var ObjData = _this.props.ObjData;
      var url = (0, _requestV.getApiUrl)("replay/getByObjId?objId=".concat(ObjData.ObjId, "&objType=").concat(ObjData.ObjType, "&startDate=").concat(startDate || "", "&endDate=").concat(endDate || ""));
      (0, _requestV.taker)(url, "GET").then(function (res) {
        if (res.Code == 1) {
          _this.setState({
            reviewList: res.Data || []
          });
        }
      });
    };

    _this._handleTimePickConfirm = function (date) {
      var startDate = date.startDate,
          endDate = date.endDate;

      _this.getReviewList(startDate, endDate);

      _this.setState({
        startDate: _this._enFormatDate(startDate),
        endDate: _this._enFormatDate(endDate)
      });
    };

    _this._handlerReviewPopChange = function (submitType) {
      if (submitType) {
        _this.setState({
          startDate: "",
          endDate: ""
        }, function () {
          return _this.getReviewList();
        });
      }

      _this.setState({
        isShowReviewPop: false
      });
    };

    _this._enFormatDate = function (date) {
      return date && "".concat(date.replace(/\//, "年").replace(/\//, "月"), "\u65E5");
    };

    _this._deFormatDate = function (date) {
      return date && date.replace(/年/, "/").replace(/月/, "/").replace(/日/, "");
    };

    _this.stopPropagation = function (e) {
      e.nativeEvent.stopImmediatePropagation();
      e.stopPropagation();
    };

    _this.state = {
      isShowReviewPop: false,
      startDate: "",
      endDate: "",
      editType: 0,
      replayId: 0,
      reviewList: [{
        replayId: 0,
        creatDate: "",
        editable: true
      }]
    };
    return _this;
  }

  _createClass(Review, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.getReviewList();
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(newProps) {
      this.getReviewList();
    } // 获取复盘了列表

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

      var _this$state = this.state,
          isShowReviewPop = _this$state.isShowReviewPop,
          startDate = _this$state.startDate,
          endDate = _this$state.endDate,
          editType = _this$state.editType,
          reviewList = _this$state.reviewList,
          replayId = _this$state.replayId;
      var _this$props = this.props,
          className = _this$props.className,
          isCompactMode = _this$props.isCompactMode,
          defaultRange = _this$props.defaultRange,
          ObjData = _this$props.ObjData,
          editAble = _this$props.editAble,
          feedId = _this$props.feedId,
          createTask = _this$props.createTask,
          isOkrPanel = _this$props.isOkrPanel;
      var isFiltered = startDate && endDate; // 判断是否筛选过

      return /*#__PURE__*/_react["default"].createElement(_style.ReviewContainer, {
        className: className,
        mode: isCompactMode ? 0 : 1
      }, /*#__PURE__*/_react["default"].createElement(_style.ReviewHead, {
        mode: isCompactMode ? 0 : 1
      }, /*#__PURE__*/_react["default"].createElement(_style.ReviewAdd, {
        style: {
          visibility: _common.isHavePermission || editAble ? "visible" : "hidden"
        },
        onClick: function onClick() {
          return _this2.setState({
            isShowReviewPop: true,
            editType: 0
          });
        }
      }, /*#__PURE__*/_react["default"].createElement(_style.IconAdd, {
        className: "tu-icon-add",
        mode: isCompactMode ? 0 : 1
      }), /*#__PURE__*/_react["default"].createElement("span", null, (0, _getLocale.getLocale)("OKR_MyO_KRP_AddReview"))), (reviewList.length > 0 || isFiltered) && /*#__PURE__*/_react["default"].createElement(_style.ReviewFilter, null, /*#__PURE__*/_react["default"].createElement(_rangePickerPop["default"], {
        align: "bottom right",
        format: "YYYY/MM/DD",
        defaultRange: defaultRange,
        container: this.props.popContainer,
        onConfirm: this._handleTimePickConfirm,
        popupPlacement: "bottomRight"
      }, !isFiltered && /*#__PURE__*/_react["default"].createElement("span", null, (0, _getLocale.getLocale)("OKR_MyO_Ew_Butt_Filterbytime")), /*#__PURE__*/_react["default"].createElement(_style.IconFilter, {
        className: "tu-icon-calendar"
      }), isFiltered && /*#__PURE__*/_react["default"].createElement(_style.FilterTime, null, "".concat(startDate, " - ").concat(endDate))))), reviewList.length === 0 ? /*#__PURE__*/_react["default"].createElement(_style.ReviewEmpty, {
        mode: isCompactMode ? 0 : 1
      }, isFiltered ? /*#__PURE__*/_react["default"].createElement("p", null, (0, _getLocale.getLocale)("Mod_ lookingfor")) : /*#__PURE__*/_react["default"].createElement("p", null, (0, _getLocale.getLocale)("OKR_MyO_Re_Notreviewed")), !(0, _openData.isPlatform)("dd") && /*#__PURE__*/_react["default"].createElement("p", {
        className: "learnmore"
      }, /*#__PURE__*/_react["default"].createElement("a", {
        href: (0, _platform.isFeishu)("https://wiki.tita.com/x/vIK3") || "https://docs.tita.com/tita-how-to-write-review-summary/",
        target: "_blank",
        rel: "noreferrer"
      }, /*#__PURE__*/_react["default"].createElement(_style.IconWiki, {
        className: "tu-icon-wiki",
        mode: isCompactMode ? 0 : 1
      }), /*#__PURE__*/_react["default"].createElement("span", null, (0, _getLocale.getLocale)("OKR_MyO_KRP_Pop_Understandt"))))) : /*#__PURE__*/_react["default"].createElement(_style.ReviewList, null, reviewList.map(function (item, index) {
        return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, {
          key: feedId
        }, /*#__PURE__*/_react["default"].createElement(_ReviewItem["default"], {
          isCompactMode: isCompactMode,
          feedId: feedId,
          editAble: editAble,
          reviewItemData: item,
          krIndex: ObjData.ObjIndex,
          editReview: function editReview() {
            return _this2.setState({
              isShowReviewPop: true,
              editType: 1,
              replayId: item.replayId
            });
          }
        }));
      })), /*#__PURE__*/_react["default"].createElement(_Portals["default"], null, /*#__PURE__*/_react["default"].createElement(_transition["default"], {
        visible: isShowReviewPop,
        animate: true,
        transitionName: "modal",
        enterActiveTimeout: 300,
        enterEndTimeout: 100,
        leaveActiveTimeout: 100,
        leaveEndTimeout: 300
      }, /*#__PURE__*/_react["default"].createElement(_ReviewPop["default"], {
        ObjData: ObjData,
        EditType: editType,
        ReplayId: replayId,
        createTask: createTask,
        isOkrPanel: isOkrPanel,
        onSubmit: function onSubmit(submitType) {
          return _this2._handlerReviewPopChange(submitType);
        }
      }))));
    }
  }]);

  return Review;
}(_react.PureComponent);

exports["default"] = Review;
Review.defaultProps = {
  isCompactMode: false
};