"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import { forwardRef } from "react";
import { getIcon } from "../icon/config.js";
import { useEnsuredId } from "../useEnsuredId.js";
import { MenuItem } from "./MenuItem.js";
const noop = ()=>{
// do nothing
};
/**
 * **Client Component**
 *
 * A wrapper for the `<input type="file">` element that works within menus.
 *
 * @see {@link https://react-md.dev/components/menu#menuitemfileinput-example | DropdownMenu Demos}
 * @since 5.0.0
 * @since 6.0.0 No longer creates an invisible file input element within the
 * menu item. This allows the menu to be closed immediately when this menu item
 * is clicked.
 */ export const MenuItemFileInput = /*#__PURE__*/ forwardRef(function MenuItemFileInput(props, ref) {
    const { id: propId, onClick = noop, onChange, accept, capture, multiple, children, leftAddon: propLeftAddon, preventMenuHideOnClick = false, ...remaining } = props;
    const id = useEnsuredId(propId, "menu-item");
    const leftAddon = getIcon("upload", propLeftAddon);
    return /*#__PURE__*/ _jsx(MenuItem, {
        ...remaining,
        id: id,
        ref: ref,
        leftAddon: leftAddon,
        onClick: (event)=>{
            onClick(event);
            if (preventMenuHideOnClick) {
                event.stopPropagation();
            }
            // Since the menu closes when the menu item is clicked causing the
            // elements to be removed from the DOM, a normal `<input type="file" />`
            // can't be used. Instead, create a temporary file input element and
            // click it to trigger the file upload behavior.
            let input = document.createElement("input");
            input.type = "file";
            if (accept) {
                input.accept = accept;
            }
            if (multiple) {
                input.multiple = multiple;
            }
            if (capture) {
                input.capture = capture === true ? "" : capture;
            }
            // eslint-disable-next-line @typescript-eslint/ban-ts-comment
            // @ts-expect-error
            input.onchange = onChange;
            input.click();
            input = null;
        },
        children: children
    });
});

//# sourceMappingURL=MenuItemFileInput.js.map