import React from 'react';
import { Zap, Activity, BatteryCharging, Power } from 'lucide-react';
import { UpsData } from '../app/page';
import styles from './StatCards.module.css';
interface StatCardsProps {
data: UpsData | null;
}
export default function StatCards({ data }: StatCardsProps) {
// If no data received yet (device offline), show dashes
if (!data) {
return (
{['Output Status', 'Charging Status', 'Battery Level', 'Power Source'].map(title => (
))}
);
}
const outputOn = data.on === 1;
const isCharging = data.charging === 1;
const chgError = data.chgError === 1;
const isFull = data.charging === 0 && (data.battP ?? 0) >= 95 && (data.line ?? 0) > 0;
let chargingText = "Discharging";
if (chgError) chargingText = "Error";
else if (isFull) chargingText = "Fully Charged";
else if (isCharging) chargingText = "Charging";
else if ((data.line ?? 0) > 0) chargingText = "Standby";
const battPercent = data.battP ?? 0;
const battVoltage = data.v ?? "0.00";
const isBypass = (data.line ?? 0) > 0;
const powerSource = isBypass ? "Adaptor" : "Battery";
return (
{/* Card 1: Output Status */}
{outputOn ? 'ON' : 'OFF'}
{outputOn ? 'Powering Load' : 'Disabled'}
{/* Card 2: Charging Status */}
{chargingText}
{chgError ? 'Check Battery' : isCharging ? 'Active' : 'Idle'}
{/* Card 3: Battery Level */}
{battPercent}
%
({battVoltage}V)
{/* Card 4: Power Source */}
{powerSource}
Relay: {isBypass ? 'Bypass Mode' : 'Inverter Mode'}
);
}