"use client"; import { useState, useCallback } from "react"; import { motion } from "framer-motion"; import { Thermometer, Plus, Minus } from "lucide-react"; import { setClimateTemp } from "@/lib/api"; interface Props { entityId: string; currentTemp?: number; targetTemp?: number; state: string; onUpdate: () => void; } export default function TemperatureCard({ entityId, currentTemp, targetTemp, state, onUpdate, }: Props) { const [target, setTarget] = useState(targetTemp || 22); const isHeating = state === "heat"; const adjust = useCallback( async (delta: number) => { const next = Math.min(30, Math.max(16, target + delta)); setTarget(next); await setClimateTemp(entityId, next); onUpdate(); }, [target, entityId, onUpdate] ); const tempDiff = currentTemp ? currentTemp - target : 0; return (
Термостат
{isHeating ? "Нагрев" : "Ожидание"}
{currentTemp?.toFixed(1) ?? "—"}°
текущая
Целевая температура
adjust(-0.5)} className="w-8 h-8 rounded-lg flex items-center justify-center" style={{ background: "rgba(255,255,255,0.08)" }} whileTap={{ scale: 0.85 }} > {target}° adjust(0.5)} className="w-8 h-8 rounded-lg flex items-center justify-center" style={{ background: "rgba(99,102,241,0.2)" }} whileTap={{ scale: 0.85 }} >
); }