import { View, Text, Pressable, StyleSheet } from 'react-native';
import Ionicons from '@expo/vector-icons/Ionicons';
import { spacing, radii } from '../../../theme';
import { trackingColors } from '../theme';
import { formatDateHeader } from '../utils/format';

type Props = {
  date: string;
  streak: number;
  fastingEnabled: boolean;
  isToday: boolean;
  onOpenCalendar: () => void;
  onOpenFasting: () => void;
  onOpenWeight: () => void;
};

export function TrackingHeader({ date, streak, fastingEnabled, isToday, onOpenCalendar, onOpenFasting, onOpenWeight }: Props) {
  return (
    <View style={styles.wrap}>
      <Pressable style={styles.dateRow} onPress={onOpenCalendar} hitSlop={6}>
        <Text style={styles.date}>{formatDateHeader(date)}{isToday ? '' : ' · historique'}</Text>
        <Ionicons name="calendar-outline" size={16} color={trackingColors.textMuted} />
      </Pressable>

      <View style={styles.chipsRow}>
        {fastingEnabled && (
          <Pressable style={styles.chip} onPress={onOpenFasting} hitSlop={4}>
            <Ionicons name="time-outline" size={13} color={trackingColors.text} />
            <Text style={styles.chipText}>Jeûne</Text>
          </Pressable>
        )}
        <Pressable style={styles.chip} onPress={onOpenWeight} hitSlop={4}>
          <Ionicons name="trending-up-outline" size={13} color={trackingColors.text} />
          <Text style={styles.chipText}>Poids</Text>
        </Pressable>
        {streak > 0 && (
          <View style={[styles.chip, styles.streakChip]}>
            <Text style={styles.streakChipText}>{streak} j</Text>
          </View>
        )}
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  wrap: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', flexWrap: 'wrap', gap: spacing.xs },
  dateRow: { flexDirection: 'row', alignItems: 'center', gap: 6 },
  date: { fontSize: 14, fontWeight: '600', color: trackingColors.textMuted },
  chipsRow: { flexDirection: 'row', flexWrap: 'wrap', gap: spacing.xs },
  chip: {
    flexDirection: 'row',
    alignItems: 'center',
    gap: 4,
    borderWidth: 1,
    borderColor: trackingColors.borderStrong,
    paddingHorizontal: 12,
    paddingVertical: 6,
    borderRadius: radii.pill,
  },
  streakChip: { backgroundColor: trackingColors.warnBg, borderColor: trackingColors.warnBg },
  chipText: { fontSize: 12, fontWeight: '600', color: trackingColors.text },
  streakChipText: { fontSize: 12, fontWeight: '700', color: trackingColors.warnText },
});
