{"version":3,"sources":["../src/components/Combobox/useComboboxFilter.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport type { JSXElement } from '@fluentui/react-utilities';\n\ntype UseComboboxFilterConfig = {\n  /**\n   * The current query string used to filter the options.\n   */\n  query: string;\n  /**\n   * The list of options to filter.\n   */\n  options: string[];\n  /**\n   * Optional filter function to override the default filtering behavior.\n   */\n  filter?: (option: string, index: number) => boolean;\n  /**\n   * Element to render when there are no options to display.\n   */\n  noOptionsElement: JSXElement;\n  /**\n   * A function that renders an option element for a given option.\n   * Use it to customize how options are displayed in the listbox.\n   */\n  renderOption: (option: string) => JSXElement;\n};\n\n/**\n * A hook that filters a list of options based on a query string and returns the filtered options as JSX elements.\n *\n * @param config - The configuration object for the hook.\n * @returns An array of JSX elements representing the filtered options.\n */\nexport function useComboboxFilter({\n  filter: filterOverride,\n  noOptionsElement,\n  renderOption,\n  query,\n  options,\n}: UseComboboxFilterConfig): JSXElement[] {\n  const defaultFilter = React.useCallback(\n    (option: string) => {\n      const trimmedQuery = query.trim();\n      return trimmedQuery === '' || option.toLowerCase().includes(trimmedQuery.toLowerCase());\n    },\n    [query],\n  );\n  const filter = filterOverride ?? defaultFilter;\n  const filteredOptions = React.useMemo(\n    () =>\n      options.reduce<JSXElement[]>((accumulator, option, index) => {\n        if (filter(option, index)) {\n          accumulator.push(renderOption(option));\n        }\n        return accumulator;\n      }, []),\n    [options, renderOption, filter],\n  );\n\n  return filteredOptions.length === 0\n    ? [noOptionsElement.key ? noOptionsElement : React.cloneElement(noOptionsElement, { key: 'no-options' })]\n    : filteredOptions;\n}\n"],"names":["useComboboxFilter","filter","filterOverride","noOptionsElement","renderOption","query","options","defaultFilter","React","useCallback","option","trimmedQuery","trim","toLowerCase","includes","filteredOptions","useMemo","reduce","accumulator","index","push","length","key","cloneElement"],"mappings":"AAAA;;;;;+BAmCgBA;;;eAAAA;;;;iEAjCO;AAiChB,SAASA,kBAAkB,EAChCC,QAAQC,cAAc,EACtBC,gBAAgB,EAChBC,YAAY,EACZC,KAAK,EACLC,OAAO,EACiB;IACxB,MAAMC,gBAAgBC,OAAMC,WAAW,CACrC,CAACC;QACC,MAAMC,eAAeN,MAAMO,IAAI;QAC/B,OAAOD,iBAAiB,MAAMD,OAAOG,WAAW,GAAGC,QAAQ,CAACH,aAAaE,WAAW;IACtF,GACA;QAACR;KAAM;IAET,MAAMJ,SAASC,kBAAkBK;IACjC,MAAMQ,kBAAkBP,OAAMQ,OAAO,CACnC,IACEV,QAAQW,MAAM,CAAe,CAACC,aAAaR,QAAQS;YACjD,IAAIlB,OAAOS,QAAQS,QAAQ;gBACzBD,YAAYE,IAAI,CAAChB,aAAaM;YAChC;YACA,OAAOQ;QACT,GAAG,EAAE,GACP;QAACZ;QAASF;QAAcH;KAAO;IAGjC,OAAOc,gBAAgBM,MAAM,KAAK,IAC9B;QAAClB,iBAAiBmB,GAAG,GAAGnB,iCAAmBK,OAAMe,YAAY,CAACpB,kBAAkB;YAAEmB,KAAK;QAAa;KAAG,GACvGP;AACN"}