define(['jquery', 'lodash', 'i18n', 'ui/generis/widget/widget', 'handlebars', 'lib/handlebars/helpers'], function ($$1, _, __, widgetFactory, Handlebars, Helpers0) { 'use strict';

    $$1 = $$1 && Object.prototype.hasOwnProperty.call($$1, 'default') ? $$1['default'] : $$1;
    _ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
    __ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
    widgetFactory = widgetFactory && Object.prototype.hasOwnProperty.call(widgetFactory, 'default') ? widgetFactory['default'] : widgetFactory;
    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); partials = this.merge(partials, Handlebars.partials); data = data || {};
      var buffer = "", stack1, functionType="function", escapeExpression=this.escapeExpression, self=this, helperMissing=helpers.helperMissing;

    function program1(depth0,data,depth1) {
      
      var buffer = "", stack1, helper, options;
      buffer += "\n            <div class=\"option\">\n                <label>\n                    <input type=\"checkbox\" name=\""
        + escapeExpression(((stack1 = (depth0 && depth0.uri)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))
        + "\" value=\""
        + escapeExpression(((stack1 = (depth0 && depth0.uri)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))
        + "\" ";
      stack1 = (helper = helpers.includes || (depth1 && depth1.includes),options={hash:{},inverse:self.noop,fn:self.program(2, program2, data),data:data},helper ? helper.call(depth0, (depth1 && depth1.values), (depth0 && depth0.uri), options) : helperMissing.call(depth0, "includes", (depth1 && depth1.values), (depth0 && depth0.uri), options));
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += ">\n                    <span class=\"icon-checkbox\"></span>\n                    "
        + escapeExpression(((stack1 = (depth0 && depth0.label)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))
        + "\n                </label>\n            </div>\n            ";
      return buffer;
      }
    function program2(depth0,data) {
      
      
      return "\n                        checked=\"true\" ";
      }

      buffer += "<div class=\"ui-generis-widget check-box\">\n    <div class=\"left\">\n        ";
      stack1 = self.invokePartial(partials['ui-generis-widget-label'], 'ui-generis-widget-label', depth0, helpers, partials, data);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "\n    </div>\n    <div class=\"right\">\n        <div class=\"check-box-input\">\n            ";
      stack1 = helpers.each.call(depth0, (depth0 && depth0.range), {hash:{},inverse:self.noop,fn:self.programWithDepth(1, program1, data, depth0),data:data});
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "\n        </div>\n    </div>\n</div>";
      return buffer;
      });
    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.validator]
     * @param {String} config.label
     * @param {String[]} config.range
     * @param {String} [confgi.required = false]
     * @param {String} config.uri
     * @param {String[]} [config.values]
     * @returns {ui/component}
     */
    function factory(options, config) {
      var validator = options.validator || [];
      var widget;

      // todo - handle required fields

      widget = widgetFactory({
        validator: validator
      }, {
        /**
         * Overrides get method
         * @returns {String[]}
         */
        get: function get() {
          var ret = this.config.values || [];
          if (this.is('rendered')) {
            ret = [];
            this.getElement().find('.option input:checked').map(function () {
              ret.push($$1(this).val());
            });
          }
          return ret;
        },
        /**
         * Overrides set method
         * @param {String[]} values
         * @returns {String[]}
         */
        set: function set(values) {
          if (Array.isArray(values)) {
            this.config.values = values;
          } else {
            this.config.values.push(values);
          }
          if (this.is('rendered')) {
            _.each(this.config.values, function (value) {
              this.getElement().find('input[name=' + value + ']').prop('checked', true);
            });
          }
          return this.config.values;
        }
      }).setTemplate(tpl).init({
        label: config.label,
        range: config.range || [],
        required: config.required || false,
        uri: config.uri,
        values: config.values || []
      });

      // Validations
      if (widget.config.required) {
        widget.validator.addValidation({
          message: __('This field is required'),
          predicate: function (value) {
            return value.length > 0;
          },
          precedence: 1
        });
      }
      return widget;
    }

    return factory;

});
