import x from "./index-extends.js";
import D from "./index-objectWithoutPropertiesLoose.js";
import * as g from "react";
import t from "./index-_virtual16.js";
import U from "./index-useTheme.js";
import { reflow as q, getTransitionProps as $ } from "./index-utils6.js";
import { jsx as A } from "react/jsx-runtime";
import F from "./index-Transition.js";
import G from "./index-useForkRef.js";
import J from "./index-getReactElementRef.js";
import K from "./index-debounce3.js";
import O from "./index-ownerWindow2.js";
import Q from "./index-elementAcceptingRef.js";
import Z from "./index-chainPropTypes.js";
import ee from "./index-HTMLElementType.js";
const te = ["addEndListener", "appear", "children", "container", "direction", "easing", "in", "onEnter", "onEntered", "onEntering", "onExit", "onExited", "onExiting", "style", "timeout", "TransitionComponent"];
function ne(s, r, f) {
  const n = r.getBoundingClientRect(), i = f && f.getBoundingClientRect(), h = O(r);
  let c;
  if (r.fakeTransform)
    c = r.fakeTransform;
  else {
    const a = h.getComputedStyle(r);
    c = a.getPropertyValue("-webkit-transform") || a.getPropertyValue("transform");
  }
  let d = 0, u = 0;
  if (c && c !== "none" && typeof c == "string") {
    const a = c.split("(")[1].split(")")[0].split(",");
    d = parseInt(a[4], 10), u = parseInt(a[5], 10);
  }
  return s === "left" ? i ? `translateX(${i.right + d - n.left}px)` : `translateX(${h.innerWidth + d - n.left}px)` : s === "right" ? i ? `translateX(-${n.right - i.left - d}px)` : `translateX(-${n.left + n.width - d}px)` : s === "up" ? i ? `translateY(${i.bottom + u - n.top}px)` : `translateY(${h.innerHeight + u - n.top}px)` : i ? `translateY(-${n.top - i.top + n.height - u}px)` : `translateY(-${n.top + n.height - u}px)`;
}
function V(s) {
  return typeof s == "function" ? s() : s;
}
function y(s, r, f) {
  const n = V(f), i = ne(s, r, n);
  i && (r.style.webkitTransform = i, r.style.transform = i);
}
const re = /* @__PURE__ */ g.forwardRef(function(r, f) {
  const n = U(), i = {
    enter: n.transitions.easing.easeOut,
    exit: n.transitions.easing.sharp
  }, h = {
    enter: n.transitions.duration.enteringScreen,
    exit: n.transitions.duration.leavingScreen
  }, {
    addEndListener: c,
    appear: d = !0,
    children: u,
    container: a,
    direction: p = "down",
    easing: w = i,
    in: m,
    onEnter: R,
    onEntered: S,
    onEntering: v,
    onExit: k,
    onExited: C,
    onExiting: j,
    style: T,
    timeout: b = h,
    // eslint-disable-next-line react/prop-types
    TransitionComponent: I = F
  } = r, M = D(r, te), l = g.useRef(null), W = G(J(u), l, f), E = (e) => (o) => {
    e && (o === void 0 ? e(l.current) : e(l.current, o));
  }, X = E((e, o) => {
    y(p, e, a), q(e), R && R(e, o);
  }), Y = E((e, o) => {
    const P = $({
      timeout: b,
      style: T,
      easing: w
    }, {
      mode: "enter"
    });
    e.style.webkitTransition = n.transitions.create("-webkit-transform", x({}, P)), e.style.transition = n.transitions.create("transform", x({}, P)), e.style.webkitTransform = "none", e.style.transform = "none", v && v(e, o);
  }), _ = E(S), z = E(j), B = E((e) => {
    const o = $({
      timeout: b,
      style: T,
      easing: w
    }, {
      mode: "exit"
    });
    e.style.webkitTransition = n.transitions.create("-webkit-transform", o), e.style.transition = n.transitions.create("transform", o), y(p, e, a), k && k(e);
  }), N = E((e) => {
    e.style.webkitTransition = "", e.style.transition = "", C && C(e);
  }), H = (e) => {
    c && c(l.current, e);
  }, L = g.useCallback(() => {
    l.current && y(p, l.current, a);
  }, [p, a]);
  return g.useEffect(() => {
    if (m || p === "down" || p === "right")
      return;
    const e = K(() => {
      l.current && y(p, l.current, a);
    }), o = O(l.current);
    return o.addEventListener("resize", e), () => {
      e.clear(), o.removeEventListener("resize", e);
    };
  }, [p, m, a]), g.useEffect(() => {
    m || L();
  }, [m, L]), /* @__PURE__ */ A(I, x({
    nodeRef: l,
    onEnter: X,
    onEntered: _,
    onEntering: Y,
    onExit: B,
    onExited: N,
    onExiting: z,
    addEndListener: H,
    appear: d,
    in: m,
    timeout: b
  }, M, {
    children: (e, o) => /* @__PURE__ */ g.cloneElement(u, x({
      ref: W,
      style: x({
        visibility: e === "exited" && !m ? "hidden" : void 0
      }, T, u.props.style)
    }, o))
  }));
});
process.env.NODE_ENV !== "production" && (re.propTypes = {
  // ┌────────────────────────────── Warning ──────────────────────────────┐
  // │ These PropTypes are generated from the TypeScript type definitions. │
  // │    To update them, edit the d.ts file and run `pnpm proptypes`.     │
  // └─────────────────────────────────────────────────────────────────────┘
  /**
   * Add a custom transition end trigger. Called with the transitioning DOM
   * node and a done callback. Allows for more fine grained transition end
   * logic. Note: Timeouts are still used as a fallback if provided.
   */
  addEndListener: t.func,
  /**
   * Perform the enter transition when it first mounts if `in` is also `true`.
   * Set this to `false` to disable this behavior.
   * @default true
   */
  appear: t.bool,
  /**
   * A single child content element.
   */
  children: Q.isRequired,
  /**
   * An HTML element, or a function that returns one.
   * It's used to set the container the Slide is transitioning from.
   */
  container: Z(t.oneOfType([ee, t.func]), (s) => {
    if (s.open) {
      const r = V(s.container);
      if (r && r.nodeType === 1) {
        const f = r.getBoundingClientRect();
        if (process.env.NODE_ENV !== "test" && f.top === 0 && f.left === 0 && f.right === 0 && f.bottom === 0)
          return new Error(["MUI: The `container` prop provided to the component is invalid.", "The anchor element should be part of the document layout.", "Make sure the element is present in the document or that it's not display none."].join(`
`));
      } else if (!r || typeof r.getBoundingClientRect != "function" || r.contextElement != null && r.contextElement.nodeType !== 1)
        return new Error(["MUI: The `container` prop provided to the component is invalid.", "It should be an HTML element instance."].join(`
`));
    }
    return null;
  }),
  /**
   * Direction the child node will enter from.
   * @default 'down'
   */
  direction: t.oneOf(["down", "left", "right", "up"]),
  /**
   * The transition timing function.
   * You may specify a single easing or a object containing enter and exit values.
   * @default {
   *   enter: theme.transitions.easing.easeOut,
   *   exit: theme.transitions.easing.sharp,
   * }
   */
  easing: t.oneOfType([t.shape({
    enter: t.string,
    exit: t.string
  }), t.string]),
  /**
   * If `true`, the component will transition in.
   */
  in: t.bool,
  /**
   * @ignore
   */
  onEnter: t.func,
  /**
   * @ignore
   */
  onEntered: t.func,
  /**
   * @ignore
   */
  onEntering: t.func,
  /**
   * @ignore
   */
  onExit: t.func,
  /**
   * @ignore
   */
  onExited: t.func,
  /**
   * @ignore
   */
  onExiting: t.func,
  /**
   * @ignore
   */
  style: t.object,
  /**
   * The duration for the transition, in milliseconds.
   * You may specify a single timeout for all transitions, or individually with an object.
   * @default {
   *   enter: theme.transitions.duration.enteringScreen,
   *   exit: theme.transitions.duration.leavingScreen,
   * }
   */
  timeout: t.oneOfType([t.number, t.shape({
    appear: t.number,
    enter: t.number,
    exit: t.number
  })])
});
export {
  re as default,
  y as setTranslateValue
};
