import{gI as x,gJ as E,gK as Q,gL as R,r as s,g5 as q,gM as L,gN as _,gO as w}from"./index-d6499a22.js";var k={encode:x,decode:E},j={encode:Q,decode:R};function m(e,r,a){a===void 0&&(a=L);var n=(e.current==null||r==null)&&e.current===r||!a(e.current,r);s.useEffect(function(){n&&(e.current=r)},[e,r,n])}function D(e){return typeof e=="object"?typeof window<"u"?e.search:q.extract(""+e.pathname+(e.search?e.search:"")):""}function b(e,r,a,n,l,t){var d,i=!L(n.current,a),v=(d=a.equals)!==null&&d!==void 0?d:L,u=w(D(e)),f=!L(l.current,u[r]),g=f?u[r]:l.current;if(!f&&!i&&t.current!==void 0)return t.current;var c=a.decode(g),S=(t.current==null||c==null)&&t.current===c||!v(t.current,c);return S?c:t.current}var z=function(e,r){r===void 0&&(r=k);var a=_(),n=a.location,l=a.getLocation,t=a.setLocation,d=w(D(n)),i=s.useRef(),v=s.useRef(r),u=s.useRef(),f=b(n,e,r,v,i,u);m(i,d[e]),m(v,r),m(u,f,r.equals);var g={paramConfig:r,name:e,setLocation:t,getLocation:l},c=s.useRef(g);c.current=g;var S=s.useCallback(function(p,P){var N,o=c.current,h;if(typeof p=="function"){var y=b(o.getLocation(),o.name,o.paramConfig,v,i,u);u.current=y,h=o.paramConfig.encode(p(y))}else h=o.paramConfig.encode(p);o.setLocation((N={},N[o.name]=h,N),P)},[]);return[f,S]};export{j as N,k as S,z as u};
