import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { STATUS_COLORS } from './constants';
import { LegendItem } from './types';

const LEGEND_ITEMS: LegendItem[] = [
  { label: '经期', key: 'period' },
  { label: '预测经期', key: 'predicted-period' },
  { label: '排卵期', key: 'fertile' },
  { label: '排卵日', key: 'ovulation-day' },
];

export const Legend: React.FC = () => {
  return (
    <View style={styles.legendRow}>
      {LEGEND_ITEMS.map((item) => (
        <View key={item.key} style={styles.legendItem}>
          <View
            style={[
              styles.legendDot,
              { backgroundColor: STATUS_COLORS[item.key].bg },
              item.key === 'ovulation-day' && styles.legendDotRing,
            ]}
          />
          <Text style={styles.legendLabel}>{item.label}</Text>
        </View>
      ))}
    </View>
  );
};

const styles = StyleSheet.create({
  legendRow: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    gap: 12,
    marginBottom: 12,
    paddingHorizontal: 4,
  },
  legendItem: {
    flexDirection: 'row',
    alignItems: 'center',
  },
  legendDot: {
    width: 16,
    height: 16,
    borderRadius: 8,
    marginRight: 6,
  },
  legendDotRing: {
    borderWidth: 2,
    borderColor: '#fff',
  },
  legendLabel: {
    fontSize: 13,
    color: '#111827',
    fontFamily: 'AliRegular',
  },
});
