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

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

var _dropSelector = _interopRequireWildcard(require("../../../../drop-selector"));

var _lineDownArrow = _interopRequireDefault(require("../../images/line-down-arrow.svg"));

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

require("../index.css");

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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

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

var preCls = "ode-search-form";

function _default(props) {
  var checkedStatus = props.checkedStatus,
      setCheckedStatus = props.setCheckedStatus;

  var onItemClickHandler = function onItemClickHandler(name, isChecked) {
    if (name == "all" && isChecked) return setCheckedStatus(["all", "unstart", "doing", "finish", "delay", "cancel", "pause"]);
    if (name == "all" && !isChecked) return setCheckedStatus([]);

    var newChecked = _toConsumableArray(checkedStatus);

    if (newChecked.indexOf(name) != -1) {
      newChecked = newChecked.filter(function (itname) {
        return itname != name;
      });
      newChecked = newChecked.filter(function (itname) {
        return itname != "all";
      });
    } else {
      newChecked.push(name);

      if (!newChecked.includes("all") && newChecked.length === 6) {
        newChecked = ["all", "unstart", "doing", "finish", "delay", "cancel", "pause"];
      }
    }

    setCheckedStatus(newChecked);
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(preCls, "__field")
  }, /*#__PURE__*/_react["default"].createElement(_dropSelector["default"], {
    multi: true,
    checked: checkedStatus,
    popupPlacement: "bottomLeft",
    hideOnChange: false,
    onChange: onItemClickHandler,
    limitHeight: false,
    trigger: /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])("".concat(preCls, "__field-status"))
    }, (0, _getLocale.getLocale)("Mod_States"), " ", /*#__PURE__*/_react["default"].createElement("i", {
      className: "tu-icon-arrow-down"
    }))
  }, /*#__PURE__*/_react["default"].createElement(_dropSelector.Item, {
    name: "all"
  }, (0, _getLocale.getLocale)("OKR_MyO_Butt_AllStates")), /*#__PURE__*/_react["default"].createElement(_dropSelector.Item, {
    name: "unstart"
  }, (0, _getLocale.getLocale)("OKR_MyO_E_From_NotStarted")), /*#__PURE__*/_react["default"].createElement(_dropSelector.Item, {
    name: "doing"
  }, (0, _getLocale.getLocale)("Per_MyRe_text_Inprogress")), /*#__PURE__*/_react["default"].createElement(_dropSelector.Item, {
    name: "finish"
  }, (0, _getLocale.getLocale)("OKR_MyO_E_From_Completed")), /*#__PURE__*/_react["default"].createElement(_dropSelector.Item, {
    name: "delay"
  }, (0, _getLocale.getLocale)("OKR_MyO_E_From_Delayed")), /*#__PURE__*/_react["default"].createElement(_dropSelector.Item, {
    name: "cancel"
  }, (0, _getLocale.getLocale)("OKR_MyO_E_From_Cancelled")), /*#__PURE__*/_react["default"].createElement(_dropSelector.Item, {
    name: "pause"
  }, (0, _getLocale.getLocale)("OKR_MyO_E_From_Suspended"))));
}