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

/**
 * Returns the `checkoutSettings` applied to the checkout.
 */
function useCheckoutSettings() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('checkoutSettings' in api)) {
    throw new ExtensionHasNoFieldError('checkoutSettings', extensionTarget);
  }
  return useSubscription(api.checkoutSettings);
}

export { useCheckoutSettings };
