'use strict';

var TooltipPrimitive = require('@radix-ui/react-tooltip');
var react$1 = require('react');
var tailwindMerge = require('tailwind-merge');
var lodashEs = require('lodash-es');
var react = require('@tw-classed/react');
var core = require('@tw-classed/core');
require('clsx');
var createVariatGroupTransfomer = require('tailwind-group-variant');
var dotDiver = require('@clickbar/dot-diver');
var jsxRuntime = require('react/jsx-runtime');
var InformationCircleIcon = require('@heroicons/react/24/outline/InformationCircleIcon');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

function _interopNamespace(e) {
  if (e && e.__esModule) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var TooltipPrimitive__namespace = /*#__PURE__*/_interopNamespace(TooltipPrimitive);
var createVariatGroupTransfomer__default = /*#__PURE__*/_interopDefault(createVariatGroupTransfomer);
var InformationCircleIcon__default = /*#__PURE__*/_interopDefault(InformationCircleIcon);

// src/components/Tooltip/Tooltip.tsx
var twMerge = tailwindMerge.extendTailwindMerge({
  classGroups: {
    "font-size": [
      {
        // Fixes incorect merging of text size
        text: ["h1", "h2", "h3", "h4", "h5", "h6"]
      }
    ]
  }
});
var { classed } = react.createClassed({ merger: twMerge });
core.createClassed({ merger: twMerge });

// src/utils/notEmpty.ts
function notEmpty(value) {
  return value !== null && value !== void 0;
}

// src/utils/classed/expandVariant.ts
createVariatGroupTransfomer__default.default({});

// src/utils/environment-utils.ts
function isClientSide() {
  return typeof window !== "undefined";
}
function isDevelopment() {
  if (typeof window === "undefined" && typeof process !== "undefined" && process.env.NODE_ENV === "development") {
    return true;
  }
  if (typeof window !== "undefined" && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1")) {
    return true;
  }
  return false;
}
function getByPath(object, path, _maxDepth) {
  return dotDiver.getByPath(object, path);
}

// src/utils/objectMap.ts
function objectMap(obj, fn) {
  return Object.fromEntries(
    Object.entries(obj).map(([k, v], index) => fn({ key: k, value: v, index, get: getByPath })).filter(notEmpty)
  );
}

// src/utils/pickProps.ts
function generatePropPickerFn(pickedRecord) {
  const pickedKeys = Object.keys(pickedRecord);
  const pickerFn = (props, options) => {
    const { defaultProps } = options ?? {};
    return { ...defaultProps, ...lodashEs.pick(props, pickedKeys) };
  };
  pickerFn.pickedKeys = pickedKeys;
  pickerFn.pickedRecord = pickedRecord;
  pickerFn.omit = (props) => lodashEs.omit(props, pickedKeys);
  return pickerFn;
}
var NO_DEFAULT_VALUE = "_pick_";
function pickProps(props, pickedProps, options) {
  const { shouldValidatePickProp = true } = options ?? {};
  const entries = Object.entries(pickedProps).map(([path, defaultValue]) => {
    const prop = lodashEs.get(props, path);
    if (defaultValue === NO_DEFAULT_VALUE) {
      return [path, prop];
    }
    if (shouldValidatePickProp) {
      validatePickProp(defaultValue, pickedProps);
    }
    return [path, prop ?? defaultValue];
  });
  return Object.fromEntries(entries);
}
function validatePickProp(input, pickedProps) {
  if (isDevelopment()) {
    const startsWith = ["_p", "pick"];
    const isLikelyTypo = typeof input === "string" && startsWith.some((typo) => input.startsWith(typo));
    if (isLikelyTypo) {
      const functionName = "`pickProps`";
      throw new Error(`
      Error thrown from ${functionName}
      
      A possible typo was detected in the arguments passed to the ${functionName} function.

      Expected value: "${NO_DEFAULT_VALUE}"

      Received value: "${input}" \u274C

      ${JSON.stringify(
        objectMap(pickedProps, ({ key, value }) => [
          key,
          value === input ? `${value} \u274C` : value
        ]),
        null,
        2
      )}
 
      If this is intended, add \`shouldValidatePickProp: true\` to the options.

      Note: This error is thrown only during development.

      `);
    }
  }
}

// src/utils/getElement.ts
function getElement(elementOrRef) {
  if (!elementOrRef)
    return void 0;
  if (elementOrRef instanceof HTMLElement || elementOrRef instanceof Element) {
    return elementOrRef;
  }
  return elementOrRef.current;
}

// src/utils/getNearestColorSchemeAttribute.ts
function getNearestColorSchemeAttribute(element, fallback = "default") {
  if (!isClientSide() || !element)
    return fallback;
  const nearestScheme = element.closest("[data-color-scheme]")?.getAttribute("data-color-scheme");
  return nearestScheme ?? fallback;
}

// src/hooks/useNearestColorSchemeAttribute.tsx
function useNearestColorSchemeAttribute({
  element
}) {
  const [colorSchemeAttribute, setColorSchemeAttribute] = react$1.useState(
    void 0
  );
  react$1.useLayoutEffect(() => {
    queueMicrotask(() => {
      const el = getElement(element);
      const colorScheme = getNearestColorSchemeAttribute(el);
      setColorSchemeAttribute(colorScheme);
    });
  }, [element]);
  return colorSchemeAttribute;
}
var TooltipContentElement = classed(
  TooltipPrimitive__namespace.TooltipContent,
  "radix-side-top:animate-slide-down-fade",
  "radix-side-right:animate-slide-left-fade",
  "radix-side-bottom:animate-slide-up-fade",
  "radix-side-left:animate-slide-right-fade",
  "inline-flex items-center py-8 px-10",
  "text-sm font-body",
  "rounded",
  "bg-surface-soft text-content-strong",
  "ring-1 ring-inset ring-content-tint",
  "z-50 relative",
  {
    variants: {
      size: {
        xs: "text-xs py-2 px-4",
        sm: "text-sm py-4 px-6",
        md: "text-md py-6 px-8",
        lg: "text-lg py-4 px-12"
      },
      maxWidth: {
        false: "",
        xs: "max-w-[20ch]",
        sm: "max-w-[30ch]",
        md: "max-w-[38ch]",
        lg: "max-w-[65ch]"
      },
      selectNone: {
        true: "select-none"
      }
    },
    defaultVariants: {
      maxWidth: "md",
      selectNone: true
    }
  }
);
var pickTooltipContentProps = generatePropPickerFn({
  style: "_pick_",
  className: "_pick_",
  "aria-label": "_pick_",
  size: "_pick_",
  align: "_pick_",
  maxWidth: "_pick_",
  selectNone: "_pick_",
  side: "_pick_",
  sideOffset: "_pick_",
  alignOffset: "_pick_",
  arrowPadding: "_pick_",
  collisionBoundary: "_pick_",
  collisionPadding: "_pick_",
  sticky: "_pick_",
  hideWhenDetached: "_pick_",
  avoidCollisions: "_pick_",
  stopPropogation: "_pick_",
  onTooltipClick: "_pick_"
});
var Tooltip = (props) => {
  const triggerRef = react$1.useRef(null);
  const colorSchemeAttribute = useNearestColorSchemeAttribute({ element: triggerRef });
  const { children, tooltip, triggerProps, triggerAsChild } = pickProps(props, {
    triggerAsChild: true,
    children: "_pick_",
    tooltip: "_pick_",
    triggerProps: {},
    forceMount: "_pick_"
  });
  const tooltipContentProps = pickTooltipContentProps(props);
  const tooltipRootProps = pickProps(props, {
    defaultOpen: "_pick_",
    open: "_pick_",
    onOpenChange: "_pick_",
    delayDuration: "_pick_",
    disableHoverableContent: "_pick_"
  });
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsxs(TooltipPrimitive__namespace.Root, { delayDuration: 100, ...tooltipRootProps, children: [
    /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Trigger, { asChild: triggerAsChild, ref: triggerRef, ...triggerProps, children }),
    /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(TooltipContent2, { colorScheme: colorSchemeAttribute, ...tooltipContentProps, children: tooltip }) })
  ] }) });
};
var TooltipContent2 = ({
  children,
  colorScheme,
  onTooltipClick,
  stopPropogation,
  side = "bottom",
  asChild,
  ...contentProps
}) => {
  return /* @__PURE__ */ jsxRuntime.jsx(
    TooltipContentElement,
    {
      size: "md",
      side,
      sideOffset: 4,
      collisionPadding: 4,
      alignOffset: 4,
      "data-color-scheme": colorScheme,
      asChild,
      ...contentProps,
      onClick: (e) => {
        if (stopPropogation) {
          e.stopPropagation();
        }
        onTooltipClick?.(e);
      },
      children
    }
  );
};
Tooltip.Provider = TooltipPrimitive__namespace.Provider;
Tooltip.Root = TooltipPrimitive__namespace.Root;
Tooltip.Trigger = TooltipPrimitive__namespace.Trigger;
Tooltip.Portal = TooltipPrimitive__namespace.Portal;
Tooltip.PrimitiveContent = TooltipPrimitive__namespace.Content;
Tooltip.Content = TooltipContent2;
var InfoIconElement = classed(
  InformationCircleIcon__default.default,
  "rounded-full min-w-[24px] min-h-[24px] h-full w-full"
);
var IconButtonElement = classed("button", "focus:ring-boundary-tint rounded-full");
var InfoTooltipIcon = ({
  iconClassName,
  size,
  onClick,
  tooltipProps,
  tooltip,
  hideWhenTooltipIsEmpty = true,
  ...props
}) => {
  if (hideWhenTooltipIsEmpty && !tooltip)
    return null;
  return /* @__PURE__ */ jsxRuntime.jsx(Tooltip, { tooltip, ...tooltipProps, children: /* @__PURE__ */ jsxRuntime.jsx(
    IconButtonElement,
    {
      type: "button",
      onClick: (e) => {
        e.stopPropagation();
      },
      ...props,
      children: /* @__PURE__ */ jsxRuntime.jsx(InfoIconElement, { className: iconClassName })
    }
  ) });
};

exports.InfoTooltipIcon = InfoTooltipIcon;
exports.Tooltip = Tooltip;
exports.TooltipContent = TooltipContent2;
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.cjs.map