export function formateaFecha(fecha) {
  if (!fecha) return '—';
  const partes = fecha.split(" ")[0].split("-");
  return `${partes[2]}/${partes[1]}/${partes[0]}`;
}

export function showToast(message, type = 'info') {
  const icon = type === 'success' ? 'success' : (type === 'danger' ? 'error' : 'info');
  Swal.fire({
    toast: true,
    position: 'top-end',
    showConfirmButton: false,
    timer: 2500,
    icon,
    title: message
  });
}

export function formatNumber(value) {
  const n = Number(value || 0);
  return new Intl.NumberFormat('es-MX', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(n);
}

export function formatInteger(value) {
  const n = Number(value || 0);
  return new Intl.NumberFormat('es-MX', { maximumFractionDigits: 0 }).format(n);
}

export function formatPercent(value) {
  if (value === null || value === undefined || value === '') return '0%';
  const n = Number(value || 0);
  // Mostrar sin decimales si es entero
  const s = Number.isInteger(n) ? n.toString() : n.toFixed(2).replace(/\.00$/, '');
  return `${s}%`;
}
