// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useState } from 'react';
import type { LocalizerType } from '../types/Util.js';
import { formatFileSize } from '../util/formatFileSize.js';
import { SpinnerV2 } from './SpinnerV2.js';
import { ContextMenu } from './ContextMenu.js';
import { BackupMediaDownloadCancelConfirmationDialog } from './BackupMediaDownloadCancelConfirmationDialog.js';
import { LeftPaneDialog } from './LeftPaneDialog.js';
import { WidthBreakpoint } from './_util.js';
export type PropsType = Readonly<{
i18n: LocalizerType;
downloadedBytes: number;
totalBytes: number;
isIdle: boolean;
isOnline: boolean;
isPaused: boolean;
widthBreakpoint: WidthBreakpoint;
handleCancel: VoidFunction;
handleClose: VoidFunction;
handleResume: VoidFunction;
handlePause: VoidFunction;
}>;
export function BackupMediaDownloadProgress({
i18n,
downloadedBytes,
totalBytes,
isIdle,
isOnline,
isPaused,
handleCancel: handleConfirmedCancel,
handleClose,
handleResume,
handlePause,
widthBreakpoint,
}: PropsType): JSX.Element | null {
const [isShowingCancelConfirmation, setIsShowingCancelConfirmation] =
useState(false);
if (totalBytes <= 0) {
return null;
}
function handleCancel() {
setIsShowingCancelConfirmation(true);
}
let content: JSX.Element | undefined;
let icon: JSX.Element | undefined;
const isCompleted = downloadedBytes === totalBytes;
const actionButton =
isCompleted || isIdle ? (
) : (