import React, { useEffect, useState } from 'react'; import { useI18n } from '../../application/i18n/I18nProvider'; import { hostTreeInlineGroupDeleteStore, useHostTreeInlineGroupDeleteTarget, } from '../../application/state/hostTreeInlineGroupDeleteStore'; import { VaultGroupDeletionConfirmationChangedError } from '../../application/state/useVaultGroupDeletion'; import { toast } from '../ui/toast'; import { Button } from '../ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '../ui/dialog'; type HostTreeGroupDeleteDialogProps = { managedGroupPaths?: Set; managedFilesByGroupPath?: Map; onConfirmDelete: (groupPath: string, deleteHosts: boolean) => void | Promise; }; export const HostTreeGroupDeleteDialog: React.FC = ({ managedGroupPaths, managedFilesByGroupPath, onConfirmDelete, }) => { const { t } = useI18n(); const targetPath = useHostTreeInlineGroupDeleteTarget(); const [deleteHosts, setDeleteHosts] = useState(false); const isOpen = Boolean(targetPath); const isManaged = Boolean(targetPath && managedGroupPaths?.has(targetPath)); const descendantManagedFiles: string[] = []; if (targetPath && managedFilesByGroupPath) { for (const [groupPath, files] of managedFilesByGroupPath) { if ( (groupPath === targetPath || groupPath.startsWith(`${targetPath}/`)) ) { for (const filePath of files) { if ( filePath && !descendantManagedFiles.includes(filePath) ) { descendantManagedFiles.push(filePath); } } } } } useEffect(() => { if (!isOpen) { setDeleteHosts(false); } }, [isOpen]); return ( { if (!open) hostTreeInlineGroupDeleteStore.close(); }} > {t('vault.groups.deleteDialogTitle')} {isManaged ? t('vault.groups.deleteDialog.managedDesc') : descendantManagedFiles.length > 0 ? t('vault.groups.deleteDialog.mixedDesc') : t('vault.groups.deleteDialog.desc')}
{targetPath && ( <>

{t('vault.groups.pathLabel')}:{' '} {targetPath}

{descendantManagedFiles.length > 0 && (

{t('vault.groups.deleteDialog.managedWarning')}

{descendantManagedFiles.length > 0 && (
{descendantManagedFiles.map((filePath) => (

{t('vault.groups.deleteDialog.managedFile', { file: filePath })}

))}
)}
)} {!isManaged && ( )} )}
); };