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

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

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

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

var _constant = require("./constant");

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

var _leftImg = _interopRequireDefault(require("./img/left-img.jpg"));

require("./index.css");

var _excluded = ["hasSetting"],
    _excluded2 = ["isOpenCustom"];

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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

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-ork-guide';

var OkrGuide = function OkrGuide(props) {
  var visible = props.visible,
      handlerOnclickCreatOkr = props.handlerOnclickCreatOkr;

  var _useState = (0, _react.useState)(_constant.cycleList),
      _useState2 = _slicedToArray(_useState, 2),
      cycleListData = _useState2[0],
      setCycleListData = _useState2[1];

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

  var _useState5 = (0, _react.useState)({
    isOpenCustom: false,
    isOpenMonth: false,
    isOpenQuarter: true,
    isOpenYear: true,
    isOpenBimonthly: false,
    isOpenHalfYear: false
  }),
      _useState6 = _slicedToArray(_useState5, 2),
      setting = _useState6[0],
      changeSetting = _useState6[1];

  var getIsOpenById = {
    1: {
      isOpen: setting.isOpenYear
    },
    2: {
      isOpen: setting.isOpenQuarter
    },
    3: {
      isOpen: setting.isOpenMonth
    },
    4: {
      isOpen: setting.isOpenHalfYear
    },
    5: {
      isOpen: setting.isOpenBimonthly
    }
  };
  (0, _react.useEffect)(function () {
    var keys = ['isOpenMonth', 'isOpenQuarter', 'isOpenYear', 'isOpenBimonthly', 'isOpenHalfYear'];
    var count = 0;
    keys.forEach(function (k) {
      if (setting[k]) count++;
    });
    setIsOpenCount(count);
  }, [setting]);
  (0, _react.useEffect)(function () {
    (0, _requestApi.getCycleSetting)().then(function (res) {
      var hasSetting = res.hasSetting,
          onthers = _objectWithoutProperties(res, _excluded);

      changeSetting(onthers);
    });
  }, []);

  var handlerOnchangeSwitch = function handlerOnchangeSwitch(e, id) {
    var isOpen = e;

    if (isOpen) {
      if (isOpenCount > 2) {
        _toast["default"].Warning('周期最多选择 3 项');

        return;
      }
    } else {
      if (isOpenCount < 2) {
        _toast["default"].Warning('周期至少选择 1 项');

        return;
      }
    }

    switch (id) {
      case 1:
        changeSetting(_objectSpread(_objectSpread({}, setting), {}, {
          isOpenYear: isOpen
        }));
        break;

      case 2:
        changeSetting(_objectSpread(_objectSpread({}, setting), {}, {
          isOpenQuarter: isOpen
        }));
        break;

      case 3:
        changeSetting(_objectSpread(_objectSpread({}, setting), {}, {
          isOpenMonth: isOpen
        }));
        break;

      case 4:
        changeSetting(_objectSpread(_objectSpread({}, setting), {}, {
          isOpenHalfYear: isOpen
        }));
        break;

      case 5:
        changeSetting(_objectSpread(_objectSpread({}, setting), {}, {
          isOpenBimonthly: isOpen
        }));
        break;

      default:
        break;
    }
  };

  var handleSubmit = function handleSubmit() {
    if (isOpenCount > 3) {
      _toast["default"].Warning('周期最多选择 3 项');

      return;
    }

    var isOpenCustom = setting.isOpenCustom,
        others = _objectWithoutProperties(setting, _excluded2);

    (0, _requestApi.addCycleSetting)(_objectSpread({}, others)).then(function () {
      handlerOnclickCreatOkr();
    });
  };

  return /*#__PURE__*/_react["default"].createElement(_dialog["default"], {
    extraClass: preCls,
    wrapClassName: "".concat(preCls, "__wrap"),
    visible: visible,
    mask: false,
    noHeadLine: true,
    noFooterLine: true,
    noCloseIcon: true,
    noFooter: true,
    zIndex: 2001
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__bg")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container-box")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container__top")
  }, "\u2728\u6B22\u8FCE\u4F7F\u7528 Tita OKR"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container__card")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container__card__left")
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: _leftImg["default"]
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container__card__right")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container__card__right__title")
  }, "\uD83D\uDC4B Hi\uFF5E \u8BF7\u5148\u8BBE\u7F6E\u4E00\u4E0B\u76EE\u6807\u5468\u671F"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container__card__right__desc")
  }, "\u4F01\u4E1A\u6B65\u8C03\u4E00\u81F4\uFF0C\u7EDF\u4E00\u884C\u52A8\u63A8\u8FDB OKR\uFF0C\u6210\u529F\u7387\u5C06\u63D0\u5347 80%"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container__card__right__checkbox")
  }, cycleListData.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_react.Fragment, {
      key: item.id
    }, /*#__PURE__*/_react["default"].createElement(_switch["default"], {
      onChange: function onChange(e) {
        return handlerOnchangeSwitch(e, item.id);
      },
      label: item.name,
      checked: getIsOpenById[item.id].isOpen
    }));
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__container__card__right__btn"),
    onClick: handleSubmit
  }, /*#__PURE__*/_react["default"].createElement(_button["default"], {
    type: 'primary'
  }, "\u5B8C\u6210\u8BBE\u7F6E\uFF0C\u521B\u5EFA OKR"))))))));
};

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