import{r as e}from"./rolldown-runtime-Dw2cE7zH.js";import{k as t}from"./vendor-markdown-DngssFHR.js";import{u as n}from"./vendor-react-Cts2Wj-s.js";var r=e(t(),1);function i(e){let[t,i]=n(),a=(0,r.useRef)(e);a.current=e;let o=(0,r.useMemo)(()=>{let t=new Set;for(let n of e)t.add(n.urlKey??n.key);return t},[e]),s=(0,r.useRef)(o);s.current=o;let c=(0,r.useMemo)(()=>{let n={};for(let r of e){let e=r.urlKey??r.key;n[r.key]=t.get(e)||r.defaultValue}return n},[t,e]),l=(0,r.useCallback)((e,t)=>{i(n=>{let r=new URLSearchParams;for(let[e,t]of n.entries())s.current.has(e)||r.set(e,t);if(t)for(let e of t)r.delete(e);for(let t of a.current){let i=t.urlKey??t.key,a=t.key in e?e[t.key]:n.get(i);a&&a!==t.defaultValue&&r.set(i,a)}return r},{replace:!0})},[i]),u=(0,r.useCallback)((e,t)=>{l({[e]:t})},[l]),d=(0,r.useCallback)(e=>{l(e)},[l]),f=(0,r.useCallback)(e=>{let t=a.current.find(t=>t.key===e);l({[e]:t?.defaultValue??``})},[l]),p=(0,r.useCallback)(()=>{let e={};for(let t of a.current)t.persistent||(e[t.key]=t.defaultValue);l(e)},[l]),m=(0,r.useMemo)(()=>e.filter(e=>!e.persistent&&c[e.key]!==e.defaultValue).map(e=>e.key),[c,e]);return{filters:c,setFilter:u,setFilters:d,clearFilter:f,clearAll:p,hasActiveFilters:m.length>0,activeFilterKeys:m}}export{i as t};