var T;import{useRef as c,useState as S}from"react";import{disposables as m}from'../utils/disposables.js';import{useDisposables as g}from'./use-disposables.js';import{useFlags as E}from'./use-flags.js';import{useIsoMorphicEffect as y}from'./use-iso-morphic-effect.js';typeof process!="undefined"&&typeof globalThis!="undefined"&&((T=process==null?void 0:process.env)==null?void 0:T["NODE_ENV"])==="test"&&typeof Element.prototype.getAnimations=="undefined"&&(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(`
`)),[]});var A=(r=>(r[r.None=0]="None",r[r.Closed=1]="Closed",r[r.Enter=2]="Enter",r[r.Leave=4]="Leave",r))(A||{});function H(e){let n={};for(let t in e)e[t]===!0&&(n[`data-${t}`]="");return n}function R(e,n,t,i){let[r,o]=S(t),{hasFlag:s,addFlag:a,removeFlag:l}=E(e&&r?3:0),u=c(!1),f=c(!1),b=g();return y(()=>{var d;if(e){if(t&&o(!0),!n){t&&a(3);return}return(d=i==null?void 0:i.start)==null||d.call(i,t),L(n,{inFlight:u,prepare(){f.current?f.current=!1:f.current=u.current,u.current=!0,!f.current&&(t?(a(3),l(4)):(a(4),l(2)))},run(){f.current?t?(l(3),a(4)):(l(4),a(3)):t?l(1):a(1)},done(){var p;f.current&&typeof n.getAnimations=="function"&&n.getAnimations().length>0||(u.current=!1,l(7),t||o(!1),(p=i==null?void 0:i.end)==null||p.call(i,t))}})}},[e,t,n,b]),e?[r,{closed:s(1),enter:s(2),leave:s(4),transition:s(2)||s(4)}]:[t,{closed:void 0,enter:void 0,leave:void 0,transition:void 0}]}function L(e,{prepare:n,run:t,done:i,inFlight:r}){let o=m();return M(e,{prepare:n,inFlight:r}),o.nextFrame(()=>{t(),o.requestAnimationFrame(()=>{o.add(C(e,i))})}),o.dispose}function C(e,n){var o,s;let t=m();if(!e)return t.dispose;let i=!1;t.add(()=>{i=!0});let r=(s=(o=e.getAnimations)==null?void 0:o.call(e).filter(a=>a instanceof CSSTransition))!=null?s:[];return r.length===0?(n(),t.dispose):(Promise.allSettled(r.map(a=>a.finished)).then(()=>{i||n()}),t.dispose)}function M(e,{inFlight:n,prepare:t}){if(n!=null&&n.current){t();return}let i=e.style.transition;e.style.transition="none",t(),e.offsetHeight,e.style.transition=i}export{H as transitionDataAttributes,R as useTransition};
