import be from "./index-objectWithoutPropertiesLoose.js";
import n from "./index-extends.js";
import * as p from "react";
import o from "./index-_virtual16.js";
import { clsx as D } from "./index-clsx.js";
import { c as Uo } from "./index-colorManipulator2.js";
import { useRtl as ge } from "./index-RtlProvider.js";
import f, { getTooltipUtilityClass as Te } from "./index-tooltipClasses.js";
import { jsxs as So, jsx as I } from "react/jsx-runtime";
import { useDefaultProps as ye } from "./index-DefaultPropsProvider.js";
import Wo from "./index-Grow.js";
import ve from "./index-useTheme.js";
import j, { Timeout as Pe } from "./index-useTimeout.js";
import we from "./index-useControlled2.js";
import Re from "./index-useId2.js";
import Bo from "./index-useEventCallback2.js";
import xe from "./index-useIsFocusVisible2.js";
import Ce from "./index-useForkRef.js";
import Oe from "./index-getReactElementRef.js";
import A from "./index-appendOwnerState.js";
import zo from "./index-Popper.js";
import Ho from "./index-capitalize.js";
import Ee from "./index-composeClasses.js";
import J from "./index-styled.js";
import Me from "./index-elementAcceptingRef.js";
const _e = ["arrow", "children", "classes", "components", "componentsProps", "describeChild", "disableFocusListener", "disableHoverListener", "disableInteractive", "disableTouchListener", "enterDelay", "enterNextDelay", "enterTouchDelay", "followCursor", "id", "leaveDelay", "leaveTouchDelay", "onClose", "onOpen", "open", "placement", "PopperComponent", "PopperProps", "slotProps", "slots", "title", "TransitionComponent", "TransitionProps"];
function Ne(r) {
  return Math.round(r * 1e5) / 1e5;
}
const Le = (r) => {
  const {
    classes: t,
    disableInteractive: s,
    arrow: m,
    touch: R,
    placement: x
  } = r, C = {
    popper: ["popper", !s && "popperInteractive", m && "popperArrow"],
    tooltip: ["tooltip", m && "tooltipArrow", R && "touch", `tooltipPlacement${Ho(x.split("-")[0])}`],
    arrow: ["arrow"]
  };
  return Ee(C, Te, t);
}, $e = J(zo, {
  name: "MuiTooltip",
  slot: "Popper",
  overridesResolver: (r, t) => {
    const {
      ownerState: s
    } = r;
    return [t.popper, !s.disableInteractive && t.popperInteractive, s.arrow && t.popperArrow, !s.open && t.popperClose];
  }
})(({
  theme: r,
  ownerState: t,
  open: s
}) => n({
  zIndex: (r.vars || r).zIndex.tooltip,
  pointerEvents: "none"
}, !t.disableInteractive && {
  pointerEvents: "auto"
}, !s && {
  pointerEvents: "none"
}, t.arrow && {
  [`&[data-popper-placement*="bottom"] .${f.arrow}`]: {
    top: 0,
    marginTop: "-0.71em",
    "&::before": {
      transformOrigin: "0 100%"
    }
  },
  [`&[data-popper-placement*="top"] .${f.arrow}`]: {
    bottom: 0,
    marginBottom: "-0.71em",
    "&::before": {
      transformOrigin: "100% 0"
    }
  },
  [`&[data-popper-placement*="right"] .${f.arrow}`]: n({}, t.isRtl ? {
    right: 0,
    marginRight: "-0.71em"
  } : {
    left: 0,
    marginLeft: "-0.71em"
  }, {
    height: "1em",
    width: "0.71em",
    "&::before": {
      transformOrigin: "100% 100%"
    }
  }),
  [`&[data-popper-placement*="left"] .${f.arrow}`]: n({}, t.isRtl ? {
    left: 0,
    marginLeft: "-0.71em"
  } : {
    right: 0,
    marginRight: "-0.71em"
  }, {
    height: "1em",
    width: "0.71em",
    "&::before": {
      transformOrigin: "0 0"
    }
  })
})), De = J("div", {
  name: "MuiTooltip",
  slot: "Tooltip",
  overridesResolver: (r, t) => {
    const {
      ownerState: s
    } = r;
    return [t.tooltip, s.touch && t.touch, s.arrow && t.tooltipArrow, t[`tooltipPlacement${Ho(s.placement.split("-")[0])}`]];
  }
})(({
  theme: r,
  ownerState: t
}) => n({
  backgroundColor: r.vars ? r.vars.palette.Tooltip.bg : Uo.alpha(r.palette.grey[700], 0.92),
  borderRadius: (r.vars || r).shape.borderRadius,
  color: (r.vars || r).palette.common.white,
  fontFamily: r.typography.fontFamily,
  padding: "4px 8px",
  fontSize: r.typography.pxToRem(11),
  maxWidth: 300,
  margin: 2,
  wordWrap: "break-word",
  fontWeight: r.typography.fontWeightMedium
}, t.arrow && {
  position: "relative",
  margin: 0
}, t.touch && {
  padding: "8px 16px",
  fontSize: r.typography.pxToRem(14),
  lineHeight: `${Ne(16 / 14)}em`,
  fontWeight: r.typography.fontWeightRegular
}, {
  [`.${f.popper}[data-popper-placement*="left"] &`]: n({
    transformOrigin: "right center"
  }, t.isRtl ? n({
    marginLeft: "14px"
  }, t.touch && {
    marginLeft: "24px"
  }) : n({
    marginRight: "14px"
  }, t.touch && {
    marginRight: "24px"
  })),
  [`.${f.popper}[data-popper-placement*="right"] &`]: n({
    transformOrigin: "left center"
  }, t.isRtl ? n({
    marginRight: "14px"
  }, t.touch && {
    marginRight: "24px"
  }) : n({
    marginLeft: "14px"
  }, t.touch && {
    marginLeft: "24px"
  })),
  [`.${f.popper}[data-popper-placement*="top"] &`]: n({
    transformOrigin: "center bottom",
    marginBottom: "14px"
  }, t.touch && {
    marginBottom: "24px"
  }),
  [`.${f.popper}[data-popper-placement*="bottom"] &`]: n({
    transformOrigin: "center top",
    marginTop: "14px"
  }, t.touch && {
    marginTop: "24px"
  })
})), Ie = J("span", {
  name: "MuiTooltip",
  slot: "Arrow",
  overridesResolver: (r, t) => t.arrow
})(({
  theme: r
}) => ({
  overflow: "hidden",
  position: "absolute",
  width: "1em",
  height: "0.71em",
  boxSizing: "border-box",
  color: r.vars ? r.vars.palette.Tooltip.bg : Uo.alpha(r.palette.grey[700], 0.9),
  "&::before": {
    content: '""',
    margin: "auto",
    display: "block",
    width: "100%",
    height: "100%",
    backgroundColor: "currentColor",
    transform: "rotate(45deg)"
  }
}));
let F = !1;
const Vo = new Pe();
let w = {
  x: 0,
  y: 0
};
function k(r, t) {
  return (s, ...m) => {
    t && t(s, ...m), r(s, ...m);
  };
}
const je = /* @__PURE__ */ p.forwardRef(function(t, s) {
  var m, R, x, C, Q, Z, oo, eo, to, ro, no, so, po, io, lo, ao, co, uo, mo;
  const S = ye({
    props: t,
    name: "MuiTooltip"
  }), {
    arrow: fo = !1,
    children: W,
    components: O = {},
    componentsProps: h = {},
    describeChild: Yo = !1,
    disableFocusListener: qo = !1,
    disableHoverListener: ho = !1,
    disableInteractive: Go = !1,
    disableTouchListener: Ko = !1,
    enterDelay: bo = 100,
    enterNextDelay: go = 0,
    enterTouchDelay: Xo = 700,
    followCursor: B = !1,
    id: Jo,
    leaveDelay: To = 0,
    leaveTouchDelay: Qo = 1500,
    onClose: yo,
    onOpen: vo,
    open: Po,
    placement: wo = "bottom",
    PopperComponent: V,
    PopperProps: b = {},
    slotProps: g = {},
    slots: E = {},
    title: d,
    TransitionComponent: Zo = Wo,
    TransitionProps: oe
  } = S, Ro = be(S, _e), c = /* @__PURE__ */ p.isValidElement(W) ? W : /* @__PURE__ */ I("span", {
    children: W
  }), xo = ve(), ee = ge(), [l, Co] = p.useState(), [U, te] = p.useState(null), M = p.useRef(!1), z = Go || B, Oo = j(), H = j(), _ = j(), Eo = j(), [re, Mo] = we({
    controlled: Po,
    default: !1,
    name: "Tooltip",
    state: "open"
  });
  let u = re;
  if (process.env.NODE_ENV !== "production") {
    const {
      current: e
    } = p.useRef(Po !== void 0);
    p.useEffect(() => {
      l && l.disabled && !e && d !== "" && l.tagName.toLowerCase();
    }, [d, l, e]);
  }
  const Y = Re(Jo), T = p.useRef(), N = Bo(() => {
    T.current !== void 0 && (document.body.style.WebkitUserSelect = T.current, T.current = void 0), Eo.clear();
  });
  p.useEffect(() => N, [N]);
  const _o = (e) => {
    Vo.clear(), F = !0, Mo(!0), vo && !u && vo(e);
  }, L = Bo(
    /**
     * @param {React.SyntheticEvent | Event} event
     */
    (e) => {
      Vo.start(800 + To, () => {
        F = !1;
      }), Mo(!1), yo && u && yo(e), Oo.start(xo.transitions.duration.shortest, () => {
        M.current = !1;
      });
    }
  ), $ = (e) => {
    M.current && e.type !== "touchstart" || (l && l.removeAttribute("title"), H.clear(), _.clear(), bo || F && go ? H.start(F ? go : bo, () => {
      _o(e);
    }) : _o(e));
  }, q = (e) => {
    H.clear(), _.start(To, () => {
      L(e);
    });
  }, {
    isFocusVisibleRef: No,
    onBlur: ne,
    onFocus: se,
    ref: pe
  } = xe(), [, Lo] = p.useState(!1), $o = (e) => {
    ne(e), No.current === !1 && (Lo(!1), q(e));
  }, Do = (e) => {
    l || Co(e.currentTarget), se(e), No.current === !0 && (Lo(!0), $(e));
  }, Io = (e) => {
    M.current = !0;
    const i = c.props;
    i.onTouchStart && i.onTouchStart(e);
  }, ie = (e) => {
    Io(e), _.clear(), Oo.clear(), N(), T.current = document.body.style.WebkitUserSelect, document.body.style.WebkitUserSelect = "none", Eo.start(Xo, () => {
      document.body.style.WebkitUserSelect = T.current, $(e);
    });
  }, le = (e) => {
    c.props.onTouchEnd && c.props.onTouchEnd(e), N(), _.start(Qo, () => {
      L(e);
    });
  };
  p.useEffect(() => {
    if (!u)
      return;
    function e(i) {
      (i.key === "Escape" || i.key === "Esc") && L(i);
    }
    return document.addEventListener("keydown", e), () => {
      document.removeEventListener("keydown", e);
    };
  }, [L, u]);
  const ae = Ce(Oe(c), pe, Co, s);
  !d && d !== 0 && (u = !1);
  const G = p.useRef(), ce = (e) => {
    const i = c.props;
    i.onMouseMove && i.onMouseMove(e), w = {
      x: e.clientX,
      y: e.clientY
    }, G.current && G.current.update();
  }, y = {}, K = typeof d == "string";
  Yo ? (y.title = !u && K && !ho ? d : null, y["aria-describedby"] = u ? Y : null) : (y["aria-label"] = K ? d : null, y["aria-labelledby"] = u && !K ? Y : null);
  const a = n({}, y, Ro, c.props, {
    className: D(Ro.className, c.props.className),
    onTouchStart: Io,
    ref: ae
  }, B ? {
    onMouseMove: ce
  } : {});
  process.env.NODE_ENV !== "production" && (a["data-mui-internal-clone-element"] = !0, p.useEffect(() => {
    l && l.getAttribute("data-mui-internal-clone-element");
  }, [l]));
  const v = {};
  Ko || (a.onTouchStart = ie, a.onTouchEnd = le), ho || (a.onMouseOver = k($, a.onMouseOver), a.onMouseLeave = k(q, a.onMouseLeave), z || (v.onMouseOver = $, v.onMouseLeave = q)), qo || (a.onFocus = k(Do, a.onFocus), a.onBlur = k($o, a.onBlur), z || (v.onFocus = Do, v.onBlur = $o)), process.env.NODE_ENV !== "production" && c.props.title;
  const ue = p.useMemo(() => {
    var e;
    let i = [{
      name: "arrow",
      enabled: !!U,
      options: {
        element: U,
        padding: 4
      }
    }];
    return (e = b.popperOptions) != null && e.modifiers && (i = i.concat(b.popperOptions.modifiers)), n({}, b.popperOptions, {
      modifiers: i
    });
  }, [U, b]), P = n({}, S, {
    isRtl: ee,
    arrow: fo,
    disableInteractive: z,
    placement: wo,
    PopperComponentProp: V,
    touch: M.current
  }), X = Le(P), jo = (m = (R = E.popper) != null ? R : O.Popper) != null ? m : $e, Ao = (x = (C = (Q = E.transition) != null ? Q : O.Transition) != null ? C : Zo) != null ? x : Wo, Fo = (Z = (oo = E.tooltip) != null ? oo : O.Tooltip) != null ? Z : De, ko = (eo = (to = E.arrow) != null ? to : O.Arrow) != null ? eo : Ie, me = A(jo, n({}, b, (ro = g.popper) != null ? ro : h.popper, {
    className: D(X.popper, b == null ? void 0 : b.className, (no = (so = g.popper) != null ? so : h.popper) == null ? void 0 : no.className)
  }), P), de = A(Ao, n({}, oe, (po = g.transition) != null ? po : h.transition), P), fe = A(Fo, n({}, (io = g.tooltip) != null ? io : h.tooltip, {
    className: D(X.tooltip, (lo = (ao = g.tooltip) != null ? ao : h.tooltip) == null ? void 0 : lo.className)
  }), P), he = A(ko, n({}, (co = g.arrow) != null ? co : h.arrow, {
    className: D(X.arrow, (uo = (mo = g.arrow) != null ? mo : h.arrow) == null ? void 0 : uo.className)
  }), P);
  return /* @__PURE__ */ So(p.Fragment, {
    children: [/* @__PURE__ */ p.cloneElement(c, a), /* @__PURE__ */ I(jo, n({
      as: V ?? zo,
      placement: wo,
      anchorEl: B ? {
        getBoundingClientRect: () => ({
          top: w.y,
          left: w.x,
          right: w.x,
          bottom: w.y,
          width: 0,
          height: 0
        })
      } : l,
      popperRef: G,
      open: l ? u : !1,
      id: Y,
      transition: !0
    }, v, me, {
      popperOptions: ue,
      children: ({
        TransitionProps: e
      }) => /* @__PURE__ */ I(Ao, n({
        timeout: xo.transitions.duration.shorter
      }, e, de, {
        children: /* @__PURE__ */ So(Fo, n({}, fe, {
          children: [d, fo ? /* @__PURE__ */ I(ko, n({}, he, {
            ref: te
          })) : null]
        }))
      }))
    }))]
  });
});
process.env.NODE_ENV !== "production" && (je.propTypes = {
  // ┌────────────────────────────── Warning ──────────────────────────────┐
  // │ These PropTypes are generated from the TypeScript type definitions. │
  // │    To update them, edit the d.ts file and run `pnpm proptypes`.     │
  // └─────────────────────────────────────────────────────────────────────┘
  /**
   * If `true`, adds an arrow to the tooltip.
   * @default false
   */
  arrow: o.bool,
  /**
   * Tooltip reference element.
   */
  children: Me.isRequired,
  /**
   * Override or extend the styles applied to the component.
   */
  classes: o.object,
  /**
   * @ignore
   */
  className: o.string,
  /**
   * The components used for each slot inside.
   *
   * This prop is an alias for the `slots` prop.
   * It's recommended to use the `slots` prop instead.
   *
   * @default {}
   */
  components: o.shape({
    Arrow: o.elementType,
    Popper: o.elementType,
    Tooltip: o.elementType,
    Transition: o.elementType
  }),
  /**
   * The extra props for the slot components.
   * You can override the existing props or add new ones.
   *
   * This prop is an alias for the `slotProps` prop.
   * It's recommended to use the `slotProps` prop instead, as `componentsProps` will be deprecated in the future.
   *
   * @default {}
   */
  componentsProps: o.shape({
    arrow: o.object,
    popper: o.object,
    tooltip: o.object,
    transition: o.object
  }),
  /**
   * Set to `true` if the `title` acts as an accessible description.
   * By default the `title` acts as an accessible label for the child.
   * @default false
   */
  describeChild: o.bool,
  /**
   * Do not respond to focus-visible events.
   * @default false
   */
  disableFocusListener: o.bool,
  /**
   * Do not respond to hover events.
   * @default false
   */
  disableHoverListener: o.bool,
  /**
   * Makes a tooltip not interactive, i.e. it will close when the user
   * hovers over the tooltip before the `leaveDelay` is expired.
   * @default false
   */
  disableInteractive: o.bool,
  /**
   * Do not respond to long press touch events.
   * @default false
   */
  disableTouchListener: o.bool,
  /**
   * The number of milliseconds to wait before showing the tooltip.
   * This prop won't impact the enter touch delay (`enterTouchDelay`).
   * @default 100
   */
  enterDelay: o.number,
  /**
   * The number of milliseconds to wait before showing the tooltip when one was already recently opened.
   * @default 0
   */
  enterNextDelay: o.number,
  /**
   * The number of milliseconds a user must touch the element before showing the tooltip.
   * @default 700
   */
  enterTouchDelay: o.number,
  /**
   * If `true`, the tooltip follow the cursor over the wrapped element.
   * @default false
   */
  followCursor: o.bool,
  /**
   * This prop is used to help implement the accessibility logic.
   * If you don't provide this prop. It falls back to a randomly generated id.
   */
  id: o.string,
  /**
   * The number of milliseconds to wait before hiding the tooltip.
   * This prop won't impact the leave touch delay (`leaveTouchDelay`).
   * @default 0
   */
  leaveDelay: o.number,
  /**
   * The number of milliseconds after the user stops touching an element before hiding the tooltip.
   * @default 1500
   */
  leaveTouchDelay: o.number,
  /**
   * Callback fired when the component requests to be closed.
   *
   * @param {React.SyntheticEvent} event The event source of the callback.
   */
  onClose: o.func,
  /**
   * Callback fired when the component requests to be open.
   *
   * @param {React.SyntheticEvent} event The event source of the callback.
   */
  onOpen: o.func,
  /**
   * If `true`, the component is shown.
   */
  open: o.bool,
  /**
   * Tooltip placement.
   * @default 'bottom'
   */
  placement: o.oneOf(["bottom-end", "bottom-start", "bottom", "left-end", "left-start", "left", "right-end", "right-start", "right", "top-end", "top-start", "top"]),
  /**
   * The component used for the popper.
   * @default Popper
   */
  PopperComponent: o.elementType,
  /**
   * Props applied to the [`Popper`](/material-ui/api/popper/) element.
   * @default {}
   */
  PopperProps: o.object,
  /**
   * The extra props for the slot components.
   * You can override the existing props or add new ones.
   *
   * This prop is an alias for the `componentsProps` prop, which will be deprecated in the future.
   *
   * @default {}
   */
  slotProps: o.shape({
    arrow: o.object,
    popper: o.object,
    tooltip: o.object,
    transition: o.object
  }),
  /**
   * The components used for each slot inside.
   *
   * This prop is an alias for the `components` prop, which will be deprecated in the future.
   *
   * @default {}
   */
  slots: o.shape({
    arrow: o.elementType,
    popper: o.elementType,
    tooltip: o.elementType,
    transition: o.elementType
  }),
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx: o.oneOfType([o.arrayOf(o.oneOfType([o.func, o.object, o.bool])), o.func, o.object]),
  /**
   * Tooltip title. Zero-length titles string, undefined, null and false are never displayed.
   */
  title: o.node,
  /**
   * The component used for the transition.
   * [Follow this guide](/material-ui/transitions/#transitioncomponent-prop) to learn more about the requirements for this component.
   * @default Grow
   */
  TransitionComponent: o.elementType,
  /**
   * Props applied to the transition element.
   * By default, the element is based on this [`Transition`](https://reactcommunity.org/react-transition-group/transition/) component.
   */
  TransitionProps: o.object
});
export {
  je as default
};
