"use strict";(globalThis.webpackChunk_openmrs_esm_patient_registration_app=globalThis.webpackChunk_openmrs_esm_patient_registration_app||[]).push([["4970"],{48470:function(e,t,i){i.r(t),i.d(t,{default:()=>o,immutable:()=>l});var n=i(27350),r=i(43100),a=i(4771);let s=n.use||(e=>{if("pending"===e.status)throw e;if("fulfilled"===e.status)return e.value;if("rejected"===e.status)throw e.reason;throw e.status="pending",e.then(t=>{e.status="fulfilled",e.value=t},t=>{e.status="rejected",e.reason=t}),e}),d={dedupe:!0};a.OBJECT.defineProperty(a.SWRConfig,"defaultValue",{value:a.defaultConfig});let u=(0,a.withArgs)((e,t,i)=>{let{cache:u,compare:l,suspense:o,fallbackData:f,revalidateOnMount:c,revalidateIfStale:E,refreshInterval:g,refreshWhenHidden:R,refreshWhenOffline:U,keepPreviousData:_}=i,[p,v,T,h]=a.SWRGlobalState.get(u),[V,m]=(0,a.serialize)(e),b=(0,n.useRef)(!1),C=(0,n.useRef)(!1),L=(0,n.useRef)(V),S=(0,n.useRef)(t),w=(0,n.useRef)(i),I=()=>w.current,O=()=>I().isVisible()&&I().isOnline(),[k,A,N,y]=(0,a.createCacheHelper)(u,V),D=(0,n.useRef)({}).current,F=(0,a.isUndefined)(f)?i.fallback[V]:f,P=(e,t)=>{for(let i in D)if("data"===i){if(!l(e[i],t[i])&&(!(0,a.isUndefined)(e[i])||!l(B,t[i])))return!1}else if(t[i]!==e[i])return!1;return!0},M=(0,n.useMemo)(()=>{let e=!!V&&!!t&&((0,a.isUndefined)(c)?!I().isPaused()&&!o&&(!!(0,a.isUndefined)(E)||E):c),i=t=>{let i=(0,a.mergeObjects)(t);return(delete i._k,e)?{isValidating:!0,isLoading:!0,...i}:i},n=k(),r=y(),s=i(n),d=n===r?s:i(r),u=s;return[()=>{let e=i(k());return P(e,u)?(u.data=e.data,u.isLoading=e.isLoading,u.isValidating=e.isValidating,u.error=e.error,u):(u=e,e)},()=>d]},[u,V]),j=(0,r.useSyncExternalStore)((0,n.useCallback)(e=>N(V,(t,i)=>{P(i,t)||e()}),[u,V]),M[0],M[1]),G=!b.current,W=p[V]&&p[V].length>0,Y=j.data,q=(0,a.isUndefined)(Y)?F:Y,x=j.error,z=(0,n.useRef)(q),B=_?(0,a.isUndefined)(Y)?z.current:Y:q,H=(!W||!!(0,a.isUndefined)(x))&&(G&&!(0,a.isUndefined)(c)?c:!I().isPaused()&&(o?!(0,a.isUndefined)(q)&&E:(0,a.isUndefined)(q)||E)),J=!!(V&&t&&G&&H),K=(0,a.isUndefined)(j.isValidating)?J:j.isValidating,Q=(0,a.isUndefined)(j.isLoading)?J:j.isLoading,X=(0,n.useCallback)(async e=>{let t,n,r=S.current;if(!V||!r||C.current||I().isPaused())return!1;let s=!0,d=e||{},u=!T[V]||!d.dedupe,o=()=>a.IS_REACT_LEGACY?!C.current&&V===L.current&&b.current:V===L.current,f={isValidating:!1,isLoading:!1},c=()=>{A(f)},E=()=>{let e=T[V];e&&e[1]===n&&delete T[V]},g={isValidating:!0};(0,a.isUndefined)(k().data)&&(g.isLoading=!0);try{if(u&&(A(g),i.loadingTimeout&&(0,a.isUndefined)(k().data)&&setTimeout(()=>{s&&o()&&I().onLoadingSlow(V,i)},i.loadingTimeout),T[V]=[r(m),(0,a.getTimestamp)()]),[t,n]=T[V],t=await t,u&&setTimeout(E,i.dedupingInterval),!T[V]||T[V][1]!==n)return u&&o()&&I().onDiscarded(V),!1;f.error=a.UNDEFINED;let e=v[V];if(!(0,a.isUndefined)(e)&&(n<=e[0]||n<=e[1]||0===e[1]))return c(),u&&o()&&I().onDiscarded(V),!1;let d=k().data;f.data=l(d,t)?d:t,u&&o()&&I().onSuccess(t,V,i)}catch(i){E();let e=I(),{shouldRetryOnError:t}=e;!e.isPaused()&&(f.error=i,u&&o()&&(e.onError(i,V,e),(!0===t||(0,a.isFunction)(t)&&t(i))&&(!I().revalidateOnFocus||!I().revalidateOnReconnect||O())&&e.onErrorRetry(i,V,e,e=>{let t=p[V];t&&t[0]&&t[0](a.revalidateEvents.ERROR_REVALIDATE_EVENT,e)},{retryCount:(d.retryCount||0)+1,dedupe:!0})))}return s=!1,c(),!0},[V,u]),Z=(0,n.useCallback)((...e)=>(0,a.internalMutate)(u,L.current,...e),[]);if((0,a.useIsomorphicLayoutEffect)(()=>{S.current=t,w.current=i,(0,a.isUndefined)(Y)||(z.current=Y)}),(0,a.useIsomorphicLayoutEffect)(()=>{if(!V)return;let e=X.bind(a.UNDEFINED,d),t=0,i=(0,a.subscribeCallback)(V,p,(i,n={})=>{if(i==a.revalidateEvents.FOCUS_EVENT){let i=Date.now();I().revalidateOnFocus&&i>t&&O()&&(t=i+I().focusThrottleInterval,e())}else if(i==a.revalidateEvents.RECONNECT_EVENT)I().revalidateOnReconnect&&O()&&e();else if(i==a.revalidateEvents.MUTATE_EVENT)return X();else if(i==a.revalidateEvents.ERROR_REVALIDATE_EVENT)return X(n)});return C.current=!1,L.current=V,b.current=!0,A({_k:m}),H&&((0,a.isUndefined)(q)||a.IS_SERVER?e():(0,a.rAF)(e)),()=>{C.current=!0,i()}},[V]),(0,a.useIsomorphicLayoutEffect)(()=>{let e;function t(){let t=(0,a.isFunction)(g)?g(k().data):g;t&&-1!==e&&(e=setTimeout(i,t))}function i(){!k().error&&(R||I().isVisible())&&(U||I().isOnline())?X(d).then(t):t()}return t(),()=>{e&&(clearTimeout(e),e=-1)}},[g,R,U,V]),(0,n.useDebugValue)(B),o&&(0,a.isUndefined)(q)&&V){if(!a.IS_REACT_LEGACY&&a.IS_SERVER)throw Error("Fallback data is required when using suspense in SSR.");S.current=t,w.current=i,C.current=!1;let e=h[V];if((0,a.isUndefined)(e)||s(Z(e)),(0,a.isUndefined)(x)){let e=X(d);(0,a.isUndefined)(B)||(e.status="fulfilled",e.value=!0),s(e)}else throw x}return{mutate:Z,get data(){return D.data=!0,B},get error(){return D.error=!0,x},get isValidating(){return D.isValidating=!0,K},get isLoading(){return D.isLoading=!0,Q}}}),l=e=>(t,i,n)=>(n.revalidateOnFocus=!1,n.revalidateIfStale=!1,n.revalidateOnReconnect=!1,e(t,i,n)),o=(0,a.withMiddleware)(u,l)}}]);