'use strict';

var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
var _createClass = require('@babel/runtime/helpers/createClass');
var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
var _inherits = require('@babel/runtime/helpers/inherits');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var isNil = require('../../../../node_modules/lodash-es/isNil.js');
var isEqual = require('../../../../node_modules/lodash-es/isEqual.js');
var debounce = require('../../../../node_modules/lodash-es/debounce.js');
var memoize = require('../../../../node_modules/lodash-es/memoize.js');
require('core-js/modules/es.symbol.js');
require('core-js/modules/es.array.concat.js');
require('core-js/modules/es.array.filter.js');
require('core-js/modules/es.array.find.js');
require('core-js/modules/es.array.includes.js');
require('core-js/modules/es.array.map.js');
require('core-js/modules/es.array.slice.js');
require('core-js/modules/es.array.sort.js');
require('core-js/modules/es.object.get-own-property-descriptor.js');
require('core-js/modules/es.object.get-own-property-descriptors.js');
require('core-js/modules/es.object.keys.js');
require('core-js/modules/es.object.to-string.js');
require('core-js/modules/es.reflect.construct.js');
require('core-js/modules/web.dom-collections.for-each.js');
var React = require('react');
var PropTypes = require('prop-types');
var react = require('@carbon/react');
var classnames = require('classnames');
var warning = require('warning');
var componentUtilityFunctions = require('../../../../utils/componentUtilityFunctions.js');
var Settings = require('../../../../constants/Settings.js');
var Filters = require('../../../../constants/Filters.js');
var ComboBox = require('../../../ComboBox/ComboBox.js');
var TableToolbarSVGButton = require('../../TableToolbar/TableToolbarSVGButton.js');
var iconsReact = require('@carbon/icons-react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _classCallCheck__default = /*#__PURE__*/_interopDefault(_classCallCheck);
var _createClass__default = /*#__PURE__*/_interopDefault(_createClass);
var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefault(_possibleConstructorReturn);
var _getPrototypeOf__default = /*#__PURE__*/_interopDefault(_getPrototypeOf);
var _inherits__default = /*#__PURE__*/_interopDefault(_inherits);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var React__default = /*#__PURE__*/_interopDefault(React);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var warning__default = /*#__PURE__*/_interopDefault(warning);

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _callSuper(t, o, e) { return o = _getPrototypeOf__default.default(o), _possibleConstructorReturn__default.default(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf__default.default(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var iotPrefix = Settings.settings.iotPrefix,
  prefix = Settings.settings.prefix;
var getFilterForState = function getFilterForState(filters, col) {
  var appliedFilter = filters.find(function (i) {
    return i.columnId === col.id;
  });
  if (appliedFilter && col.options && componentUtilityFunctions.isEmptyString(appliedFilter.value)) {
    return Filters.FILTER_EMPTY_STRING;
  }
  if (appliedFilter && !isNil(appliedFilter.value)) {
    return appliedFilter.value;
  }
  return '';
};
var FilterHeaderRow = /*#__PURE__*/function (_Component) {
  function FilterHeaderRow(props) {
    var _this;
    _classCallCheck__default.default(this, FilterHeaderRow);
    _this = _callSuper(this, FilterHeaderRow, [props]);
    _defineProperty__default.default(_this, "state", {
      dropdownMaxHeight: 'unset',
      filterValues: _this.props.columns.reduce(function (acc, curr) {
        return _objectSpread(_objectSpread({}, acc), {}, _defineProperty__default.default({}, curr.id, getFilterForState(_this.props.filters, curr)));
      }, {}),
      filterIconTopOffset: 96
    });
    _defineProperty__default.default(_this, "updateDropdownHeight", function () {
      if (_this.rowRef.current) {
        var tableContainer = _this.rowRef.current.closest(".".concat(prefix, "--data-table-content"));
        var tableHead = _this.rowRef.current.closest("thead");
        if (tableContainer) {
          var _tableContainer$getBo = tableContainer.getBoundingClientRect(),
            containerHeight = _tableContainer$getBo.height;
          var _tableHead$getBoundin = tableHead.getBoundingClientRect(),
            headHeight = _tableHead$getBoundin.height;
          var height = containerHeight - headHeight - 16;
          _this.setState({
            dropdownMaxHeight: "".concat(height, "px")
          });
        }
      }
    });
    _defineProperty__default.default(_this, "updateFilterIconPosition", function () {
      /* istanbul ignore else */
      if (!_this.props.tableOptions.hasFilterRowIcon) {
        return;
      }

      /* istanbul ignore next */
      if (_this.filterCellRef.current) {
        var siblingTopOffset = _this.filterCellRef.current.getBoundingClientRect().top;
        var tableTopOffset = _this.filterCellRef.current.closest(".".concat(iotPrefix, "--table-container")).getBoundingClientRect().top;
        _this.setState(function (prevState) {
          if (_this.props.pinHeaderAndFooter) {
            // Subtract 48px of toolbar height
            return _objectSpread(_objectSpread({}, prevState), {}, {
              filterIconTopOffset: siblingTopOffset - tableTopOffset - 48
            });
          }
          return _objectSpread(_objectSpread({}, prevState), {}, {
            filterIconTopOffset: siblingTopOffset - tableTopOffset
          });
        });
      }
    });
    _defineProperty__default.default(_this, "setFirstFilterableRef", function (node) {
      if (!_this.firstFilterableRef.current && node) {
        _this.firstFilterableRef.current = node;
      }
    });
    _defineProperty__default.default(_this, "updateFocus", function () {
      if (_this.firstFilterableRef.current) {
        if (typeof _this.firstFilterableRef.current.focus === 'function') {
          _this.firstFilterableRef.current.focus();
        } else if (typeof _this.firstFilterableRef.current.textInput.current.focus === 'function') {
          _this.firstFilterableRef.current.textInput.current.focus();
        }
      }
    });
    /**
     * take the state with the filter values and send to our listener
     */
    _defineProperty__default.default(_this, "handleApplyFilter", function () {
      var onApplyFilter = _this.props.onApplyFilter;
      var filterValues = _this.state.filterValues;
      onApplyFilter(filterValues);
    });
    // when a user clicks or hits ENTER, we'll clear the input
    _defineProperty__default.default(_this, "handleClearFilter", function (event, column) {
      _this.setState(function (state) {
        return {
          filterValues: _objectSpread(_objectSpread({}, state.filterValues), {}, _defineProperty__default.default({}, column.id, ''))
        };
      }, _this.handleApplyFilter);
    });
    _defineProperty__default.default(_this, "handleTranslation", function (idToTranslate) {
      var _this$props = _this.props,
        clearSelectionText = _this$props.clearSelectionText,
        openMenuText = _this$props.openMenuText,
        closeMenuText = _this$props.closeMenuText;
      switch (idToTranslate) {
        default:
          return '';
        case 'clear.selection':
          return clearSelectionText;
        case 'clear.all':
          return clearSelectionText;
        case 'open.menu':
          return openMenuText;
        case 'close.menu':
          return closeMenuText;
      }
    });
    _this.rowRef = /*#__PURE__*/React__default.default.createRef();
    _this.firstFilterableRef = /*#__PURE__*/React__default.default.createRef();
    _this.filterCellRef = /*#__PURE__*/React__default.default.createRef();
    return _this;
  }
  _inherits__default.default(FilterHeaderRow, _Component);
  return _createClass__default.default(FilterHeaderRow, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.updateDropdownHeight();
      this.updateFocus();
      this.updateFilterIconPosition();
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate(prevProps, prevState) {
      var dropdownMaxHeight = this.state.dropdownMaxHeight;
      var size = this.props.size;
      if (dropdownMaxHeight !== prevState.dropdownMaxHeight || size !== prevProps.size) {
        this.updateDropdownHeight();
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;
      var _this$props2 = this.props,
        columns = _this$props2.columns,
        ordering = _this$props2.ordering,
        clearFilterText = _this$props2.clearFilterText,
        filterText = _this$props2.filterText,
        _this$props2$tableOpt = _this$props2.tableOptions,
        hasRowSelection = _this$props2$tableOpt.hasRowSelection,
        hasRowExpansion = _this$props2$tableOpt.hasRowExpansion,
        hasRowNesting = _this$props2$tableOpt.hasRowNesting,
        hasRowActions = _this$props2$tableOpt.hasRowActions,
        useRadioButtonSingleSelect = _this$props2$tableOpt.useRadioButtonSingleSelect,
        hasFilterRowIcon = _this$props2$tableOpt.hasFilterRowIcon,
        hasResize = _this$props2$tableOpt.hasResize,
        isVisible = _this$props2.isVisible,
        lightweight = _this$props2.lightweight,
        isDisabled = _this$props2.isDisabled,
        hasFastFilter = _this$props2.hasFastFilter,
        testId = _this$props2.testId,
        showExpanderColumn = _this$props2.showExpanderColumn,
        langDir = _this$props2.langDir,
        showColumnGroups = _this$props2.showColumnGroups,
        filterRowIcon = _this$props2.filterRowIcon,
        filterRowIconDescription = _this$props2.filterRowIconDescription,
        onFilterRowIconClick = _this$props2.onFilterRowIconClick,
        hasDragAndDrop = _this$props2.hasDragAndDrop;
      var _this$state = this.state,
        dropdownMaxHeight = _this$state.dropdownMaxHeight,
        filterValues = _this$state.filterValues,
        filterIconTopOffset = _this$state.filterIconTopOffset;
      var visibleColumns = ordering.filter(function (c) {
        return !c.isHidden;
      });
      return isVisible ? /*#__PURE__*/React__default.default.createElement(react.TableRow, {
        "data-testid": testId,
        style: {
          '--filter-header-dropdown-max-height': dropdownMaxHeight
        }
      }, hasDragAndDrop ?
      /*#__PURE__*/
      /* istanbul ignore next */
      React__default.default.createElement(react.TableHeader, {
        className: "".concat(iotPrefix, "--filter-header-row--header")
      }) : null, hasRowSelection === 'multi' || hasRowSelection === 'single' && useRadioButtonSingleSelect ? /*#__PURE__*/React__default.default.createElement(react.TableHeader, {
        className: "".concat(iotPrefix, "--filter-header-row--header"),
        ref: this.rowRef
      }) : null, hasRowExpansion || hasRowNesting ? /*#__PURE__*/React__default.default.createElement(react.TableHeader, {
        className: "".concat(iotPrefix, "--filter-header-row--header")
      }) : null, visibleColumns.map(function (c, i) {
        var column = columns.find(function (item) {
          return c.columnId === item.id;
        });
        var columnStateValue = filterValues[column.id]; // eslint-disable-line react/destructuring-assignment
        var filterColumnOptions = function filterColumnOptions(options) {
          options.sort(function (a, b) {
            return a.text.localeCompare(b.text, {
              sensitivity: 'base'
            });
          });
          return options;
        };
        var memoizeColumnOptions = memoize(filterColumnOptions); // TODO: this memoize isn't really working, should refactor to a higher column level
        var isLastColumn = visibleColumns.length - 1 === i;
        var lastVisibleColumn = visibleColumns.slice(-1)[0];
        var isLastVisibleColumn = column.id === lastVisibleColumn.columnId;
        /* istanbul ignore next */
        var CustomInput = column.customInput;
        // undefined check has the effect of making isFilterable default to true
        // if unspecified
        var headerContent = column.isFilterable !== undefined && !column.isFilterable ? /*#__PURE__*/React__default.default.createElement("div", null) : /* istanbul ignore next */
        column.customInput !== undefined ? /*#__PURE__*/React__default.default.createElement(CustomInput, {
          ref: _this2.setFirstFilterableRef,
          id: "column-".concat(i),
          onChange: function onChange(event) {
            if (event.persist) {
              event.persist();
            }
            _this2.setState(function (state) {
              var _event$selectedItems;
              return {
                filterValues: _objectSpread(_objectSpread({}, state.filterValues), {}, _defineProperty__default.default({}, column.id, event.selectedItem ? componentUtilityFunctions.getFilterValue(event.selectedItem) : ((_event$selectedItems = event.selectedItems) === null || _event$selectedItems === void 0 ? void 0 : _event$selectedItems.length) > 0 ? event.selectedItems.map(componentUtilityFunctions.getMultiselectFilterValue) : event.target.value))
              };
            }, debounce(_this2.handleApplyFilter, 1000));
          },
          column: column,
          columns: columns,
          value: filterValues[column.id]
        }) : column.options ? column.isMultiselect ? /*#__PURE__*/React__default.default.createElement(react.FilterableMultiSelect, {
          ref: _this2.setFirstFilterableRef,
          key: columnStateValue,
          className: classnames__default.default("".concat(iotPrefix, "--filterheader-multiselect"), "".concat(iotPrefix, "--filterheader-multiselect__menu--fit-content"), _defineProperty__default.default({}, "".concat(iotPrefix, "--filterheader-multiselect__menu--flip-horizontal"), isLastColumn)),
          id: "column-".concat(i),
          "aria-label": filterText,
          placeholder: column.placeholderText || 'Choose an option',
          translateWithId: _this2.handleTranslation,
          items: memoizeColumnOptions(column.options),
          label: column.placeholderText || 'Choose an option',
          itemToString: function itemToString(item) {
            return item.text;
          },
          initialSelectedItems: componentUtilityFunctions.getMultiSelectItems(column, columnStateValue),
          onChange: function onChange(evt) {
            _this2.setState(function (state) {
              return {
                filterValues: _objectSpread(_objectSpread({}, state.filterValues), {}, _defineProperty__default.default({}, column.id, evt.selectedItems.map(componentUtilityFunctions.getMultiselectFilterValue)))
              };
            }, _this2.handleApplyFilter);
          },
          light: true,
          disabled: isDisabled
        }) : /*#__PURE__*/React__default.default.createElement(ComboBox, {
          ref: _this2.setFirstFilterableRef,
          menuFitContent: true,
          horizontalDirection: isLastColumn ? 'start' : 'end',
          key: columnStateValue,
          className: "".concat(iotPrefix, "--filterheader-combo"),
          id: "column-".concat(i),
          "aria-label": filterText,
          translateWithId: _this2.handleTranslation,
          items: memoizeColumnOptions(column.options),
          itemToString: function itemToString(item) {
            return item ? item.text : '';
          },
          initialSelectedItem: {
            id: columnStateValue,
            text: componentUtilityFunctions.getAppliedFilterText(column, columnStateValue)
          },
          placeholder: column.placeholderText || 'Choose an option',
          onChange: function onChange(selectedItem) {
            _this2.setState(function (state) {
              return {
                filterValues: _objectSpread(_objectSpread({}, state.filterValues), {}, _defineProperty__default.default({}, column.id, componentUtilityFunctions.getFilterValue(selectedItem)))
              };
            }, _this2.handleApplyFilter);
          },
          light: lightweight,
          disabled: isDisabled
        }) : /*#__PURE__*/React__default.default.createElement(react.FormItem, {
          className: "".concat(iotPrefix, "--filter-header-row--form-item")
        }, /*#__PURE__*/React__default.default.createElement(react.TextInput, {
          ref: _this2.setFirstFilterableRef,
          id: column.id,
          labelText: column.id,
          hideLabel: true,
          light: lightweight,
          placeholder: column.placeholderText || 'Type and hit enter to apply',
          title: filterValues[column.id] || column.placeholderText // eslint-disable-line react/destructuring-assignment
          ,
          onChange: function onChange(event) {
            event.persist();
            _this2.setState(function (state) {
              return {
                filterValues: _objectSpread(_objectSpread({}, state.filterValues), {}, _defineProperty__default.default({}, column.id, event.target.value))
              };
            }, hasFastFilter ? debounce(_this2.handleApplyFilter, 150) : null // only apply the filter at debounced interval
            );
          },
          onKeyDown: !hasFastFilter ? function (event) {
            return componentUtilityFunctions.handleEnterKeyDown(event, _this2.handleApplyFilter);
          } : null // if fast filter off, then filter on key press
          ,
          onBlur: !hasFastFilter ? _this2.handleApplyFilter : null // if fast filter off, then filter on blur
          ,
          value: filterValues[column.id] // eslint-disable-line react/destructuring-assignment
          ,
          disabled: isDisabled
        }), filterValues[column.id] ?
        /*#__PURE__*/
        // eslint-disable-line react/destructuring-assignment
        React__default.default.createElement("div", {
          role: "button",
          className: classnames__default.default("".concat(prefix, "--list-box__selection"), _defineProperty__default.default({}, "".concat(iotPrefix, "--clear-filters-button--disabled"), isDisabled)),
          tabIndex: isDisabled ? '-1' : '0',
          onMouseDown: function onMouseDown(event) {
            return event.preventDefault();
          },
          onClick: function onClick(event) {
            if (!isDisabled) {
              _this2.handleClearFilter(event, column);
            }
          },
          onKeyDown: function onKeyDown(event) {
            return componentUtilityFunctions.handleEnterKeyDown(event, function () {
              if (!isDisabled) {
                _this2.handleClearFilter(event, column);
              }
            });
          },
          title: clearFilterText
        }, /*#__PURE__*/React__default.default.createElement(iconsReact.Close, {
          description: clearFilterText
        })) : null);
        return /*#__PURE__*/React__default.default.createElement(react.TableHeader, {
          className: classnames__default.default("".concat(iotPrefix, "--tableheader-filter"), "".concat(iotPrefix, "--filter-header-row--header"), _defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--filter-header-row--header-width"), column.width === undefined), "".concat(iotPrefix, "--filter-header-row--last-column"), isLastVisibleColumn), "".concat(iotPrefix, "--filter-header-row--with-icon"), isLastVisibleColumn && hasFilterRowIcon), "".concat(iotPrefix, "--filter-header-row--with-margin"), isLastVisibleColumn && hasFilterRowIcon && (!showColumnGroups || !hasRowActions))),
          "data-column": column.id,
          key: "FilterHeader".concat(column.id),
          width: column.width,
          ref: isLastVisibleColumn ? _this2.filterCellRef : undefined
        }, headerContent, hasFilterRowIcon && isLastVisibleColumn ? /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, /*#__PURE__*/React__default.default.createElement(TableToolbarSVGButton, {
          testId: "filter-row-icon",
          className: classnames__default.default("".concat(iotPrefix, "--filter-header-icon ").concat(iotPrefix, "-hide-tooltip-icon"), _defineProperty__default.default(_defineProperty__default.default({}, "".concat(iotPrefix, "--filter-header-icon--with-border"), hasResize && showColumnGroups && !hasRowActions), "".concat(iotPrefix, "--filter-header-icon--with-margin"), hasRowActions)),
          description: filterRowIconDescription,
          title: filterRowIconDescription,
          onClick: onFilterRowIconClick,
          renderIcon: filterRowIcon,
          size: "field",
          style: {
            top: "".concat(filterIconTopOffset, "px")
          },
          tooltipAlignment: langDir === 'ltr' ? 'end' : 'start'
        }), hasRowActions ? /*#__PURE__*/React__default.default.createElement("div", {
          className: "".concat(iotPrefix, "--filter-header-row--icon-support"),
          style: {
            top: "".concat(filterIconTopOffset, "px")
          }
        }) : null) : null);
      }), hasRowActions ? /*#__PURE__*/React__default.default.createElement(react.TableHeader, {
        className: "".concat(iotPrefix, "--filter-header-row--header")
      }) : null, showExpanderColumn ? /*#__PURE__*/React__default.default.createElement(react.TableHeader, {
        "data-testid": "".concat(testId, "-expander-column"),
        className: "".concat(iotPrefix, "--filter-header-row--header")
      }) : null) : null;
    }
  }], [{
    key: "getDerivedStateFromProps",
    value:
    // TODO: we should really do this through a useEffect hook when we refactor to functional component
    function getDerivedStateFromProps(props, state) {
      // If the filter props change from the outside, we need to reset the filterValues inside local state
      if (!isEqual(props.filters, state.prevPropsFilters)) {
        var newFilters = props.columns.reduce(function (acc, curr) {
          return _objectSpread(_objectSpread({}, acc), {}, _defineProperty__default.default({}, curr.id, getFilterForState(props.filters, curr)));
        }, {});
        if (!isEqual(newFilters, state.filterValues)) {
          return {
            filterValues: newFilters,
            prevPropsFilters: props.filters
          };
        }
        // Need to store the updated filters from before
        return {
          prevPropsFilters: props.filters
        };
      }
      return null;
    }
  }]);
}(React.Component);
_defineProperty__default.default(FilterHeaderRow, "propTypes", {
  columns: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
    id: PropTypes__default.default.string,
    /** When false, no filter shows */
    isFilterable: PropTypes__default.default.bool,
    /** i18N text for translation */
    placeholderText: PropTypes__default.default.string,
    /** if options is empty array, assume text input for filter */
    options: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
      id: PropTypes__default.default.oneOfType([PropTypes__default.default.string, PropTypes__default.default.number, PropTypes__default.default.bool]).isRequired,
      text: PropTypes__default.default.string.isRequired
    })),
    /** if isMultiselect and isFilterable are true, the table is filtered based on a multiselect */
    isMultiselect: PropTypes__default.default.bool,
    /**
     * customInput should be a React component that will accept the following props. value, onChange, id, column, columns etc.
     * The expectation is that the input component will use value as the default value and onChange will be called when the value changes.  The FilterTableRow will debounce the values so the component does not need to do this
     */
    customInput: PropTypes__default.default.elementType
  })).isRequired,
  /** internationalized string */
  filterText: PropTypes__default.default.string,
  clearFilterText: PropTypes__default.default.string,
  clearSelectionText: PropTypes__default.default.string,
  openMenuText: PropTypes__default.default.string,
  closeMenuText: PropTypes__default.default.string,
  ordering: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
    columnId: PropTypes__default.default.string.isRequired,
    /* Visibility of column in table, defaults to false */
    isHidden: PropTypes__default.default.bool
  })).isRequired,
  filters: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
    columnId: PropTypes__default.default.string.isRequired,
    value: PropTypes__default.default.oneOfType([PropTypes__default.default.string, PropTypes__default.default.number, PropTypes__default.default.bool, PropTypes__default.default.arrayOf(PropTypes__default.default.string)]).isRequired
  })),
  /** Callback when filter is applied sends object of keys and values with the filter values */
  onApplyFilter: PropTypes__default.default.func,
  /** properties global to the table */
  tableOptions: PropTypes__default.default.shape({
    hasRowSelection: PropTypes__default.default.oneOf(['multi', 'single', false]),
    hasRowExpansion: PropTypes__default.default.bool,
    hasRowNesting: PropTypes__default.default.bool,
    hasRowActions: PropTypes__default.default.bool,
    useRadioButtonSingleSelect: PropTypes__default.default.bool,
    hasFilterRowIcon: PropTypes__default.default.bool,
    hasResize: PropTypes__default.default.bool
  }),
  /** filter can be hidden by the user but filters will still apply to the table */
  isVisible: PropTypes__default.default.bool,
  /** disabled filters are shown and active but cannot be modified */
  isDisabled: PropTypes__default.default.bool,
  lightweight: PropTypes__default.default.bool,
  /** should we filter as the user types or after they press enter */
  hasFastFilter: PropTypes__default.default.bool,
  testId: PropTypes__default.default.string,
  /** shows an additional column that can expand/shrink as the table is resized  */
  showExpanderColumn: PropTypes__default.default.bool.isRequired,
  /** Size prop from Carbon to shrink row height (and header height in some instances) */
  size: function checkProps(props, propName, componentName) {
    if (['compact', 'short', 'normal', 'tall'].includes(props[propName])) {
      warning__default.default(false, "The value `".concat(props[propName], "` has been deprecated for the ") + "`".concat(propName, "` prop on the ").concat(componentName, " component. It will be removed in the next major ") + "release. Please use 'xs', 'sm', 'md', 'lg', or 'xl' instead.") ;
    }
  },
  /** language direction for current table */
  langDir: PropTypes__default.default.oneOf(['rtl', 'ltr']),
  /** indicator if columns have grouping */
  showColumnGroups: PropTypes__default.default.bool,
  /** icon element for filter row icon */
  filterRowIcon: PropTypes__default.default.oneOfType([PropTypes__default.default.func, PropTypes__default.default.object]),
  /** tooltip text for filter row icon button */
  filterRowIconDescription: PropTypes__default.default.string,
  /** call back function for when icon button in filter row is clicked  (evt) => {} */
  onFilterRowIconClick: PropTypes__default.default.func.isRequired,
  /** Freezes table header and footer */
  pinHeaderAndFooter: PropTypes__default.default.bool,
  /** Set to true if the table support drag and drop. Inserts a cell in the "drag handle" column
   * for spacing. */
  hasDragAndDrop: PropTypes__default.default.bool
});
_defineProperty__default.default(FilterHeaderRow, "defaultProps", {
  tableOptions: {
    hasRowSelection: 'multi'
  },
  filters: [],
  isVisible: true,
  isDisabled: false,
  onApplyFilter: componentUtilityFunctions.defaultFunction,
  filterText: 'Filter',
  clearFilterText: 'Clear filter',
  clearSelectionText: 'Clear selection',
  openMenuText: 'Open menu',
  closeMenuText: 'Close menu',
  lightweight: false,
  hasFastFilter: true,
  testId: '',
  size: undefined,
  langDir: 'ltr',
  showColumnGroups: false,
  filterRowIcon: null,
  filterRowIconDescription: 'Edit filters',
  pinHeaderAndFooter: false,
  hasDragAndDrop: false
});
FilterHeaderRow.__docgenInfo = {
  "description": "",
  "methods": [{
    "name": "updateDropdownHeight",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "updateFilterIconPosition",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "setFirstFilterableRef",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "node",
      "type": null
    }],
    "returns": null
  }, {
    "name": "updateFocus",
    "docblock": null,
    "modifiers": [],
    "params": [],
    "returns": null
  }, {
    "name": "handleApplyFilter",
    "docblock": "take the state with the filter values and send to our listener",
    "modifiers": [],
    "params": [],
    "returns": null,
    "description": "take the state with the filter values and send to our listener"
  }, {
    "name": "handleClearFilter",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "event",
      "type": null
    }, {
      "name": "column",
      "type": null
    }],
    "returns": null
  }, {
    "name": "handleTranslation",
    "docblock": null,
    "modifiers": [],
    "params": [{
      "name": "idToTranslate",
      "type": null
    }],
    "returns": null
  }],
  "displayName": "FilterHeaderRow",
  "props": {
    "tableOptions": {
      "defaultValue": {
        "value": "{ hasRowSelection: 'multi' }",
        "computed": false
      },
      "description": "properties global to the table",
      "type": {
        "name": "shape",
        "value": {
          "hasRowSelection": {
            "name": "enum",
            "value": [{
              "value": "'multi'",
              "computed": false
            }, {
              "value": "'single'",
              "computed": false
            }, {
              "value": "false",
              "computed": false
            }],
            "required": false
          },
          "hasRowExpansion": {
            "name": "bool",
            "required": false
          },
          "hasRowNesting": {
            "name": "bool",
            "required": false
          },
          "hasRowActions": {
            "name": "bool",
            "required": false
          },
          "useRadioButtonSingleSelect": {
            "name": "bool",
            "required": false
          },
          "hasFilterRowIcon": {
            "name": "bool",
            "required": false
          },
          "hasResize": {
            "name": "bool",
            "required": false
          }
        }
      },
      "required": false
    },
    "filters": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": {
            "columnId": {
              "name": "string",
              "required": true
            },
            "value": {
              "name": "union",
              "value": [{
                "name": "string"
              }, {
                "name": "number"
              }, {
                "name": "bool"
              }, {
                "name": "arrayOf",
                "value": {
                  "name": "string"
                }
              }],
              "required": true
            }
          }
        }
      },
      "required": false
    },
    "isVisible": {
      "defaultValue": {
        "value": "true",
        "computed": false
      },
      "description": "filter can be hidden by the user but filters will still apply to the table",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "isDisabled": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "disabled filters are shown and active but cannot be modified",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "onApplyFilter": {
      "defaultValue": {
        "value": "defaultFunction",
        "computed": true
      },
      "description": "Callback when filter is applied sends object of keys and values with the filter values",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "filterText": {
      "defaultValue": {
        "value": "'Filter'",
        "computed": false
      },
      "description": "internationalized string",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "clearFilterText": {
      "defaultValue": {
        "value": "'Clear filter'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "clearSelectionText": {
      "defaultValue": {
        "value": "'Clear selection'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "openMenuText": {
      "defaultValue": {
        "value": "'Open menu'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "closeMenuText": {
      "defaultValue": {
        "value": "'Close menu'",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "lightweight": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasFastFilter": {
      "defaultValue": {
        "value": "true",
        "computed": false
      },
      "description": "should we filter as the user types or after they press enter",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "testId": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "size": {
      "defaultValue": {
        "value": "undefined",
        "computed": true
      },
      "description": "Size prop from Carbon to shrink row height (and header height in some instances)",
      "type": {
        "name": "custom",
        "raw": "function checkProps(props, propName, componentName) {\n  if (['compact', 'short', 'normal', 'tall'].includes(props[propName])) {\n    warning(\n      false,\n      `The value \\`${props[propName]}\\` has been deprecated for the ` +\n        `\\`${propName}\\` prop on the ${componentName} component. It will be removed in the next major ` +\n        `release. Please use 'xs', 'sm', 'md', 'lg', or 'xl' instead.`\n    );\n  }\n}"
      },
      "required": false
    },
    "langDir": {
      "defaultValue": {
        "value": "'ltr'",
        "computed": false
      },
      "description": "language direction for current table",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'rtl'",
          "computed": false
        }, {
          "value": "'ltr'",
          "computed": false
        }]
      },
      "required": false
    },
    "showColumnGroups": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "indicator if columns have grouping",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "filterRowIcon": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "icon element for filter row icon",
      "type": {
        "name": "union",
        "value": [{
          "name": "func"
        }, {
          "name": "object"
        }]
      },
      "required": false
    },
    "filterRowIconDescription": {
      "defaultValue": {
        "value": "'Edit filters'",
        "computed": false
      },
      "description": "tooltip text for filter row icon button",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "pinHeaderAndFooter": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Freezes table header and footer",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasDragAndDrop": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Set to true if the table support drag and drop. Inserts a cell in the \"drag handle\" column\nfor spacing.",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "columns": {
      "description": "",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": {
            "id": {
              "name": "string",
              "required": false
            },
            "isFilterable": {
              "name": "bool",
              "description": "When false, no filter shows",
              "required": false
            },
            "placeholderText": {
              "name": "string",
              "description": "i18N text for translation",
              "required": false
            },
            "options": {
              "name": "arrayOf",
              "value": {
                "name": "shape",
                "value": {
                  "id": {
                    "name": "union",
                    "value": [{
                      "name": "string"
                    }, {
                      "name": "number"
                    }, {
                      "name": "bool"
                    }],
                    "required": true
                  },
                  "text": {
                    "name": "string",
                    "required": true
                  }
                }
              },
              "description": "if options is empty array, assume text input for filter",
              "required": false
            },
            "isMultiselect": {
              "name": "bool",
              "description": "if isMultiselect and isFilterable are true, the table is filtered based on a multiselect",
              "required": false
            },
            "customInput": {
              "name": "elementType",
              "description": "customInput should be a React component that will accept the following props. value, onChange, id, column, columns etc.\nThe expectation is that the input component will use value as the default value and onChange will be called when the value changes.  The FilterTableRow will debounce the values so the component does not need to do this",
              "required": false
            }
          }
        }
      },
      "required": true
    },
    "ordering": {
      "description": "",
      "type": {
        "name": "arrayOf",
        "value": {
          "name": "shape",
          "value": {
            "columnId": {
              "name": "string",
              "required": true
            },
            "isHidden": {
              "name": "bool",
              "required": false
            }
          }
        }
      },
      "required": true
    },
    "showExpanderColumn": {
      "description": "shows an additional column that can expand/shrink as the table is resized",
      "type": {
        "name": "bool"
      },
      "required": true
    },
    "onFilterRowIconClick": {
      "description": "call back function for when icon button in filter row is clicked  (evt) => {}",
      "type": {
        "name": "func"
      },
      "required": true
    }
  }
};
var FilterHeaderRow$1 = FilterHeaderRow;

module.exports = FilterHeaderRow$1;
