"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 _classnames = _interopRequireDefault(require("classnames"));

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

var _header = _interopRequireDefault(require("./components/header"));

var _tabs = _interopRequireWildcard(require("../tabs"));

var _tabPanelContent = _interopRequireDefault(require("./components/tab-panel-content"));

var _baseInfo = _interopRequireDefault(require("./base-info"));

var _schedule = _interopRequireDefault(require("./schedule"));

var _requestApis = require("./request-apis");

var _helper = require("./helper");

var _okrReview = _interopRequireDefault(require("../okr-review"));

var _reportList = _interopRequireDefault(require("../eReport/eReportLists/reportList"));

var _cooperation = _interopRequireDefault(require("./cooperation"));

var _detailFooter = _interopRequireDefault(require("./detail-footer"));

var _eList = _interopRequireDefault(require("./e-list"));

var _okrList = _interopRequireDefault(require("./okr-list"));

var _detailHeader = _interopRequireDefault(require("./detail-header"));

var _context2 = _interopRequireDefault(require("../drawer-manager/context"));

var _errorPage = _interopRequireDefault(require("./error-page"));

var _loading = _interopRequireDefault(require("./loading"));

var _aoNice = _interopRequireDefault(require("./components/ao-nice"));

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

require("./index.css");

var _window$BSGlobal$tena;

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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var preCls = 'okr-detail'; // E周报和复盘开关

var EWorkReport = BSGlobal.OkrAdvancedSetting ? BSGlobal.OkrAdvancedSetting.KRSetting.EWorkReport : false;
var OkrAnalyse = BSGlobal.OkrAdvancedSetting ? BSGlobal.OkrAdvancedSetting.KRSetting.OkrAnalyse : false;
var source = (_window$BSGlobal$tena = window.BSGlobal.tenantInfo) === null || _window$BSGlobal$tena === void 0 ? void 0 : _window$BSGlobal$tena.Source;

function OkrDetail(props) {
  var okrId = props.okrId;

  var _useState = (0, _react.useState)(true),
      _useState2 = _slicedToArray(_useState, 2),
      loading = _useState2[0],
      setLoading = _useState2[1];

  var _useState3 = (0, _react.useState)({}),
      _useState4 = _slicedToArray(_useState3, 2),
      okrInfo = _useState4[0],
      setOkrInfo = _useState4[1];

  var _useState5 = (0, _react.useState)(props.activeTabKey || 'okr'),
      _useState6 = _slicedToArray(_useState5, 2),
      activeTabKey = _useState6[0],
      setActiveTabKey = _useState6[1];

  var drawerManagerContext = (0, _react.useContext)(_context2["default"]);

  var _useState7 = (0, _react.useState)(''),
      _useState8 = _slicedToArray(_useState7, 2),
      errorMsg = _useState8[0],
      setErrorMsg = _useState8[1];

  var changeTabActive = function changeTabActive(key) {
    if (!'okr,exec,progress,cooperation,eReport,review,baseInfo'.match(key)) {
      return console.log("\u672A\u627E\u5230\u5BF9\u5E94\u7684tab\u9875\u7B7E: ".concat(key));
    }

    drawerManagerContext && drawerManagerContext.saveProps({
      activeTabKey: key
    });
    setActiveTabKey(key);

    if (key == 'cooperation') {
      bottomReply.current.show(undefined, false);
    } else {
      bottomReply.current.hide();
    }
  };

  (0, _react.useEffect)(function () {
    setActiveTabKey(props.activeTabKey);
  }, [props.activeTabKey]);
  (0, _react.useEffect)(function () {
    if (okrId && okrInfo.feedId) {
      var _window$titaTracker;

      window.titaTracker && ((_window$titaTracker = window.titaTracker("discoveryAction")) === null || _window$titaTracker === void 0 ? void 0 : _window$titaTracker.record({
        "actionName": "查看okr",
        "actionGroup": "okr推屏",
        "productName": 'okr',
        "requestPath": 'user-okr-action',
        "feedId": okrInfo.feedId,
        "action_id": 1,
        "okr_id": okrId
      }));
    }
  }, [okrId, okrInfo]);

  var _useState9 = (0, _react.useState)({}),
      _useState10 = _slicedToArray(_useState9, 2),
      generalPrincipalUser = _useState10[0],
      setGeneralPrincipalUser = _useState10[1]; // 负责人


  var _useState11 = (0, _react.useState)(),
      _useState12 = _slicedToArray(_useState11, 2),
      generalOkrClassify = _useState12[0],
      setGeneralOkrClassify = _useState12[1]; // 类别


  var _useState13 = (0, _react.useState)(),
      _useState14 = _slicedToArray(_useState13, 2),
      generalVisibility = _useState14[0],
      setGeneralVisibility = _useState14[1]; // 可见范围


  var _useState15 = (0, _react.useState)(),
      _useState16 = _slicedToArray(_useState15, 2),
      generalOkrType = _useState16[0],
      setGeneralOkrType = _useState16[1]; // 目标类型


  var _useState17 = (0, _react.useState)(false),
      _useState18 = _slicedToArray(_useState17, 2),
      showOkrEvalute = _useState18[0],
      setShowOkrEvalute = _useState18[1];

  var _useState19 = (0, _react.useState)(),
      _useState20 = _slicedToArray(_useState19, 2),
      generalCycle = _useState20[0],
      setGeneralCycle = _useState20[1]; // 目标周期


  var _useState21 = (0, _react.useState)(),
      _useState22 = _slicedToArray(_useState21, 2),
      generalParent = _useState22[0],
      setGeneralParent = _useState22[1]; // 对齐目标


  var _useState23 = (0, _react.useState)(),
      _useState24 = _slicedToArray(_useState23, 2),
      generalRoleType = _useState24[0],
      setGeneralRoleType = _useState24[1];

  var _useState25 = (0, _react.useState)({
    isOpen: false
  }),
      _useState26 = _slicedToArray(_useState25, 2),
      approvalSetting = _useState26[0],
      setApprovalSetting = _useState26[1]; // 计算元素的ref，用于实现 tabs 吸顶，点赞吸底


  var tabRef = (0, _react.useRef)();
  var tabsContnetRef = (0, _react.useRef)();
  var bodyRef = (0, _react.useRef)();
  var bottomReply = (0, _react.useRef)();
  var communicationRef = (0, _react.useRef)();
  var okrListRef = (0, _react.useRef)();
  var onAfterReply = (0, _react.useCallback)(function () {
    communicationRef && communicationRef.current && communicationRef.current.refresh();
    setActiveTabKey('cooperation');
  }, []);

  var getData = function getData() {
    (0, _requestApis.getOkrDetail)({
      okrId: okrId
    }).then(function (detailInfo) {
      setOkrInfo(detailInfo);
      setLoading(false);
    })["catch"](function (e) {
      setErrorMsg(e);
      console.error(e);
    });
  };

  var refreshAll = function refreshAll() {
    getData();
  };

  var getApprovalShow = function getApprovalShow() {
    (0, _requestApis.getOkrApprovalSettingInfo)().then(function (resp) {
      if (resp.Code === 1) {
        setApprovalSetting((0, _helper.getApprovalOpenItem)(resp.Data));
      }
    });
  };

  (0, _react.useEffect)(function () {
    setLoading(true);
    getData();
    getApprovalShow();
  }, []);
  (0, _react.useEffect)(function () {
    var _window$BSGlobal$logi;

    if (!okrInfo || !okrInfo.workId) return;
    setGeneralPrincipalUser(okrInfo.principalUser); // 负责人

    setGeneralOkrClassify(okrInfo.okrClassify); // 类别：承诺｜愿景

    setGeneralVisibility({
      visibility: okrInfo.visibility,
      visibilityScope: okrInfo.visibilityScope
    });
    var roleType = 0;

    if (okrInfo.principalUser.userId == ((_window$BSGlobal$logi = window.BSGlobal.loginUserInfo) === null || _window$BSGlobal$logi === void 0 ? void 0 : _window$BSGlobal$logi.Id)) {
      roleType = 1;
    } else if (okrInfo.authority.roleRelation) {
      roleType = okrInfo.authority.roleRelation.roleType;
    }

    setGeneralRoleType(roleType);
    setGeneralOkrType({
      okrType: okrInfo.okrType,
      departmentId: okrInfo.departmentId,
      departmentName: okrInfo.departmentName,
      groupId: okrInfo.groupId,
      groupName: okrInfo.groupName
    });
    setGeneralCycle({
      cycleType: okrInfo.cycleType,
      annualNum: okrInfo.annualNum,
      yqmNum: okrInfo.yqmnum,
      // 默认当前季度
      startDate: okrInfo.startDate,
      endDate: okrInfo.endDate
    }); // setGeneralParent({
    //   'parentId': okrInfo.parentKrId || okrInfo.parentId,
    //   'parentType': okrInfo.parentKrId ? 2 : 1, // 1:目标， 2: kr
    //   'parentOkr': okrInfo.parentOkr,
    //   'parentKr': okrInfo.parentKr
    // })
  }, [okrInfo]);

  var onScrollHandler = function onScrollHandler() {
    // tabs 粘顶
    var tabsNav = tabsContnetRef.current.querySelector('.rc-tabs-nav');
    if (bodyRef.current.scrollTop > 98) tabsNav.classList.add('okr-tabs-fixed-top');else tabsNav.classList.remove('okr-tabs-fixed-top');
  };

  var handleContainerMouseDown = (0, _react.useCallback)(function () {
    if (activeTabKey == 'cooperation') return;
    bottomReply && bottomReply.current && bottomReply.current.hide();
  }, [activeTabKey]);

  var refreshKrs = function refreshKrs() {
    var active = activeTabKey || 'okr';

    if (active == 'okr') {
      okrListRef.current && okrListRef.current.updateKrs();
    }
  };

  if (errorMsg) return /*#__PURE__*/_react["default"].createElement(_errorPage["default"], {
    message: errorMsg
  });
  return /*#__PURE__*/_react["default"].createElement(_context.CommonContext.Provider, {
    value: _objectSpread(_objectSpread({}, _context.defaultConfig), {}, {
      okrInfo: okrInfo,
      changeTabActive: changeTabActive,
      refreshAll: refreshAll,
      setOkrInfo: setOkrInfo,
      refreshKrs: refreshKrs,
      approvalSetting: approvalSetting
    })
  }, /*#__PURE__*/_react["default"].createElement(_context.GeneralDataContext.Provider, {
    value: {
      generalPrincipalUser: generalPrincipalUser,
      setGeneralPrincipalUser: setGeneralPrincipalUser,
      generalOkrClassify: generalOkrClassify,
      setGeneralOkrClassify: setGeneralOkrClassify,
      generalVisibility: generalVisibility,
      setGeneralVisibility: setGeneralVisibility,
      generalOkrType: generalOkrType,
      setGeneralOkrType: setGeneralOkrType,
      generalRoleType: generalRoleType,
      setGeneralRoleType: setGeneralRoleType,
      generalCycle: generalCycle,
      setGeneralCycle: setGeneralCycle,
      generalParent: generalParent,
      setGeneralParent: setGeneralParent,
      showOkrEvalute: showOkrEvalute,
      setShowOkrEvalute: setShowOkrEvalute
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])(preCls),
    onMouseDown: handleContainerMouseDown
  }, !loading ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_detailHeader["default"], {
    detailInfo: okrInfo
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__body")),
    onScroll: onScrollHandler,
    ref: bodyRef
  }, /*#__PURE__*/_react["default"].createElement(_header["default"], {
    okrInfo: okrInfo
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__tabs-content")),
    ref: tabsContnetRef
  }, /*#__PURE__*/_react["default"].createElement("div", {
    ref: tabRef
  }, /*#__PURE__*/_react["default"].createElement(_tabs["default"], {
    size: "big",
    destroyInactiveTabPane: true,
    activeKey: activeTabKey,
    onChange: changeTabActive,
    tabBarStyle: {
      boxShadow: '0px 0px 24px 0px rgba(127, 145, 180, 0.2)'
    }
  }, /*#__PURE__*/_react["default"].createElement(_tabs.TabPane, {
    tab: "OKRs",
    key: "okr"
  }, /*#__PURE__*/_react["default"].createElement(_tabPanelContent["default"], {
    style: {
      paddingTop: 5
    }
  }, /*#__PURE__*/_react["default"].createElement(_okrList["default"], {
    okrId: okrId,
    okrInfo: okrInfo,
    ref: okrListRef
  }))), /*#__PURE__*/_react["default"].createElement(_tabs.TabPane, {
    tab: (0, _getLocale.getLocale)('OKR_MyO_Exec_Tab_Execution'),
    key: "exec"
  }, /*#__PURE__*/_react["default"].createElement(_tabPanelContent["default"], {
    style: {
      paddingTop: 10
    }
  }, /*#__PURE__*/_react["default"].createElement(_eList["default"], {
    okrId: okrId,
    okrInfo: okrInfo
  }))), /*#__PURE__*/_react["default"].createElement(_tabs.TabPane, {
    tab: (0, _getLocale.getLocale)('Feed_Tab_Title_Progress'),
    key: "progress"
  }, /*#__PURE__*/_react["default"].createElement(_tabPanelContent["default"], {
    style: {
      paddingTop: 0
    }
  }, /*#__PURE__*/_react["default"].createElement(_schedule["default"], {
    okrInfo: okrInfo
  }))), /*#__PURE__*/_react["default"].createElement(_tabs.TabPane, {
    tab: (0, _getLocale.getLocale)('OKR_MyO_KRP_nteract'),
    key: "cooperation"
  }, /*#__PURE__*/_react["default"].createElement(_tabPanelContent["default"], {
    style: {
      marginRight: 32,
      marginLeft: 32
    }
  }, /*#__PURE__*/_react["default"].createElement(_cooperation["default"], {
    feedId: okrInfo.feedId,
    defaultOperationRecordNum: 4,
    onComment: function onComment() {
      var _bottomReply$current;

      return (_bottomReply$current = bottomReply.current).show.apply(_bottomReply$current, arguments);
    },
    communicationRef: communicationRef
  }))), EWorkReport && source != 861 && /*#__PURE__*/_react["default"].createElement(_tabs.TabPane, {
    tab: (0, _getLocale.getLocale)('OKR_MyO_Ew_Tab_Eweekly'),
    key: "eReport"
  }, /*#__PURE__*/_react["default"].createElement(_tabPanelContent["default"], {
    style: {
      marginRight: 32,
      marginLeft: 32
    }
  }, /*#__PURE__*/_react["default"].createElement(_reportList["default"], {
    okrId: okrInfo.workId,
    okrName: okrInfo.workName,
    isVisible: okrInfo.visibility
  }))), OkrAnalyse && /*#__PURE__*/_react["default"].createElement(_tabs.TabPane, {
    tab: (0, _getLocale.getLocale)('OKR_MyO_KRP_Review'),
    key: "review"
  }, /*#__PURE__*/_react["default"].createElement(_tabPanelContent["default"], {
    style: {
      marginRight: 32,
      marginLeft: 32
    }
  }, /*#__PURE__*/_react["default"].createElement(_okrReview["default"], {
    editAble: true,
    feedId: okrInfo.feedId,
    ObjData: {
      ObjId: okrInfo.workId,
      ObjName: okrInfo.workName,
      ObjType: 62,
      ObjIndex: 0
    },
    defaultRange: {
      startDate: okrInfo.startDate,
      endDate: okrInfo.endDate
    }
  }))), /*#__PURE__*/_react["default"].createElement(_tabs.TabPane, {
    tab: (0, _getLocale.getLocale)('Per_Ass_New_title_text_BasicIn'),
    key: "baseInfo"
  }, /*#__PURE__*/_react["default"].createElement(_tabPanelContent["default"], {
    style: {
      paddingTop: 8
    }
  }, /*#__PURE__*/_react["default"].createElement(_baseInfo["default"], {
    okrId: okrId,
    detailInfo: okrInfo
  }))))), /*#__PURE__*/_react["default"].createElement(_aoNice["default"], {
    activeTab: activeTabKey,
    okrInfo: okrInfo
  }))), /*#__PURE__*/_react["default"].createElement(_detailFooter["default"], {
    feedId: okrInfo.feedId,
    ref: bottomReply,
    onAfterSubmit: onAfterReply,
    isFocusReply: props.activeTabKey === 'cooperation'
  })) : /*#__PURE__*/_react["default"].createElement(_loading["default"], {
    type: "zone"
  }))));
}

OkrDetail.EList = _eList["default"];
OkrDetail.CommonContext = _context.CommonContext;
var _default = OkrDetail;
exports["default"] = _default;