import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
import React__default, { forwardRef, useState, useCallback, useEffect } from 'react';
import { c as cva } from './index-D7Zy7P05.js';
import { c as cn } from './utils-DdHUxIdC.js';
import { T as Typography } from './Typography-ClPJbLjP.js';
import { HoverCard, HoverCardTrigger, HoverCardContent } from './primitives/HoverCard.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) => (jsx(Typography, { variant: "body2", weight: "semibold", color: "inherit", asChild: true, children: jsx("div", { ref: ref, "data-slot": "popover-title", className: className, ...otherProps, children: 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) => {
    // Internal state for uncontrolled mode + hideAfter
    const [internalOpen, setInternalOpen] = useState(false);
    const isControlled = openProp !== undefined;
    const open = isControlled ? openProp : internalOpen;
    const handleOpenChange = useCallback((next) => {
        if (!isControlled)
            setInternalOpen(next);
        onOpenChangeProp?.(next);
    }, [isControlled, onOpenChangeProp]);
    // Auto-hide after hideAfter ms
    useEffect(() => {
        if (!open || hideAfter <= 0)
            return;
        const timer = setTimeout(() => handleOpenChange(false), hideAfter);
        return () => clearTimeout(timer);
    }, [open, hideAfter, handleOpenChange]);
    if (disabled) {
        return jsx(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.isValidElement(trigger) ? (trigger) : (jsx("span", { children: trigger }));
    return (jsxs(HoverCard, { open: open, onOpenChange: handleOpenChange, defaultOpen: defaultOpen, openDelay: openDelay, closeDelay: closeDelay, children: [jsx(HoverCardTrigger, { asChild: true, children: triggerElement }), jsx(HoverCardContent, { ref: ref, side: side, align: align, className: cn(popoverVariants({ variant }), className), ...contentProps, children: children })] }));
});
Popover.displayName = "Popover";
Popover.Title = Title;

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