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

/**
 * Returns the current gift cards applied to the cart, and automatically re-renders
 * your component if gift cards are added or removed.
 */
function useAppliedGiftCards() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('appliedGiftCards' in api)) {
    throw new ExtensionHasNoFieldError('appliedGiftCards', extensionTarget);
  }
  return useSubscription(api.appliedGiftCards);
}

export { useAppliedGiftCards };
