import { useApi } from './api.mjs';
import { useSubscription } from './subscription.mjs';
import { ExtensionHasNoFieldError } from './errors.mjs';

/**
 * Returns the market of the checkout, and automatically re-renders
 * your component if it changes.
 */
function useLocalizationMarket() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('market' in api.localization)) {
    throw new ExtensionHasNoFieldError('market', extensionTarget);
  }
  return useSubscription(api.localization.market);
}

export { useLocalizationMarket };
