"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 _rcTooltip = _interopRequireDefault(require("rc-tooltip"));

var _switch = _interopRequireDefault(require("../../../../../components/switch"));

var _popup = _interopRequireDefault(require("../../../../../components/popup"));

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

var _searchDropdown = _interopRequireDefault(require("../../../../../components/search-dropdown"));

var _periodSelector = _interopRequireDefault(require("../../../../../components/period-selector"));

var _iconButtonList = _interopRequireDefault(require("../../../../../components/icon-button-list"));

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

var _showKrConfirm = _interopRequireDefault(require("./show-kr-confirm"));

var _numberSelect = _interopRequireDefault(require("../../../number-select"));

require("./index.css");

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

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 preCls = 'titapage-okr-map';

function _default(props) {
  var onShowKrClick = props.onShowKrClick,
      onShowCardKr = props.onShowCardKr,
      onSearchChange = props.onSearchChange,
      onBtnClick = props.onBtnClick,
      onPeriodChange = props.onPeriodChange,
      onThemeChange = props.onThemeChange,
      onLevelChange = props.onLevelChange,
      searchType = props.searchType,
      fullScreen = props.fullScreen,
      direction = props.direction,
      darkTheme = props.darkTheme,
      period = props.period,
      showkr = props.showkr,
      showCardKr = props.showCardKr,
      openLevel = props.openLevel;

  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),
      ovisible = _useState4[0],
      setOVisible = _useState4[1];

  var iconButtons = [{
    icon: 'daochu',
    overlay: (0, _getLocale.getLocale)('Mod_Export'),
    type: 'export'
  }, {
    icon: 'fenxiang',
    overlay: (0, _getLocale.getLocale)('OKR_MyO_Share'),
    type: 'share'
  }, {
    icon: fullScreen ? 'restore' : 'quanping',
    overlay: (0, _getLocale.getLocale)('OKR_Ali_Butt_Fullscreen'),
    type: fullScreen ? 'quit-fullscreen' : 'fullscreen'
  }, {
    icon: direction == 'horizontal' ? 'yangshi-ditu' : 'yangshi-ditu',
    overlay: direction == 'horizontal' ? "".concat((0, _getLocale.getLocale)('OKR_Ali_Butt_Toggleportrait')) : "".concat((0, _getLocale.getLocale)('OKR_Ali_Butt_Togglelandscape')),
    placement: 'topRight',
    rotate: direction == 'horizontal' ? 0 : -90,
    type: direction == 'horizontal' ? 'vertical' : 'horizontal'
  }];

  var onConfirmHandler = function onConfirmHandler(checked) {
    onShowKrClick(checked);

    if (showCardKr && checked) {
      _toast["default"].Warning('仅允许开启一项');

      onShowCardKr(false);
    }
  };

  var onhandleShowCardKr = function onhandleShowCardKr(checked) {
    onShowCardKr(checked);

    if (showkr && checked) {
      _toast["default"].Warning('仅允许开启一项');

      onShowKrClick(false);
    }
  };

  var popup = /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__show-more-popup"))
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-action-showkr"))
  }, /*#__PURE__*/_react["default"].createElement(_switch["default"], {
    label: (0, _getLocale.getLocale)('OKR_Db_KRDetails'),
    checked: showCardKr,
    onChange: onhandleShowCardKr
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-action-showkr"))
  }, /*#__PURE__*/_react["default"].createElement(_switch["default"], {
    label: (0, _getLocale.getLocale)('OKR_Ali_Butt_ExhibitionKRs'),
    checked: showkr,
    onChange: onConfirmHandler
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-action-level"))
  }, /*#__PURE__*/_react["default"].createElement(_numberSelect["default"], {
    max: 10,
    min: 1,
    onChange: function onChange(num) {
      return onLevelChange(num);
    },
    label: (0, _getLocale.getLocale)('OKR_Ali_Butt_Displaylevel'),
    defaultValue: openLevel
  })));

  var _useState5 = (0, _react.useState)(false),
      _useState6 = _slicedToArray(_useState5, 2),
      fold = _useState6[0],
      setFold = _useState6[1];

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__header"), _defineProperty({}, "".concat(preCls, "__header__folded"), fold))
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-title"))
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-title-text"))
  }, (0, _getLocale.getLocale)('OKR_Ali_Title_Objectivemap')), /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-title-right"))
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-theme")),
    onClick: onThemeChange
  }, "\u5207\u6362", darkTheme ? '浅色' : '深色', "\u6A21\u5F0F"), /*#__PURE__*/_react["default"].createElement(_periodSelector["default"], {
    align: "bottomRight",
    onChange: onPeriodChange,
    selected: period,
    yearsRange: [2018, 2030],
    buttonClass: "".concat(preCls, "__header-period")
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-action"))
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-action-search"))
  }, /*#__PURE__*/_react["default"].createElement(_searchDropdown["default"], {
    placeholder: (0, _getLocale.getLocale)('Mod_Pleaseselect'),
    value: searchType,
    onChange: onSearchChange
  }, /*#__PURE__*/_react["default"].createElement(_searchDropdown["default"].Option, {
    value: "company"
  }, (0, _getLocale.getLocale)('OKR_Ali_From_Companyobje')), /*#__PURE__*/_react["default"].createElement(_searchDropdown["default"].Option, {
    value: "depart"
  }, (0, _getLocale.getLocale)('OKR_Ali_From_Viewdepartment')), _utils.OkrTypeSetting && /*#__PURE__*/_react["default"].createElement(_searchDropdown["default"].Option, {
    value: "group"
  }, (0, _getLocale.getLocale)('OKR_Ali_From_Viewteam')), /*#__PURE__*/_react["default"].createElement(_searchDropdown["default"].Option, {
    value: "user"
  }, (0, _getLocale.getLocale)('OKR_Ali_From_Viewmember')))), /*#__PURE__*/_react["default"].createElement(_popup["default"], {
    popup: popup
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-action--show-more"))
  }, (0, _getLocale.getLocale)('OKR_Ali_Butt_Exhibitionmore'))), /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-action-btns"))
  }, /*#__PURE__*/_react["default"].createElement(_iconButtonList["default"], {
    items: iconButtons,
    onClick: function onClick(e, iconType) {
      return onBtnClick(iconType);
    }
  }))), /*#__PURE__*/_react["default"].createElement(_rcTooltip["default"], {
    overlay: fold ? "".concat((0, _getLocale.getLocale)('Mod_Unfold')) : "".concat((0, _getLocale.getLocale)('Mod_Fold')),
    placement: "top"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: (0, _classnames["default"])("".concat(preCls, "__header-fold"), _defineProperty({}, "".concat(preCls, "__header-fold__close"), fold)),
    onClick: function onClick() {
      return setFold(!fold);
    }
  })), /*#__PURE__*/_react["default"].createElement(_showKrConfirm["default"], {
    visible: visible,
    setVisible: setVisible,
    onConfirmHandler: onConfirmHandler,
    showkr: showkr
  }), /*#__PURE__*/_react["default"].createElement(_showKrConfirm["default"], {
    visible: ovisible,
    setVisible: setOVisible,
    onConfirmHandler: onhandleShowCardKr,
    showkr: showCardKr
  }));
}