import Fuse from 'fuse.js'; export function searchApps(items,query,{rank=true}={}){ const text=query.trim();if(!text)return items; if(text.length===1)return items.filter(item=>(item.name+' '+item.description+' '+item.category).toLowerCase().includes(text.toLowerCase())); const engine=new Fuse(items,{keys:[{name:'name',weight:3},{name:'description',weight:1},{name:'category',weight:.3}],threshold:.32,ignoreLocation:true,minMatchCharLength:2}); const found=engine.search(text).map(result=>result.item); return rank?found:items.filter(item=>found.some(match=>match.id===item.id)); } export function orderedFavorites(ids,visibleOrder){return [...new Set([...visibleOrder,...ids])];}