import { memo } from 'react' import { Battery, RotateCcw, ShieldCheck, Smartphone } from 'lucide-react' import type { Device } from '../../types' type DeviceStatsCardsProps = { device: Device } function formatWorkTimeHours(worktime?: number | null) { if (typeof worktime !== 'number') return '-' const hours = worktime / 1000 / 60 / 60 if (hours < 1) { const minutes = Math.round(worktime / 1000 / 60) return `${minutes} мин` } if (hours < 10) { return `${hours.toFixed(1)} ч` } return `${Math.round(hours)} ч` } function areStatsCardsPropsEqual( prev: DeviceStatsCardsProps, next: DeviceStatsCardsProps, ) { return ( prev.device.battery === next.device.battery && prev.device.batteryMaxCapacity === next.device.batteryMaxCapacity && prev.device.chargeCycles === next.device.chargeCycles && prev.device.totalWorkTime === next.device.totalWorkTime && prev.device.mediumImpacts === next.device.mediumImpacts ) } export const DeviceStatsCards = memo(function DeviceStatsCards({ device, }: DeviceStatsCardsProps) { const batteryValue = typeof device.battery === 'number' ? Math.max(0, Math.min(100, device.battery)) : null const batterySize = 110 const batteryStroke = 12 const batteryRadius = (batterySize - batteryStroke) / 2 const batteryLength = 2 * Math.PI * batteryRadius const batteryProgress = batteryValue !== null ? batteryValue / 100 : 0 const batteryDashOffset = batteryLength * (1 - batteryProgress) function getBatteryColor(value: number | null) { if (value === null) return 'var(--device-battery-progress-empty)' if (value <= 20) return 'var(--device-battery-progress-danger)' if (value <= 50) return 'var(--device-battery-progress-warning)' return 'var(--device-battery-progress-strong)' } return (