import { jsx as _jsx } from "react/jsx-runtime";
import { useCallback, useRef, } from "react";
import { useOneUIView } from "../../context/OneUIProvider";
import Styles from "./FileInput.module.scss";
/**
 * A component to provide the upload of a file
 **/
function FileInput({ onFile, ...props }) {
    const View = useOneUIView("component.fileInput.View", "FileInput");
    const inputRef = useRef(null);
    const onFileSelected = useCallback(((e) => {
        const file = e.target.files.item(0);
        onFile(file || undefined);
    }), []);
    return (_jsx(View, { ...props, onAction: () => {
            if (props.file) {
                inputRef.current.value = "";
                onFile(undefined);
            }
            else {
                inputRef.current.click();
            }
        }, inputEl: _jsx("input", { ...props, ref: inputRef, onChange: onFileSelected, type: "file", className: Styles.hidden }) }));
}
/**
 * A simple file uploader that lets users select and upload files from their device.
 */
export default FileInput;
//# sourceMappingURL=FileInput.js.map