"use strict";const t=require("react"),z=n=>JSON.stringify(n,(e,r)=>!r||typeof r!="object"||Array.isArray(r)?r:Object.keys(r).sort().reduce((u,f)=>(u[f]=r[f],u),{}));function P(n,e,r=300,u=1e3,f){const[R,d]=t.useState(!1),[g,o]=t.useState(!1),a=t.useRef(null),i=t.useRef(0),T=t.useRef(n),w=t.useRef(e),l=f||z;t.useEffect(()=>{i.current+=1;const m=i.current,k=T.current!==n,b=w.current!==e;if(T.current=n,w.current=e,e===null){const s=window.setTimeout(()=>{m===i.current&&(d(!1),o(!1))},0);return()=>clearTimeout(s)}if(b&&!k){const s=window.setTimeout(()=>{if(m===i.current){const c=l(n),y=l(e);d(c!==y),o(!1)}},0);return()=>clearTimeout(s)}const D=k?window.setTimeout(()=>{m===i.current&&o(!0)},0):null,I=setTimeout(()=>{const s=window.requestIdleCallback||(c=>window.setTimeout(()=>c({didTimeout:!1,timeRemaining:()=>50}),1));a.current=s(c=>{if(c.timeRemaining()>0||c.didTimeout){if(m!==i.current)return;const y=l(n),h=l(e);d(y!==h),o(!1)}},{timeout:u})},r);return()=>{D!==null&&clearTimeout(D),clearTimeout(I),a.current!==null&&((window.cancelIdleCallback||window.clearTimeout)(a.current),a.current=null)}},[n,e,r,u,l]);const C=t.useCallback(()=>{d(!1),o(!1)},[]);return{isDirty:e===null?!1:R,isDirtyPending:e===null?!1:g,resetDirty:C}}exports.useDebouncedDirtyCheck=P;
