'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var index = require('./index-vioSzJOw.js');
var utils = require('./utils-BhM0B89p.js');
var primitives_HoverCard = require('./primitives/HoverCard.js');
var Typography = require('./Typography-BW6xEk10.js');

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

var React__default = /*#__PURE__*/_interopDefault(React);

const SIDE_MAP = {
  top: "top",
  bottom: "bottom",
  left: "left",
  right: "right",
  "top-start": "top",
  "top-end": "top",
  "bottom-start": "bottom",
  "bottom-end": "bottom",
  "left-start": "left",
  "left-end": "left",
  "right-start": "right",
  "right-end": "right",
  auto: "bottom"
};
const ALIGN_MAP = {
  top: "center",
  bottom: "center",
  left: "center",
  right: "center",
  "top-start": "start",
  "top-end": "end",
  "bottom-start": "start",
  "bottom-end": "end",
  "left-start": "start",
  "left-end": "end",
  "right-start": "start",
  "right-end": "end",
  auto: "center"
};

const popoverVariants = index.cva("flex flex-col gap-2 p-4", {
  variants: {
    variant: {
      default: "",
      primary: "bg-primary text-primary-foreground ring-0 shadow-lg"
    }
  },
  defaultVariants: {
    variant: "default"
  }
});
const Title = React.forwardRef(
  ({ children, className, ...otherProps }, ref) => /* @__PURE__ */ jsxRuntime.jsx(Typography.Typography, { variant: "body2", weight: "semibold", color: "inherit", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
    "div",
    {
      ref,
      "data-slot": "popover-title",
      className,
      ...otherProps,
      children
    }
  ) })
);
Title.displayName = "Popover.Title";
const Popover = React.forwardRef(
  ({
    children,
    trigger,
    variant = "default",
    disabled = false,
    position = "auto",
    className,
    open: openProp,
    onOpenChange: onOpenChangeProp,
    hideAfter = -1,
    defaultOpen,
    openDelay = 200,
    closeDelay = 200,
    // Radix HoverCardContent props forwarded
    ...contentProps
  }, ref) => {
    const [internalOpen, setInternalOpen] = React.useState(false);
    const isControlled = openProp !== void 0;
    const open = isControlled ? openProp : internalOpen;
    const handleOpenChange = React.useCallback(
      (next) => {
        if (!isControlled) setInternalOpen(next);
        onOpenChangeProp?.(next);
      },
      [isControlled, onOpenChangeProp]
    );
    React.useEffect(() => {
      if (!open || hideAfter <= 0) return;
      const timer = setTimeout(() => handleOpenChange(false), hideAfter);
      return () => clearTimeout(timer);
    }, [open, hideAfter, handleOpenChange]);
    if (disabled) {
      return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: trigger });
    }
    const side = SIDE_MAP[position] ?? "bottom";
    const align = ALIGN_MAP[position] ?? "center";
    const triggerElement = React__default.default.isValidElement(trigger) ? trigger : /* @__PURE__ */ jsxRuntime.jsx("span", { children: trigger });
    return /* @__PURE__ */ jsxRuntime.jsxs(
      primitives_HoverCard.HoverCard,
      {
        open,
        onOpenChange: handleOpenChange,
        defaultOpen,
        openDelay,
        closeDelay,
        children: [
          /* @__PURE__ */ jsxRuntime.jsx(primitives_HoverCard.HoverCardTrigger, { asChild: true, children: triggerElement }),
          /* @__PURE__ */ jsxRuntime.jsx(
            primitives_HoverCard.HoverCardContent,
            {
              ref,
              side,
              align,
              className: utils.cn(popoverVariants({ variant }), className),
              ...contentProps,
              children
            }
          )
        ]
      }
    );
  }
);
Popover.displayName = "Popover";
Popover.Title = Title;

exports.Popover = Popover;
//# sourceMappingURL=Popover-DuRSsDHz.js.map
