'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var index = require('./index-BZhTddX0.js');
var utils = require('./utils-CTr7wn5d.js');
var primitives_HoverCard = require('./primitives/HoverCard.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.5", {
    variants: {
        variant: {
            default: "",
            primary: "bg-primary text-primary-foreground ring-0 shadow-lg",
        },
    },
    defaultVariants: {
        variant: "default",
    },
});
const Title = React.forwardRef(({ children, className, ...otherProps }, ref) => (jsxRuntime.jsx("div", { ref: ref, "data-slot": "popover-title", className: utils.cn("text-sm font-semibold", className), ...otherProps, children: 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) => {
    // Internal state for uncontrolled mode + hideAfter
    const [internalOpen, setInternalOpen] = React.useState(false);
    const isControlled = openProp !== undefined;
    const open = isControlled ? openProp : internalOpen;
    const handleOpenChange = React.useCallback((next) => {
        if (!isControlled)
            setInternalOpen(next);
        onOpenChangeProp?.(next);
    }, [isControlled, onOpenChangeProp]);
    // Auto-hide after hideAfter ms
    React.useEffect(() => {
        if (!open || hideAfter <= 0)
            return;
        const timer = setTimeout(() => handleOpenChange(false), hideAfter);
        return () => clearTimeout(timer);
    }, [open, hideAfter, handleOpenChange]);
    if (disabled) {
        return jsxRuntime.jsx(jsxRuntime.Fragment, { children: trigger });
    }
    const side = SIDE_MAP[position] ?? "bottom";
    const align = ALIGN_MAP[position] ?? "center";
    // Wrap non-element trigger in a span
    const triggerElement = React__default.default.isValidElement(trigger) ? (trigger) : (jsxRuntime.jsx("span", { children: trigger }));
    return (jsxRuntime.jsxs(primitives_HoverCard.HoverCard, { open: open, onOpenChange: handleOpenChange, defaultOpen: defaultOpen, openDelay: openDelay, closeDelay: closeDelay, children: [jsxRuntime.jsx(primitives_HoverCard.HoverCardTrigger, { asChild: true, children: triggerElement }), jsxRuntime.jsx(primitives_HoverCard.HoverCardContent, { ref: ref, side: side, align: align, className: utils.cn(popoverVariants({ variant }), className), ...contentProps, children: children })] }));
});
Popover.displayName = "Popover";
Popover.Title = Title;

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