"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.SingleSelectFilterBase = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _designSystem = require("@wix/design-system");
var _react = _interopRequireDefault(require("react"));
var _mobxReactLite = require("mobx-react-lite");
var _useWindowFlipPopoverProps = require("../../utils/useWindowFlipPopoverProps");
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/SingleSelectFilterBase/SingleSelectFilterBase.tsx";
function _SingleSelectFilterBase(props) {
  var _selectedValues$;
  const {
    filter,
    dropdownSelect,
    placeholder,
    onSelect,
    renderItem,
    renderSection,
    clearButton,
    disabled,
    options = [],
    popoverProps,
    ...rest
  } = props;
  const {
    select: {
      selectedValues
    },
    container: {
      translate: t
    }
  } = dropdownSelect;
  const {
    windowFlipPopoverProps,
    inputRef
  } = (0, _useWindowFlipPopoverProps.useWindowFlipPopoverProps)({
    popoverProps
  });
  return /*#__PURE__*/_react.default.createElement(_designSystem.Dropdown, (0, _extends2.default)({
    inputRef: ref => {
      inputRef.current = ref;
    },
    dataHook: `collection-filter-${filter.name}`,
    border: "round",
    closeOnSelect: true,
    options: options,
    clearButton: clearButton,
    onClear: clearButton ? dropdownSelect.clear : undefined,
    onClose: () => {
      dropdownSelect.close();
    },
    selectedId: (_selectedValues$ = selectedValues[0]) == null ? void 0 : _selectedValues$.key,
    valueParser: option => option.label,
    textOverflow: "ellipsis",
    placeholder: placeholder ?? t('cairo.selectPlaceholder'),
    onSelect: option => {
      const keyedItem = option == null ? void 0 : option.keyedItem;
      if (keyedItem) {
        dropdownSelect.setSingle(keyedItem);
      }
      onSelect == null || onSelect(option, false);
    },
    popoverProps: windowFlipPopoverProps
  }, rest, {
    __self: this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 53,
      columnNumber: 5
    }
  }));
}
const SingleSelectFilterBase = exports.SingleSelectFilterBase = (0, _mobxReactLite.observer)(_SingleSelectFilterBase);
//# sourceMappingURL=SingleSelectFilterBase.js.map