'use client' import { useEffect, useState } from 'react' import { isSuppressed, type PuntoCiegoData, type SuppressedPayload, type DashboardFilters, } from '@/lib/dashboard-types' import { queries } from '@/lib/dashboard-queries' import { WidgetShell } from './widget-shell' const MAX_BAR_HEIGHT = 70 export function PuntoCiegoCard({ surveyId, filters }: { surveyId: string; filters: DashboardFilters }) { const [data, setData] = useState(null) const [error, setError] = useState(false) useEffect(() => { setData(null); setError(false) queries.mePuntoCiego(surveyId, filters) .then((d) => setData(d as PuntoCiegoData | SuppressedPayload)) .catch(() => setError(true)) }, [surveyId, JSON.stringify(filters)]) const status = error ? 'error' : data === null ? 'loading' : isSuppressed(data) ? 'suppressed' : 'ok' const ok = status === 'ok' ? (data as PuntoCiegoData) : null const cargaHeight = ok ? Math.max(6, (ok.carga_real_pct / 100) * MAX_BAR_HEIGHT) : 0 const apoyoHeight = ok && ok.apoyo_percibido_pct !== null ? Math.max(6, (ok.apoyo_percibido_pct / 100) * MAX_BAR_HEIGHT) : 0 return ( {ok && ( <>
{ok.carga_real_pct}%
carga real
{ok.apoyo_percibido_pct !== null ? ( <>
{ok.apoyo_percibido_pct}%
) : (
n<5
)}
se siente apoyado
{ok.brecha_pp !== null && (

Brecha: {ok.brecha_pp} puntos porcentuales

)} )} ) }