"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,n=require("react"),i=require("../utils/disposables.js"),r=require("./use-disposables.js"),s=require("./use-flags.js"),o=require("./use-iso-morphic-effect.js");"undefined"!=typeof process&&"undefined"!=typeof globalThis&&"undefined"!=typeof Element&&"test"===(null==(e=null==process?void 0:process.env)?void 0:e.NODE_ENV)&&void 0===(null==(t=null==Element?void 0:Element.prototype)?void 0:t.getAnimations)&&(Element.prototype.getAnimations=function(){return console.warn(["Headless UI has polyfilled `Element.prototype.getAnimations` for your tests.","Please install a proper polyfill e.g. `jsdom-testing-mocks`, to silence these warnings.","","Example usage:","```js","import { mockAnimationsApi } from 'jsdom-testing-mocks'","mockAnimationsApi()","```"].join("\n")),[]});var l,a=((l=a||{})[l.None=0]="None",l[l.Closed=1]="Closed",l[l.Enter=2]="Enter",l[l.Leave=4]="Leave",l);exports.transitionDataAttributes=function(e){let t={};for(let n in e)!0===e[n]&&(t[`data-${n}`]="");return t},exports.useTransition=function(e,t,l,a){let[u,d]=n.useState(l),{hasFlag:p,addFlag:c,removeFlag:f}=s.useFlags(e&&u?3:0),m=n.useRef(!1),v=n.useRef(!1),g=r.useDisposables();return o.useIsoMorphicEffect((()=>{var n;if(e)return l&&d(!0),t?(null==(n=null==a?void 0:a.start)||n.call(a,l),function(e,t){let{prepare:n,run:r,done:s,inFlight:o}=t,l=i.disposables();return function(e,t){let{inFlight:n,prepare:i}=t;if(null!=n&&n.current)return void i();let r=e.style.transition;e.style.transition="none",i(),e.offsetHeight,e.style.transition=r}(e,{prepare:n,inFlight:o}),l.nextFrame((()=>{r(),l.requestAnimationFrame((()=>{l.add(function(e,t){var n,r;let s=i.disposables();if(!e)return s.dispose;let o=!1;s.add((()=>{o=!0}));let l=null!=(r=null==(n=e.getAnimations)?void 0:n.call(e).filter((e=>e instanceof CSSTransition)))?r:[];return 0===l.length?(t(),s.dispose):(Promise.allSettled(l.map((e=>e.finished))).then((()=>{o||t()})),s.dispose)}(e,s))}))})),l.dispose}(t,{inFlight:m,prepare(){v.current?v.current=!1:v.current=m.current,m.current=!0,!v.current&&(l?(c(3),f(4)):(c(4),f(2)))},run(){v.current?l?(f(3),c(4)):(f(4),c(3)):l?f(1):c(1)},done(){var e;v.current&&function(e){var t,n;return(null!=(n=null==(t=e.getAnimations)?void 0:t.call(e))?n:[]).some((e=>e instanceof CSSTransition&&"finished"!==e.playState))}(t)||(m.current=!1,f(7),l||d(!1),null==(e=null==a?void 0:a.end)||e.call(a,l))}})):void(l&&c(3))}),[e,l,t,g]),e?[u,{closed:p(1),enter:p(2),leave:p(4),transition:p(2)||p(4)}]:[l,{closed:void 0,enter:void 0,leave:void 0,transition:void 0}]};
//# sourceMappingURL=use-transition.js.map
