import { WARN_DISPLAY_PERCENT } from '../../lib/battery.js'; const WARN_FLASH_MS = 1600; const URGENT_FLASH_MS = 800; function classNames(...values) { return values.filter(Boolean).join(' '); } export default function BatteryBar({ visual, orientation = 'horizontal', variant = 'inline', compact = false, showLabel, className = '', }) { const isBackground = variant === 'background'; const isVertical = orientation === 'vertical'; const resolvedShowLabel = showLabel ?? !isBackground; if (!visual?.available) { if (isBackground) { const warnPercent = WARN_DISPLAY_PERCENT; const markerClass = classNames( 'absolute z-10', isVertical ? 'left-0 right-0 h-[2px]' : 'top-0 bottom-0 w-[2px]', 'bg-black/70', isWarn && !isUrgent && 'battery-tick-warn', ); const markerStyle = isVertical ? { bottom: `${warnPercent}%` } : { left: `${warnPercent}%` }; const containerClass = classNames('absolute inset-0 pointer-events-none', className); return (
Battery telemetry unavailable
; } const percentDisplay = visual.percentDisplay ?? 0; const percent = Math.max(0, Math.min(100, percentDisplay)); const warnPercent = visual.warnDisplayPercent ?? WARN_DISPLAY_PERCENT; const isUrgent = Boolean(visual.urgentActive); const isWarn = Boolean(visual.warnActive); const shouldFlash = isUrgent || isWarn; const animationDuration = isUrgent ? `${URGENT_FLASH_MS}ms` : isWarn ? `${WARN_FLASH_MS}ms` : undefined; const fillColor = isUrgent || isWarn ? 'bg-red-500' : 'bg-emerald-500'; const fillTone = isBackground ? isUrgent || isWarn ? 'bg-red-500/45' : 'bg-emerald-500/45' : fillColor; const baseTone = isUrgent || isWarn ? 'bg-red-900/35' : 'bg-slate-900/35'; const baseToneStrong = isUrgent || isWarn ? 'bg-red-900/45' : 'bg-slate-900/35'; const containerClass = classNames( isBackground ? 'absolute inset-0 pointer-events-none' : 'relative pointer-events-auto', isVertical && !isBackground ? 'flex flex-col items-center justify-center' : 'w-full', className, ); if (isBackground) { const fillStyle = isVertical ? { height: `${percent}%` } : { width: `${percent}%` }; const fillClass = classNames( 'absolute', isVertical ? 'bottom-0 left-0 right-0' : 'left-0 top-0 bottom-0', fillTone, 'transition-[width,height]', isUrgent && 'battery-urgent-flash', ); const markerClass = classNames( 'absolute z-10', isVertical ? 'left-0 right-0 h-[2px]' : 'top-0 bottom-0 w-[2px]', 'bg-black/70', isWarn && !isUrgent && 'battery-tick-warn', ); const markerStyle = isVertical ? { bottom: `${warnPercent}%` } : { left: `${warnPercent}%` }; return (