import{_ as d,T as c}from"./preact.js";import{w as m}from"./use-sync-external-store.js";import{i as p}from"./use-isomorphic-layout-effect.js";import{I as g}from"./xstate.js";function y(r){var n=d();return n.current||(n.current={v:r()}),n.current.v}globalThis&&globalThis.__read;globalThis&&globalThis.__values;function S(r){return r.status!==0?r.getSnapshot():r.machine.initialState}function v(r){return"state"in r&&"machine"in r}function w(r,n,e){if(r.status===g.NotStarted)return!0;var t=e.changed===void 0&&(Object.keys(e.children).length>0||typeof n.changed=="boolean");return!(e.changed||t)}function E(r){return r}function T(r){return"state"in r}function A(r){return"deferred"in r}function x(r){return"getSnapshot"in r?v(r)?S(r):r.getSnapshot():T(r)?r.state:void 0}function G(r,n){n===void 0&&(n=x);var e=d(r),t=d([]),a=c(function(i){var u=r.subscribe(i).unsubscribe;return u},[r]),s=c(function(){return n(r)},[r,n]),o=c(function(i,u){return v(r)?w(r,i,u):i===u},[r]),l=m.useSyncExternalStoreWithSelector(a,s,s,E,o),b=y(function(){return function(){for(var i=[],u=0;u<arguments.length;u++)i[u]=arguments[u];var h=i[0],f=e.current;A(f)&&f.deferred?t.current.push(h):f.send(h)}});return p(function(){for(e.current=r;t.current.length>0;){var i=t.current.shift();r.send(i)}},[r]),[l,b]}export{G as u};
