/* ── Helpers partagés Admin ───────────────────────────────────── */
export function fmt(iso) {
  if (!iso) return '—';
  const utc = iso.includes('T') || iso.endsWith('Z')
    ? iso
    : iso.replace(' ', 'T') + 'Z';
  return new Date(utc).toLocaleString('fr-FR', {
    day: '2-digit', month: '2-digit', year: 'numeric',
    hour: '2-digit', minute: '2-digit',
  });
}

export function Badge({ role }) {
  const isAdmin = role === 'admin';
  return (
    <span style={{
      display: 'inline-block', padding: '2px 10px', borderRadius: 12,
      fontSize: 11, fontWeight: 700, letterSpacing: '.04em',
      background: isAdmin ? 'rgba(234,179,8,.15)' : 'rgba(100,116,139,.15)',
      color: isAdmin ? '#ca8a04' : '#64748b',
      border: `1px solid ${isAdmin ? 'rgba(234,179,8,.35)' : 'rgba(100,116,139,.25)'}`,
    }}>
      {isAdmin ? 'Admin' : 'Utilisateur'}
    </span>
  );
}

export function StatusBadge({ status }) {
  const ok = status === 'ok';
  return (
    <span style={{
      display: 'inline-block', padding: '2px 10px', borderRadius: 12,
      fontSize: 11, fontWeight: 700,
      background: ok ? 'rgba(34,197,94,.12)' : 'rgba(239,68,68,.12)',
      color: ok ? '#16a34a' : '#dc2626',
      border: `1px solid ${ok ? 'rgba(34,197,94,.3)' : 'rgba(239,68,68,.3)'}`,
    }}>
      {ok ? 'OK' : 'Erreur'}
    </span>
  );
}
