import * as TooltipPrimitive from '@radix-ui/react-tooltip';
import { useRef, useState, useLayoutEffect } from 'react';
import { extendTailwindMerge } from 'tailwind-merge';
import { get, pick, omit } from 'lodash-es';
import { createClassed } from '@tw-classed/react';
import { createClassed as createClassed$1 } from '@tw-classed/core';
import 'clsx';
import createVariatGroupTransfomer from 'tailwind-group-variant';
import { getByPath as getByPath$1 } from '@clickbar/dot-diver';
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
import InformationCircleIcon from '@heroicons/react/24/outline/InformationCircleIcon';

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

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

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

// 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 getByPath$1(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, ...pick(props, pickedKeys) };
  };
  pickerFn.pickedKeys = pickedKeys;
  pickerFn.pickedRecord = pickedRecord;
  pickerFn.omit = (props) => 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 = 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] = useState(
    void 0
  );
  useLayoutEffect(() => {
    queueMicrotask(() => {
      const el = getElement(element);
      const colorScheme = getNearestColorSchemeAttribute(el);
      setColorSchemeAttribute(colorScheme);
    });
  }, [element]);
  return colorSchemeAttribute;
}
var TooltipContentElement = classed(
  TooltipPrimitive.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 = 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__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(TooltipPrimitive.Root, { delayDuration: 100, ...tooltipRootProps, children: [
    /* @__PURE__ */ jsx(TooltipPrimitive.Trigger, { asChild: triggerAsChild, ref: triggerRef, ...triggerProps, children }),
    /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsx(TooltipContent2, { colorScheme: colorSchemeAttribute, ...tooltipContentProps, children: tooltip }) })
  ] }) });
};
var TooltipContent2 = ({
  children,
  colorScheme,
  onTooltipClick,
  stopPropogation,
  side = "bottom",
  asChild,
  ...contentProps
}) => {
  return /* @__PURE__ */ 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.Provider;
Tooltip.Root = TooltipPrimitive.Root;
Tooltip.Trigger = TooltipPrimitive.Trigger;
Tooltip.Portal = TooltipPrimitive.Portal;
Tooltip.PrimitiveContent = TooltipPrimitive.Content;
Tooltip.Content = TooltipContent2;
var InfoIconElement = classed(
  InformationCircleIcon,
  "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__ */ jsx(Tooltip, { tooltip, ...tooltipProps, children: /* @__PURE__ */ jsx(
    IconButtonElement,
    {
      type: "button",
      onClick: (e) => {
        e.stopPropagation();
      },
      ...props,
      children: /* @__PURE__ */ jsx(InfoIconElement, { className: iconClassName })
    }
  ) });
};

export { InfoTooltipIcon, Tooltip, TooltipContent2 as TooltipContent };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map