| 
									
										
										
										
											2025-09-28 19:04:09 -03:00
										 |  |  | // src/features/legislativas/nacionales/ResultadosNacionalesCardsWidget.tsx
 | 
					
						
							|  |  |  | import { useQuery } from '@tanstack/react-query'; | 
					
						
							|  |  |  | import { getResumenPorProvincia } from '../../../apiService'; | 
					
						
							|  |  |  | import { ProvinciaCard } from './components/ProvinciaCard'; | 
					
						
							|  |  |  | import './ResultadosNacionalesCardsWidget.css'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-01 10:03:01 -03:00
										 |  |  | // --- 1. AÑADIR LA PROP A LA INTERFAZ ---
 | 
					
						
							| 
									
										
										
										
											2025-09-28 19:04:09 -03:00
										 |  |  | interface Props { | 
					
						
							|  |  |  |     eleccionId: number; | 
					
						
							| 
									
										
										
										
											2025-10-01 10:03:01 -03:00
										 |  |  |     focoDistritoId?: string; | 
					
						
							|  |  |  |     focoCategoriaId?: number; | 
					
						
							|  |  |  |     cantidadResultados?: number; | 
					
						
							|  |  |  |     mostrarBancas?: boolean; // Booleano opcional
 | 
					
						
							| 
									
										
										
										
											2025-09-28 19:04:09 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-10-01 10:03:01 -03:00
										 |  |  | // --- 2. RECIBIR LA PROP Y ESTABLECER UN VALOR POR DEFECTO ---
 | 
					
						
							|  |  |  | export const ResultadosNacionalesCardsWidget = ({  | 
					
						
							|  |  |  |     eleccionId,  | 
					
						
							|  |  |  |     focoDistritoId,  | 
					
						
							|  |  |  |     focoCategoriaId,  | 
					
						
							|  |  |  |     cantidadResultados, | 
					
						
							|  |  |  |     mostrarBancas = false // Por defecto, no se muestran las bancas
 | 
					
						
							|  |  |  | }: Props) => { | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2025-09-28 19:04:09 -03:00
										 |  |  |     const { data, isLoading, error } = useQuery({ | 
					
						
							| 
									
										
										
										
											2025-10-01 10:03:01 -03:00
										 |  |  |         queryKey: ['resumenPorProvincia', eleccionId, focoDistritoId, focoCategoriaId, cantidadResultados], | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         queryFn: () => getResumenPorProvincia(eleccionId, { | 
					
						
							|  |  |  |             focoDistritoId, | 
					
						
							|  |  |  |             focoCategoriaId, | 
					
						
							|  |  |  |             cantidadResultados | 
					
						
							|  |  |  |         }), | 
					
						
							| 
									
										
										
										
											2025-09-28 19:04:09 -03:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (isLoading) return <div>Cargando resultados por provincia...</div>; | 
					
						
							|  |  |  |     if (error) return <div>Error al cargar los datos.</div>; | 
					
						
							| 
									
										
										
										
											2025-10-01 10:03:01 -03:00
										 |  |  |     if (!data || data.length === 0) return <div>No hay resultados para mostrar con los filtros seleccionados.</div> | 
					
						
							| 
									
										
										
										
											2025-09-28 19:04:09 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return ( | 
					
						
							|  |  |  |         <section className="cards-widget-container"> | 
					
						
							|  |  |  |             <div className="cards-grid"> | 
					
						
							|  |  |  |                 {data?.map(provinciaData => ( | 
					
						
							| 
									
										
										
										
											2025-10-01 10:03:01 -03:00
										 |  |  |                     <ProvinciaCard  | 
					
						
							|  |  |  |                         key={provinciaData.provinciaId}  | 
					
						
							|  |  |  |                         data={provinciaData}  | 
					
						
							|  |  |  |                         mostrarBancas={mostrarBancas}  | 
					
						
							|  |  |  |                     /> | 
					
						
							| 
									
										
										
										
											2025-09-28 19:04:09 -03:00
										 |  |  |                 ))} | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |         </section> | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  | }; |