/**
 * 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 ComboboxSearchManager {
    constructor() {
        this.debounceTimer = null;
    }
    filter(searchValue, originalItems, getSearchText) {
        if (!originalItems || originalItems.length === 0) {
            return { filteredItems: [], showNoResults: true };
        }
        if (!searchValue || searchValue.trim() === '') {
            return { filteredItems: [...originalItems], showNoResults: false };
        }
        const needle = searchValue.toLowerCase();
        const filteredItems = originalItems.filter((item) => {
            const text = getSearchText(item);
            return text.toLowerCase().includes(needle);
        });
        return { filteredItems, showNoResults: filteredItems.length === 0 };
    }
    debounceSearch(callback, query, debounceMs) {
        if (this.debounceTimer) {
            clearTimeout(this.debounceTimer);
        }
        this.debounceTimer = setTimeout(() => {
            callback(query);
            this.debounceTimer = null;
        }, debounceMs);
    }
    cancelDebounce() {
        if (this.debounceTimer) {
            clearTimeout(this.debounceTimer);
            this.debounceTimer = null;
        }
    }
}
//# sourceMappingURL=search-manager.js.map