import React from 'react'; import Typography from '../../ui/Typography'; import { cn } from '../../../lib/utils'; import { useWalletStore } from '../../../stores/walletStore'; import type { ChatSession } from '../../../../main/db/schema'; import { FiPlus, FiTrash2, FiClock, FiWifi, FiWifiOff, FiShield, FiUser, FiUsers, FiChevronDown, } from 'react-icons/fi'; /** * Top header with session selector and network indicators. */ export type ChatHeaderProps = { mode: 'personal' | 'hcs10'; isConnected: boolean; statusText: string; networkLabel: string; accountSuffix: string; sessions: ChatSession[]; currentSession: ChatSession | null; isLoadingSessions: boolean; isSelectorOpen: boolean; onToggleSelector: () => void; onCreateSession: () => void; onSelectSession: (session: ChatSession) => void; onRequestDeleteSession: (sessionId: string) => void; }; function getDisplayInfo( session: ChatSession, currentSession: ChatSession | null ) { const isHcs = session.mode === 'hcs10'; const name = session.name; const subtitle = isHcs ? `HCS-10: ${session.topicId}` : 'Personal Assistant'; const isActive = currentSession ? currentSession.id === session.id : false; const lastUsed = (session.lastMessageAt || session.updatedAt) as Date; return { name, subtitle, isHcs, isActive, lastUsed }; } export default function ChatHeader(props: ChatHeaderProps) { const { mode, isConnected, statusText, networkLabel, accountSuffix, sessions, currentSession, isLoadingSessions, isSelectorOpen, onToggleSelector, onCreateSession, onSelectSession, onRequestDeleteSession, } = props; return (
{isSelectorOpen ? ( <>
{sessions.length > 0 ? ( <> {['personal', 'hcs10'].map((group) => { const groupSessions = sessions .filter( (s) => s.mode === (group as 'personal' | 'hcs10') ) .sort( (a, b) => new Date( (b.lastMessageAt || b.updatedAt) as Date ).getTime() - new Date( (a.lastMessageAt || a.updatedAt) as Date ).getTime() ); if (groupSessions.length === 0) return null; return (
{group === 'personal' ? 'Personal Sessions' : 'HCS-10 Sessions'}
{groupSessions.map((session) => { const d = getDisplayInfo(session, currentSession); const iconBg = d.isHcs ? 'bg-gradient-to-br from-purple-500 to-purple-600' : 'bg-gradient-to-br from-blue-500 to-blue-600'; return (
); })}
); })} ) : (
No sessions yet. Create your first session!
)}
) : null}
{isConnected ? ( ) : ( )} {networkLabel}
{(() => { const s = useWalletStore.getState(); const label = s.isConnected ? `${s.network} · ${s.accountId?.slice(-6) || '—'}` : 'Disconnected'; return (
{label}
); })()}
{accountSuffix}
{statusText}
); }