!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("jotai/vanilla"),require("jotai/vanilla/internals")):"function"==typeof define&&define.amd?define(["exports","react","jotai/vanilla","jotai/vanilla/internals"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jotaiReact={},e.React,e.jotaiVanilla,e.jotaiVanillaInternals)}(this,function(e,t,n,u){"use strict";var r=t.createContext(void 0);function o(e){var u=t.useContext(r);return(null==e?void 0:e.store)||u||n.getDefaultStore()}var a=function(e){return"function"==typeof(null==e?void 0:e.then)},i=function(e){e.status||(e.status="pending",e.then(function(t){e.status="fulfilled",e.value=t},function(t){e.status="rejected",e.reason=t}))},s=t.use||function(e){if("pending"===e.status)throw e;if("fulfilled"===e.status)return e.value;throw"rejected"===e.status?e.reason:(i(e),e)},l=new WeakMap,c=function(e,t,n){var r=u.INTERNAL_getBuildingBlocksRev3(e),o=r[26],i=l.get(t);return i||(i=new Promise(function(u,s){var c=t,f=function(e){return function(t){c===e&&u(t)}},d=function(e){return function(t){c===e&&s(t)}},v=function(){try{var t=n();a(t)?(l.set(t,i),c=t,t.then(f(t),d(t)),o(r,e,t,v)):u(t)}catch(e){s(e)}};t.then(f(t),d(t)),o(r,e,t,v)}),l.set(t,i)),i};function f(e,n){var u=n||{},r=u.delay,l=u.unstable_promiseStatus,f=void 0===l?!t.use:l,d=o(n),v=t.useReducer(function(t){var n=d.get(e);return Object.is(t[0],n)&&t[1]===d&&t[2]===e?t:[n,d,e]},void 0,function(){return[d.get(e),d,e]}),m=v[0],g=m[0],p=m[1],y=m[2],h=v[1],b=g;if(p===d&&y===e||(h(),b=d.get(e)),t.useEffect(function(){var t=d.sub(e,function(){if(f)try{var t=d.get(e);a(t)&&i(c(d,t,function(){return d.get(e)}))}catch(e){}if("number"==typeof r)return console.warn("[DEPRECATED] delay option is deprecated and will be removed in v3.\n\nMigration guide:\n\nCreate a custom hook like the following.\n\nfunction useAtomValueWithDelay<Value>(\n  atom: Atom<Value>,\n  options: { delay: number },\n): Value {\n  const { delay } = options\n  const store = useStore(options)\n  const [value, setValue] = useState(() => store.get(atom))\n  useEffect(() => {\n    const unsub = store.sub(atom, () => {\n      setTimeout(() => setValue(store.get(atom)), delay)\n    })\n    return unsub\n  }, [store, atom, delay])\n  return value\n}\n"),void setTimeout(h,r);h()});return h(),t},[d,e,r,f]),t.useDebugValue(b),a(b)){var j=c(d,b,function(){return d.get(e)});return f&&i(j),s(j)}return b}function d(e,n){var u=o(n),r=t.useCallback(function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return u.set.apply(u,[e].concat(n))},[u,e]);return r}e.Provider=function(e){var u=e.children,o=e.store,a=t.useRef(null);return o?t.createElement(r.Provider,{value:o},u):(null===a.current&&(a.current=n.createStore()),t.createElement(r.Provider,{value:a.current},u))},e.useAtom=function(e,t){return[f(e,t),d(e,t)]},e.useAtomValue=f,e.useSetAtom=d,e.useStore=o});
