"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSyncFiles = void 0;
const react_1 = require("react");
const isEmpty_1 = require("../../../utils/isEmpty");
const useSyncFiles = (props) => {
    const { isMultiple, files, selfFiles } = props;
    const handleSingleFileChange = (updatedFiles) => {
        const { onChange } = props;
        onChange(updatedFiles.length > 0 ? updatedFiles[0] : null);
    };
    const handleMultipleFileChange = (updatedFiles) => {
        const { onChange } = props;
        onChange(updatedFiles);
    };
    (0, react_1.useEffect)(() => {
        if ((0, isEmpty_1.isEmpty)(selfFiles)) {
            return;
        }
        const updatedFiles = files.map((file) => {
            // Исключаем signal, так как он не является свойством UploadFile
            const { controller, ...currentFileData } = selfFiles[file.id] || {};
            return {
                ...file,
                ...(currentFileData || {}),
            };
        });
        if (isMultiple) {
            handleMultipleFileChange(updatedFiles);
        }
        else {
            handleSingleFileChange(updatedFiles);
        }
    }, [selfFiles]);
};
exports.useSyncFiles = useSyncFiles;
