import { useApi } from './api.esnext';
import { ExtensionHasNoFieldError } from './errors.esnext';

/**
 * Returns the `Shop` where the checkout is taking place.
 */
function useShop() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('shop' in api)) {
    throw new ExtensionHasNoFieldError('shop', extensionTarget);
  }
  return api.shop;
}

export { useShop };
