define(['handlebars', 'lib/handlebars/helpers'], function (Handlebars, Helpers0) { 'use strict';

    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, helper, options, functionType="function", escapeExpression=this.escapeExpression, self=this, helperMissing=helpers.helperMissing;

    function program1(depth0,data) {
      
      var buffer = "", stack1;
      buffer += "\n            <option value=\""
        + escapeExpression(((stack1 = (depth0 && depth0.uri)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))
        + "\">"
        + escapeExpression(((stack1 = (depth0 && depth0.label)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1))
        + "</option>\n            ";
      return buffer;
      }

      buffer += "<div class=\"form-widget ";
      if (helper = helpers.widgetType) { stack1 = helper.call(depth0, {hash:{},data:data}); }
      else { helper = (depth0 && depth0.widgetType); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
      buffer += escapeExpression(stack1)
        + "\">\n    <div class=\"widget-label\">\n        ";
      stack1 = self.invokePartial(partials['ui-form-widget-label'], 'ui-form-widget-label', depth0, helpers, partials, data);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "\n    </div>\n    <div class=\"widget-field\">\n        <select class=\"widget-input-inline\" name=\"";
      if (helper = helpers.uri) { stack1 = helper.call(depth0, {hash:{},data:data}); }
      else { helper = (depth0 && depth0.uri); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
      buffer += escapeExpression(stack1)
        + "\">\n            <option value=\"\">"
        + escapeExpression((helper = helpers.__ || (depth0 && depth0.__),options={hash:{},data:data},helper ? helper.call(depth0, "Choose a value...", options) : helperMissing.call(depth0, "__", "Choose a value...", options)))
        + "</option>\n            ";
      stack1 = helpers.each.call(depth0, (depth0 && depth0.range), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "\n        </select>\n    </div>\n</div>\n";
      return buffer;
      });
    function comboBoxTpl(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) 2019 Open Assessment Technologies SA ;
     */

    /**
     * Defines the provider for a comboBox widget.
     *
     * @example
     * import widgetComboBoxProvider from 'ui/form/widget/providers/comboBox';
     * widgetFactory.registerProvider('comboBox', widgetComboBoxProvider);
     * const widget = widgetFactory(container, {
     *     widget: 'comboBox'
     *     uri: 'cb',
     *     label: 'All good?',
     *     range: [{
     *         uri: 'yes',
     *         label: 'Yes'
     *     }, {
     *         uri: 'no',
     *         label: 'No'
     *     }]
     * });
     */
    const widgetComboBoxProvider = {
      /**
       * Initialize the widget.
       * @param {widgetConfig} config
       */
      init(config) {
        // the type will be reflected to the HTML markup
        config.widgetType = 'combo-box';

        // initial value
        this.on('render', () => this.getWidgetElement().val(this.getConfig().value));
      },
      /**
       * Expose the template to the factory and it will apply it
       */
      template: comboBoxTpl
    };

    return widgetComboBoxProvider;

});
