import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import React__default, { useCallback } from 'react';
import { CheckIcon } from '@heroicons/react/24/outline';
import { cn } from '../../../utils/cn.js';
import { useContextMenuContext } from './ContextMenuContext.js';
import { MenuItem } from '../MenuItem/MenuItem.js';

/**
 * ContextMenuItem - Individual menu item with optional check indicator.
 * Built on shared MenuItem, adds checked state and ContextMenu context integration.
 */
const ContextMenuItem = React__default.forwardRef(({ children, className, checked = false, disabled = false, isDanger = false, shortcut, onSelect, startContent, endContent, subtitle, ...props }, ref) => {
    const { onOpenChange, theme } = useContextMenuContext();
    const handleActivate = useCallback(() => {
        if (disabled)
            return;
        onSelect === null || onSelect === void 0 ? void 0 : onSelect();
        onOpenChange(false);
    }, [disabled, onSelect, onOpenChange]);
    // Combine checked icon with startContent (CheckIcon uses absolute positioning)
    const hasPrefix = checked || !!startContent;
    const resolvedStartContent = hasPrefix ? (jsxs(Fragment, { children: [checked && (jsx(CheckIcon, { className: theme.itemCheckedStyle, "aria-hidden": "true" })), startContent] })) : undefined;
    // Build end content: user's endContent OR shortcut display
    const resolvedEndContent = endContent ||
        (shortcut ? (jsx("span", { className: "text-sm text-[var(--color-text-muted)] font-mono", children: shortcut })) : undefined);
    return (jsx(MenuItem, { ref: ref, role: "menuitem", disabled: disabled, isDanger: isDanger, startContent: resolvedStartContent, endContent: resolvedEndContent, subtitle: subtitle, onActivate: handleActivate, "data-checked": checked, "aria-checked": checked ? "true" : undefined, className: cn(checked && "pl-8", className), theme: {
            baseStyle: theme.itemStyle,
            dangerStyle: theme.itemDangerStyle,
            focusStyle: theme.itemFocusStyle,
        }, ...props, children: children }));
});
ContextMenuItem.displayName = "ContextMenuItem";

export { ContextMenuItem };
