'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var primitives_DropdownMenu = require('../primitives/DropdownMenu.js');
var reactI18next = require('react-i18next');
var utils = require('../utils-CTr7wn5d.js');
var renderIcon = require('../renderIcon-fLF3odqg.js');
var primitives_Button = require('../primitives/Button.js');
var primitives_ButtonGroup = require('../primitives/ButtonGroup.js');
var chevronDown = require('../chevron-down-CPsWSS51.js');
require('../chevron-right-0jNdwX2Q.js');
require('../createLucideIcon-D0tRgV6l.js');
require('../check-BQgcDXys.js');
require('../index-COPkC3I5.js');
require('../index-D-iDn9RI.js');
require('../index-CGUGhyIp.js');
require('../index-CyrAgb4H.js');
require('../index-CCdG4z4E.js');
require('../index-DMbj7vXd.js');
require('react-dom');
require('../index-D1SiRLYs.js');
require('../index-Ch55j1or.js');
require('../index-BY6wgiQV.js');
require('../index-Bvu9MiFi.js');
require('../index-lWVw05cs.js');
require('../index-ChSOMM8b.js');
require('../index-BwAq9ba8.js');
require('../index-C9ICrOhM.js');
require('../floating-ui.react-dom-B4Aw6O7R.js');
require('../index-Bf0WsHta.js');
require('../index-Df-Ffa3s.js');
require('../index-DcCSSgb7.js');
require('../index-DoVhdseB.js');
require('../button--P7-oIJb.js');
require('../index-BZhTddX0.js');
require('../index-DuNgWCXZ.js');
require('../separator-CPy2gyg1.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: "end",
};
const BUTTON_STYLE_MAP = {
    primary: "default",
    secondary: "secondary",
    tertiary: "outline",
    text: "ghost",
    danger: "destructive",
    "danger-text": "ghost",
    link: "link",
};
const BUTTON_SIZE_MAP = {
    small: "sm",
    medium: "default",
    large: "lg",
};
const MENU_ITEM_STYLE_MAP = {
    default: "default",
    danger: "destructive",
};
const CHEVRON_SIZE_MAP = {
    small: "size-3.5",
    medium: "size-4",
    large: "size-4",
};

const SplitTrigger = React.forwardRef(({ label, icon, buttonStyle, buttonSize, buttonProps, disabled, isOpen, onClick, actionButtonRef, className, ...otherProps }, ref) => {
    const { t } = reactI18next.useTranslation();
    const variant = BUTTON_STYLE_MAP[buttonStyle];
    const size = BUTTON_SIZE_MAP[buttonSize];
    return (jsxRuntime.jsxs(primitives_ButtonGroup.ButtonGroup, { ref: ref, className: utils.cn("neeto-ui-action-dropdown", className), ...otherProps, children: [jsxRuntime.jsxs(primitives_Button.Button, { ref: actionButtonRef, type: "button", variant: variant, size: size, disabled: disabled, onClick: onClick, "data-testid": "action-dropdown-btn", ...buttonProps, children: [icon && renderIcon.renderIcon(icon, "size-4"), label && jsxRuntime.jsx("span", { children: label })] }), jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuTrigger, { asChild: true, disabled: disabled, children: jsxRuntime.jsx(primitives_Button.Button, { type: "button", variant: variant, size: size, disabled: disabled, "aria-label": t("neetoatoms.dropdownMenu.openMenu", "Open dropdown menu"), className: "px-1.5", children: jsxRuntime.jsx(chevronDown.ChevronDown, { "aria-hidden": "true", className: utils.cn(CHEVRON_SIZE_MAP[buttonSize], "shrink-0 transition-transform duration-200", isOpen && "rotate-180") }) }) })] }));
});
SplitTrigger.displayName = "Dropdown.SplitTrigger";

const TriggerButton = React.forwardRef(({ label, icon, buttonStyle, buttonSize, buttonProps, disabled, isOpen, onClick, className, ...otherProps }, ref) => (jsxRuntime.jsx(primitives_Button.Button, { ref: ref, type: "button", variant: BUTTON_STYLE_MAP[buttonStyle], size: BUTTON_SIZE_MAP[buttonSize], disabled: disabled, className: utils.cn(buttonStyle === "danger-text" &&
        "text-destructive hover:text-destructive", "gap-1.5", className), onClick: onClick, ...otherProps, ...buttonProps, children: jsxRuntime.jsxs("span", { className: "inline-flex items-center gap-1.5", children: [icon && renderIcon.renderIcon(icon, "size-4"), label && jsxRuntime.jsx("span", { children: label }), jsxRuntime.jsx(chevronDown.ChevronDown, { "aria-hidden": "true", className: utils.cn(CHEVRON_SIZE_MAP[buttonSize], "shrink-0 transition-transform duration-200", isOpen && "rotate-180") })] }) })));
TriggerButton.displayName = "Dropdown.TriggerButton";

const DropdownContext = React.createContext({ closeOnSelect: true });

const DropdownBase = ({ label, icon, buttonStyle = "primary", buttonSize = "medium", buttonProps, customTarget, disabled = false, children, position = "bottom-end", closeOnEsc = true, closeOnSelect = true, closeOnOutsideClick = true, isOpen: isOpenProp, onClose, onClick, className, triggerRef, dropdownProps, }) => {
    const [internalOpen, setInternalOpen] = React.useState(false);
    const isControlled = isOpenProp !== undefined;
    const open = isControlled ? isOpenProp : internalOpen;
    const handleOpenChange = React.useCallback((next) => {
        if (!isControlled)
            setInternalOpen(next);
        if (!next)
            onClose?.();
    }, [isControlled, onClose]);
    const side = SIDE_MAP[position] ?? "bottom";
    const align = ALIGN_MAP[position] ?? "end";
    // Split-button mode: onClick provided without a customTarget.
    const isSplit = !!onClick && !customTarget;
    const sharedTriggerProps = {
        label,
        icon,
        buttonStyle,
        buttonSize,
        buttonProps,
        disabled,
        isOpen: open,
        onClick,
    };
    const triggerNode = isSplit ? (jsxRuntime.jsx(SplitTrigger, { ...sharedTriggerProps, actionButtonRef: triggerRef, className: className })) : (jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuTrigger, { asChild: true, disabled: disabled, className: className, children: customTarget ? (typeof customTarget === "function" ? (customTarget({ isOpen: open })) : (customTarget)) : (jsxRuntime.jsx(TriggerButton, { ref: triggerRef, ...sharedTriggerProps })) }));
    return (jsxRuntime.jsx(DropdownContext.Provider, { value: { closeOnSelect }, children: jsxRuntime.jsxs(primitives_DropdownMenu.DropdownMenu, { open: open, onOpenChange: handleOpenChange, modal: closeOnOutsideClick, children: [triggerNode, jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuContent, { side: side, align: align, onEscapeKeyDown: closeOnEsc ? undefined : e => e.preventDefault(), onInteractOutside: closeOnOutsideClick ? undefined : e => e.preventDefault(), ...dropdownProps, children: children })] }) }));
};

const Divider = React.forwardRef((props, ref) => jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuSeparator, { ref: ref, ...props }));
Divider.displayName = "Dropdown.Divider";

const Label = React.forwardRef(({ children, className, ...otherProps }, ref) => (jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuLabel, { ref: ref, className: className, ...otherProps, children: children })));
Label.displayName = "Dropdown.Label";

const Menu = React.forwardRef(({ children, className, ...otherProps }, ref) => (jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuGroup, { ref: ref, className: utils.cn("flex flex-col", className), ...otherProps, children: children })));
Menu.displayName = "Dropdown.Menu";

const MenuItemButton = React.forwardRef(({ children, isActive = false, isDisabled = false, style = "default", prefix, suffix, to, href, className, onClick, variant: _variant, disabled: _disabled, asChild: _asChild, onSelect: _onSelect, ...otherProps }, ref) => {
    const { closeOnSelect } = React.useContext(DropdownContext);
    const variant = MENU_ITEM_STYLE_MAP[style];
    const linkHref = to ?? href;
    const handleSelect = React.useCallback((e) => {
        if (!closeOnSelect)
            e.preventDefault();
        onClick?.(e);
    }, [closeOnSelect, onClick]);
    const itemContent = React.useMemo(() => (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [prefix && (jsxRuntime.jsx("span", { "data-slot": "menu-item-prefix", className: "shrink-0", children: prefix })), jsxRuntime.jsx("span", { className: "flex-1 truncate", children: children }), suffix && (jsxRuntime.jsx("span", { "data-slot": "menu-item-suffix", className: "ms-auto shrink-0 text-muted-foreground", children: suffix }))] })), [prefix, children, suffix]);
    return (jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuItem, { ref: ref, variant: variant, disabled: isDisabled, "data-active": isActive || undefined, className: utils.cn(isActive && "bg-accent text-accent-foreground", className), asChild: !!linkHref, onSelect: handleSelect, ...otherProps, children: linkHref ? jsxRuntime.jsx("a", { href: linkHref, children: itemContent }) : itemContent }));
});
MenuItemButton.displayName = "Dropdown.MenuItem.Button";

const MenuItem = React.forwardRef(({ children, ...otherProps }, ref) => (jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuItem, { ref: ref, ...otherProps, children: children })));
MenuItem.displayName = "Dropdown.MenuItem";
MenuItem.Button = MenuItemButton;

const SubMenu = React.forwardRef(({ label, icon, children, className, triggerProps, contentProps }, ref) => (jsxRuntime.jsxs(primitives_DropdownMenu.DropdownMenuSub, { children: [jsxRuntime.jsxs(primitives_DropdownMenu.DropdownMenuSubTrigger, { ref: ref, className: className, ...triggerProps, children: [icon && jsxRuntime.jsx("span", { className: "shrink-0", children: renderIcon.renderIcon(icon, "size-4") }), label && jsxRuntime.jsx("span", { children: label })] }), jsxRuntime.jsx(primitives_DropdownMenu.DropdownMenuSubContent, { ...contentProps, children: children })] })));
SubMenu.displayName = "Dropdown.SubMenu";

const DropdownMenu = DropdownBase;
DropdownMenu.displayName = "DropdownMenu";
DropdownMenu.Menu = Menu;
DropdownMenu.MenuItem = MenuItem;
DropdownMenu.Divider = Divider;
DropdownMenu.Label = Label;
DropdownMenu.SubMenu = SubMenu;

exports.DropdownMenu = DropdownMenu;
//# sourceMappingURL=DropdownMenu.js.map
