import type { RefObject } from 'preact'; import { CheckCheck, Download, Paperclip, Plus, RefreshCw, Star, StarOff, Trash2, Upload, X } from 'lucide-preact'; import type { Cipher, Folder, VaultDraft, VaultDraftField } from '@/lib/types'; import { t } from '@/lib/i18n'; import { CREATE_TYPE_OPTIONS, cipherTypeLabel, formatAttachmentSize, toBooleanFieldValue } from '@/components/vault/vault-page-helpers'; interface VaultEditorProps { draft: VaultDraft; isCreating: boolean; busy: boolean; folders: Folder[]; selectedCipher: Cipher | null; editExistingAttachments: Array; removedAttachmentIds: Record; removedAttachmentCount: number; attachmentQueue: File[]; attachmentInputRef: RefObject; localError: string; downloadingAttachmentKey: string; attachmentDownloadPercent: number | null; onUpdateDraft: (patch: Partial) => void; onSeedSshDefaults: (force?: boolean) => void; onUpdateSshPublicKey: (value: string) => void; onUpdateDraftLoginUri: (index: number, value: string) => void; onQueueAttachmentFiles: (list: FileList | null) => void; onToggleExistingAttachmentRemoval: (attachmentId: string) => void; onRemoveQueuedAttachment: (index: number) => void; onDownloadAttachment: (cipher: Cipher, attachmentId: string) => void; onPatchDraftCustomField: (index: number, patch: Partial) => void; onUpdateDraftCustomFields: (fields: VaultDraftField[]) => void; onOpenFieldModal: () => void; onSave: () => void; onCancel: () => void; onDeleteSelected: () => void; } export default function VaultEditor(props: VaultEditorProps) { const formatDownloadLabel = (attachmentId: string) => { const downloadKey = `${props.selectedCipher?.id || ''}:${attachmentId}`; if (props.downloadingAttachmentKey !== downloadKey) return t('txt_download'); return props.attachmentDownloadPercent == null ? t('txt_downloading') : t('txt_downloading_percent', { percent: props.attachmentDownloadPercent }); }; return ( <>

{props.isCreating ? t('txt_new_type_header', { type: cipherTypeLabel(props.draft.type) }) : t('txt_edit_type_header', { type: cipherTypeLabel(props.draft.type) })}

{props.draft.type === 1 && (

{t('txt_login_credentials')}

{t('txt_websites')}

{props.draft.loginUris.map((uri, index) => (
props.onUpdateDraftLoginUri(index, (e.currentTarget as HTMLInputElement).value)} /> {props.draft.loginUris.length > 1 && ( )}
))}
)} {props.draft.type === 3 && (

{t('txt_card_details')}

)} {props.draft.type === 4 && (

{t('txt_identity_details')}

)} {props.draft.type === 5 && (

{t('txt_ssh_key')}