import{b as e}from"./index.chunk.CJx-PkC0.js";import{r}from"./router.chunk.YsRm4bSN.js";import{bz as s,bA as t,bB as u,bC as c}from"./main.chunk.N-eZ2ybB.js";const n=({keyMap:n,form:a,paramsToForm:l,formToParams:o,watchFields:f})=>{const[m,i]=e(n),b=r.useRef(m),h=r.useRef(!0),{isRouteChanged:p}=s(),d=r.useCallback(e=>{const r=t(e).reduce((e,[r,s])=>({...e,[r]:s??null}),{});i(r)},[i]),k=r.useMemo(()=>u(d,300),[d]),C=r.useCallback(()=>{const e=t(n).reduce((e,[r])=>({...e,[r]:null}),{});i(e),a.reset.call(null)},[n,i,a.reset]);return r.useEffect(()=>{p&&!h.current&&C()},[p]),r.useEffect(()=>{if(h.current)return a.reset.call(null,l(m)),void(h.current=!1);const e=l(m),r=l(b.current);!c(e,r)&&a.reset.call(null,e),b.current=m},[m,a.reset,l]),r.useEffect(()=>{if(!f||0===f.length)return;const e=a.watch.call(null,e=>{const r=o(e);k(r)});return()=>{e.unsubscribe()}},[a.watch,o,k,f]),{params:m,syncQueryParams:d}};export{n as u};
