<commit_before>import loadTemplate from '../../utils/loadTemplate';
import BaseView from '../baseVw';
import Provider from './SearchProvider';
import app from '../../app';
import AddProvider from './AddProvider';

export default class extends BaseView {
  constructor(options = {}) {
    super(options);
    this.options = options;
    this.providerViews = [];

    this.listenTo(app.searchProviders, 'add', (md) => {
      const view = this.createProviderView(md);
      if (view) {
        this.providerViews.push(view);
        this.render();
      }
    });

    this.listenTo(app.searchProviders, 'remove', (md, cl, removeOpts) => {
      this.providerViews.splice(removeOpts.index, 1)[0].remove();
      this.render();
    });
  }

  className() {
    return 'searchProviders flexVCent gutterH';
  }

  events() {
    return {
      'click .js-openAddBtn': 'onClickOpenAdd',
    };
  }

  onClickOpenAdd() {
    this.createAddBox();
  }

  createAddBox() {
    if (this.addProvider) this.addProvider.remove();
    this.addProvider = this.createChild(AddProvider, { ...this.options });
    this.getCachedEl('.js-addWrapper').append(this.addProvider.render().$el);
    this.addProvider.getCachedEl('.js-addProviderInput').focus();
  }

  get lastIndex() {
    return app.searchProviders.length ? app.searchProviders.length - 1 : 0;
  }

  createProviderView(model, options = {}) {
    // when in Tor mode, do not show providers that don't have Tor URLs.
    if (this.options.usingTor && !model.get('torlistings')) return false;

    const view = this.createChild(Provider, {
      model,
      ...options,<commit_msg>Remove unused lastIndex<commit_after>import loadTemplate from '../../utils/loadTemplate';
import BaseView from '../baseVw';
import Provider from './SearchProvider';
import app from '../../app';
import AddProvider from './AddProvider';

export default class extends BaseView {
  constructor(options = {}) {
    super(options);
    this.options = options;
    this.providerViews = [];

    this.listenTo(app.searchProviders, 'add', (md) => {
      const view = this.createProviderView(md);
      if (view) {
        this.providerViews.push(view);
        this.render();
      }
    });

    this.listenTo(app.searchProviders, 'remove', (md, cl, removeOpts) => {
      this.providerViews.splice(removeOpts.index, 1)[0].remove();
      this.render();
    });
  }

  className() {
    return 'searchProviders flexVCent gutterH';
  }

  events() {
    return {
      'click .js-openAddBtn': 'onClickOpenAdd',
    };
  }

  onClickOpenAdd() {
    this.createAddBox();
  }

  createAddBox() {
    if (this.addProvider) this.addProvider.remove();
    this.addProvider = this.createChild(AddProvider, { ...this.options });
    this.getCachedEl('.js-addWrapper').append(this.addProvider.render().$el);
    this.addProvider.getCachedEl('.js-addProviderInput').focus();
  }

  createProviderView(model, options = {}) {
    // when in Tor mode, do not show providers that don't have Tor URLs.
    if (this.options.usingTor && !model.get('torlistings')) return false;

    const view = this.createChild(Provider, {
      model,
      ...options,
{'fraction_non_alphanumeric': 0.15741034592192954, 'fraction_numerical': 0.001904157410345922, 'mean_word_length': 3.1419185282522997, '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': '7467308', 'n_tokens_mistral': 970, 'n_tokens_neox': 960, 'n_words': 196}