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

/**
 * Returns the setting values defined by the merchant for the extension.
 */
function useSettings() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('settings' in api)) {
    throw new ExtensionHasNoFieldError('settings', extensionTarget);
  }
  const settings = useSubscription(api.settings);
  return settings;
}

export { useSettings };
