"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useVisibleOptions = void 0;
var _useFilterOptions = require("../hooks/use-filter-options");
const typeaheadOptionsFilter = (it, searchValue, searchFields, showAll) => {
  return showAll || (0, _useFilterOptions.defaultFilter)(it, searchValue, searchFields);
};
const useVisibleOptions = ({
  formatSearchValue,
  searchValue,
  options,
  searchFields,
  isShowAll
}) => {
  const formattedSearchValue = formatSearchValue && formatSearchValue(searchValue) || searchValue;
  const visibleOptions = (0, _useFilterOptions.useFilterOptions)(options, formattedSearchValue ?? '', searchFields ?? [], (it, searchVal, searchFlds) => typeaheadOptionsFilter(it, searchVal, searchFlds, isShowAll));
  const isShowOptions = !(!isShowAll && !formattedSearchValue || !visibleOptions.length);
  return {
    visibleOptions,
    isShowOptions
  };
};
exports.useVisibleOptions = useVisibleOptions;