import React from 'react'; import { View, Text, StyleSheet, ScrollView, Pressable } from 'react-native'; import { Colors } from '../theme/colors'; import { FontSize, FontWeight, Radius, Spacing, RAIL_WIDTH } from '../theme/layout'; import { t, type TranslationKey } from '../../i18n'; const LABEL_MAP: Record = { network: 'feature.short.network', console: 'feature.short.console', native: 'feature.short.native', navigation: 'feature.short.navigation', state: 'feature.short.state', track: 'feature.short.track', clipboard: 'feature.short.clipboard', environment: 'feature.short.environment', connect: 'feature.short.connect', history: 'feature.short.history', accounts: 'feature.short.accounts', tabs: 'feature.short.tabs', }; const DEFAULT_LABELS: Record = { network: 'Network', console: 'Console', native: 'Native', navigation: 'Navigation', state: 'State', track: 'Track', clipboard: 'Clipboard', environment: 'Environment', connect: 'Connect', history: 'History', accounts: 'Accounts', tabs: 'Custom', }; const FULL_LABEL_KEYS: Record = { network: 'feature.network', console: 'feature.console', native: 'feature.native', navigation: 'feature.navigation', state: 'feature.state', track: 'feature.track', clipboard: 'feature.clipboard', environment: 'feature.environment', connect: 'feature.connect', history: 'feature.history', accounts: 'feature.accounts', tabs: 'feature.tabs', }; export function shortLabelForFeature(label: string, id: string): string { const mapped = LABEL_MAP[id]; const fullKey = FULL_LABEL_KEYS[id]; if (mapped && ( label.trim() === DEFAULT_LABELS[id] || (fullKey && label.trim() === t(fullKey)) )) { return t(mapped); } return label.trim().slice(0, 12); } export interface RailItem { id: string; label: string; dotColor?: string | null; count?: number; } interface FeatureRailProps { items: RailItem[]; activeIndex: number; onSelectTab: (index: number) => void; } export function FeatureRail({ items, activeIndex, onSelectTab }: FeatureRailProps) { return ( {items.map((item, index) => { const isActive = index === activeIndex; const label = shortLabelForFeature(item.label, item.id); const hasCount = item.count != null && item.count > 0; const countLabel = hasCount && item.count != null && item.count > 99 ? '99+' : item.count; return ( onSelectTab(index)} style={[styles.item, isActive && styles.activeItem]} accessibilityRole="tab" accessibilityLabel={item.label} accessibilityState={{ selected: isActive }} > {isActive && } {label} {hasCount && ( {countLabel} )} ); })} ); } const styles = StyleSheet.create({ rail: { width: RAIL_WIDTH, backgroundColor: Colors.railBackground, borderRightWidth: 1, borderRightColor: Colors.panelDivider, overflow: 'hidden', }, topGlow: { position: 'absolute', top: -36, left: -20, width: 64, height: 64, borderRadius: 32, backgroundColor: 'rgba(77,163,255,0.06)', }, bottomShade: { position: 'absolute', bottom: -34, left: 0, right: 0, height: 96, backgroundColor: Colors.railShade, }, scrollContent: { paddingVertical: Spacing.SM, paddingHorizontal: Spacing.XS, gap: 2, }, item: { minHeight: 52, borderRadius: Radius.MD, paddingHorizontal: Spacing.XXS, paddingVertical: Spacing.SM, alignItems: 'center', justifyContent: 'center', overflow: 'hidden', }, activeItem: { backgroundColor: Colors.railActiveBg, }, activeBar: { position: 'absolute', left: 0, top: 12, bottom: 12, width: 3, borderTopRightRadius: 2, borderBottomRightRadius: 2, backgroundColor: Colors.railActiveBar, }, itemText: { color: Colors.railInactiveText, fontSize: FontSize.XS, fontWeight: FontWeight.semibold, textAlign: 'center', }, activeItemText: { color: Colors.railActiveText, }, countPill: { marginTop: 3, minWidth: 18, height: 14, borderRadius: Radius.Pill, backgroundColor: Colors.surfaceElevated, paddingHorizontal: 4, alignItems: 'center', justifyContent: 'center', }, activeCountPill: { backgroundColor: Colors.primary, }, countText: { fontSize: FontSize.XXS, fontWeight: FontWeight.bold, color: Colors.textSecondary, }, activeCountText: { color: Colors.textInverse, }, });