import React, { useId, useRef } from "react"; import { Loader2 } from "lucide-react"; import type { SftpArchiveDialogState } from "../../application/state/sftp/useSftpArchiveDialog"; import type { SftpArchiveFormat } from "../../domain/sftpArchiveCreation"; import { Button } from "../ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "../ui/dialog"; import { Input } from "../ui/input"; import { Label } from "../ui/label"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select"; interface SftpCreateArchiveDialogProps { state: SftpArchiveDialogState | null; t: (key: string, params?: Record) => string; onClose: () => void; onNameChange: (name: string) => void; onFormatChange: (format: SftpArchiveFormat) => void; onSubmit: (overwrite?: boolean) => Promise; } export function SftpCreateArchiveDialog({ state, t, onClose, onNameChange, onFormatChange, onSubmit, }: SftpCreateArchiveDialogProps) { const id = useId(); const nameRef = useRef(null); return ( { if (!open) onClose(); }}> { event.preventDefault(); nameRef.current?.focus(); nameRef.current?.select(); }} onEscapeKeyDown={(event) => { if (state?.busy) event.preventDefault(); }} onInteractOutside={(event) => { if (state?.busy) event.preventDefault(); }} > {t("sftp.archive.title")} {t("sftp.archive.description", { count: state?.paths.length ?? 0 })} {state && ( <>
onNameChange(event.target.value)} onKeyDown={(event) => { if (event.key === "Enter" && !event.nativeEvent.isComposing && !state.confirmOverwrite) { event.preventDefault(); void onSubmit(); } }} />
{t("sftp.archive.destination")}
{state.directory}
{state.error && } {state.confirmOverwrite && (

{t("sftp.archive.overwriteTitle")}

{t("sftp.archive.overwriteDescription", { name: state.archiveName })}

)} )}
); }