var _excluded = ["column", "isMulti", "options", "tiny"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
import React, { useState, useCallback } from "react";
import DropdownFilter from "./dropdown";
var all = {
  value: "all",
  label: "All"
};
var SelectFilter = function SelectFilter(_ref) {
  var column = _ref.column,
    _ref$isMulti = _ref.isMulti,
    isMulti = _ref$isMulti === void 0 ? false : _ref$isMulti,
    _ref$options = _ref.options,
    options = _ref$options === void 0 ? [] : _ref$options,
    _ref$tiny = _ref.tiny,
    tiny = _ref$tiny === void 0 ? true : _ref$tiny,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var setFilterValue = column.setFilterValue,
    getFilterValue = column.getFilterValue;
  var filterValue = getFilterValue();
  var optionsWithExtraChoice = isMulti ? options : [all].concat(_toConsumableArray(options));
  var selectedValue = isMulti ? filterValue : optionsWithExtraChoice[0];
  var _useState = useState(filterValue ? filterValue : selectedValue),
    val = _useState[0],
    setVal = _useState[1];
  var onChange = useCallback(function (value) {
    setFilterValue(value);
    setVal(value);
  }, [setVal]);
  return /*#__PURE__*/React.createElement(DropdownFilter, _extends({
    value: val,
    isMulti: isMulti,
    options: optionsWithExtraChoice,
    onChange: onChange,
    styles: tiny && {
      size: "tiny"
    }
  }, rest));
};
export default SelectFilter;