import { useParameterStore } from '@statsig/react-bindings';

import {
  CURRENCY_OPTIONS,
  Currency,
  CurrencyOption,
} from '@/app/(root)/account/constants';

// Core currencies shown when 17-currency feature is disabled
const OG_CURRENCIES = [
  Currency.USD,
  Currency.EUR,
  Currency.INR,
  Currency.BRL,
  Currency.JPY,
  Currency.KRW,
];

/**
 * Hook to get available currency options based on feature flag
 *
 * Uses Statsig Parameter Store for dynamic configuration:
 * - Parameter Store: `billing-experiments`
 * - Parameter: `enable-17-ccys`
 *
 * When enabled: Returns all 17 currencies
 * When disabled: Returns only core 6 currencies (USD, EUR, BRL, INR, JPY, KRW)
 *
 * @returns Array of currency options to display
 */
export function useCurrencyOptions(): CurrencyOption[] {
  const store = useParameterStore('billing-experiments');
  const enable17Currencies = store.get('enable-17-ccys', false);

  if (enable17Currencies) {
    return CURRENCY_OPTIONS;
  }

  return CURRENCY_OPTIONS.filter((option) =>
    OG_CURRENCIES.includes(option.value)
  );
}
