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: "#DAF5ED",
          textColor: "#006C4D",
        };
      case -1:
        return {
          text: "Discharging",
          backgroundColor: "#E5EBFD",
          textColor: "#1249ED",
        };
      case 0:
        return {
          text: "Idle",
          backgroundColor: "#D8DDE7",
          textColor: "#565F70",
        };
      default:
        return {
          text: "---",
          backgroundColor: "#D8DDE7",
          textColor: "#565F70",
        };
    }
  };

  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;
