import { ExtensionHasNoMethodError } from './errors.esnext';
import { useApi } from './api.esnext';
import { useSubscription } from './subscription.esnext';

/**
 * Returns the proposed `note` applied to the checkout.
 */
function useNote() {
  return useSubscription(useApi().note);
}

/**
 * Returns a function to mutate the `note` property of the checkout.
 */
function useApplyNoteChange() {
  const api = useApi();
  if ('applyNoteChange' in api) {
    return api.applyNoteChange;
  }
  throw new ExtensionHasNoMethodError('applyNoteChange', api.extension.target);
}

export { useApplyNoteChange, useNote };
