"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 isActive = state !== "off"; 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 accentColor = isHeating ? "#f43f5e" : "#3b82f6"; const accentBg = isHeating ? "rgba(244,63,94,0.08)" : "rgba(59,130,246,0.08)"; const accentBorder = isHeating ? "rgba(244,63,94,0.2)" : "rgba(59,130,246,0.2)"; const accentGlow = isHeating ? "rgba(244,63,94,0.25)" : "rgba(59,130,246,0.2)"; return ( {/* Icon row */}
{/* Status badge */}
{isHeating ? "Нагрев" : isActive ? "Охлаждение" : "Выкл"}
{/* Current temperature — BIG */}
{currentTemp?.toFixed(1) ?? "—"}°
текущая температура
{/* Target temperature controls */}
Цель
adjust(-0.5)} className="w-10 h-10 rounded-xl flex items-center justify-center" style={{ background: "rgba(255,255,255,0.08)", border: "1px solid rgba(255,255,255,0.1)", }} whileTap={{ scale: 0.82 }} > {target}° adjust(0.5)} className="w-10 h-10 rounded-xl flex items-center justify-center" style={{ background: `${accentColor}22`, border: `1px solid ${accentColor}50`, }} whileTap={{ scale: 0.82 }} >
); }