<commit_before>'use strict';

var analytics = require('./lib/analytics');
var DropinError = require('./lib/dropin-error');
var EventEmitter = require('@braintree/event-emitter');
var constants = require('./constants');
var paymentMethodTypes = constants.paymentMethodTypes;
var paymentOptionIDs = constants.paymentOptionIDs;
var dependencySetupStates = constants.dependencySetupStates;
var isGuestCheckout = require('./lib/is-guest-checkout');
var Promise = require('./lib/promise');
var paymentSheetViews = require('./views/payment-sheet-views');
var vaultManager = require('braintree-web/vault-manager');

var VAULTED_PAYMENT_METHOD_TYPES_THAT_SHOULD_BE_HIDDEN = [
  paymentMethodTypes.applePay,
  paymentMethodTypes.googlePay,
  paymentMethodTypes.venmo
];
var DEFAULT_PAYMENT_OPTION_PRIORITY = [
  paymentOptionIDs.card,
  paymentOptionIDs.paypal,
  paymentOptionIDs.paypalCredit,
  paymentOptionIDs.venmo,
  paymentOptionIDs.applePay,
  paymentOptionIDs.googlePay
];
var NON_PAYMENT_OPTION_DEPENDENCIES = ['threeDSecure', 'dataCollector'];
var ASYNC_DEPENDENCIES = DEFAULT_PAYMENT_OPTION_PRIORITY.concat(NON_PAYMENT_OPTION_DEPENDENCIES);
var DEPENDENCY_READY_CHECK_INTERVAL = 200;

function DropinModel(options) {
  this.rootNode = options.container;
  this.componentID = options.componentID;
  this.merchantConfiguration = options.merchantConfiguration;
  this.isGuestCheckout = isGuestCheckout(options.client);
  this.dependencyStates = ASYNC_DEPENDENCIES.reduce(function (total, dependencyKey) {
    if (this._shouldIncludeDependency(dependencyKey)) {
      total[dependencyKey] = dependencySetupStates.INITIALIZING;
    }

    return total;
  }.bind(this), {});

  this.failedDependencies = {};
  this._options = options;
  this._setupComplete = false;

  while (this.rootNode.parentNode) {
    this.rootNode = this.rootNode.parentNode;
  }
  this.isInShadowDom = this.rootNode.toString() === '[object ShadowRoot]';

  EventEmitter.call(this);
}

EventEmitter.createChild(DropinModel);

DropinModel.prototype.initialize = function () {
  var dep;
  var self = this;
  var dependencyReadyInterval = setInterval(function () {
    for (dep in self.dependencyStates) {
      if (self.dependencyStates[dep] === dependencySetupStates.INITIALIZING) {
        return;
      }
    }

    clearInterval(dependencyReadyInterval);

    self._emit('asyncDependenciesReady');
  }, DEPENDENCY_READY_CHECK_INTERVAL);

  return vaultManager.create({
    client: self._options.client
  }).then(function (vaultManagerInstance) {
    self._vaultManager = vaultManagerInstance;

    return self._getSupportedPaymentOptions(self._options);
  }).then(function (paymentOptions) {
    self.supportedPaymentOptions = paymentOptions;

    return self.getVaultedPaymentMethods();
  }).then(function (paymentMethods) {
    self._paymentMethods = paymentMethods;
    self._paymentMethodIsRequestable = self._paymentMethods.length > 0;
  });
};

DropinModel.prototype.confirmDropinReady = function () {
  this._setupComplete = true;
};

DropinModel.prototype.isPaymentMethodRequestable = function () {
  return Boolean(this._paymentMethodIsRequestable);
};

DropinModel.prototype.addPaymentMethod = function (paymentMethod) {
  this._paymentMethods.push(paymentMethod);
  this._emit('addPaymentMethod', paymentMethod);
  this.changeActivePaymentMethod(paymentMethod);
};

DropinModel.prototype.removePaymentMethod = function (paymentMethod) {
  var paymentMethodLocation = this._paymentMethods.indexOf(paymentMethod);

  if (paymentMethodLocation === -1) {
    return;
  }

  this._paymentMethods.splice(paymentMethodLocation, 1);
  this._emit('removePaymentMethod', paymentMethod);
};

DropinModel.prototype.refreshPaymentMethods = function () {
  var self = this;

  return self.getVaultedPaymentMethods().then(function (paymentMethods) {
    self._paymentMethods = paymentMethods;

    self._emit('refreshPaymentMethods');
  });
};

DropinModel.prototype.changeActivePaymentMethod = function (paymentMethod) {
  this._activePaymentMethod = paymentMethod;
  this._emit('changeActivePaymentMethod', paymentMethod);
};

DropinModel.prototype.changeActiveView = function (paymentViewID) {
  var previousViewId = this._activePaymentViewId;

  this._activePaymentViewId = paymentViewID;
  this._emit('changeActiveView', {
    previousViewId: previousViewId,
    newViewId: paymentViewID
  });
};

DropinModel.prototype.removeActivePaymentMethod = function () {
  this._activePaymentMethod = null;
  this._emit('removeActivePaymentMethod');
  this.setPaymentMethodRequestable({
    isRequestable: false
  });
};

DropinModel.prototype.selectPaymentOption = function (paymentViewID) {
  this._emit('paymentOptionSelected', {
    paymentOption: paymentViewID
  });
};

DropinModel.prototype.enableEditMode = function () {
  analytics.sendEvent(this._options.client, 'manager.appeared');
  this._isInEditMode = true;
  this._emit('enableEditMode');
};

DropinModel.prototype.disableEditMode = function () {
  this._isInEditMode = false;
  this._emit('disableEditMode');
};

DropinModel.prototype.isInEditMode = function () {
  return Boolean(this._isInEditMode);
};

DropinModel.prototype.confirmPaymentMethodDeletion = function (paymentMethod) {
  this._paymentMethodWaitingToBeDeleted = paymentMethod;
  this._emit('confirmPaymentMethodDeletion', paymentMethod);
};

DropinModel.prototype._shouldIncludeDependency = function (key) {
  if (key === 'card') {
    // card is turned on by default unless the merchant explicitly
    // passes a value of `false` or omits it from a custom
    // `paymentOptionPriority` array
    if (this.merchantConfiguration.card === false) {
      return false;
    }
  } else if (!this.merchantConfiguration[key]) {
    // if the merchant does not have the non-card dependency
    // configured, do not include the dependency
    return false;
  }

  if (NON_PAYMENT_OPTION_DEPENDENCIES.indexOf(key) > -1) {
    console.log(key);
    console.log('it got here');<commit_msg>fix: remove console statements<commit_after>'use strict';

var analytics = require('./lib/analytics');
var DropinError = require('./lib/dropin-error');
var EventEmitter = require('@braintree/event-emitter');
var constants = require('./constants');
var paymentMethodTypes = constants.paymentMethodTypes;
var paymentOptionIDs = constants.paymentOptionIDs;
var dependencySetupStates = constants.dependencySetupStates;
var isGuestCheckout = require('./lib/is-guest-checkout');
var Promise = require('./lib/promise');
var paymentSheetViews = require('./views/payment-sheet-views');
var vaultManager = require('braintree-web/vault-manager');

var VAULTED_PAYMENT_METHOD_TYPES_THAT_SHOULD_BE_HIDDEN = [
  paymentMethodTypes.applePay,
  paymentMethodTypes.googlePay,
  paymentMethodTypes.venmo
];
var DEFAULT_PAYMENT_OPTION_PRIORITY = [
  paymentOptionIDs.card,
  paymentOptionIDs.paypal,
  paymentOptionIDs.paypalCredit,
  paymentOptionIDs.venmo,
  paymentOptionIDs.applePay,
  paymentOptionIDs.googlePay
];
var NON_PAYMENT_OPTION_DEPENDENCIES = ['threeDSecure', 'dataCollector'];
var ASYNC_DEPENDENCIES = DEFAULT_PAYMENT_OPTION_PRIORITY.concat(NON_PAYMENT_OPTION_DEPENDENCIES);
var DEPENDENCY_READY_CHECK_INTERVAL = 200;

function DropinModel(options) {
  this.rootNode = options.container;
  this.componentID = options.componentID;
  this.merchantConfiguration = options.merchantConfiguration;
  this.isGuestCheckout = isGuestCheckout(options.client);
  this.dependencyStates = ASYNC_DEPENDENCIES.reduce(function (total, dependencyKey) {
    if (this._shouldIncludeDependency(dependencyKey)) {
      total[dependencyKey] = dependencySetupStates.INITIALIZING;
    }

    return total;
  }.bind(this), {});

  this.failedDependencies = {};
  this._options = options;
  this._setupComplete = false;

  while (this.rootNode.parentNode) {
    this.rootNode = this.rootNode.parentNode;
  }
  this.isInShadowDom = this.rootNode.toString() === '[object ShadowRoot]';

  EventEmitter.call(this);
}

EventEmitter.createChild(DropinModel);

DropinModel.prototype.initialize = function () {
  var dep;
  var self = this;
  var dependencyReadyInterval = setInterval(function () {
    for (dep in self.dependencyStates) {
      if (self.dependencyStates[dep] === dependencySetupStates.INITIALIZING) {
        return;
      }
    }

    clearInterval(dependencyReadyInterval);

    self._emit('asyncDependenciesReady');
  }, DEPENDENCY_READY_CHECK_INTERVAL);

  return vaultManager.create({
    client: self._options.client
  }).then(function (vaultManagerInstance) {
    self._vaultManager = vaultManagerInstance;

    return self._getSupportedPaymentOptions(self._options);
  }).then(function (paymentOptions) {
    self.supportedPaymentOptions = paymentOptions;

    return self.getVaultedPaymentMethods();
  }).then(function (paymentMethods) {
    self._paymentMethods = paymentMethods;
    self._paymentMethodIsRequestable = self._paymentMethods.length > 0;
  });
};

DropinModel.prototype.confirmDropinReady = function () {
  this._setupComplete = true;
};

DropinModel.prototype.isPaymentMethodRequestable = function () {
  return Boolean(this._paymentMethodIsRequestable);
};

DropinModel.prototype.addPaymentMethod = function (paymentMethod) {
  this._paymentMethods.push(paymentMethod);
  this._emit('addPaymentMethod', paymentMethod);
  this.changeActivePaymentMethod(paymentMethod);
};

DropinModel.prototype.removePaymentMethod = function (paymentMethod) {
  var paymentMethodLocation = this._paymentMethods.indexOf(paymentMethod);

  if (paymentMethodLocation === -1) {
    return;
  }

  this._paymentMethods.splice(paymentMethodLocation, 1);
  this._emit('removePaymentMethod', paymentMethod);
};

DropinModel.prototype.refreshPaymentMethods = function () {
  var self = this;

  return self.getVaultedPaymentMethods().then(function (paymentMethods) {
    self._paymentMethods = paymentMethods;

    self._emit('refreshPaymentMethods');
  });
};

DropinModel.prototype.changeActivePaymentMethod = function (paymentMethod) {
  this._activePaymentMethod = paymentMethod;
  this._emit('changeActivePaymentMethod', paymentMethod);
};

DropinModel.prototype.changeActiveView = function (paymentViewID) {
  var previousViewId = this._activePaymentViewId;

  this._activePaymentViewId = paymentViewID;
  this._emit('changeActiveView', {
    previousViewId: previousViewId,
    newViewId: paymentViewID
  });
};

DropinModel.prototype.removeActivePaymentMethod = function () {
  this._activePaymentMethod = null;
  this._emit('removeActivePaymentMethod');
  this.setPaymentMethodRequestable({
    isRequestable: false
  });
};

DropinModel.prototype.selectPaymentOption = function (paymentViewID) {
  this._emit('paymentOptionSelected', {
    paymentOption: paymentViewID
  });
};

DropinModel.prototype.enableEditMode = function () {
  analytics.sendEvent(this._options.client, 'manager.appeared');
  this._isInEditMode = true;
  this._emit('enableEditMode');
};

DropinModel.prototype.disableEditMode = function () {
  this._isInEditMode = false;
  this._emit('disableEditMode');
};

DropinModel.prototype.isInEditMode = function () {
  return Boolean(this._isInEditMode);
};

DropinModel.prototype.confirmPaymentMethodDeletion = function (paymentMethod) {
  this._paymentMethodWaitingToBeDeleted = paymentMethod;
  this._emit('confirmPaymentMethodDeletion', paymentMethod);
};

DropinModel.prototype._shouldIncludeDependency = function (key) {
  if (key === 'card') {
    // card is turned on by default unless the merchant explicitly
    // passes a value of `false` or omits it from a custom
    // `paymentOptionPriority` array
    if (this.merchantConfiguration.card === false) {
      return false;
    }
  } else if (!this.merchantConfiguration[key]) {
    // if the merchant does not have the non-card dependency
    // configured, do not include the dependency
    return false;
  }

  if (NON_PAYMENT_OPTION_DEPENDENCIES.indexOf(key) > -1) {
{'fraction_non_alphanumeric': 0.11133484352714154, 'fraction_numerical': 0.001174595184159745, 'mean_word_length': 5.360725720384205, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4893000', 'n_tokens_mistral': 3505, 'n_tokens_neox': 3456, 'n_words': 590}