// @design-system: domain/StatusPill

import { Pill } from '@/components/ui/primitives/Pill';
import type { PillProps } from '@/components/ui/primitives/Pill';
import { useT } from '@/lib/i18n/react';
import type { DealState as RegistryDealState } from '@/lib/enums/deal-state';

// StatusPill is not shown for DRAFT/ARCHIVED deals — labelMap covers only the 7 displayed states.
export type DealState = Exclude<RegistryDealState, 'DRAFT' | 'ARCHIVED'>;

/** Props for StatusPill */
export interface StatusPillProps {
  /** The deal state to display. */
  state: DealState;
  /** Size. @default 'md' */
  size?: PillProps['size'];
  /** Additional class names. */
  className?: string;
}

const tonemap: Record<DealState, PillProps['tone']> = {
  ACTIVE: 'success',
  UNDER_REVIEW: 'info',
  PENDING_APPROVAL: 'warning',
  REJECTED: 'danger',
  EXPIRED: 'neutral',
  SOLD_OUT: 'info',
  PAUSED: 'neutral',
};

/**
 * StatusPill - semantic pill that maps deal states to visual tones.
 *
 * @example
 * ```tsx
 * <StatusPill state="ACTIVE" />
 * <StatusPill state="REJECTED" size="sm" />
 * ```
 */
export function StatusPill({ state, size = 'md', className }: StatusPillProps) {
  const t = useT('domain_status_pill');

  const labelMap: Record<DealState, string> = {
    ACTIVE: t('active'),
    UNDER_REVIEW: t('under_review'),
    PENDING_APPROVAL: t('pending'),
    REJECTED: t('rejected'),
    EXPIRED: t('expired'),
    SOLD_OUT: t('sold_out'),
    PAUSED: t('paused'),
  };

  return (
    <Pill tone={tonemap[state]} size={size} className={className}>
      {labelMap[state]}
    </Pill>
  );
}
