import { useState, useEffect, useRef } from 'react' interface VisibilityChangeModalProps { isOpen: boolean itemTitle: string currentVisibility: 'local' | 'shared' newVisibility: 'local' | 'shared' onConfirm: (dontAskAgain: boolean) => void onCancel: () => void isDarkMode: boolean } export function VisibilityChangeModal({ isOpen, itemTitle, currentVisibility, newVisibility, onConfirm, onCancel, isDarkMode, }: VisibilityChangeModalProps) { const [dontAskAgain, setDontAskAgain] = useState(false) const modalRef = useRef(null) // Handle escape key useEffect(() => { if (!isOpen) return const handleEscape = (e: KeyboardEvent) => { if (e.key === 'Escape') { onCancel() } } document.addEventListener('keydown', handleEscape) return () => document.removeEventListener('keydown', handleEscape) }, [isOpen, onCancel]) // Dark mode colors const colors = isDarkMode ? { bg: '#1f2937', cardBg: '#252525', cardBorder: '#404040', text: '#e4e4e7', textMuted: '#a1a1aa', textHeading: '#f4f4f5', warningBg: 'rgba(251, 191, 36, 0.15)', warningBorder: 'rgba(251, 191, 36, 0.3)', warningText: '#fbbf24', btnPrimaryBg: '#6366f1', btnPrimaryText: '#ffffff', btnSecondaryBg: '#333333', btnSecondaryText: '#e4e4e4', checkboxBg: '#333333', checkboxBorder: '#555555', localColor: '#6366f1', sharedColor: '#22c55e', } : { bg: '#ffffff', cardBg: '#f9fafb', cardBorder: '#e5e7eb', text: '#374151', textMuted: '#6b7280', textHeading: '#1f2937', warningBg: 'rgba(251, 191, 36, 0.1)', warningBorder: 'rgba(251, 191, 36, 0.3)', warningText: '#92400e', btnPrimaryBg: '#6366f1', btnPrimaryText: '#ffffff', btnSecondaryBg: '#f3f4f6', btnSecondaryText: '#374151', checkboxBg: '#ffffff', checkboxBorder: '#d1d5db', localColor: '#6366f1', sharedColor: '#22c55e', } if (!isOpen) return null const isSharing = currentVisibility === 'local' && newVisibility === 'shared' return (
e.stopPropagation()} style={{ backgroundColor: colors.bg, borderRadius: '12px', width: '90%', maxWidth: '420px', boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.25)', border: `1px solid ${colors.cardBorder}`, overflow: 'hidden', }} > {/* Header */}
{isSharing ? '⚠️' : '🔒'}

{isSharing ? 'Change Visibility?' : 'Make Private?'}

{/* Content */}

{isSharing ? "You're about to make this item visible to others:" : "You're about to make this item private:"}

{/* Item preview */}
📄 {itemTitle}
{/* Current vs New state */}
{isSharing ? '🔒' : '🌐'} {isSharing ? 'Private' : 'Shared'}
{isSharing ? '🌐' : '🔒'} {isSharing ? 'Shared' : 'Private'}
{/* Warning for sharing */} {isSharing && (

Note: Shared items will be visible to all collaborators on this board and may be uploaded to cloud storage.

)} {/* Info for making private */} {!isSharing && (

Note: Private items are only visible to you and remain encrypted in your browser. Other collaborators won't be able to see this item.

)} {/* Don't ask again checkbox */}
{/* Actions */}
) } // Session storage key for "don't ask again" preference const DONT_ASK_KEY = 'visibility-change-dont-ask' export function shouldSkipVisibilityPrompt(): boolean { try { return sessionStorage.getItem(DONT_ASK_KEY) === 'true' } catch { return false } } export function setSkipVisibilityPrompt(skip: boolean): void { try { if (skip) { sessionStorage.setItem(DONT_ASK_KEY, 'true') } else { sessionStorage.removeItem(DONT_ASK_KEY) } } catch { // Ignore storage errors } }