"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFileUpload = void 0;
const react_1 = require("react");
const hooks_1 = require("../../../utils/hooks");
const validate_files_1 = require("../helpers/validate-files");
const useFileUpload = ({ ref, accept, onSelect, validator, maxSizeInBytes, disabled, }) => {
    const inputRef = (0, react_1.useRef)(null);
    const mergedRef = (0, hooks_1.useMergeRefs)(inputRef, ref);
    const upload = (fileList) => {
        const { files, partitionedFiles } = (0, validate_files_1.validateFiles)(Array.from(fileList), accept, validator, maxSizeInBytes);
        onSelect(files, partitionedFiles);
    };
    const onChange = (event) => {
        const fileList = event.target.files;
        if (!fileList) {
            return;
        }
        if (!disabled) {
            upload(fileList);
        }
        // Resets the value to make it is possible to upload the same file several consecutive times
        event.target.value = "";
    };
    return {
        upload,
        onChange,
        inputRef,
        mergedRef,
    };
};
exports.useFileUpload = useFileUpload;
//# sourceMappingURL=useFileUpload.js.map