'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var jsxRuntime = require('react/jsx-runtime');
var popper = require('@chakra-ui/popper');
var portal = require('@chakra-ui/portal');
var system = require('@chakra-ui/system');
var objectUtils = require('@chakra-ui/object-utils');
var framerMotion = require('framer-motion');
var React = require('react');
var chakraTooltip_transition = require('./chakraTooltip.transition.cjs');
var react = require('@chakra-ui/react');

var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source)
    if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
      target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(source)) {
      if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
        target[prop] = source[prop];
    }
  return target;
};
const MotionDiv = system.chakra(framerMotion.motion.div);
const ChakraTooltip = system.forwardRef((props, ref) => {
  var _b, _c;
  const styles = system.useStyleConfig("Tooltip", props);
  const ownProps = system.omitThemingProps(props);
  const theme = system.useTheme();
  const _a = ownProps, {
    children,
    label,
    shouldWrapChildren,
    "aria-label": ariaLabel,
    hasArrow,
    bg,
    portalProps,
    background,
    backgroundColor,
    bgColor,
    motionProps
  } = _a, rest = __objRest(_a, [
    "children",
    "label",
    "shouldWrapChildren",
    "aria-label",
    "hasArrow",
    "bg",
    "portalProps",
    "background",
    "backgroundColor",
    "bgColor",
    "motionProps"
  ]);
  const userDefinedBg = (_c = (_b = background != null ? background : backgroundColor) != null ? _b : bg) != null ? _c : bgColor;
  if (userDefinedBg) {
    styles.bg = userDefinedBg;
    const bgVar = system.getCSSVar(theme, "colors", userDefinedBg);
    styles[popper.popperCSSVars.arrowBg.var] = bgVar;
  }
  const tooltip = react.useTooltip(__spreadProps(__spreadValues({}, rest), { direction: theme.direction }));
  const shouldWrap = typeof children === "string" || shouldWrapChildren;
  let trigger;
  if (shouldWrap) {
    trigger = /* @__PURE__ */ jsxRuntime.jsx(system.chakra.span, __spreadProps(__spreadValues({ display: "inline-block", tabIndex: 0 }, tooltip.getTriggerProps()), { children }));
  } else {
    const child = React.Children.only(children);
    trigger = React.cloneElement(child, tooltip.getTriggerProps(child.props, child.ref));
  }
  const hasAriaLabel = !!ariaLabel;
  const _tooltipProps = tooltip.getTooltipProps({}, ref);
  const tooltipProps = hasAriaLabel ? objectUtils.omit(_tooltipProps, ["role", "id"]) : _tooltipProps;
  const srOnlyProps = objectUtils.pick(_tooltipProps, ["role", "id"]);
  if (!label) {
    return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
  }
  const arrowStyles = {
    mt: props.placement === "top" ? "2.4px" : void 0,
    borderRight: props.placement === "top" ? "2px solid" : void 0,
    borderColor: props.placement === "top" ? "darkblue.600 !important" : void 0,
    // Needs !important to override PopperJS
    borderBottom: props.placement === "top" ? "2px solid" : void 0,
    boxShadow: props.placement === "top" ? "3px 1px 0px 0px var(--chakra-colors-gray-200) !important" : void 0
    // Needs !important to override PopperJS
  };
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
    trigger,
    /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { children: tooltip.isOpen && /* @__PURE__ */ jsxRuntime.jsx(portal.Portal, __spreadProps(__spreadValues({}, portalProps), { children: /* @__PURE__ */ jsxRuntime.jsx(
      system.chakra.div,
      __spreadProps(__spreadValues({}, tooltip.getTooltipPositionerProps()), {
        __css: {
          zIndex: styles.zIndex,
          pointerEvents: "none"
        },
        children: /* @__PURE__ */ jsxRuntime.jsxs(
          MotionDiv,
          __spreadProps(__spreadValues(__spreadValues({
            variants: chakraTooltip_transition.scale,
            initial: "exit",
            animate: "enter",
            exit: "exit"
          }, motionProps), tooltipProps), {
            __css: styles,
            children: [
              label,
              hasAriaLabel && /* @__PURE__ */ jsxRuntime.jsx(system.chakra.span, __spreadProps(__spreadValues({ srOnly: true }, srOnlyProps), { children: ariaLabel })),
              hasArrow && /* @__PURE__ */ jsxRuntime.jsx(system.chakra.div, { "data-popper-arrow": true, className: "chakra-tooltip__arrow-wrapper", children: /* @__PURE__ */ jsxRuntime.jsx(
                system.chakra.div,
                __spreadProps(__spreadValues({
                  "data-popper-arrow-inner": true,
                  className: "chakra-tooltip__arrow"
                }, arrowStyles), {
                  __css: { bg: styles.bg }
                })
              ) })
            ]
          })
        )
      })
    ) })) })
  ] });
});
ChakraTooltip.displayName = "Tooltip";

exports.ChakraTooltip = ChakraTooltip;
//# sourceMappingURL=ChakraTooltip.cjs.map
