"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 Sentry = _interopRequireWildcard(require("@sentry/browser"));

var _reactIntersectionObserver = require("react-intersection-observer");

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

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

var _dangerousHtml = _interopRequireDefault(require("../../../dangerous-html"));

var _tools = require("../../../../utils/tools");

var _title = _interopRequireDefault(require("../../components/title"));

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

require("./index.css");

var _excluded = ["data", "isFold"];

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 _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var getEReportType = function getEReportType(type) {
  var reportTextMap = {
    8: (0, _getLocale.getLocale)('Rep_Tab_Dailynewspaper'),
    26: (0, _getLocale.getLocale)('Rep_Tab_Weeklynewspaper'),
    27: (0, _getLocale.getLocale)('Rep_Tab_MonthlyReport')
  };
  return reportTextMap[type];
};

var prefix = 'titaui-dynamic-report-item';

var DynamicReply = function DynamicReply(_ref) {
  var data = _ref.data,
      _ref$isFold = _ref.isFold,
      isFold = _ref$isFold === void 0 ? true : _ref$isFold,
      restProps = _objectWithoutProperties(_ref, _excluded);

  var submitState = data.submitState,
      feedId = data.feedId,
      publishUser = data.publishUser,
      reportType = data.reportType;
  var contentRichTextRef = (0, _react.useRef)();
  var workPlanRichTextRef = (0, _react.useRef)();

  var _useContext = (0, _react.useContext)(_context.SearchKeyContext),
      searchKeyWord = _useContext.searchKeyWord;

  var handleClickTitle = function handleClickTitle() {
    if (window.titaTracker) {
      window.titaTracker('planAction').record({
        actionName: '查看日报',
        actionGroup: '动态-推屏',
        productName: '动态',
        feedId: feedId
      });
    } // @ts-ignore


    window.Talent.app.vent.trigger('global-daily-detail-pull-screen', feedId);
  };

  var renderSuffix = (0, _react.useMemo)(function () {
    var _classNames;

    return /*#__PURE__*/_react["default"].createElement("span", {
      className: (0, _classnames["default"])("".concat(prefix, "__complete-type"), (_classNames = {}, _defineProperty(_classNames, "".concat(prefix, "__complete-type--normal"), submitState === 1), _defineProperty(_classNames, "".concat(prefix, "__complete-type--delay"), submitState === 2), _classNames))
    }, submitState === 1 ? (0, _getLocale.getLocale)('Rep_Tab_Mys_Submitontime') : (0, _getLocale.getLocale)('Tasks_Tab_DelaSubmission'));
  }, []);
  var renderDesc = (0, _react.useMemo)(function () {
    var reportTextMap = {
      8: (0, _getLocale.getLocale)('Rep_Tab_Mys_Dailynewsp'),
      26: (0, _getLocale.getLocale)('Rep_Tab_Mys_sweeklyReport'),
      27: (0, _getLocale.getLocale)('Rep_Tab_Sub_monthlyeport')
    };
    return /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefix, "__operate-desc")
    }, reportTextMap[reportType]);
  }, [reportType]);
  (0, _react.useEffect)(function () {
    (0, _tools.highLightWord)({
      parentDom: contentRichTextRef.current,
      keyWord: searchKeyWord
    });
    (0, _tools.highLightWord)({
      parentDom: workPlanRichTextRef.current,
      keyWord: searchKeyWord
    });
  }, [data, searchKeyWord]);

  var renderContent = function renderContent() {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: prefix
    }, /*#__PURE__*/_react["default"].createElement(_header["default"], _extends({
      data: data
    }, restProps, {
      desc: renderDesc,
      user: publishUser,
      suffixContent: renderSuffix
    })), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "__content")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "__content-title")
    }, /*#__PURE__*/_react["default"].createElement(_title["default"], {
      content: (0, _tools.htmlDecodeByRegExp)(data.name),
      onClickTitle: handleClickTitle,
      type: getEReportType(reportType),
      typeBgColor: "rgba(92, 142, 255, 0.5)",
      titleBgColor: "rgba(92, 142, 255, 0.1)",
      contentColor: "#5C8EFF"
    })), data.contentRichText && /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "__summary")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "__block-title")
    }, (0, _getLocale.getLocale)('Rep_Tab_Mys_Summaryobsta')), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "__content-text"),
      ref: contentRichTextRef
    }, /*#__PURE__*/_react["default"].createElement(_dangerousHtml["default"], {
      htmlText: data.contentRichText
    }))), data.workPlanRichText && /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "__work-plan")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "__block-title")
    }, (0, _getLocale.getLocale)('Rep_Tab_Mys_NextWorkPlans')), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefix, "__content-text"),
      ref: workPlanRichTextRef
    }, /*#__PURE__*/_react["default"].createElement(_dangerousHtml["default"], {
      htmlText: data.workPlanRichText
    })))));
  };

  if (!window.IntersectionObserver) {
    Sentry.withScope(function (scope) {
      scope.setTag('error-level', "P0");
      scope.setTag('error-type', '总结在 window 找不到 IntersectionObserver');
      scope.setExtra('componentStack', '总结在 window 找不到 IntersectionObserver');
    });
    return renderContent();
  }

  var handleInView = function handleInView(inview) {
    if (!isFold) return;

    if (inview) {
      window.titaTracker('planAction').record({
        actionName: '查看日报',
        actionGroup: '动态-查看日报',
        productName: '动态',
        feedId: feedId
      });
    }
  };

  return /*#__PURE__*/_react["default"].createElement(_reactIntersectionObserver.InView, {
    triggerOnce: true,
    onChange: handleInView,
    threshold: 0.5
  }, renderContent());
};

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