"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 _popup = _interopRequireDefault(require("../popup"));

var _bookDemo = _interopRequireDefault(require("../book-demo"));

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

var _bsGlobal = require("../../utils/bs-global");

var _requestApi = require("./request-api");

var _tooltip = _interopRequireDefault(require("../tooltip"));

var _conditionRender = _interopRequireDefault(require("../condition-render"));

var _kefu = _interopRequireDefault(require("./image/kefu1.svg"));

var _yuyueyanshi = _interopRequireDefault(require("./image/yuyueyanshi.svg"));

var _helpzx = _interopRequireDefault(require("./image/helpzx.svg"));

var _upgrade = _interopRequireDefault(require("./image/upgrade.svg"));

var _okrShequ = _interopRequireDefault(require("./image/okr-shequ.svg"));

var _interface = require("./interface");

var _errorBoundary = _interopRequireDefault(require("../error-boundary"));

var _errorLevel = _interopRequireDefault(require("../../utils/error-level"));

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

var _try = _interopRequireDefault(require("./image/try.png"));

var _notTry = _interopRequireDefault(require("./image/not-try.png"));

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

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

var preCls = "help-card";
var isTry = (0, _bsGlobal.getVersion)() === 1;
var isDingding = (0, _platform.isDD)(true) === true;
var isFeis = (0, _platform.isFeishu)(true) === true;

var HelpCard = function HelpCard(_ref) {
  var restProps = _extends({}, _ref);

  var _useState = (0, _react.useState)(false),
      _useState2 = _slicedToArray(_useState, 2),
      visible = _useState2[0],
      setVisible = _useState2[1];

  var _useState3 = (0, _react.useState)(false),
      _useState4 = _slicedToArray(_useState3, 2),
      weChatCodeVisible = _useState4[0],
      setWeChatCodeVisible = _useState4[1];

  var _useState5 = (0, _react.useState)(1),
      _useState6 = _slicedToArray(_useState5, 2),
      pageNum = _useState6[0],
      setPageNum = _useState6[1];

  var _useState7 = (0, _react.useState)([]),
      _useState8 = _slicedToArray(_useState7, 2),
      guessList = _useState8[0],
      setGuessList = _useState8[1];

  var _useState9 = (0, _react.useState)([]),
      _useState10 = _slicedToArray(_useState9, 2),
      recommendList = _useState10[0],
      setRecommendList = _useState10[1];

  var _useState11 = (0, _react.useState)(0),
      _useState12 = _slicedToArray(_useState11, 2),
      guessQuestionNum = _useState12[0],
      setGuessQuestionNum = _useState12[1];

  var bookDemoRef = (0, _react.useRef)();
  var isTrial = (0, _bsGlobal.getVersion)() === 1;
  var kefuUrl = isTrial ? "https://wpa1.qq.com/vZYKN3kT?_type=wpa&qidian=true" : "https://wpa1.qq.com/o6X4XD1n?_type=wpa&qidian=true";

  var getBookDemoVersion = function getBookDemoVersion() {
    var _window$BSGlobal$tena;

    var menuVersion = (_window$BSGlobal$tena = window.BSGlobal.tenantAuthentication) === null || _window$BSGlobal$tena === void 0 ? void 0 : _window$BSGlobal$tena.MenuVersion;

    if (menuVersion === _interface.ETrialVersion.OKR) {
      return _bookDemo["default"].DemoType.TryOKR;
    }

    if (menuVersion === _interface.ETrialVersion.Performance) {
      return _bookDemo["default"].DemoType.TryPerformance;
    }

    return _bookDemo["default"].DemoType.UniversalBookDemo;
  };

  var handleSkip = function handleSkip(url) {
    setVisible(false);
    window.open(url);
  };

  (0, _react.useEffect)(function () {
    if (!visible) return;
    (0, _requestApi.getQuestionList)(pageNum).then(function (res) {
      var _res$Data$questions = res.Data.questions,
          recommendQuestion = _res$Data$questions.recommendQuestion,
          guessQuestion = _res$Data$questions.guessQuestion;
      var num = res.Data.questionTypeCount.guessQuestion;
      setGuessQuestionNum(num);

      if (recommendQuestion.length > 0) {
        setRecommendList(recommendQuestion || []);
      }

      setGuessList(guessQuestion || []);
    });
    setTimeout(function () {
      setWeChatCodeVisible(!visible);
    }, 100);
  }, [pageNum, visible]);

  var handlePoint = function handlePoint() {
    setVisible(false);

    if (bookDemoRef.current) {
      bookDemoRef.current.show();
    }

    if (window.titaTracker) {
      window.titaTracker("action").record({
        actionName: "申请演示",
        actionGroup: "试用版-申请演示",
        productName: "系统内-申请演示"
      });
    }
  };

  var handleClickTracker = function handleClickTracker(title) {
    if (window.titaTracker) {
      window.titaTracker("action").record({
        actionName: "Tita\u5C0F\u52A9\u624B__".concat(title),
        actionGroup: "Tita小助手",
        productName: "Tita小助手"
      });
    }
  };

  var handleHelpCenter = function handleHelpCenter() {
    setVisible(false);

    if ((0, _openData.isPlatform)("dd")) {
      window.open("https://wiki.tita.com/pages/viewpage.action?pageId=4915206");
    } else if ((0, _openData.isPlatform)("feishu")) {
      window.open("https://wiki.tita.com/pages/viewpage.action?pageId=12026137");
    } else {
      window.open("https://wiki.tita.com/display/TITA1/Tita");
    }

    handleClickTracker("帮助中心");
  };

  var handleKnowledgeCommunity = function handleKnowledgeCommunity() {
    setVisible(false);
    window.open("https://club.tita.com/");
    handleClickTracker("知识社区");
  };

  var handleCustomerService = function handleCustomerService() {
    if (isTrial) {
      setVisible(false);
      window.open('https://wpa1.qq.com/vZYKN3kT?_type=wpa&qidian=true');
      handleClickTracker("联系客服");
    } else {
      setWeChatCodeVisible(true);
    }
  };

  var handleUpgrade = function handleUpgrade() {
    setVisible(false);
    window.open("https://wiki.tita.com/pages/viewpage.action?pageId=15696164");
    handleClickTracker("升级通知");
  };

  var chageBatch = function chageBatch() {
    if (guessQuestionNum > pageNum * 3) {
      setPageNum(pageNum + 1);
    } else {
      setPageNum(1);
    }
  };

  var renderKefu = function renderKefu() {
    if ((0, _openData.isPlatform)("feishu") || (0, _openData.isPlatform)("dd")) return /*#__PURE__*/_react["default"].createElement("span", null);
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__footer-item"),
      onClick: handleCustomerService
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _kefu["default"],
      alt: "\u8054\u7CFB\u5BA2\u670D"
    }), "\u8054\u7CFB\u5BA2\u670D");
  };

  var popupContent = function popupContent() {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: preCls
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__header")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__header-avatar")
    }), "Tita\u5C0F\u52A9\u624B"), /*#__PURE__*/_react["default"].createElement(_conditionRender["default"], {
      condition: weChatCodeVisible === false
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item-title")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item-title-left")
    }, "\u731C\u4F60\u60F3\u95EE"), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item-title-right"),
      onClick: chageBatch
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "tu-icon-gengxin1"
    }), "\u6362\u4E00\u6279")), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item-content")
    }, guessList.map(function (item) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(preCls, "__body-item-content-item"),
        onClick: function onClick() {
          return handleSkip(item.questionUrl);
        },
        key: item.questionUrl + item.questionName
      }, item.questionName);
    }))), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item-title")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item-title-left")
    }, "\u63A8\u8350\u67E5\u770B")), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__body-item-content")
    }, recommendList.map(function (item) {
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(preCls, "__body-item-content-item"),
        onClick: function onClick() {
          return handleSkip(item.questionUrl);
        },
        key: item.questionUrl + item.questionName
      }, item.questionName);
    }))))), /*#__PURE__*/_react["default"].createElement(_conditionRender["default"], {
      condition: weChatCodeVisible === true
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__wechat")
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__wechat-title")
    }, "\u5FAE\u4FE1/\u4F01\u4E1A\u5FAE\u4FE1\u626B\u4E00\u626B"), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__wechat-content")
    }, "\u4E13\u5C5E\u5BA2\u670D\u4E3A\u4F60\u63D0\u4F9B\u54A8\u8BE2\u670D\u52A1"), /*#__PURE__*/_react["default"].createElement("img", {
      src: isTry ? _try["default"] : _notTry["default"],
      className: "".concat(preCls, "__wechat-img"),
      alt: "\u5FAE\u4FE1\u626B\u7801"
    }))), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__footer")
    }, isTrial && /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__footer-item"),
      onClick: handlePoint
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _yuyueyanshi["default"],
      alt: "\u9884\u7EA6\u6F14\u793A"
    }), "\u9884\u7EA6\u6F14\u793A"), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__footer-item"),
      onClick: handleHelpCenter
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _helpzx["default"],
      alt: "\u5E2E\u52A9\u4E2D\u5FC3"
    }), "\u5E2E\u52A9\u4E2D\u5FC3"), !isTrial && /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__footer-item"),
      onClick: handleUpgrade
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _upgrade["default"],
      alt: "\u5347\u7EA7\u901A\u77E5"
    }), "\u5347\u7EA7\u901A\u77E5"), !(0, _openData.isPlatform)("feishu") && /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(preCls, "__footer-item"),
      onClick: handleKnowledgeCommunity
    }, /*#__PURE__*/_react["default"].createElement("img", {
      src: _okrShequ["default"],
      alt: "\u77E5\u8BC6\u793E\u533A"
    }), "\u77E5\u8BC6\u793E\u533A"), renderKefu()));
  };

  return /*#__PURE__*/_react["default"].createElement("div", restProps, /*#__PURE__*/_react["default"].createElement(_popup["default"], {
    popupTransitionName: "tita-popup-zoom-left-bottom",
    placement: "topLeft",
    popupAlign: {
      offset: [-32, -10],
      overflow: {
        adjustX: 1,
        adjustY: 1
      }
    },
    popup: popupContent(),
    popupVisible: visible,
    onPopupVisibleChange: function onPopupVisibleChange(bol) {
      return setVisible(bol);
    }
  }, /*#__PURE__*/_react["default"].createElement(_tooltip["default"], {
    placement: "right",
    align: [0, 0],
    overlay: /*#__PURE__*/_react["default"].createElement("span", null, "\u9047\u5230\u95EE\u9898\u4E86\uFF1F\u70B9\u6211\u8BD5\u8BD5\uFF5E")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("home-fixed-kefu")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("home-fixed-kefu-image", {
      "home-fixed-kefu-canceled": visible
    })
  })))), /*#__PURE__*/_react["default"].createElement(_errorBoundary["default"], {
    errorLevel: _errorLevel["default"].P0,
    errorTag: "\u7533\u8BF7\u9884\u7EA6\u6F14\u793A\u5F02\u5E38"
  }, /*#__PURE__*/_react["default"].createElement(_bookDemo["default"].BookDemoPC, {
    visible: false,
    ref: bookDemoRef,
    type: getBookDemoVersion()
  })));
};

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