"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 _axios = _interopRequireDefault(require("axios"));

var _copyToClipboard = _interopRequireDefault(require("copy-to-clipboard"));

var _selectionRanges = require("selection-ranges");

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

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

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

var _button = _interopRequireDefault(require("../button"));

var _dialog = _interopRequireDefault(require("../dialog"));

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

var _mirroring = _interopRequireDefault(require("../mirroring"));

var _toast = _interopRequireDefault(require("../toast"));

var _emojiWail = _interopRequireDefault(require("./img/emoji-wail.png"));

var _qrcodeTrial = _interopRequireDefault(require("./img/qrcode-trial.png"));

var _qrcodeOfficial = _interopRequireDefault(require("./img/qrcode-official.png"));

var _utils = require("./utils");

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 _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 prefixCls = 'titaui-expiration-reminder';
var ua = navigator.userAgent.toLowerCase();
var isOffiial = ua.indexOf('micromessenger') === -1 && ua.indexOf('lark') === -1 && ua.indexOf('dingtalk') === -1;

var ExpirationReminder = function ExpirationReminder() {
  var _trialVersion, _officialVersion;

  var _getBSGlobal = (0, _bsGlobal.getBSGlobal)('tenantAuthentication'),
      Day = _getBSGlobal.Day,
      ExpireType = _getBSGlobal.ExpireType,
      Version = _getBSGlobal.Version;

  var deadLineRemind = (0, _bsGlobal.getBSGlobal)('deadLineRemind');
  var reminderEnable = ExpireType === _utils.ApplicationState.Expired || ExpireType === _utils.ApplicationState.WillExpire && deadLineRemind;
  var appVersion = Version === _utils.ApplicationVersion.Trial ? 'trialVersion' : 'officialVersion';

  var _useState = (0, _react.useState)(),
      _useState2 = _slicedToArray(_useState, 2),
      mirrorSwitch = _useState2[0],
      setMirrorSwitch = _useState2[1];

  var _useState3 = (0, _react.useState)(reminderEnable),
      _useState4 = _slicedToArray(_useState3, 2),
      visible = _useState4[0],
      setVisible = _useState4[1];

  var bookDemoRef = (0, _react.useRef)();
  var telRef = (0, _react.useRef)();

  var deleteCache = function deleteCache() {
    var UserId = (0, _bsGlobal.getUserInfo)().Id; // eslint-disable-next-line no-restricted-globals

    var url = "".concat(location.origin, "/").concat(UserId, "/CacheDeleteHome");

    _axios["default"].get(url)["finally"](function () {
      return setVisible(false);
    });
  };

  var showBookDemo = function showBookDemo() {
    var _bookDemoRef$current;

    deleteCache();
    bookDemoRef === null || bookDemoRef === void 0 ? void 0 : (_bookDemoRef$current = bookDemoRef.current) === null || _bookDemoRef$current === void 0 ? void 0 : _bookDemoRef$current.show();

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

  var onBookDemoVisibleChange = function onBookDemoVisibleChange(visibility) {
    if (!visibility && ExpireType === _utils.ApplicationState.Expired) {
      setMirrorSwitch(undefined);
      setVisible(true);
    }
  };

  var onCopy = function onCopy() {
    (0, _selectionRanges.setRange)(telRef.current, {
      start: 0,
      end: _utils.ContactNumber.length
    });
    (0, _copyToClipboard["default"])(_utils.ContactNumber);

    _toast["default"].Success('复制成功');
  }; // useEffect(() => {
  //   document.addEventListener('keydown', (e) => {
  //     e.preventDefault()
  //   })
  //   document.addEventListener('contextmenu', (e) => {
  //     e.preventDefault()
  //   })
  // })


  var reminderInfo = {
    trialVersion: (_trialVersion = {}, _defineProperty(_trialVersion, _utils.ApplicationState.Normal, {
      closeEnable: true,
      height: 466,
      qrcodeSize: 240,
      title: null,
      content: null
    }), _defineProperty(_trialVersion, _utils.ApplicationState.WillExpire, {
      closeEnable: true,
      height: 466,
      qrcodeSize: 240,
      title: /*#__PURE__*/_react["default"].createElement("h2", {
        className: "".concat(prefixCls, "__title")
      }, "\u60A8\u7684 Tita \u8BD5\u7528\u671F\u8FD8\u5269\u4F59", /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(prefixCls, "__remain-day")
      }, " ", Day, " "), "\u5929"),
      content: /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "__description")
      }, /*#__PURE__*/_react["default"].createElement("p", null, "\u52A0\u901F\u719F\u6089\u4EA7\u54C1 \u9884\u7EA6\u4EA7\u54C1\u6F14\u793A"), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement("span", null, "\u5347\u7EA7\u4E3A\u4ED8\u8D39\u7248"), /*#__PURE__*/_react["default"].createElement(_button["default"].Text, {
        onClick: function onClick() {
          return setMirrorSwitch('on');
        },
        type: "primary",
        text: " \u8BF7\u8054\u7CFB\u987E\u95EE "
      }), /*#__PURE__*/_react["default"].createElement("span", null, "\u7D22\u53D6\u4F18\u60E0~")))
    }), _defineProperty(_trialVersion, _utils.ApplicationState.Expired, {
      closeEnable: false,
      height: 466,
      qrcodeSize: 240,
      title: /*#__PURE__*/_react["default"].createElement("h2", {
        className: "".concat(prefixCls, "__title")
      }, /*#__PURE__*/_react["default"].createElement("img", {
        src: _emojiWail["default"],
        alt: "Emoji"
      }), "\u60A8\u7684 Tita \u8BD5\u7528\u5DF2\u5230\u671F"),
      content: /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "__description")
      }, /*#__PURE__*/_react["default"].createElement("p", null, "\u4F7F\u7528 Tita\uFF0C\u91CA\u653E35%+\u7684\u7BA1\u7406\u7CBE\u529B"), /*#__PURE__*/_react["default"].createElement("p", null, /*#__PURE__*/_react["default"].createElement("span", null, "\u7EE7\u7EED\u4F7F\u7528"), /*#__PURE__*/_react["default"].createElement(_button["default"].Text, {
        onClick: function onClick() {
          return setMirrorSwitch('on');
        },
        type: "primary",
        text: " \u8BF7\u8054\u7CFB\u987E\u95EE"
      })))
    }), _defineProperty(_trialVersion, "button", /*#__PURE__*/_react["default"].createElement(_button["default"].Rect, {
      onClick: showBookDemo,
      type: "primary"
    }, "\u9884\u7EA6\u6F14\u793A")), _defineProperty(_trialVersion, "qrCode", _qrcodeTrial["default"]), _trialVersion),
    officialVersion: (_officialVersion = {}, _defineProperty(_officialVersion, _utils.ApplicationState.Normal, {
      height: 466,
      qrcodeSize: 240,
      title: null,
      content: null,
      closeEnable: true
    }), _defineProperty(_officialVersion, _utils.ApplicationState.WillExpire, {
      closeEnable: true,
      height: 430,
      qrcodeSize: 210,
      title: /*#__PURE__*/_react["default"].createElement("h2", {
        className: "".concat(prefixCls, "__title")
      }, "\u60A8\u7684 Tita \u4F7F\u7528\u671F\u8FD8\u5269\u4F59", /*#__PURE__*/_react["default"].createElement("span", {
        className: "".concat(prefixCls, "__remain-day")
      }, " ", Day, " "), "\u5929"),
      content: /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "__description")
      }, /*#__PURE__*/_react["default"].createElement("p", null, "\u7EED\u8D39\u670D\u52A1 \u8BF7\u8054\u7CFB\u987E\u95EE"))
    }), _defineProperty(_officialVersion, _utils.ApplicationState.Expired, {
      closeEnable: false,
      height: 466,
      qrcodeSize: 240,
      title: /*#__PURE__*/_react["default"].createElement("h2", {
        className: "".concat(prefixCls, "__title")
      }, /*#__PURE__*/_react["default"].createElement("img", {
        src: _emojiWail["default"],
        alt: "Emoji"
      }), "\u60A8\u7684 Tita \u7CFB\u7EDF\u4F7F\u7528\u5DF2\u5230\u671F"),
      content: /*#__PURE__*/_react["default"].createElement("div", {
        className: "".concat(prefixCls, "__description")
      }, /*#__PURE__*/_react["default"].createElement("p", null, "\u9519\u8FC7\u4E86\u4E00\u5927\u6CE2\u4EA7\u54C1\u5347\u7EA7\u54E6~"), /*#__PURE__*/_react["default"].createElement("p", null, "\u4E86\u89E3 Tita \u65B0\u529F\u80FD \u8BF7\u9884\u7EA6\u987E\u95EE\u6F14\u793A"))
    }), _defineProperty(_officialVersion, "button", /*#__PURE__*/_react["default"].createElement(_button["default"].Rect, {
      onClick: function onClick() {
        return setMirrorSwitch('on');
      },
      type: "primary"
    }, "\u8054\u7CFB\u5BA2\u670D")), _defineProperty(_officialVersion, "qrCode", _qrcodeOfficial["default"]), _officialVersion)
  };
  var modalRender = (0, _react.useCallback)(function () {
    if (!reminderEnable) return null;
    var _reminderInfo$appVers = reminderInfo[appVersion],
        button = _reminderInfo$appVers.button,
        qrCode = _reminderInfo$appVers.qrCode;
    var _reminderInfo$appVers2 = reminderInfo[appVersion][ExpireType],
        closeEnable = _reminderInfo$appVers2.closeEnable,
        content = _reminderInfo$appVers2.content,
        height = _reminderInfo$appVers2.height,
        qrcodeSize = _reminderInfo$appVers2.qrcodeSize,
        title = _reminderInfo$appVers2.title;
    return /*#__PURE__*/_react["default"].createElement(_mirroring["default"], {
      mirrorSwitch: mirrorSwitch,
      style: {
        width: 420,
        height: height,
        margin: '0 auto'
      }
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: prefixCls,
      style: {
        height: height
      }
    }, title, content, /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefixCls, "__footer")
    }, /*#__PURE__*/_react["default"].createElement("p", null, button), /*#__PURE__*/_react["default"].createElement("p", {
      className: "".concat(prefixCls, "__contact")
    }, "\u8054\u7CFB\u7535\u8BDD\uFF1A", /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefixCls, "__contact-number"),
      onClick: onCopy,
      ref: telRef
    }, _utils.ContactNumber), isOffiial && /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefixCls, "__contact-out"),
      onClick: function onClick() {
        return window.open('/Account/Logout', '_self ');
      }
    }, "\u9000\u51FA\u767B\u5F55"))), closeEnable && /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefixCls, "__close"),
      onClick: deleteCache
    }), /*#__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, {
      ref: bookDemoRef,
      type: (0, _utils.getBookDemoVersion)(),
      visible: false,
      visibleChange: onBookDemoVisibleChange
    }))), /*#__PURE__*/_react["default"].createElement("div", {
      className: "".concat(prefixCls, " ").concat(prefixCls, "__qrcode"),
      style: {
        height: height
      }
    }, /*#__PURE__*/_react["default"].createElement(_button["default"].Text, {
      icon: "tu-icon-fanhui",
      text: "\u8FD4\u56DE",
      type: "primary",
      onClick: function onClick() {
        return setMirrorSwitch('off');
      }
    }), /*#__PURE__*/_react["default"].createElement("h2", {
      className: "".concat(prefixCls, "__qrcode-title")
    }, "\u5FAE\u4FE1/\u4F01\u4E1A\u5FAE\u4FE1\u626B\u4E00\u626B"), /*#__PURE__*/_react["default"].createElement("h3", {
      className: "".concat(prefixCls, "__qrcode-subtitle")
    }, "\u4E13\u5C5E\u5BA2\u670D\u4E3A\u60A8\u63D0\u4F9B\u54A8\u8BE2\u670D\u52A1"), /*#__PURE__*/_react["default"].createElement("img", {
      className: "".concat(prefixCls, "__qrcode-img"),
      src: qrCode,
      alt: "\u5FAE\u4FE1/\u4F01\u4E1A\u5FAE\u4FE1\u626B\u4E00\u626B",
      width: qrcodeSize,
      height: qrcodeSize
    })));
  }, [mirrorSwitch]);
  return /*#__PURE__*/_react["default"].createElement(_dialog["default"], {
    modalRender: modalRender,
    noCloseIcon: true,
    noFooter: true,
    noHeadLine: true,
    visible: visible
  });
};

var _default = /*#__PURE__*/(0, _react.memo)(ExpirationReminder);

exports["default"] = _default;