import React, { useState } from 'react';
import { View, Text, ScrollView, Pressable, StyleSheet } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';
import Svg, { Polyline } from 'react-native-svg';
import { Header } from '../components/Header';
import { useScrollBottomPadding } from '../components/keyboardLayout';
import { colors } from '../components/theme';
import { isGlassesConnected } from '../sdkFormat';
import type { BluetoothSdkExampleModel, SdkConsoleEvent } from '../useBluetoothSdkExample';
export function ConsoleScreen({ sdk }: { sdk: BluetoothSdkExampleModel }) {
const scrollBottomPadding = useScrollBottomPadding();
const [filter, setFilter] = useState<'ALL' | SdkConsoleEvent['tag']>('ALL');
const events = filter === 'ALL' ? sdk.events : sdk.events.filter((item) => item.tag === filter);
const counts = {
ALL: sdk.events.length,
BLE: sdk.events.filter((item) => item.tag === 'BLE').length,
LIVE: sdk.events.filter((item) => item.tag === 'LIVE').length,
STORE: sdk.events.filter((item) => item.tag === 'STORE').length,
TX: sdk.events.filter((item) => item.tag === 'TX').length,
};
return (
{/* Filter chips */}
setFilter('ALL')}>
ALL
{counts.ALL}
setFilter('LIVE')} />
setFilter('BLE')} />
setFilter('TX')} />
setFilter('STORE')} />
{/* Console block */}
mentra-sdk · live
REC
{events.map((e, i) => (
{e.time}
{e.tag}
{e.text}
))}
{/* Raw JSON disclosure */}
sdk.setRawJsonExpanded(!sdk.rawJsonExpanded)}>
SDK state JSON
{Object.keys(sdk.glasses).length + Object.keys(sdk.phone).length} keys · glasses, phone
{sdk.rawJsonExpanded ? (
{JSON.stringify({ glasses: sdk.glasses, phone: sdk.phone }, null, 2)}
) : null}
);
}
function FilterChip({ color, labelColor, label, count, onPress }: { color: string; labelColor: string; label: string; count: string; onPress: () => void }) {
return (
{label}
{count}
);
}
const styles = StyleSheet.create({
chip: { flexDirection: 'row', alignItems: 'center', minHeight: 36, gap: 6, backgroundColor: 'rgba(255,255,255,0.6)', borderWidth: 1, borderColor: colors.border, paddingVertical: 8, paddingHorizontal: 13, borderRadius: 999 },
chipDark: { borderWidth: 0 },
chipDarkText: { color: '#fff', fontSize: 11, fontWeight: '700', letterSpacing: 0.5 },
chipDarkCount: { color: 'rgba(255,255,255,0.5)', fontSize: 10, fontWeight: '500' },
chipDot: { width: 6, height: 6, borderRadius: 999 },
chipLabel: { fontSize: 12, fontWeight: '600', letterSpacing: 0.5 },
chipCount: { color: colors.muted, fontSize: 11, fontWeight: '500' },
consoleCard: { marginHorizontal: 16, marginTop: 12, borderRadius: 24, paddingVertical: 18, paddingHorizontal: 18, gap: 12, backgroundColor: 'rgba(20,22,21,0.92)', borderWidth: 1, borderColor: 'rgba(255,255,255,0.06)', shadowColor: '#0F2A1D', shadowOpacity: 0.18, shadowOffset: { width: 0, height: 12 }, shadowRadius: 40, elevation: 8 },
consoleHead: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', paddingBottom: 6, borderBottomWidth: 1, borderColor: 'rgba(255,255,255,0.06)' },
dots: { flexDirection: 'row', gap: 4 },
dot: { width: 8, height: 8, borderRadius: 999 },
consoleTitle: { color: 'rgba(255,255,255,0.5)', fontSize: 11, fontWeight: '500' },
recPill: { flexDirection: 'row', alignItems: 'center', gap: 5, backgroundColor: 'rgba(125,216,158,0.14)', borderWidth: 1, borderColor: 'rgba(125,216,158,0.3)', paddingVertical: 4, paddingHorizontal: 9, borderRadius: 999 },
recDot: { width: 5, height: 5, borderRadius: 999, backgroundColor: '#7DD89E' },
recText: { color: '#7DD89E', fontSize: 9, fontWeight: '700', letterSpacing: 0.7 },
eventRow: { flexDirection: 'row', alignItems: 'flex-start', gap: 10 },
eventTime: { width: 50, color: 'rgba(255,255,255,0.4)', fontSize: 10, fontWeight: '500', fontFamily: 'Courier', paddingTop: 2 },
eventTag: { width: 50, alignItems: 'center', paddingVertical: 3, paddingHorizontal: 6, borderRadius: 5 },
eventTagText: { fontSize: 9, fontWeight: '700', letterSpacing: 0.5 },
eventText: { flex: 1, color: colors.consoleText, fontSize: 12, lineHeight: 17, fontFamily: 'Courier' },
jsonCard: { flexDirection: 'row', alignItems: 'center', gap: 12, paddingVertical: 14, paddingHorizontal: 16, borderRadius: 18, borderWidth: 1, borderColor: colors.borderSoft },
jsonTitle: { color: colors.ink, fontSize: 13, fontWeight: '600' },
jsonSub: { color: colors.muted, fontSize: 10 },
rawJson: { marginHorizontal: 16, marginTop: 10, padding: 12, borderRadius: 14, backgroundColor: '#0E1A14', color: colors.consoleText, fontFamily: 'Courier', fontSize: 10 },
});
function tagColor(tag: SdkConsoleEvent['tag']) {
switch (tag) {
case 'BLE':
return '#84B5E8';
case 'STORE':
return '#E8C66B';
case 'TX':
return '#E89C7D';
case 'LIVE':
default:
return '#7DD89E';
}
}