'use client'; import { useState } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@repo/shadcn/card'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@repo/shadcn/select'; import { PieChart, Pie, Cell, ResponsiveContainer, Tooltip, Legend } from 'recharts'; import { SurveyStatisticsData } from '../schemas/statistics'; interface SurveyDetailsProps { data: SurveyStatisticsData | undefined; } export function SurveyDetails({ data }: SurveyDetailsProps) { const [selectedSurvey, setSelectedSurvey] = useState(''); if (!data || !data.surveyDetails || data.surveyDetails.length === 0) { return (

No hay datos detallados disponibles

); } // Set default selected survey if none is selected if (!selectedSurvey && data.surveyDetails.length > 0) { setSelectedSurvey(data.surveyDetails?.[0]?.id.toString() ?? ''); } const currentSurvey = data.surveyDetails.find( (survey) => survey.id.toString() === selectedSurvey ); const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042', '#8884d8', '#82ca9d', '#ffc658']; return (
Detalles por Encuesta Análisis detallado de respuestas por encuesta {currentSurvey && ( <>
{currentSurvey.title} {currentSurvey.description}
Total de respuestas: {currentSurvey.totalResponses}
Audiencia objetivo: {currentSurvey.targetAudience}
Fecha de creación: {new Date(currentSurvey.createdAt).toLocaleDateString()}
{currentSurvey.closingDate && (
Fecha de cierre: {new Date(currentSurvey.closingDate).toLocaleDateString()}
)}
{currentSurvey.questionStats && currentSurvey.questionStats.length > 0 && ( Distribución de Respuestas `${name}: ${(percent * 100).toFixed(0)}%`} outerRadius={80} fill="#8884d8" dataKey="count" nameKey="label" > {currentSurvey.questionStats.map((entry, index) => ( ))} [`${value}`, name]} /> {/* */} )}
)}
); }