var zt=Object.defineProperty;var Wt=(t,e,s)=>e in t?zt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var h=(t,e,s)=>Wt(t,typeof e!="symbol"?e+"":e,s);import{S as It,U as Ft,f as Yt,h as kt,x as mt,V as Kt,j as Gt}from"./oWkJTaFC.js";const q=(t,e=[])=>({parts:(...s)=>{if(Vt(e))return q(t,s);throw new Error("createAnatomy().parts(...) should only be called once. Did you mean to use .extendWith(...) ?")},extendWith:(...s)=>q(t,[...e,...s]),rename:s=>q(s,e),keys:()=>e,build:()=>[...new Set(e)].reduce((s,n)=>Object.assign(s,{[n]:{selector:[`&[data-scope="${D(t)}"][data-part="${D(n)}"]`,`& [data-scope="${D(t)}"][data-part="${D(n)}"]`].join(", "),attrs:{"data-scope":D(t),"data-part":D(n)}}}),{})}),D=t=>t.replace(/([A-Z])([A-Z])/g,"$1-$2").replace(/([a-z])([A-Z])/g,"$1-$2").replace(/[\s_]+/g,"-").toLowerCase(),Vt=t=>t.length===0,Ce=t=>t[0],De=t=>t[t.length-1],Bt=(t,e)=>t.indexOf(e)!==-1,Ut=(t,...e)=>t.concat(e),qt=(t,e)=>t.filter(s=>s!==e),je=(t,e)=>t.filter((s,n)=>n!==e),Le=t=>Array.from(new Set(t)),Ne=(t,e)=>Bt(t,e)?qt(t,e):Ut(t,e);function Ht(t){for(;t.length>0;)t.pop();return t}function vt(t,e,s={}){const{step:n=1,loop:i=!0}=s,r=e+n,a=t.length,o=a-1;return e===-1?n>0?0:o:r<0?i?o:0:r>=a?i?0:e>a?a:e:r}function $e(t,e,s={}){return t[vt(t,e,s)]}function Jt(t,e,s={}){const{step:n=1,loop:i=!0}=s;return vt(t,e,{step:-n,loop:i})}function ze(t,e,s={}){return t[Jt(t,e,s)]}const ut=(t,...e)=>(typeof t=="function"?t(...e):t)??void 0,b=t=>t,Xt=()=>{},We=(...t)=>(...e)=>{t.forEach(function(s){s==null||s(...e)})},ft=(()=>{let t=0;return()=>(t++,t.toString(36))})();function Zt(t,e,...s){var i;if(t in e){const r=e[t];return typeof r=="function"?r(...s):r}const n=new Error(`No matching key: ${JSON.stringify(t)} in ${JSON.stringify(Object.keys(e))}`);throw(i=Error.captureStackTrace)==null||i.call(Error,n,Zt),n}const Qt=(t,e)=>{var s;try{return t()}catch(n){return n instanceof Error&&((s=Error.captureStackTrace)==null||s.call(Error,n,Qt)),e==null?void 0:e()}},K=t=>Array.isArray(t),Ie=t=>t===!0||t===!1,W=t=>!(t==null||typeof t!="object"||K(t)),te=t=>typeof t=="number"&&!Number.isNaN(t),w=t=>typeof t=="string",G=t=>typeof t=="function",Fe=t=>t==null,ee=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);function V(t){if(!se(t)||t===void 0)return t;const e=Reflect.ownKeys(t).filter(n=>typeof n=="string"),s={};for(const n of e){const i=t[n];i!==void 0&&(s[n]=V(i))}return s}const se=t=>t&&typeof t=="object"&&t.constructor===Object;function Ye(t,e){const s={};for(const n of e){const i=t[n];i!==void 0&&(s[n]=i)}return s}function H(...t){const e=t.length===1?t[0]:t[1],s=t.length===2?t[0]:!0}function Y(...t){const e=t.length===1?t[0]:t[1],s=t.length===2?t[0]:!0}function ne(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function wt(t,e){const s=ne();return s?(s[t]||(s[t]=e()),s[t]):e()}const At=Symbol(),it=Symbol(),$="a",Ot="f",lt="p",Pt="c",bt="t",J="n",X="g",Rt="h",k="w",Mt="o",Tt="k";let ie=(t,e)=>new Proxy(t,e);const tt=Object.getPrototypeOf,et=new WeakMap,rt=t=>t&&(et.has(t)?et.get(t):tt(t)===Object.prototype||tt(t)===Array.prototype),dt=t=>typeof t=="object"&&t!==null,re=t=>Object.values(Object.getOwnPropertyDescriptors(t)).some(e=>!e.configurable&&!e.writable),oe=t=>{if(Array.isArray(t))return Array.from(t);const e=Object.getOwnPropertyDescriptors(t);return Object.values(e).forEach(s=>{s.configurable=!0}),Object.create(tt(t),e)},ae=(t,e)=>{const s={[Ot]:e};let n=!1;const i=(o,u)=>{if(!n){let c=s[$].get(t);if(c||(c={},s[$].set(t,c)),o===k)c[k]=!0;else{let p=c[o];p||(p=new Set,c[o]=p),p.add(u)}}},r=()=>{n=!0,s[$].delete(t)},a={get(o,u){return u===it?t:(i(Tt,u),ce(Reflect.get(o,u),s[$],s[Pt],s[bt]))},has(o,u){return u===At?(r(),!0):(i(Rt,u),Reflect.has(o,u))},getOwnPropertyDescriptor(o,u){return i(Mt,u),Reflect.getOwnPropertyDescriptor(o,u)},ownKeys(o){return i(k),Reflect.ownKeys(o)}};return e&&(a.set=a.deleteProperty=()=>!1),[a,s]},_t=t=>t[it]||t,ce=(t,e,s,n)=>{if(!rt(t))return t;let i=n&&n.get(t);if(!i){const u=_t(t);re(u)?i=[u,oe(u)]:i=[u],n==null||n.set(t,i)}const[r,a]=i;let o=s&&s.get(r);return(!o||o[1][Ot]!==!!a)&&(o=ae(r,!!a),o[1][lt]=ie(a||r,o[0]),s&&s.set(r,o)),o[1][$]=e,o[1][Pt]=s,o[1][bt]=n,o[1][lt]},he=(t,e)=>{const s=Reflect.ownKeys(t),n=Reflect.ownKeys(e);return s.length!==n.length||s.some((i,r)=>i!==n[r])},ue=(t,e,s,n,i=Object.is)=>{if(i(t,e))return!1;if(!dt(t)||!dt(e))return!0;const r=s.get(_t(t));if(!r)return!0;if(n){const o=n.get(t);if(o&&o[J]===e)return o[X];n.set(t,{[J]:e,[X]:!1})}let a=null;try{for(const o of r[Rt]||[])if(a=Reflect.has(t,o)!==Reflect.has(e,o),a)return a;if(r[k]===!0){if(a=he(t,e),a)return a}else for(const o of r[Mt]||[]){const u=!!Reflect.getOwnPropertyDescriptor(t,o),c=!!Reflect.getOwnPropertyDescriptor(e,o);if(a=u!==c,a)return a}for(const o of r[Tt]||[])if(a=ue(t[o],e[o],s,n,i),a)return a;return a===null&&(a=!0),a}finally{n&&n.set(t,{[J]:e,[X]:a})}},ke=t=>rt(t)?At in t:!1,fe=t=>rt(t)&&t[it]||null,pt=(t,e=!0)=>{et.set(t,e)},Z=t=>typeof t=="object"&&t!==null,_=wt("__zag__proxyStateMap",()=>new WeakMap),z=wt("__zag__refSet",()=>new WeakSet),le=(t=Object.is,e=(c,p)=>new Proxy(c,p),s=c=>Z(c)&&!z.has(c)&&(Array.isArray(c)||!(Symbol.iterator in c))&&!(c instanceof WeakMap)&&!(c instanceof WeakSet)&&!(c instanceof Error)&&!(c instanceof Number)&&!(c instanceof Date)&&!(c instanceof String)&&!(c instanceof RegExp)&&!(c instanceof ArrayBuffer),n=c=>{switch(c.status){case"fulfilled":return c.value;case"rejected":throw c.reason;default:throw c}},i=new WeakMap,r=(c,p,A=n)=>{const g=i.get(c);if((g==null?void 0:g[0])===p)return g[1];const y=Array.isArray(c)?[]:Object.create(Object.getPrototypeOf(c));return pt(y,!0),i.set(c,[p,y]),Reflect.ownKeys(c).forEach(R=>{const m=Reflect.get(c,R);z.has(m)?(pt(m,!1),y[R]=m):m instanceof Promise?Object.defineProperty(y,R,{get(){return A(m)}}):_.has(m)?y[R]=x(m,A):y[R]=m}),Object.freeze(y)},a=new WeakMap,o=[1,1],u=c=>{if(!Z(c))throw new Error("object required");const p=a.get(c);if(p)return p;let A=o[0];const g=new Set,y=(d,f=++o[0])=>{A!==f&&(A=f,g.forEach(l=>l(d,f)))};let R=o[1];const m=(d=++o[1])=>(R!==d&&!g.size&&(R=d,O.forEach(([f])=>{const l=f[1](d);l>A&&(A=l)})),A),at=d=>(f,l)=>{const S=[...f];S[1]=[d,...S[1]],y(S,l)},O=new Map,Lt=(d,f)=>{if(g.size){const l=f[3](at(d));O.set(d,[f,l])}else O.set(d,[f])},ct=d=>{var l;const f=O.get(d);f&&(O.delete(d),(l=f[1])==null||l.call(f))},Nt=d=>(g.add(d),g.size===1&&O.forEach(([l,S],C)=>{const L=l[3](at(C));O.set(C,[l,L])}),()=>{g.delete(d),g.size===0&&O.forEach(([l,S],C)=>{S&&(S(),O.set(C,[l]))})}),U=Array.isArray(c)?[]:Object.create(Object.getPrototypeOf(c)),I=e(U,{deleteProperty(d,f){const l=Reflect.get(d,f);ct(f);const S=Reflect.deleteProperty(d,f);return S&&y(["delete",[f],l]),S},set(d,f,l,S){var ht;const C=Reflect.has(d,f),L=Reflect.get(d,f,S);if(C&&(t(L,l)||a.has(l)&&t(L,a.get(l))))return!0;ct(f),Z(l)&&(l=fe(l)||l);let F=l;if(!((ht=Object.getOwnPropertyDescriptor(d,f))!=null&&ht.set))if(l instanceof Promise)l.then(M=>{Object.assign(l,{status:"fulfilled",value:M}),y(["resolve",[f],M])}).catch(M=>{Object.assign(l,{status:"rejected",reason:M}),y(["reject",[f],M])});else{!_.has(l)&&s(l)&&(F=ot(l));const M=!z.has(F)&&_.get(F);M&&Lt(f,M)}return Reflect.set(d,f,F,S),y(["set",[f],l,L]),!0}});a.set(c,I);const $t=[U,m,r,Nt];return _.set(I,$t),Reflect.ownKeys(c).forEach(d=>{const f=Object.getOwnPropertyDescriptor(c,d);f.get||f.set?Object.defineProperty(U,d,f):I[d]=c[d]}),I})=>[u,_,z,t,e,s,n,i,r,a,o],[de]=le();function ot(t={}){return de(t)}function st(t,e,s){const n=_.get(t);let i;const r=[],a=n[3];let o=!1;const c=a(p=>{if(r.push(p),s){e(r.splice(0));return}i||(i=Promise.resolve().then(()=>{i=void 0,o&&e(r.splice(0))}))});return o=!0,()=>{o=!1,c()}}function x(t,e){const s=_.get(t),[n,i,r]=s;return r(n,i(),e)}function gt(t){return z.add(t),t}function pe(t,e){Object.keys(e).forEach(i=>{if(Object.getOwnPropertyDescriptor(t,i))throw new Error("object property already defined");const r=e[i],{get:a,set:o}=typeof r=="function"?{get:r}:r,u={};u.get=()=>a(x(n)),o&&(u.set=c=>o(n,c)),Object.defineProperty(t,i,u)});const n=ot(t);return n}function xt(t,...e){for(const s of e){const n=V(s);for(const i in n)W(s[i])?(t[i]||(t[i]={}),xt(t[i],s[i])):t[i]=s[i]}return t}function yt(t,e,s){typeof s.value=="object"&&(s.value=j(s.value)),!s.enumerable||s.get||s.set||!s.configurable||!s.writable||e==="__proto__"?Object.defineProperty(t,e,s):t[e]=s.value}function j(t){if(typeof t!="object")return t;var e=0,s,n,i,r=Object.prototype.toString.call(t);if(r==="[object Object]"?i=Object.create(t.__proto__||null):r==="[object Array]"?i=Array(t.length):r==="[object Set]"?(i=new Set,t.forEach(function(a){i.add(j(a))})):r==="[object Map]"?(i=new Map,t.forEach(function(a,o){i.set(j(o),j(a))})):r==="[object Date]"?i=new Date(+t):r==="[object RegExp]"?i=new RegExp(t.source,t.flags):r==="[object DataView]"?i=new t.constructor(j(t.buffer)):r==="[object ArrayBuffer]"?i=t.slice(0):r.slice(-6)==="Array]"&&(i=new t.constructor(t)),i){for(n=Object.getOwnPropertySymbols(t);e<n.length;e++)yt(i,n[e],Object.getOwnPropertyDescriptor(t,n[e]));for(e=0,n=Object.getOwnPropertyNames(t);e<n.length;e++)Object.hasOwnProperty.call(i,s=n[e])&&i[s]===t[s]||yt(i,s,Object.getOwnPropertyDescriptor(t,s))}return i||t}function St(t){return j(t)}function E(t){return w(t)?{type:t}:t}function T(t){return t?K(t)?t.slice():[t]:[]}function Ct(t){return W(t)&&t.predicate!=null}const Dt=()=>!0;function B(t,e,s,n){return i=>{var r;return w(i)?!!((r=t[i])!=null&&r.call(t,e,s,n)):G(i)?i(e,s,n):i.predicate(t)(e,s,n)}}function ge(...t){return{predicate:e=>(s,n,i)=>t.map(B(e,s,n,i)).some(Boolean)}}function ye(...t){return{predicate:e=>(s,n,i)=>t.map(B(e,s,n,i)).every(Boolean)}}function Se(t){return{predicate:e=>(s,n,i)=>!B(e,s,n,i)(t)}}function Ee(...t){return(e,s,n)=>n.state.matches(...t)}const Ke={or:ge,and:ye,not:Se,stateIn:Ee};function Ge(t){return{predicate:e=>(s,n,i)=>{var r;return(r=t.find(a=>{const o=a.guard??Dt;return B(e,s,n,i)(o)}))==null?void 0:r.actions}}}function jt(t,e){return t=t??Dt,(s,n,i)=>{if(w(t)){const r=e[t];return G(r)?r(s,n,i):r}return Ct(t)?t.predicate(e)(s,n,i):t==null?void 0:t(s,n,i)}}function Q(t,e){return(s,n,i)=>Ct(t)?t.predicate(e)(s,n,i):t}var P=(t=>(t.NotStarted="Not Started",t.Running="Running",t.Stopped="Stopped",t))(P||{}),v=(t=>(t.Start="machine.start",t.Stop="machine.stop",t.Created="machine.created",t.Init="machine.init",t))(v||{}),nt=(t=>(t.Machine="machine",t.Actor="machine.actor",t))(nt||{});function me(t){var r,a;const e=t.computed??b({}),s=t.context??b({}),n=t.initial?(a=(r=t.states)==null?void 0:r[t.initial])==null?void 0:a.tags:[],i=ot({value:t.initial??"",previousValue:"",event:b({}),previousEvent:b({}),context:pe(s,e),done:!1,tags:n??[],hasTag(o){return this.tags.includes(o)},matches(...o){return o.includes(this.value)},can(o){return b(this).nextEvents.includes(o)},get nextEvents(){var c,p;const o=((p=(c=t.states)==null?void 0:c[this.value])==null?void 0:p.on)??{},u=(t==null?void 0:t.on)??{};return Object.keys({...o,...u})},get changed(){return this.event.value===v.Init||!this.previousValue?!1:this.value!==this.previousValue}});return b(i)}function N(t,e){return(s,n)=>{if(te(t))return t;if(G(t))return t(s,n);if(w(t)){const i=Number.parseFloat(t);if(!Number.isNaN(i))return i;if(e){const r=e==null?void 0:e[t];return Y(r==null,`[@zag-js/core > determine-delay] Cannot determine delay for \`${t}\`. It doesn't exist in \`options.delays\``),G(r)?r(s,n):r}}}}function ve(t){return w(t)?{target:t}:t}function we(t,e){return(s,n,i)=>T(t).map(ve).find(r=>jt(r.guard,e)(s,n,i)??r.target??r.actions)}class Ae{constructor(e,s){h(this,"status",P.NotStarted);h(this,"state");h(this,"initialState");h(this,"initialContext");h(this,"id");h(this,"type",nt.Machine);h(this,"activityEvents",new Map);h(this,"delayedEvents",new Map);h(this,"stateListeners",new Set);h(this,"doneListeners",new Set);h(this,"contextWatchers",new Set);h(this,"removeStateListener",Xt);h(this,"parent");h(this,"children",new Map);h(this,"guardMap");h(this,"actionMap");h(this,"delayMap");h(this,"activityMap");h(this,"sync");h(this,"options");h(this,"config");h(this,"_created",()=>{var s;const e=E(v.Created);this.executeActions((s=this.config)==null?void 0:s.created,e)});h(this,"start",e=>{if(this.state.value="",this.state.tags=[],this.status===P.Running)return this;this.status=P.Running,this.removeStateListener=st(this.state,()=>{this.stateListeners.forEach(o=>{o(this.stateSnapshot)})},this.sync),this.setupContextWatchers(),this.executeActivities(E(v.Start),T(this.config.activities),v.Start),this.executeActions(this.config.entry,E(v.Start));const s=E(v.Init),n=W(e)?e.value:e,i=W(e)?e.context:void 0;i&&this.setContext(i);const r={target:n??this.config.initial},a=this.getNextStateInfo(r,s);return this.initialState=a,this.performStateChangeEffects(this.state.value,a,s),this});h(this,"setupContextWatchers",()=>{const{watch:e}=this.config;if(!e)return;let s=x(this.state.context);const n=st(this.state.context,()=>{var r;const i=x(this.state.context);for(const[a,o]of Object.entries(e))(((r=this.options.compareFns)==null?void 0:r[a])??Object.is)(s[a],i[a])||this.executeActions(o,this.state.event);s=i});this.contextWatchers.add(n)});h(this,"stop",()=>{if(this.status!==P.Stopped)return this.performExitEffects(this.state.value,E(v.Stop)),this.executeActions(this.config.exit,E(v.Stop)),this.setState(""),this.setEvent(v.Stop),this.stopStateListeners(),this.stopChildren(),this.stopActivities(),this.stopDelayedEvents(),this.stopContextWatchers(),this.status=P.Stopped,this});h(this,"stopStateListeners",()=>{this.removeStateListener(),this.stateListeners.clear()});h(this,"stopContextWatchers",()=>{this.contextWatchers.forEach(e=>e()),this.contextWatchers.clear()});h(this,"stopDelayedEvents",()=>{this.delayedEvents.forEach(e=>{e.forEach(s=>s())}),this.delayedEvents.clear()});h(this,"stopActivities",e=>{var s,n;e?((s=this.activityEvents.get(e))==null||s.forEach(i=>i()),(n=this.activityEvents.get(e))==null||n.clear(),this.activityEvents.delete(e)):(this.activityEvents.forEach(i=>{i.forEach(r=>r()),i.clear()}),this.activityEvents.clear())});h(this,"sendChild",(e,s)=>{const n=E(e),i=ut(s,this.contextSnapshot),r=this.children.get(i);r||Y(`[@zag-js/core] Cannot send '${n.type}' event to unknown child`),r.send(n)});h(this,"stopChild",e=>{this.children.has(e)||Y(`[@zag-js/core > stop-child] Cannot stop unknown child ${e}`),this.children.get(e).stop(),this.children.delete(e)});h(this,"removeChild",e=>{this.children.delete(e)});h(this,"stopChildren",()=>{this.children.forEach(e=>e.stop()),this.children.clear()});h(this,"setParent",e=>{this.parent=e});h(this,"spawn",(e,s)=>{const n=ut(e);return s&&(n.id=s),n.type=nt.Actor,n.setParent(this),this.children.set(n.id,b(n)),n.onDone(()=>{this.removeChild(n.id)}).start(),b(gt(n))});h(this,"stopActivity",e=>{var n;if(!this.state.value)return;const s=this.activityEvents.get(this.state.value);(n=s==null?void 0:s.get(e))==null||n(),s==null||s.delete(e)});h(this,"addActivityCleanup",(e,s,n)=>{var i;e&&(this.activityEvents.has(e)?(i=this.activityEvents.get(e))==null||i.set(s,n):this.activityEvents.set(e,new Map([[s,n]])))});h(this,"setState",e=>{this.state.previousValue=this.state.value,this.state.value=e;const s=this.getStateNode(e);e==null?Ht(this.state.tags):this.state.tags=T(s==null?void 0:s.tags)});h(this,"setContext",e=>{e&&xt(this.state.context,V(e))});h(this,"setOptions",e=>{const s=V(e);this.actionMap={...this.actionMap,...s.actions},this.delayMap={...this.delayMap,...s.delays},this.activityMap={...this.activityMap,...s.activities},this.guardMap={...this.guardMap,...s.guards}});h(this,"getStateNode",e=>{var s;if(e)return(s=this.config.states)==null?void 0:s[e]});h(this,"getNextStateInfo",(e,s)=>{const n=this.determineTransition(e,s),i=!(n!=null&&n.target),r=(n==null?void 0:n.target)??this.state.value,a=this.state.value!==r,o=this.getStateNode(r),c={reenter:!i&&!a&&!(n!=null&&n.internal),transition:n,stateNode:o,target:r,changed:a};return this.log("NextState:",`[${s.type}]`,this.state.value,"---->",c.target),c});h(this,"getAfterActions",(e,s)=>{let n;return{entry:()=>{n=globalThis.setTimeout(()=>{const i=this.getNextStateInfo(e,this.state.event);this.performStateChangeEffects(this.state.value,i,this.state.event)},s)},exit:()=>{globalThis.clearTimeout(n)}}});h(this,"getDelayedEventActions",e=>{const s=this.getStateNode(e),n=this.state.event;if(!s||!s.after)return;const i=[],r=[];if(K(s.after)){const a=this.determineTransition(s.after,n);if(!a)return;if(!ee(a,"delay"))throw new Error(`[@zag-js/core > after] Delay is required for after transition: ${JSON.stringify(a)}`);const u=N(a.delay,this.delayMap)(this.contextSnapshot,n),c=this.getAfterActions(a,u);return i.push(c.entry),r.push(c.exit),{entries:i,exits:r}}if(W(s.after))for(const a in s.after){const o=s.after[a],c=N(a,this.delayMap)(this.contextSnapshot,n),p=this.getAfterActions(o,c);i.push(p.entry),r.push(p.exit)}return{entries:i,exits:r}});h(this,"executeActions",(e,s)=>{var i;const n=Q(e,this.guardMap)(this.contextSnapshot,s,this.guardMeta);for(const r of T(n)){const a=w(r)?(i=this.actionMap)==null?void 0:i[r]:r;H(w(r)&&!a,`[@zag-js/core > execute-actions] No implementation found for action: \`${r}\``),a==null||a(this.state.context,s,this.meta)}});h(this,"executeActivities",(e,s,n)=>{var i;for(const r of s){const a=w(r)?(i=this.activityMap)==null?void 0:i[r]:r;if(!a){H(`[@zag-js/core > execute-activity] No implementation found for activity: \`${r}\``);continue}const o=a(this.state.context,e,this.meta);if(o){const u=w(r)?r:r.name||ft();this.addActivityCleanup(n??this.state.value,u,o)}}});h(this,"createEveryActivities",(e,s)=>{if(e)if(K(e)){const n=T(e).find(o=>{const u=o.delay,p=N(u,this.delayMap)(this.contextSnapshot,this.state.event);return jt(o.guard,this.guardMap)(this.contextSnapshot,this.state.event,this.guardMeta)??p!=null});if(!n)return;const r=N(n.delay,this.delayMap)(this.contextSnapshot,this.state.event);s(()=>{const o=globalThis.setInterval(()=>{this.executeActions(n.actions,this.state.event)},r);return()=>{globalThis.clearInterval(o)}})}else for(const n in e){const i=e==null?void 0:e[n],a=N(n,this.delayMap)(this.contextSnapshot,this.state.event);s(()=>{const u=globalThis.setInterval(()=>{this.executeActions(i,this.state.event)},a);return()=>{globalThis.clearInterval(u)}})}});h(this,"setEvent",e=>{this.state.previousEvent=this.state.event,this.state.event=gt(E(e))});h(this,"performExitEffects",(e,s)=>{const n=this.state.value;if(n==="")return;const i=e?this.getStateNode(e):void 0;this.stopActivities(n);const r=Q(i==null?void 0:i.exit,this.guardMap)(this.contextSnapshot,s,this.guardMeta),a=T(r),o=this.delayedEvents.get(n);o&&a.push(...o),this.executeActions(a,s)});h(this,"performEntryEffects",(e,s)=>{const n=this.getStateNode(e),i=T(n==null?void 0:n.activities);this.createEveryActivities(n==null?void 0:n.every,u=>{i.unshift(u)}),i.length>0&&this.executeActivities(s,i);const r=Q(n==null?void 0:n.entry,this.guardMap)(this.contextSnapshot,s,this.guardMeta),a=T(r),o=this.getDelayedEventActions(e);n!=null&&n.after&&o&&(this.delayedEvents.set(e,o==null?void 0:o.exits),a.push(...o.entries)),this.executeActions(a,s),(n==null?void 0:n.type)==="final"&&(this.state.done=!0,this.doneListeners.forEach(u=>{u(this.stateSnapshot)}),this.stop())});h(this,"performTransitionEffects",(e,s)=>{const n=this.determineTransition(e,s);this.executeActions(n==null?void 0:n.actions,s)});h(this,"performStateChangeEffects",(e,s,n)=>{this.setEvent(n);const i=s.changed||s.reenter;i&&this.performExitEffects(e,n),this.performTransitionEffects(s.transition,n),this.setState(s.target),i&&this.performEntryEffects(s.target,n)});h(this,"determineTransition",(e,s)=>{const n=we(e,this.guardMap);return n==null?void 0:n(this.contextSnapshot,s,this.guardMeta)});h(this,"sendParent",e=>{var n;this.parent||Y("[@zag-js/core > send-parent] Cannot send event to an unknown parent");const s=E(e);(n=this.parent)==null||n.send(s)});h(this,"log",(...e)=>{});h(this,"send",e=>{const s=E(e);this.transition(this.state.value,s)});h(this,"transition",(e,s)=>{var o,u;const n=w(e)?this.getStateNode(e):e==null?void 0:e.stateNode,i=E(s);if(!n&&!this.config.on){const c=this.status===P.Stopped?"[@zag-js/core > transition] Cannot transition a stopped machine":`[@zag-js/core > transition] State does not have a definition for \`state\`: ${e}, \`event\`: ${i.type}`;H(c);return}const r=((o=n==null?void 0:n.on)==null?void 0:o[i.type])??((u=this.config.on)==null?void 0:u[i.type]),a=this.getNextStateInfo(r,i);return this.performStateChangeEffects(this.state.value,a,i),a.stateNode});h(this,"subscribe",e=>(this.stateListeners.add(e),this.status===P.Running&&e(this.stateSnapshot),()=>{this.stateListeners.delete(e)}));h(this,"onDone",e=>(this.doneListeners.add(e),this));h(this,"onTransition",e=>(this.stateListeners.add(e),this.status===P.Running&&e(this.stateSnapshot),this));var n,i,r,a,o;this.config=St(e),this.options=St(s??{}),this.id=this.config.id??`machine-${ft()}`,this.guardMap=((n=this.options)==null?void 0:n.guards)??{},this.actionMap=((i=this.options)==null?void 0:i.actions)??{},this.delayMap=((r=this.options)==null?void 0:r.delays)??{},this.activityMap=((a=this.options)==null?void 0:a.activities)??{},this.sync=((o=this.options)==null?void 0:o.sync)??!1,this.state=me(this.config),this.initialContext=x(this.state.context)}get stateSnapshot(){return b(x(this.state))}getState(){return this.stateSnapshot}get contextSnapshot(){return this.stateSnapshot.context}get self(){const e=this;return{id:this.id,send:this.send.bind(this),sendParent:this.sendParent.bind(this),sendChild:this.sendChild.bind(this),stop:this.stop.bind(this),stopChild:this.stopChild.bind(this),spawn:this.spawn.bind(this),stopActivity:this.stopActivity.bind(this),get state(){return e.stateSnapshot},get initialContext(){return e.initialContext},get initialState(){var s;return((s=e.initialState)==null?void 0:s.target)??""}}}get meta(){var e;return{state:this.stateSnapshot,guards:this.guardMap,send:this.send.bind(this),self:this.self,initialContext:this.initialContext,initialState:((e=this.initialState)==null?void 0:e.target)??"",getState:()=>this.stateSnapshot,getAction:s=>this.actionMap[s],getGuard:s=>this.guardMap[s]}}get guardMeta(){return{state:this.stateSnapshot}}get[Symbol.toStringTag](){return"Machine"}getHydrationState(){const e=this.getState();return{value:e.value,tags:e.tags}}}const Ve=(t,e)=>new Ae(t,e);function Oe(t){return new Proxy({},{get(){return t}})}function Pe(t){return t.charAt(0).toUpperCase()+t.substr(1).toLowerCase()}const Et={htmlFor:"for",className:"class",onDoubleClick:"onDblclick",onChange:"onInput",onFocus:"onFocusin",onBlur:"onFocusout",defaultValue:"value",defaultChecked:"checked"};function be(t){return t in Et?Et[t]:t.startsWith("on")?`on${Pe(t.substr(2))}`:t.toLowerCase()}const Be=Oe(t=>{const e={};for(const s in t){const n=t[s];s==="children"?typeof n=="string"&&(e.innerHTML=n):e[be(s)]=t[s]}return e});function Re(t,e){const{actions:s,context:n}=e??{},i=It(t.state),r=st(t.state,()=>{i.value=x(t.state)});return Ft(()=>{r==null||r()}),Yt(()=>{t.setOptions({actions:s})}),n&&kt(n,a=>{t.setContext(mt(a))},{deep:!0}),i}function Me(t,e){const{state:s,context:n}=e??{},i=typeof t=="function"?t():t;return n&&i.setContext(mt(n)),i._created(),Kt(()=>{i.start(s),Gt(()=>{i.stop()})}),i}function Ue(t,e){const s=Me(t,e);return[Re(s,e),s.send,s]}export{ce as A,fe as B,ke as C,w as D,W as E,ee as F,Xt as G,Fe as H,ut as I,G as J,je as K,Le as L,ze as M,$e as N,vt as O,Jt as P,V as a,Ve as b,q as c,Ut as d,gt as e,Ce as f,Ke as g,K as h,Ie as i,Ne as j,ot as k,De as l,Zt as m,Be as n,Y as o,Ye as p,b as q,qt as r,st as s,Qt as t,Ue as u,We as v,H as w,Ge as x,te as y,ue as z};
