"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"] = _default;

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _shareDialog = _interopRequireDefault(require("../../share-dialog"));

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

var _level2Search = _interopRequireDefault(require("../../level2-search"));

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

var _noOkr = _interopRequireDefault(require("../../no-okr"));

var _requestApis = require("../../request-apis");

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

var _unsupportIe = _interopRequireDefault(require("../../unsupport-ie"));

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 _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 _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 _default() {
  var _useState = (0, _react.useState)(function () {
    var hashQuery = {};
    var urlHash = decodeURIComponent(window.location.hash);
    var hashQueryStr = urlHash.split('?')[1];
    hashQueryStr.split('&').forEach(function (it) {
      var _it$split = it.split('='),
          _it$split2 = _slicedToArray(_it$split, 2),
          key = _it$split2[0],
          value = _it$split2[1];

      if (key == 'level2Selected' || key == 'period' || key == 'rootNode') hashQuery[key] = JSON.parse(value);else if (key == 'showkr' || key == 'darkTheme') hashQuery[key] = value == 'true';else hashQuery[key] = value;
    });
    return hashQuery;
  }),
      _useState2 = _slicedToArray(_useState, 1),
      hashQuery = _useState2[0];

  var _useState3 = (0, _react.useState)(hashQuery.searchType),
      _useState4 = _slicedToArray(_useState3, 1),
      searchType = _useState4[0];

  var _useState5 = (0, _react.useState)(hashQuery.period),
      _useState6 = _slicedToArray(_useState5, 2),
      period = _useState6[0],
      setPeriod = _useState6[1];

  var _useState7 = (0, _react.useState)(hashQuery.showkr),
      _useState8 = _slicedToArray(_useState7, 2),
      showkr = _useState8[0],
      setShowKr = _useState8[1];

  var _useState9 = (0, _react.useState)(hashQuery.showCardKr),
      _useState10 = _slicedToArray(_useState9, 2),
      showCardKr = _useState10[0],
      setShowCardKr = _useState10[1];

  var _useState11 = (0, _react.useState)(hashQuery.darkTheme),
      _useState12 = _slicedToArray(_useState11, 2),
      darkTheme = _useState12[0],
      setDarkTheme = _useState12[1];

  var _useState13 = (0, _react.useState)(hashQuery.direction),
      _useState14 = _slicedToArray(_useState13, 2),
      direction = _useState14[0],
      setDirection = _useState14[1];

  var _useState15 = (0, _react.useState)(hashQuery.rootNode),
      _useState16 = _slicedToArray(_useState15, 2),
      rootNode = _useState16[0],
      setRootNode = _useState16[1];

  var _useState17 = (0, _react.useState)(false),
      _useState18 = _slicedToArray(_useState17, 2),
      forceRender = _useState18[0],
      setForceRender = _useState18[1];

  var okrMapRef = (0, _react.useRef)();

  var onMapActionsHandler = function onMapActionsHandler(iconType) {
    switch (iconType) {
      case 'export':
        exportCurrentFlow();
        break;

      case 'horizontal':
        setDirection(iconType);
        setForceRender(true);
        setTimeout(function () {
          return setForceRender(false);
        }, 100);
        break;

      case 'vertical':
        setDirection(iconType);
        setForceRender(true);
        setTimeout(function () {
          return setForceRender(false);
        }, 100);
        break;

      default:
        break;
    }
  }; // 导出图片


  var exportCurrentFlow = function exportCurrentFlow() {
    okrMapRef.current.exportCurrentFlow();
  };

  return /*#__PURE__*/_react["default"].createElement(_unsupportIe["default"], null, function (OkrSearchPanel) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])(_defineProperty({}, "".concat(_precls["default"], "__dark"), darkTheme))
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])(_precls["default"], "".concat(_precls["default"], "-share"))
    }, /*#__PURE__*/_react["default"].createElement(_header["default"], {
      showkr: showkr,
      showCardKr: showCardKr,
      darkTheme: darkTheme,
      direction: direction,
      setShowKr: setShowKr,
      setShowCardKr: setShowCardKr,
      setDirection: setDirection,
      onBtnClick: onMapActionsHandler,
      setDarkTheme: setDarkTheme
    }), /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])("".concat(_precls["default"], "__content"))
    }, function () {
      if (forceRender) return /*#__PURE__*/_react["default"].createElement("span", null);
      return /*#__PURE__*/_react["default"].createElement(OkrSearchPanel, _extends({
        ref: okrMapRef,
        searchType: searchType,
        showkr: showkr,
        showCardKr: showCardKr,
        direction: direction,
        darkTheme: darkTheme
      }, period, rootNode, {
        okrType: _utils.OkrTypeSetting ? _utils.okrTypeMap[searchType] : ''
      }));
    }())));
  });
}