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

/**
 * Returns a `Money` value representing the minimum a buyer can expect to pay at the current
 * step of checkout. This value excludes amounts yet to be negotiated. For example,
 * the information step might not have delivery costs calculated.
 */
function useTotalAmount() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('cost' in api)) {
    throw new ExtensionHasNoFieldError('cost', extensionTarget);
  }
  return useSubscription(api.cost.totalAmount);
}

export { useTotalAmount };
