import { useEncryptionKey } from '@/contexts/encryption-key-context'; import { cn } from '@/lib/utils'; import { __ } from '@/utils/i18n'; import { LockKeyhole, LockKeyholeOpen } from 'lucide-react'; import { useEffect, useState } from 'react'; import { Button } from './ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from './ui/dialog'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from './ui/tooltip'; import UnlockMessageDialog from './unlock-message-dialog'; export function EncryptionKeyButton() { const { isKeySet, encryptedMessageData, fetchEncryptedMessage, clearEncryptionKey, } = useEncryptionKey(); const [showUnlockDialog, setShowUnlockDialog] = useState(false); const [showClearDialog, setShowClearDialog] = useState(false); useEffect(() => { if (!encryptedMessageData) { fetchEncryptedMessage(); } }, [encryptedMessageData, fetchEncryptedMessage]); function handleClick() { if (isKeySet) { setShowClearDialog(true); } else { if (!encryptedMessageData) { fetchEncryptedMessage(); } setShowUnlockDialog(true); } } function handleClearKey() { clearEncryptionKey(); setShowClearDialog(false); } function handleUnlock() { setShowUnlockDialog(false); } return ( <> {isKeySet ? __('Click to lock encryption key') : __('Click to unlock encryption key')} {encryptedMessageData && ( )} {__('Clear Encryption Key?')} {__( "This will remove your encryption key from this browser session. You'll need to enter your password again to unlock encrypted content.", )} ); }