import { Download, FileArchive, FolderOpen, RefreshCw, RotateCcw, Trash2 } from 'lucide-preact';
import type { RemoteBackupBrowserResponse } from '@/lib/api/backup';
import { formatBytes, formatDateTime, isZipCandidate } from '@/lib/backup-center';
import { t } from '@/lib/i18n';
interface RemoteBackupBrowserProps {
canBrowse: boolean;
destinationIsSaved: boolean;
disableWhileBusy: boolean;
loadingRemoteBrowser: boolean;
remoteBrowser: RemoteBackupBrowserResponse | null;
visibleItems: RemoteBackupBrowserResponse['items'];
currentPage: number;
totalPages: number;
downloadingRemotePath: string;
downloadingRemotePercent: number | null;
restoringRemotePath: string;
deletingRemotePath: string;
onRefresh: () => void;
onShowPath: (path: string) => void;
onDownload: (path: string) => void;
onRestore: (path: string) => void;
onPromptDelete: (path: string) => void;
onChangePage: (page: number) => void;
}
export function RemoteBackupBrowser(props: RemoteBackupBrowserProps) {
const getDownloadLabel = (path: string) => {
if (props.downloadingRemotePath !== path) return t('txt_backup_remote_download');
return props.downloadingRemotePercent == null
? t('txt_downloading')
: t('txt_downloading_percent', { percent: props.downloadingRemotePercent });
};
return (
<>
{t('txt_backup_remote_title')}
{props.canBrowse ? (
) : null}
{!props.destinationIsSaved ? (
{t('txt_backup_remote_save_first')}
) : !props.remoteBrowser ? (
{t('txt_backup_remote_cached_empty')}
) : (
<>
{t('txt_backup_remote_current_path')}
{props.remoteBrowser.currentPath ? `/${props.remoteBrowser.currentPath}` : '/'}
{props.loadingRemoteBrowser ? (
{t('txt_backup_remote_loading')}
) : props.remoteBrowser.items.length ? (
<>
{props.visibleItems.map((item) => (
{item.modifiedAt ? formatDateTime(item.modifiedAt) : t('txt_backup_remote_unknown_time')}
{item.isDirectory ? t('txt_backup_remote_folder') : formatBytes(item.size)}
{item.isDirectory ? (
) : isZipCandidate(item) ? (
<>
>
) : null}
))}
{props.totalPages > 1 ? (
{props.currentPage} / {props.totalPages}
) : null}
>
) : (
{t('txt_backup_remote_empty')}
)}
>
)}
>
);
}