2026-08-25 07:51:38 +02:00
|
|
|
"use client";
|
|
|
|
|
|
2026-08-25 16:43:28 +02:00
|
|
|
import { Card, CardContent, CardHeader } from "@/components/ui/card";
|
2026-08-25 07:51:38 +02:00
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { ActuatorSlider } from "./ActuatorSlider";
|
|
|
|
|
import type { ConnectedDeviceInfo } from "@/lib/buttplug/types";
|
2026-08-25 21:26:18 +02:00
|
|
|
import { Battery, BatteryFull, BatteryLow, BatteryMedium, BatteryWarning, Unlink } from "lucide-react";
|
2026-08-25 07:51:38 +02:00
|
|
|
|
|
|
|
|
interface DeviceCardProps {
|
|
|
|
|
device: ConnectedDeviceInfo;
|
2026-08-25 17:33:48 +02:00
|
|
|
batteryLevel: number | null;
|
2026-08-25 07:51:38 +02:00
|
|
|
actuatorValues: Record<number, number>;
|
|
|
|
|
transmittingFeatureIndex: number | null;
|
|
|
|
|
onActuatorChange: (featureIndex: number, value: number) => void;
|
|
|
|
|
onStop: () => void;
|
2026-08-25 21:26:18 +02:00
|
|
|
onDisconnect: () => void;
|
2026-08-25 07:51:38 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-25 17:33:48 +02:00
|
|
|
function BatteryIndicator({ level }: { level: number }) {
|
|
|
|
|
const Icon = level < 0.15 ? BatteryWarning : level < 0.4 ? BatteryLow : level < 0.8 ? BatteryMedium : BatteryFull;
|
|
|
|
|
return (
|
|
|
|
|
<span className={`flex items-center gap-1 ${level < 0.15 ? "text-destructive" : "text-muted-foreground"}`}>
|
|
|
|
|
<Icon className="size-3.5" />
|
|
|
|
|
<span className="bp-readout text-xs">{Math.round(level * 100)}%</span>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-25 07:51:38 +02:00
|
|
|
export function DeviceCard({
|
|
|
|
|
device,
|
2026-08-25 17:33:48 +02:00
|
|
|
batteryLevel,
|
2026-08-25 07:51:38 +02:00
|
|
|
actuatorValues,
|
|
|
|
|
transmittingFeatureIndex,
|
|
|
|
|
onActuatorChange,
|
|
|
|
|
onStop,
|
2026-08-25 21:26:18 +02:00
|
|
|
onDisconnect,
|
2026-08-25 07:51:38 +02:00
|
|
|
}: DeviceCardProps) {
|
|
|
|
|
return (
|
|
|
|
|
<Card className="bp-glass">
|
2026-08-25 16:43:28 +02:00
|
|
|
<CardHeader className="flex flex-row items-center justify-between pb-3">
|
|
|
|
|
<span className="text-sm font-medium text-foreground">{device.displayName ?? device.name}</span>
|
2026-08-25 17:33:48 +02:00
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
{device.hasBattery &&
|
|
|
|
|
(batteryLevel !== null ? (
|
|
|
|
|
<BatteryIndicator level={batteryLevel} />
|
|
|
|
|
) : (
|
|
|
|
|
<Battery className="size-3.5 text-muted-foreground" aria-label="Reading battery level" />
|
|
|
|
|
))}
|
|
|
|
|
<Button variant="outline" size="sm" onClick={onStop}>
|
|
|
|
|
Stop
|
|
|
|
|
</Button>
|
2026-08-25 21:26:18 +02:00
|
|
|
<Button variant="ghost" size="icon-sm" onClick={onDisconnect} aria-label="Disconnect device">
|
|
|
|
|
<Unlink className="size-3.5" />
|
|
|
|
|
</Button>
|
2026-08-25 17:33:48 +02:00
|
|
|
</div>
|
2026-08-25 07:51:38 +02:00
|
|
|
</CardHeader>
|
2026-08-25 16:43:28 +02:00
|
|
|
<div className="bp-hairline mx-4" />
|
|
|
|
|
<CardContent className="flex flex-col gap-3 pt-3">
|
2026-08-25 07:51:38 +02:00
|
|
|
{device.actuators.length === 0 ? (
|
|
|
|
|
<p className="text-sm text-muted-foreground">No controllable actuators reported.</p>
|
|
|
|
|
) : (
|
|
|
|
|
device.actuators.map((actuator) => (
|
|
|
|
|
<ActuatorSlider
|
|
|
|
|
key={actuator.featureIndex}
|
|
|
|
|
actuator={actuator}
|
|
|
|
|
value={actuatorValues[actuator.featureIndex] ?? 0}
|
|
|
|
|
transmitting={transmittingFeatureIndex === actuator.featureIndex}
|
|
|
|
|
onChange={(value) => onActuatorChange(actuator.featureIndex, value)}
|
|
|
|
|
/>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|