import React, { useState } from 'react'; import { Trash2, AlertTriangle, X, Loader2, CheckCircle } from 'lucide-react'; import { useTheme } from '../contexts/ThemeContext'; const ClearDataModal = ({ authToken, onClose, onDataCleared }) => { const { isDark } = useTheme(); const [profile, setProfile] = useState(false); const [chats, setChats] = useState(false); const [canvas, setCanvas] = useState(false); const [clearing, setClearing] = useState(false); const [result, setResult] = useState(null); const noneSelected = !profile && !chats && !canvas; const handleClear = async () => { if (noneSelected) return; setClearing(true); try { const resp = await fetch(`${process.env.REACT_APP_API_URL}/api/users/me/clear-data`, { method: 'POST', headers: { 'Authorization': `Bearer ${authToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ profile, chats, canvas }), }); if (resp.ok) { const data = await resp.json(); setResult(data.cleared); if (onDataCleared) onDataCleared({ profile, chats, canvas }); } else { setResult(['Error clearing data']); } } catch { setResult(['Network error']); } finally { setClearing(false); } }; const overlay = { position: 'fixed', inset: 0, background: 'rgba(0,0,0,0.5)', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 9999, }; const modal = { background: isDark ? '#1f2937' : '#fff', borderRadius: 16, padding: 28, width: 400, maxWidth: '90vw', boxShadow: '0 20px 60px rgba(0,0,0,0.3)', color: isDark ? '#f3f4f6' : '#111827', }; const checkRow = { display: 'flex', alignItems: 'center', gap: 12, padding: '12px 14px', borderRadius: 10, cursor: 'pointer', border: `1px solid ${isDark ? '#374151' : '#e5e7eb'}`, marginBottom: 10, transition: 'all 0.15s ease', }; const checkRowActive = (active) => ({ ...checkRow, background: active ? (isDark ? 'rgba(239,68,68,0.12)' : 'rgba(239,68,68,0.06)') : 'transparent', borderColor: active ? '#ef4444' : (isDark ? '#374151' : '#e5e7eb'), }); const checkbox = (checked) => ({ width: 20, height: 20, borderRadius: 4, flexShrink: 0, border: `2px solid ${checked ? '#ef4444' : (isDark ? '#6b7280' : '#9ca3af')}`, background: checked ? '#ef4444' : 'transparent', display: 'flex', alignItems: 'center', justifyContent: 'center', transition: 'all 0.15s ease', color: '#fff', fontSize: 13, fontWeight: 700, }); if (result) { return (
{result.join(', ')}
Select which data to clear. Profile data removal will reset your onboarding progress.
{/* Checkboxes */}