-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtop-consumers-list.tsx
More file actions
59 lines (56 loc) · 2.12 KB
/
top-consumers-list.tsx
File metadata and controls
59 lines (56 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { memo } from 'react';
import { Text } from '@/app/components/primitives';
import { getThemeSurfaceTokens } from '@/app/components/shared/theme/theme-surface-tokens';
import { useTheme } from '@/app/hooks';
import type { EnergyConsumer } from '../../types/energy.types';
import { formatEnergyPercent, formatEnergyValue } from '../../utils/energy-formatters';
import { EnergyWidgetShell } from '../energy-widget-shell';
interface TopConsumersListProps {
title: string;
eyebrow: string;
consumers: EnergyConsumer[];
}
export const TopConsumersList = memo(function TopConsumersList({
title,
eyebrow,
consumers,
}: TopConsumersListProps) {
const { theme } = useTheme();
const surface = getThemeSurfaceTokens(theme);
return (
<EnergyWidgetShell title={title} eyebrow={eyebrow}>
{consumers.length === 0 ? (
<Text tone="muted" className="text-sm">
No device-level consumption is available yet.
</Text>
) : (
<div className="space-y-3">
{consumers.map((consumer, index) => (
<div
key={consumer.id}
className={`flex items-center justify-between gap-4 rounded-[24px] border p-4 ${surface.border} ${surface.panelMuted}`}
>
<div className="min-w-0">
<div className={`text-sm font-semibold ${surface.textPrimary}`}>
{index + 1}. {consumer.name}
</div>
<Text tone="muted" className="mt-1 text-sm">
{(consumer.room ?? 'Unassigned').trim()} ·{' '}
{formatEnergyPercent(consumer.shareOfLoad * 100)}% of live load
</Text>
</div>
<div className="text-right">
<div className={`text-sm font-semibold ${surface.textPrimary}`}>
{formatEnergyValue(consumer.powerW / 1000)} kW
</div>
<Text tone="muted" className="mt-1 text-sm">
{formatEnergyValue(consumer.energyKWh)} kWh today
</Text>
</div>
</div>
))}
</div>
)}
</EnergyWidgetShell>
);
});