'use client' import { useState, useEffect } from 'react' import Link from 'next/link' import { useAuth } from '@/lib/auth/context' import ProfileSettings from '@/components/settings/ProfileSettings' import TrustedDevicesCard from '@/components/settings/TrustedDevicesCard' import SecurityActivityCard from '@/components/settings/SecurityActivityCard' import { updateUserPreferences } from '@/lib/api/user' import { motion, AnimatePresence } from 'framer-motion' import { UserIcon, LockIcon, BoxIcon, ChevronRightIcon, ChevronDownIcon, ExternalLinkIcon, } from '@ciphera-net/ui' // Inline SVG icons not available in ciphera-ui function BellIcon({ className }: { className?: string }) { return ( ) } // --- Types --- type ProfileSubTab = 'profile' | 'security' | 'preferences' type NotificationSubTab = 'email' | 'center' type ActiveSelection = | { section: 'profile'; subTab: ProfileSubTab } | { section: 'notifications'; subTab: NotificationSubTab } | { section: 'account' } | { section: 'devices' } | { section: 'activity' } type ExpandableSection = 'profile' | 'notifications' | 'account' // --- Sidebar Components --- function SectionHeader({ expanded, active, onToggle, icon: Icon, label, description, hasChildren = true, }: { expanded: boolean active: boolean onToggle: () => void icon: React.ElementType label: string description?: string hasChildren?: boolean }) { return ( ) } function SubItem({ active, onClick, label, external = false, }: { active: boolean onClick: () => void label: string external?: boolean }) { return ( ) } function ExpandableSubItems({ expanded, children }: { expanded: boolean; children: React.ReactNode }) { return ( {expanded && (
{children}
)}
) } // --- Content Components --- // Email Notification Preferences Card const PULSE_NOTIFICATION_OPTIONS = [ { key: 'security_alerts', label: 'Security Alerts', description: 'Important security events like new logins, password changes, and 2FA updates.' }, ] function EmailNotificationPreferencesCard() { const { user } = useAuth() const [emailNotifications, setEmailNotifications] = useState>({}) useEffect(() => { if (user?.preferences?.email_notifications) { setEmailNotifications(user.preferences.email_notifications) } else { const defaults = PULSE_NOTIFICATION_OPTIONS.reduce((acc, option) => ({ ...acc, [option.key]: true }), {} as Record) setEmailNotifications(defaults) } }, [user]) const handleToggle = async (key: string) => { const newState = { ...emailNotifications, [key]: !emailNotifications[key] } setEmailNotifications(newState) try { await updateUserPreferences({ email_notifications: newState as { new_file_received: boolean; file_downloaded: boolean; security_alerts: boolean } }) } catch { setEmailNotifications(prev => ({ ...prev, [key]: !prev[key] })) } } return (

Email Notifications

Choose which email notifications you receive

{PULSE_NOTIFICATION_OPTIONS.map((item) => (
{item.label} {item.description}
))}
) } function AccountManagementCard() { const accountLinks = [ { label: 'Profile & Personal Info', description: 'Update your name, email, and avatar', href: 'https://auth.ciphera.net/settings', icon: UserIcon, }, { label: 'Security & 2FA', description: 'Password, two-factor authentication, and passkeys', href: 'https://auth.ciphera.net/settings?tab=security', icon: LockIcon, }, { label: 'Active Sessions', description: 'Manage devices logged into your account', href: 'https://auth.ciphera.net/settings?tab=sessions', icon: BoxIcon, }, ] return (

Ciphera Account

Manage your account across all Ciphera products

{accountLinks.map((link) => (
{link.label}

{link.description}

))}

These settings apply to your Ciphera Account and affect all products (Drop, Pulse, and Auth).

) } // --- Main Settings Section --- function AppSettingsSection() { const [active, setActive] = useState({ section: 'profile', subTab: 'profile' }) const [expanded, setExpanded] = useState>(new Set(['profile'])) const toggleSection = (section: ExpandableSection) => { setExpanded(prev => { const next = new Set(prev) if (next.has(section)) { next.delete(section) } else { next.add(section) } return next }) } const selectSubTab = (selection: ActiveSelection) => { setActive(selection) if ('subTab' in selection) { setExpanded(prev => new Set(prev).add(selection.section as ExpandableSection)) } } const renderContent = () => { switch (active.section) { case 'profile': return case 'notifications': if (active.subTab === 'email') return if (active.subTab === 'center') return (

Notification Center

View and manage all your notifications in one place.

Open Notification Center
) return null case 'account': return case 'devices': return case 'activity': return default: return null } } return (
{/* Sidebar Navigation */} {/* Content Area */}
{renderContent()}
) } export default function SettingsPageClient() { const { user } = useAuth() return (
{/* Page Header */}

Settings

Manage your Pulse preferences and Ciphera account settings

{/* Breadcrumb / Context */}
You are signed in as {user?.email} Manage in Ciphera Account
{/* Settings Content */}
) }