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

interface BatteryStatusProps {
  status: 1 | 0 | -1 | null;
  style?: ViewStyle;
}

const BatteryStatus: React.FC<BatteryStatusProps> = ({ status, style }) => {
  const getStatusConfig = (): {
    text: string;
    backgroundColor: string;
    textColor: string;
  } => {
    switch (status) {
      case 1:
        return {
          text: "Charging",
          backgroundColor: "#006C4D",
          textColor: "#006C4D",
        };
      case -1:
        return {
          text: "Discharging",
          backgroundColor: "#E5EBFD",
          textColor: "#1249ED",
        };
      case 0:
        return {
          text: "Idle",
          backgroundColor: "#565F70",
          textColor: "#565F70",
        };
      case null:
        return {
          text: "---",
          backgroundColor: "#e2e3e5",
          textColor: "#6c757d",
        };
      default:
        return {
          text: "Unknown",
          backgroundColor: "#f8f9fa",
          textColor: "#6c757d",
        };
    }
  };

  const config = getStatusConfig();

  return (
    <View
      style={[
        styles.container,
        {
          backgroundColor: config.backgroundColor,
        },
        style,
      ]}
    >
      <Text
        style={[
          styles.text,
          {
            color: config.textColor,
          },
        ]}
      >
        {config.text}
      </Text>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    paddingHorizontal: 8,
    paddingVertical: 2,
    borderRadius: 4,
    justifyContent: "center",
  },
  text: {
    fontSize: 16,
    fontWeight: "500",
  },
});

export default BatteryStatus;
