import { useCallback, useState } from 'react';
import { DEFAULT_FILE_STATUS } from '../../constants';
export const useSelfFiles = () => {
    const [selfFiles, setSelfFiles] = useState({});
    const setLoadingStatusFile = useCallback((fileId, progress) => setSelfFiles((currentFiles) => ({
        ...currentFiles,
        [fileId]: {
            ...currentFiles[fileId],
            status: { ...DEFAULT_FILE_STATUS, isLoading: true, progress },
        },
    })), []);
    const setSuccessStatusFile = useCallback((fileId) => setSelfFiles((currentFiles) => ({
        ...currentFiles,
        [fileId]: { ...currentFiles[fileId], status: DEFAULT_FILE_STATUS },
    })), []);
    const setErrorStatusFile = useCallback((fileId, errorMsg) => setSelfFiles((currentFiles) => ({
        ...currentFiles,
        [fileId]: {
            ...currentFiles[fileId],
            status: { ...DEFAULT_FILE_STATUS, isUploadError: true, errorMsg },
        },
    })), []);
    const updateFileInfo = useCallback((fileId, data) => setSelfFiles((currentFiles) => ({
        ...currentFiles,
        [fileId]: { ...currentFiles[fileId], ...data },
    })), []);
    return {
        selfFiles,
        setLoadingStatusFile,
        setSuccessStatusFile,
        setErrorStatusFile,
        updateFileInfo,
    };
};
