import {
Box,
CircularProgress,
Alert,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
Paper,
Typography,
Tooltip
} from '@mui/material';
import type { CotizacionBolsa } from '../models/mercadoModels';
import { useApiData } from '../hooks/useApiData';
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
import RemoveIcon from '@mui/icons-material/Remove'; // Para cambios neutros
// Función para formatear números
const formatNumber = (num: number) => {
return new Intl.NumberFormat('es-AR', {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
}).format(num);
};
// Componente para mostrar la variación con color e icono
const Variacion = ({ value }: { value: number }) => {
const color = value > 0 ? 'success.main' : value < 0 ? 'error.main' : 'text.secondary';
const Icon = value > 0 ? ArrowUpwardIcon : value < 0 ? ArrowDownwardIcon : RemoveIcon;
return (
{formatNumber(value)}%
);
};
export const BolsaLocalWidget = () => {
const { data, loading, error } = useApiData('/mercados/bolsa/local');
if (loading) {
return ;
}
if (error) {
return {error};
}
if (!data || data.length === 0) {
return No hay datos disponibles para el mercado local en este momento.;
}
return (
Símbolo
Precio Actual
Apertura
Cierre Anterior
% Cambio
{data.map((row) => (
{row.ticker}
${formatNumber(row.precioActual)}
${formatNumber(row.apertura)}
${formatNumber(row.cierreAnterior)}
))}
Fuente: Yahoo Finance
);
};