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

/**
 * Returns the current line items for the checkout, and automatically re-renders
 * your component if line items are added, removed, or updated.
 */
function useCartLines() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('lines' in api)) {
    throw new ExtensionHasNoFieldError('lines', extensionTarget);
  }
  return useSubscription(api.lines);
}

export { useCartLines };
