'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var hooks = require('preact/hooks');
var api = require('./api.js');
var errors = require('./errors.js');
var subscription = require('./subscription.js');

/**
 * Returns the shipping option the extension is attached to. This hook can only be used by extensions in the following
 * extension targets:
 * - `purchase.checkout.shipping-option-item.render-after`
 * - `purchase.checkout.shipping-option-item.details.render`
 */
function useShippingOptionTarget() {
  const api$1 = api.useApi();
  if (!api$1.target || api$1.isTargetSelected === undefined) {
    throw new errors.ExtensionHasNoTargetError('useShippingOptionTarget', api$1.extension.target);
  }
  const shippingOptionTarget = subscription.useSubscription(api$1.target);
  const isTargetSelected = subscription.useSubscription(api$1.isTargetSelected);
  const renderMode = api$1.renderMode;
  const shippingOption = hooks.useMemo(() => {
    return {
      shippingOptionTarget,
      isTargetSelected,
      renderMode
    };
  }, [shippingOptionTarget, isTargetSelected, renderMode]);
  return shippingOption;
}

exports.useShippingOptionTarget = useShippingOptionTarget;
