import React from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import { PRIORITY_COLORS } from '@/constants';
import { Priority } from '@/types';
import { useSettings } from '@/theme';
import Svg, { Circle } from 'react-native-svg';

interface PrioritySelectorProps {
  value: Priority;
  onChange: (value: Priority) => void;
}

const priorities: Array<{ value: Priority; label: string }> = [
  { value: 'none', label: 'None' },
  { value: 'low', label: 'Low' },
  { value: 'medium', label: 'Medium' },
  { value: 'high', label: 'High' },
  { value: 'critical', label: 'Critical' },
];

export function PrioritySelector({ value, onChange }: PrioritySelectorProps) {
  const { theme } = useSettings();

  return (
    <View style={styles.container}>
      <Text style={[styles.label, { color: theme.text }]}>Priority</Text>
      <View style={styles.options}>
        {priorities.map((priority) => (
          <TouchableOpacity
            key={priority.value}
            style={[
              styles.option,
              { backgroundColor: theme.card, borderColor: theme.borderStrong },
              value === priority.value && { borderColor: theme.accent, backgroundColor: theme.accentSoft, borderWidth: 2 },
            ]}
            onPress={() => onChange(priority.value)}
            activeOpacity={0.8}
          >
            <View style={[
              styles.colorIndicator,
              { backgroundColor: PRIORITY_COLORS[priority.value] },
              value === priority.value && styles.colorIndicatorSelected,
            ]} />
            <Text style={[
              styles.optionText,
              { color: theme.textFaint },
              value === priority.value && { color: theme.accent, fontWeight: '600' },
            ]}>
              {priority.label}
            </Text>
          </TouchableOpacity>
        ))}
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    gap: 10,
  },
  label: {
    fontSize: 14,
    fontWeight: '600',
  },
  options: {
    flexDirection: 'row',
    gap: 8,
  },
  option: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    gap: 6,
    paddingVertical: 12,
    paddingHorizontal: 16,
    borderRadius: 12,
    borderWidth: 1,
  },
  colorIndicator: {
    width: 10,
    height: 10,
    borderRadius: 5,
    opacity: 0.5,
  },
  colorIndicatorSelected: {
    opacity: 1,
    width: 12,
    height: 12,
    borderRadius: 6,
  },
  optionText: {
    fontSize: 13,
    fontWeight: '500',
  },
});