/** * Copyright Aquera Inc 2025 * * This source code is licensed under the BSD-3-Clause license found in the * LICENSE file in the root directory of this source tree. */ export class VirtualSelectSearchManager { static filterVirtualOptions( searchValue: string, originalOptionItems: any[], data: any[], renderItemFunction: (item: any) => string, getItemDescription: (item: any) => string, descriptionSearchEnabled: boolean, getSearchText?: (item: any) => string ): { filteredItems: any[], showNoResults: boolean } { if (originalOptionItems.length === 0 && data.length > 0) { return { filteredItems: [...data], showNoResults: false }; } if (!originalOptionItems || originalOptionItems.length === 0) { return { filteredItems: [], showNoResults: true }; } if (!searchValue || searchValue.trim() === '') { return { filteredItems: [...originalOptionItems], showNoResults: false }; } const lowerCaseSearchValue = searchValue.toLowerCase(); const searchTextFn = getSearchText || renderItemFunction; const filteredItems = originalOptionItems.filter((item: any) => { const itemValue = searchTextFn(item); const lowerCaseItemValue = itemValue.toLowerCase(); const itemDescription = getItemDescription(item); if (descriptionSearchEnabled && itemDescription) { return lowerCaseItemValue.includes(lowerCaseSearchValue) || itemDescription.includes(lowerCaseSearchValue); } return lowerCaseItemValue.includes(lowerCaseSearchValue); }); return { filteredItems, showNoResults: filteredItems.length === 0 }; } }