import { b as c } from "./mergeProps-B-cqsBhL.es.js";
import { flushSync as u } from "react-dom";
import { useState as o, useCallback as s } from "react";
function $(t, n = !0) {
  let [i, a] = o(!0), e = i && n;
  return c(() => {
    if (e && t.current && "getAnimations" in t.current)
      for (let r of t.current.getAnimations()) r instanceof CSSTransition && r.cancel();
  }, [
    t,
    e
  ]), f(t, e, s(() => a(!1), [])), e;
}
function g(t, n) {
  let [i, a] = o(n ? "open" : "closed");
  switch (i) {
    case "open":
      n || a("exiting");
      break;
    case "closed":
    case "exiting":
      n && a("open");
      break;
  }
  let e = i === "exiting";
  return f(t, e, s(() => {
    a((r) => r === "exiting" ? "closed" : r);
  }, [])), e;
}
function f(t, n, i) {
  c(() => {
    if (n && t.current) {
      if (!("getAnimations" in t.current)) {
        i();
        return;
      }
      let a = t.current.getAnimations();
      if (a.length === 0) {
        i();
        return;
      }
      let e = !1;
      return Promise.all(a.map((r) => r.finished)).then(() => {
        e || u(() => {
          i();
        });
      }).catch(() => {
      }), () => {
        e = !0;
      };
    }
  }, [
    t,
    n,
    i
  ]);
}
export {
  g as $,
  $ as a
};
//# sourceMappingURL=animation-BfmkkMe7.es.js.map
