'use strict';

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

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

/**
 * Returns the proposed `attributes` applied to the checkout.
 */
function useAttributes() {
  const api$1 = api.useApi();
  const extensionTarget = api$1.extension.target;
  if (!('attributes' in api$1)) {
    throw new errors.ExtensionHasNoFieldError('attributes', extensionTarget);
  }
  return subscription.useSubscription(api$1.attributes);
}

/**
 * Returns the values for the specified `attributes` applied to the checkout.
 *
 * @param keys - An array of attribute keys.
 */
function useAttributeValues(keys) {
  const attributes = useAttributes();
  if (!(attributes !== null && attributes !== void 0 && attributes.length)) {
    return [];
  }
  return keys.map(key => {
    const attribute = attributes.find(attribute => attribute.key === key);
    return attribute === null || attribute === void 0 ? void 0 : attribute.value;
  });
}

exports.useAttributeValues = useAttributeValues;
exports.useAttributes = useAttributes;
