"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("../../../components/tooltip"));

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

var _precls = require("../precls");

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

var _common = require("../../../components/period-selector/common");

require("./index.css");

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 Comments(props) {
  var toUserId = props.toUserId,
      relation = props.relation,
      userInfo = props.userInfo;
  var pushRef = (0, _react.useRef)();

  var _useContext = (0, _react.useContext)(_context.Context),
      OkrCommunicationPush = _useContext.OkrCommunicationPush,
      annualNum = _useContext.annualNum,
      cycleType = _useContext.cycleType,
      yqmNum = _useContext.yqmNum;

  var openComments = function openComments() {
    pushRef.current && pushRef.current.show(); // @ts-ignore

    window.titaTracker // @ts-ignore
    && window.titaTracker("action").record({
      actionName: "OKR__点击图标【沟通】",
      actionGroup: "OKR-沟通",
      productName: "OKR"
    });
  };

  if (!toUserId && relation != 1) return null;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(_precls.precls, "__header-item")
  }, /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
    overlay: (0, _getLocale.getLocale)("Mod_Communication"),
    placement: "top"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(_precls.precls, "__header-icon")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "tu-icon-feed",
    onClick: openComments
  }))), (toUserId !== undefined || relation == 1) && !!userInfo && /*#__PURE__*/_react["default"].createElement(OkrCommunicationPush, {
    ref: pushRef,
    feedId: 0,
    key: userInfo.userId,
    okrCycle: "\uFF08".concat((0, _common.formatPeriod)({
      annualNum: annualNum,
      cycleType: cycleType,
      yqmNum: yqmNum
    }), "\uFF09"),
    okrFeedParams: {
      objId: userInfo.userId,
      objType: 1,
      cycleType: Number(cycleType),
      // 目标周期：0-自定义，1-年度，2-季度，3-月度
      yqmNum: Number(yqmNum || 0),
      annualNum: Number(annualNum)
    },
    userInfo: {
      Id: userInfo.userId,
      Name: userInfo.name,
      Color: userInfo.avatar.color,
      AvatarsUrl: userInfo.avatar.original,
      Type: 1
    }
  }));
}

var _default = Comments;
exports["default"] = _default;