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

/**
 * 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 };
