import { jsx as e, jsxs as y, Fragment as T } from "react/jsx-runtime";
import { useWindowResize as W } from "./index-use-window.resize.js";
import { PopoverPopper as w } from "./index-PopoverPopper.js";
import { Render as k } from "./index-Render.js";
import { Text as m, FontWeights as C, TextTypes as M } from "./index-Text.js";
import { useState as b, useEffect as j } from "react";
import E from "./index-Tooltip.js";
const H = (c) => {
  const {
    children: n,
    message: t,
    title: i,
    position: p = "top",
    arrow: f = !0,
    wrapChildren: d = !0,
    maxWidth: s,
    interactive: u = !1,
    replacements: a,
    theme: h = "dark",
    hideUnderBreakpoint: r,
    className: x
  } = c, l = W(), [P, o] = b(!1);
  if (j(() => {
    r && l < r && o(!1);
  }, []), !t)
    return n;
  function g() {
    return typeof t == "string" ? y(T, {
      children: [e(k, {
        if: !!i && typeof i == "string",
        children: e(m, {
          replacements: a,
          fontWeight: C.bold,
          children: i
        })
      }), e(m, {
        type: M.textHelp,
        replacements: a,
        children: t
      })]
    }) : t ?? "";
  }
  function v() {
    return d ? e("span", {
      children: n
    }, 1) : n;
  }
  return e(E, {
    title: g(),
    arrow: f,
    placement: p,
    PopperComponent: w,
    open: P,
    classes: x,
    PopperProps: {
      style: {
        maxWidth: s
      },
      className: h === "dark" ? "MuiTooltip-popper-dark" : "",
      placement: p
    },
    disableInteractive: !u,
    componentsProps: {
      tooltip: {
        style: {
          maxWidth: s
        }
      }
    },
    onMouseEnter: () => {
      if (r && l < r) {
        o(!1);
        return;
      }
      o(!0);
    },
    onMouseLeave: () => {
      o(!1);
    },
    children: v()
  });
};
export {
  H as Popover
};
