import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

/** 事件/日志列表块:用于展示监听事件、连续读取结果与降级操作日志 */
export function EventsBlock({
  title,
  events,
  testID = 'events_block',
}: {
  title: string;
  events: string[];
  testID?: string;
}) {
  const visibleEvents = events ?? [];
  return (
    <View testID={testID} style={styles.box}>
      <Text style={styles.title}>
        {title}({visibleEvents.length})
      </Text>
      {visibleEvents.length === 0 ? (
        <Text testID={`${testID}_empty`} style={styles.empty}>
          暂无事件(0 条)
        </Text>
      ) : (
        visibleEvents.map((event, index) => (
          <Text key={`${index}-${event}`} style={styles.line}>
            {event}
          </Text>
        ))
      )}
    </View>
  );
}

const styles = StyleSheet.create({
  box: { backgroundColor: '#fff', borderRadius: 8, padding: 12, marginBottom: 8 },
  title: { fontWeight: 'bold', fontSize: 13, marginBottom: 4, color: '#1f2329' },
  empty: { fontSize: 12, color: '#86909c', lineHeight: 18 },
  line: { fontSize: 12, color: '#333', lineHeight: 18 },
});