'use client';
import { FunctionComponent } from 'react';
import { useTranslations } from 'next-intl';
import type { ChipProps } from '@mui/material/Chip';
import StatusChip, { StatusKind } from '@/components/StatusChip';
import type { PaymentTransactionStatus } from '@/services/payment/types';

// The full b10 enum → chip kind; a status missing here fails the type check, so a contract enum change
// surfaces at build time instead of rendering an unmapped chip.
const STATUS_KIND: Record<PaymentTransactionStatus, StatusKind> = {
  pending: 'pending',
  succeeded: 'verified',
  failed: 'rejected',
};

export interface PaymentStatusBadgeProps extends Omit<ChipProps, 'color' | 'icon' | 'label'> {
  status: PaymentTransactionStatus;
}

/**
 * Payment-transaction status chip: maps the b10 wire code to a `--bal-*` semantic StatusChip variant and
 * an i18n label (`payment.pstatus_*` — labels are keys off the code, never derived from it). Shared by
 * the checkout return surface now and the f10 refund / f11 BNPL surfaces later.
 * @component PaymentStatusBadge
 */
const PaymentStatusBadge: FunctionComponent<PaymentStatusBadgeProps> = ({ status, ...rest }) => {
  const t = useTranslations('payment');
  return <StatusChip status={STATUS_KIND[status]} label={t(`pstatus_${status}`)} {...rest} />;
};

export default PaymentStatusBadge;
