import{useCallback as E,useMemo as I,useState as W}from"react";var J={search:"",tags:[],stability:[],domain:[]};function Z(G){let[x,B]=W(J),K=E((q)=>{B((j)=>({...j,search:q}))},[]),N=E((q)=>{B((j)=>({...j,tags:j.tags.includes(q)?j.tags.filter((z)=>z!==q):[...j.tags,q]}))},[]),O=E((q)=>{B((j)=>({...j,stability:j.stability.includes(q)?j.stability.filter((z)=>z!==q):[...j.stability,q]}))},[]),Q=E((q)=>{B((j)=>({...j,domain:j.domain.includes(q)?j.domain.filter((z)=>z!==q):[...j.domain,q]}))},[]),R=E(()=>B(J),[]),U=I(()=>{return x.search.length>0||x.tags.length>0||x.stability.length>0||x.domain.length>0},[x]),V=I(()=>{return G.filter((q)=>{if(x.search){let j=x.search.toLowerCase();if(!((q.meta.title??"").toLowerCase().includes(j)||q.meta.description?.toLowerCase().includes(j)||q.meta.key.toLowerCase().includes(j)))return!1}if(x.tags.length>0){if(!x.tags.some((z)=>q.meta.tags?.includes(z)))return!1}if(x.stability.length>0){if(!x.stability.includes(q.meta.stability??"unknown"))return!1}if(x.domain.length>0){if(!x.domain.includes(q.meta.domain??"unknown"))return!1}return!0})},[G,x]);return{filters:x,setSearch:K,toggleTag:N,toggleStability:O,toggleDomain:Q,clearFilters:R,filteredFeatures:V,hasActiveFilters:U}}export{Z as useFeatureFilters};
