import type { ReactNode } from 'react' import { useQuery } from '@tanstack/react-query' import { devicesApi } from '../../api' import type { WidgetConfig } from '../../hooks' import './widget-styles.css' type IconProps = { className?: string } const IconBase = ({ className, children }: IconProps & { children: ReactNode }) => ( {children} ) const ThermometerIcon = ({ className }: IconProps) => ( ) const DropletIcon = ({ className }: IconProps) => ( ) const AirQualityIcon = ({ className }: IconProps) => ( ) const AcousticIcon = ({ className }: IconProps) => ( ) const LightIcon = ({ className }: IconProps) => ( ) interface ComfortIndexWidgetProps { config: WidgetConfig } export default function ComfortIndexWidget({ config }: ComfortIndexWidgetProps) { const deviceId = config.deviceIds[0] const { data, isLoading, error } = useQuery({ queryKey: ['comfort-index', deviceId], queryFn: async () => { const response = await devicesApi.getComfortIndex(deviceId) return response.data }, refetchInterval: 5000, // Refresh every 5 seconds enabled: !!deviceId, }) if (isLoading) { return (
) } if (error || !data) { return (
Failed to load comfort index
) } const getRatingColor = (rating: string) => { switch (rating) { case 'Excellent': return 'text-success' case 'Good': return 'text-info' case 'Fair': return 'text-warning' case 'Poor': return 'text-error' case 'Very Poor': return 'text-error' default: return 'text-base-content' } } const getScoreColor = (score: number) => { if (score >= 90) return 'text-success' if (score >= 75) return 'text-info' if (score >= 60) return 'text-warning' if (score >= 40) return 'text-error' return 'text-error' } return (
{/* Title */}

{config.title}

{/* Overall Score */}
{data.overall_score}
{data.rating}
Comfort Index
{/* Component Scores */}
Temperature
{data.components.temperature}
Humidity
{data.components.humidity}
Air Quality
{data.components.air_quality}
Acoustic
{data.components.acoustic}
Lighting
{data.components.light}
{/* Suggestions */} {data.suggestions.length > 0 && (
Suggestions
{data.suggestions.map((suggestion, i) => (
{suggestion}
))}
)}
) }