// cpvSuggestions.js
// Service to filter CPV codes for suggestions based on user input

/**
 * Filters a list of CPV codes by a search string.
 * @param {Array} cpvList - Array of CpvCode objects.
 * @param {string} search - The search string to filter by.
 * @param {number} [maxResults=10] - Maximum number of suggestions to return.
 * @returns {Array} Filtered list of CpvCode objects.
 */
export function filterCPVSuggestions(cpvList, search, maxResults = 10) {
    if (!search || typeof search !== 'string') return [];
    const lower = search.trim().toLowerCase();
    return cpvList.filter(cpv =>
        (cpv.cpv && cpv.cpv.toLowerCase().includes(lower)) ||
        (cpv.title && cpv.title.toLowerCase().includes(lower))
    ).slice(0, maxResults);
}
