define(['jquery', 'lodash', 'ui/component', 'handlebars', 'lib/handlebars/helpers', 'css!ui/generis/validator/css/validator.css'], function ($$1, _, componentFactory, Handlebars, Helpers0, validator_css) { 'use strict';

    $$1 = $$1 && Object.prototype.hasOwnProperty.call($$1, 'default') ? $$1['default'] : $$1;
    _ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
    componentFactory = componentFactory && Object.prototype.hasOwnProperty.call(componentFactory, 'default') ? componentFactory['default'] : componentFactory;
    Handlebars = Handlebars && Object.prototype.hasOwnProperty.call(Handlebars, 'default') ? Handlebars['default'] : Handlebars;
    Helpers0 = Helpers0 && Object.prototype.hasOwnProperty.call(Helpers0, 'default') ? Helpers0['default'] : Helpers0;

    if (!Helpers0.__initialized) {
      Helpers0(Handlebars);
      Helpers0.__initialized = true;
    }
    var Template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
      this.compilerInfo = [4,'>= 1.0.0'];
    helpers = this.merge(helpers, Handlebars.helpers);  


      return "<div class=\"ui-generis-validator\"></div>";
      });
    function tpl(data, options, asString) {
      var html = Template(data, options);
      return (asString || true) ? html : $(html);
    }

    /**
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * as published by the Free Software Foundation; under version 2
     * of the License (non-upgradable).
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     *
     * Copyright (c) 2017 (original work) Open Assessment Technologies SA;
     */

    /**
     * The factory
     * @param {Object[]} [options.validations]
     * @return {ui/component}
     * @deprecated replaced by `ui/form/validator/validator` and `ui/form/validator/renderer`
     */
    function factory(options) {
      var validator;
      options = options || {};
      validator = componentFactory({
        /**
         * Run all validations (i.e. populate errors property)
         * @param {String} value
         * @return {this}
         */
        run: function run(value) {
          this.errors = _(this.validations)
          // run validations
          .reject(function (validation) {
            if (validation.predicate instanceof RegExp) {
              return validation.predicate.test(value);
            } else if (typeof validation.predicate === 'function') {
              return validation.predicate(value);
            }
          }, this)
          // sort validations by precedence
          .sortBy('precedence')
          // return validations' message
          .map(function (validation) {
            return validation.message;
          }).value();
          return this;
        },
        /**
         * Clears validation errors from dom
         * @return {this}
         */
        clear: function clear() {
          this.errors = [];
          if (this.is('rendered')) {
            this.getElement().empty();
          }
          return this;
        },
        /**
         * Displays validation errors in dom
         * @return {this}
         */
        display: function display() {
          var $this = this.getElement();
          if (this.is('rendered')) {
            $this.empty();
            _.each(this.errors, function (error) {
              $this.append($$1('<div>', {
                class: 'validation-error'
              }).text(error));
            });
          }
          return this;
        },
        /**
         * Adds validation
         * @param {Object} validation
         * @return {this}
         */
        addValidation: function addValidation(validation) {
          this.validations.push(validation);
          return this;
        },
        /**
         * Removes all validations
         * @return {this}
         */
        removeValidations: function removeValidations() {
          this.validations = [];
          return this;
        }
      }).setTemplate(tpl).init();
      validator.errors = [];
      validator.validations = options.validations || [];
      return validator;
    }

    return factory;

});
