define([



], function () {

  function countResults (data) {

    var count = 0;



    for (var d = 0; d < data.length; d++) {

      var item = data[d];



      if (item.children) {

        count += countResults(item.children);

      } else {

        count++;

      }

    }



    return count;

  }



  function MinimumResultsForSearch (decorated, $element, options, dataAdapter) {

    this.minimumResultsForSearch = options.get('minimumResultsForSearch');



    if (this.minimumResultsForSearch < 0) {

      this.minimumResultsForSearch = Infinity;

    }



    decorated.call(this, $element, options, dataAdapter);

  }



  MinimumResultsForSearch.prototype.showSearch = function (decorated, params) {

    if (countResults(params.data.results) < this.minimumResultsForSearch) {

      return false;

    }



    return decorated.call(this, params);

  };



  return MinimumResultsForSearch;

});

