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

/**
 * Returns the current customer privacy settings and metadata and
 * re-renders your component if the customer privacy settings change.
 */
function useCustomerPrivacy() {
  const api = useApi();
  const extensionTarget = api.extension.target;
  if (!('customerPrivacy' in api)) {
    throw new ExtensionHasNoFieldError('customerPrivacy', extensionTarget);
  }
  return useSubscription(useApi().customerPrivacy);
}

export { useCustomerPrivacy };
