import { useContext, useMemo } from 'react';
import { ConfigContext, } from '../../../../ConfigProvider';
import { Image, setDefaultImageStyles } from '../styles';
export const useLogic = ({ fileId, file, isUploadError, onDelete, onRetry, }) => {
    const { imagesMap, components } = useContext(ConfigContext);
    const configRenderImage = components?.placeholder?.defaultProps?.renderImage;
    const RenderImage = useMemo(() => configRenderImage ? setDefaultImageStyles(configRenderImage) : Image, [configRenderImage]);
    const { errorFileImgSrc } = imagesMap;
    const isVisibleRetryButton = Boolean(isUploadError && onRetry);
    const handleDelete = () => onDelete(fileId);
    const handleRetry = () => onRetry?.(fileId, file);
    return {
        isVisibleRetryButton,
        RenderImage,
        imageProps: {
            src: errorFileImgSrc,
        },
        deleteButtonProps: { onClick: handleDelete },
        retryButtonProps: { onClick: handleRetry },
    };
};
