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

var _content = _interopRequireDefault(require("./components/content"));

var _demoClose = _interopRequireDefault(require("../../img/demo-close.svg"));

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

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

require("./index.css");

var _window$BSGlobal, _window$BSGlobal$tena, _window$BSGlobal2, _window$BSGlobal2$log, _window$BSGlobal3, _window$BSGlobal3$log, _getTenantInfo, _window$BSGlobal4, _window$BSGlobal4$ten;

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

var preCls = 'titaui-book-demo-pc';
var version = (_window$BSGlobal = window.BSGlobal) === null || _window$BSGlobal === void 0 ? void 0 : (_window$BSGlobal$tena = _window$BSGlobal.tenantAuthentication) === null || _window$BSGlobal$tena === void 0 ? void 0 : _window$BSGlobal$tena.Version;
var role = (_window$BSGlobal2 = window.BSGlobal) === null || _window$BSGlobal2 === void 0 ? void 0 : (_window$BSGlobal2$log = _window$BSGlobal2.loginUserInfo) === null || _window$BSGlobal2$log === void 0 ? void 0 : _window$BSGlobal2$log.Role;
var isSubmitted = localStorage.getItem('isSubmitted');
var time = Number(localStorage.getItem('pointDemoTime'));
var newDate = new Date().getTime();
var uname = ((_window$BSGlobal3 = window.BSGlobal) === null || _window$BSGlobal3 === void 0 ? void 0 : (_window$BSGlobal3$log = _window$BSGlobal3.loginUserInfo) === null || _window$BSGlobal3$log === void 0 ? void 0 : _window$BSGlobal3$log.Name) || '';
var uid = ((_getTenantInfo = (0, _bsGlobal.getTenantInfo)()) === null || _getTenantInfo === void 0 ? void 0 : _getTenantInfo.Id) || '';
var Source = ((_window$BSGlobal4 = window.BSGlobal) === null || _window$BSGlobal4 === void 0 ? void 0 : (_window$BSGlobal4$ten = _window$BSGlobal4.tenantInfo) === null || _window$BSGlobal4$ten === void 0 ? void 0 : _window$BSGlobal4$ten.Source) || (0, _utils.getSource)();
var BookDemoPC = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var type = _ref.type,
      visible = _ref.visible,
      visibleChange = _ref.visibleChange,
      _ref$autoShow = _ref.autoShow,
      autoShow = _ref$autoShow === void 0 ? false : _ref$autoShow,
      source = _ref.source;

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

  var _useState3 = (0, _react.useState)([]),
      _useState4 = _slicedToArray(_useState3, 2),
      data = _useState4[0],
      setData = _useState4[1];

  var handleCloseBookDemo = function handleCloseBookDemo() {
    var content = uid ? "\u79DF\u6237ID\uFF1A".concat(uid, "\uFF0C\u79DF\u6237\u8D26\u53F7\u540D\u79F0\uFF1A").concat(uname, ",") : '';
    data.forEach(function (item) {
      content += "".concat(item.name, ": ").concat(Array.isArray(item.value) ? item.value.join(',') : item.value, ",");
    });
    content += "source: ".concat(source || Source);

    if (window.titaTracker && !localStorage.getItem('titaccc')) {
      window.titaTracker('action').record({
        productName: '预约演示',
        actionGroup: '取消预约演示',
        actionName: "\u53D6\u6D88\u9884\u7EA6\u6F14\u793A:\u586B\u5199\u60C5\u51B5\uFF1A".concat(content)
      });
    }

    setDialogVisible(false);

    if (visibleChange) {
      visibleChange(false);
    }
  };

  var handleSuccessCloseBookDemo = function handleSuccessCloseBookDemo() {
    setDialogVisible(false);

    if (visibleChange) {
      visibleChange(false);
    }
  };

  var handleChangeData = function handleChangeData(result) {
    setData(result);
  };

  var handleShowBookDemo = function handleShowBookDemo() {
    setDialogVisible(true);

    if (visibleChange) {
      visibleChange(true);
    }
  };

  (0, _react.useImperativeHandle)(ref, function () {
    return {
      show: handleShowBookDemo,
      hide: handleCloseBookDemo
    };
  });
  (0, _react.useEffect)(function () {
    setDialogVisible(visible);
  }, [visible]);
  (0, _react.useEffect)(function () {
    if (!isSubmitted && autoShow) {
      if (time && newDate > time) {
        if (version === 1 && role === 2) {
          setTimeout(function () {
            var date = new Date().getTime() + 86400000;
            localStorage.setItem('pointDemoTime', date.toString());
            setDialogVisible(true);
          }, 30000);
        }
      } else if (!time) {
        if (version === 1 && role === 2) {
          setTimeout(function () {
            var date = new Date().getTime() + 86400000;
            localStorage.setItem('pointDemoTime', date.toString());
            setDialogVisible(true);
          }, 30000);
        }
      }
    }
  }, []);
  return /*#__PURE__*/_react["default"].createElement(_dialog["default"], {
    zIndex: 1200,
    noHeadLine: true,
    visible: dialogVisible,
    onClose: handleCloseBookDemo,
    noFooter: true,
    noCloseIcon: true,
    destroyOnClose: true,
    style: {
      width: '742px',
      borderRadius: '24px'
    },
    maskClosable: false
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__close"),
    onClick: handleCloseBookDemo
  }, /*#__PURE__*/_react["default"].createElement("img", {
    alt: "close",
    src: _demoClose["default"],
    className: (0, _classnames["default"])("".concat(preCls, "__close-icon"))
  })), /*#__PURE__*/_react["default"].createElement(_content["default"], {
    onChange: handleChangeData,
    source: source,
    type: type,
    onSubmitSuccess: handleSuccessCloseBookDemo
  }));
});
BookDemoPC.defaultProps = {
  autoShow: false,
  visibleChange: function visibleChange() {},
  source: 0
};
var _default = BookDemoPC;
exports["default"] = _default;