import { STATUS_STYLES } from './tokens'

// Unified StatusBadge — replaces both src/components/StatusBadge.jsx
// and the StatusBadge in TablePrimitives.jsx.
//
// Greek labels map to the canonical status keys used across the app.
const LABELS = {
  free:           'Ελεύθερο',
  open:           'Ανοιχτό',
  active:         'Ενεργό',
  partially_paid: 'Μερική πληρωμή',
  paid:           'Πληρώθηκε',
  closed:         'Κλειστό',
  closed_item:    'Κλειστό (απλήρωτο)',
  'force-closed': 'Αναγκαστικό κλείσιμο',
  cancelled:      'Ακυρώθηκε',
  completed:      'Ολοκληρώθηκε',
  failed:         'Απέτυχε',
  success:        'Επιτυχία',
}

export default function Badge({ status, pulse = false }) {
  const s = STATUS_STYLES[status] || STATUS_STYLES.closed
  const label = LABELS[status] ?? (status ? status.replace(/[_-]/g, ' ') : 'άγνωστο')

  return (
    <span className={`inline-flex items-center gap-1.5 rounded-full px-2 py-0.5 text-[10px] font-mono uppercase tracking-[0.08em] ring-1 ring-inset ${s.bg} ${s.text} ${s.ring}`}>
      <span className={`relative inline-block h-1.5 w-1.5 rounded-full flex-shrink-0 ${s.dot}`}>
        {pulse && (status === 'active' || status === 'open') && (
          <span className={`absolute inset-0 rounded-full ${s.dot} animate-ping opacity-75`} />
        )}
      </span>
      {label}
    </span>
  )
}
