import { EXCHANGE_STATUS_PILL, ExchangesTab } from './constants';
import {
  type Exchange,
  type ExchangePill,
  ExchangeStatus,
  type ExchangesTabValue,
} from './types';

export const isValidExchangesTab = (
  value: string,
): value is ExchangesTabValue =>
  (Object.values(ExchangesTab) as string[]).includes(value);

export const getExchangePill = (exchange: Exchange): ExchangePill => {
  // The expired state only lives in `status`; `statusWithoutTranslation` keeps
  // the original delivery state, so it is checked first.
  if (exchange.status === ExchangeStatus.EXPIRED) {
    return EXCHANGE_STATUS_PILL[ExchangeStatus.EXPIRED];
  }

  return (
    EXCHANGE_STATUS_PILL[exchange.statusWithoutTranslation] ??
    EXCHANGE_STATUS_PILL[ExchangeStatus.PENDING_DELIVERY]
  );
};
