import { useState, useEffect } from "react";
import { SettingsIcon, User, Sliders, LogOut, Lock } from "lucide-react"
import { useTranslation } from 'react-i18next';
import { useAuth } from './context/AuthContext';
import { useTheme } from './context/ThemeContext';
import { useNavigate } from 'react-router-dom';
function Toggle({ enabled, onToggle }) {
return (
);
}
export default function Settings() {
const { user, logout } = useAuth();
const navigate = useNavigate();
const { t, i18n } = useTranslation();
const [displayName, setDisplayName] = useState("");
const [email, setEmail] = useState("");
const [emailNotif, setEmailNotif] = useState(true);
const [desktopAlerts, setDesktopAlerts] = useState(false);
const [autoDelete, setAutoDelete] = useState(true);
const [apiKey] = useState("sk-••••••••••••••••••••••••");
const [twoFactor, setTwoFactor] = useState(false);
const [language, setLanguage] = useState(i18n.language || "en");
const [sensitivity, setSensitivity] = useState(75);
useEffect(() => {
i18n.changeLanguage(language);
}, [language, i18n]);
useEffect(() => {
const fetchProfile = async () => {
try {
const apiUrl = import.meta.env.VITE_API_URL || 'http://127.0.0.1:5000';
const token = localStorage.getItem('token');
const response = await fetch(`${apiUrl}/api/profile`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
...(token ? { 'Authorization': `Bearer ${token}` } : {})
}
});
const result = await response.json();
if (result.status === 'success' && result.data?.user_aktif) {
setDisplayName(result.data.user_aktif.display_name);
setEmail(result.data.user_aktif.email);
}
} catch (error) {
console.error("Failed to fetch profile settings", error);
}
};
fetchProfile();
}, []);
return (
{/* Main */}
{/* Unauthenticated Overlay */}
{!user && (
{t('analysis.lockedTitle')}
{t('analysis.lockedMessage')}
)}
{/* Header */}
{t('settings.title')}
{t('settings.subtitle')}
{/* User Block with Theme & Logout */}
{user?.display_name ? user.display_name.charAt(0).toUpperCase() : 'AI'}
{user?.display_name || t('app.adminName', 'Admin User')}
{user?.role || t('app.adminRole', 'Administrator')}
{/* Account Settings */}
{t('settings.accountSettings')}
{/*/!* Notifications *!/*/}
{/**/}
{/* */}
{/* 🔔*/}
{/*
{t('settings.notifications')}
*/}
{/* */}
{/* */}
{/*
*/}
{/*
*/}
{/*
{t('settings.emailNotifications')}
*/}
{/*
{t('settings.emailNotifDesc')}
*/}
{/*
*/}
{/*
setEmailNotif(!emailNotif)} />*/}
{/* */}
{/*
*/}
{/*
*/}
{/*
*/}
{/*
{t('settings.desktopAlerts')}
*/}
{/*
{t('settings.desktopAlertsDesc')}
*/}
{/*
*/}
{/*
setDesktopAlerts(!desktopAlerts)} />*/}
{/* */}
{/*
*/}
{/**/}
{/*/!* Security & Privacy *!/*/}
{/**/}
{/* */}
{/* 🛡*/}
{/*
{t('settings.securityPrivacy')}
*/}
{/* */}
{/* */}
{/*
*/}
{/*
*/}
{/*
{t('settings.autoDelete')}
*/}
{/*
{t('settings.autoDeleteDesc')}
*/}
{/*
*/}
{/*
setAutoDelete(!autoDelete)} />*/}
{/* */}
{/*
*/}
{/*
*/}
{/*
*/}
{/*
{t('settings.twoFactor')}
*/}
{/*
{t('settings.twoFactorDesc')}
*/}
{/*
*/}
{/*
setTwoFactor(!twoFactor)} />*/}
{/* */}
{/*
*/}
{/*
*/}
{/*
*/}
{/*
*/}
{/* */}
{/* */}
{/*
*/}
{/*
*/}
{/*
*/}
{/*
*/}
{/* */}
{/*
*/}
{/*
*/}
{/**/}
{/* Preferences */}
{t('settings.preferences')}
{/* Help button */}
);
}