import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
import React__default, { forwardRef, useState, useCallback, useEffect } from 'react';
import { c as cva } from './index-Bo3AAQJp.js';
import { c as cn } from './utils-BJnb9o5c.js';
import { HoverCard, HoverCardTrigger, HoverCardContent } from './primitives/HoverCard.js';
import { T as Typography } from './Typography-CiQzW5Fy.js';

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 = 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 = forwardRef(
  ({ children, className, ...otherProps }, ref) => /* @__PURE__ */ jsx(Typography, { variant: "body2", weight: "semibold", color: "inherit", asChild: true, children: /* @__PURE__ */ jsx(
    "div",
    {
      ref,
      "data-slot": "popover-title",
      className,
      ...otherProps,
      children
    }
  ) })
);
Title.displayName = "Popover.Title";
const Popover = 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] = useState(false);
    const isControlled = openProp !== void 0;
    const open = isControlled ? openProp : internalOpen;
    const handleOpenChange = useCallback(
      (next) => {
        if (!isControlled) setInternalOpen(next);
        onOpenChangeProp?.(next);
      },
      [isControlled, onOpenChangeProp]
    );
    useEffect(() => {
      if (!open || hideAfter <= 0) return;
      const timer = setTimeout(() => handleOpenChange(false), hideAfter);
      return () => clearTimeout(timer);
    }, [open, hideAfter, handleOpenChange]);
    if (disabled) {
      return /* @__PURE__ */ jsx(Fragment, { children: trigger });
    }
    const side = SIDE_MAP[position] ?? "bottom";
    const align = ALIGN_MAP[position] ?? "center";
    const triggerElement = React__default.isValidElement(trigger) ? trigger : /* @__PURE__ */ jsx("span", { children: trigger });
    return /* @__PURE__ */ jsxs(
      HoverCard,
      {
        open,
        onOpenChange: handleOpenChange,
        defaultOpen,
        openDelay,
        closeDelay,
        children: [
          /* @__PURE__ */ jsx(HoverCardTrigger, { asChild: true, children: triggerElement }),
          /* @__PURE__ */ jsx(
            HoverCardContent,
            {
              ref,
              side,
              align,
              className: cn(popoverVariants({ variant }), className),
              ...contentProps,
              children
            }
          )
        ]
      }
    );
  }
);
Popover.displayName = "Popover";
Popover.Title = Title;

export { Popover as P };
//# sourceMappingURL=Popover-Cco_6txS.js.map
