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

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

export { useNote };
