/** * Sync profile component for PodTUI * Displays user profile information and sync status */ import { createSignal } from "solid-js" import { useAuthStore } from "../stores/auth" import { format } from "date-fns" interface SyncProfileProps { focused?: boolean onLogout?: () => void onManageSync?: () => void } type FocusField = "sync" | "export" | "logout" export function SyncProfile(props: SyncProfileProps) { const auth = useAuthStore() const [focusField, setFocusField] = createSignal("sync") const [lastSyncTime] = createSignal(new Date()) const fields: FocusField[] = ["sync", "export", "logout"] const handleKeyPress = (key: { name: string; shift?: boolean }) => { if (key.name === "tab") { const currentIndex = fields.indexOf(focusField()) const nextIndex = key.shift ? (currentIndex - 1 + fields.length) % fields.length : (currentIndex + 1) % fields.length setFocusField(fields[nextIndex]) } else if (key.name === "return" || key.name === "enter") { if (focusField() === "sync" && props.onManageSync) { props.onManageSync() } else if (focusField() === "logout" && props.onLogout) { handleLogout() } } } const handleLogout = () => { auth.logout() if (props.onLogout) { props.onLogout() } } const formatDate = (date: Date | null | undefined): string => { if (!date) return "Never" return format(date, "MMM d, yyyy HH:mm") } const user = () => auth.state().user // Get user initials for avatar const userInitials = () => { const name = user()?.name || "?" return name.slice(0, 2).toUpperCase() } return ( User Profile {/* User avatar and info */} {/* ASCII avatar */} {userInitials()} {/* User details */} {user()?.name || "Guest User"} {user()?.email || "No email"} Joined: {formatDate(user()?.createdAt)} {/* Sync status section */} Sync Status Status: {user()?.syncEnabled ? "Enabled" : "Disabled"} Last Sync: {formatDate(lastSyncTime())} Method: File-based (JSON/XML) {/* Action buttons */} [S] Manage Sync [E] Export Data [L] Logout Tab to navigate, Enter to select ) }