import{Reason as s,transition as g}from"../components/transitions/utils/transition.js";import{disposables as E}from"../utils/disposables.js";import{match as n}from"../utils/match.js";import{useDisposables as M}from"./use-disposables.js";import{useEvent as a}from"./use-event.js";import{useIsMounted as T}from"./use-is-mounted.js";import{useIsoMorphicEffect as R}from"./use-iso-morphic-effect.js";import{useLatestValue as j}from"./use-latest-value.js";function H({container:u,direction:o,classes:c,events:t,onStart:d,onStop:l}){let f=T(),m=M(),e=j(o),b=a(()=>n(e.current,{enter:()=>t.current.beforeEnter(),leave:()=>t.current.beforeLeave(),idle:()=>{}})),p=a(()=>n(e.current,{enter:()=>t.current.afterEnter(),leave:()=>t.current.afterLeave(),idle:()=>{}}));R(()=>{let r=E();m.add(r.dispose);let i=u.current;if(!!i&&e.current!=="idle"&&!!f.current)return r.dispose(),b(),d.current(e.current),r.add(g(i,c.current,e.current==="enter",v=>{r.dispose(),n(v,{[s.Ended](){p(),l.current(e.current)},[s.Cancelled]:()=>{}})})),r.dispose},[o])}export{H as useTransition};
