import React, { useMemo } from 'react';
import { cn } from '@/lib/utils';

const STATUS_META = {
  paid:      { label: 'Paid',      cls: 'bg-emerald-500/15 text-emerald-500 border border-emerald-500/30 dark:bg-emerald-300/10 dark:text-emerald-200 dark:border-emerald-300/30' },
  upcoming:  { label: 'Upcoming',  cls: 'bg-secondary text-muted-foreground border border-border' },
  due_soon:  { label: 'Due Soon',  cls: 'bg-amber-400/15 text-amber-500 border border-amber-400/30 dark:bg-amber-300/10 dark:text-amber-200 dark:border-amber-300/28' },
  late:      { label: 'Late',      cls: 'bg-orange-400/15 text-orange-500 border border-orange-400/30 dark:bg-orange-300/10 dark:text-orange-200 dark:border-orange-300/26' },
  missed:    { label: 'Missed',    cls: 'bg-red-400/15 text-red-500 border border-red-400/30 dark:bg-rose-300/10 dark:text-rose-200 dark:border-rose-300/26' },
  autodraft: { label: 'Autodraft', cls: 'bg-sky-400/15 text-sky-500 border border-sky-400/30 dark:bg-sky-300/10 dark:text-sky-200 dark:border-sky-300/28' },
  skipped:   { label: 'Skipped',   cls: 'bg-muted text-muted-foreground border border-border' },
};

export const StatusBadge = React.memo(function StatusBadge({ status }) {
  const meta = useMemo(() => STATUS_META[status] || STATUS_META.upcoming, [status]);
  return (
    <span className={cn(
      'inline-flex items-center px-2.5 py-0.5 text-[11px] rounded-md font-semibold',
      'uppercase tracking-wide whitespace-nowrap',
      meta.cls,
    )}>
      {meta.label}
    </span>
  );
});

StatusBadge.displayName = 'StatusBadge';
