define(['lodash', 'ui/maths/calculator/defaultCalculator', 'handlebars', 'lib/handlebars/helpers'], function (_, defaultCalculatorFactory, Handlebars, Helpers0) { 'use strict';

    _ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
    defaultCalculatorFactory = defaultCalculatorFactory && Object.prototype.hasOwnProperty.call(defaultCalculatorFactory, 'default') ? defaultCalculatorFactory['default'] : defaultCalculatorFactory;
    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);  var buffer = "", stack1, functionType="function";


      buffer += "<div class=\"calculator-keyboard\">\n    <div class=\"row\">\n        <button class=\"key command\" data-command=\"historyUp\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.HISTORYUP)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key command\" data-command=\"historyDown\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.HISTORYDOWN)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key command\" data-command=\"deleteLeft\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.BACKSPACE)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key command\" data-command=\"clear\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.RESET)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n    </div>\n    <div class=\"row\">\n        <button class=\"key operator\" data-command=\"term\" data-param=\"LPAR\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.LPAR)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operator\" data-command=\"term\" data-param=\"RPAR\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.RPAR)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operator\" data-command=\"term\" data-param=\"POW\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.POWY)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operator\" data-command=\"term\" data-param=\"SQRT\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.SQRT)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n    </div>\n    <div class=\"row\">\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM7\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM7)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM8\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM8)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM9\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM9)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operator\" data-command=\"term\" data-param=\"DIV\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.DIV)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n    </div>\n    <div class=\"row\">\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM4\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM4)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM5\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM5)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM6\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM6)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operator\" data-command=\"term\" data-param=\"MUL\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.MUL)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n    </div>\n    <div class=\"row\">\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM1\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM1)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM2\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM2)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM3\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM3)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operator\" data-command=\"term\" data-param=\"SUB\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.SUB)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n    </div>\n    <div class=\"row\">\n        <button class=\"key operand\" data-command=\"term\" data-param=\"NUM0\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.NUM0)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operand\" data-command=\"term\" data-param=\"DOT\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.DOT)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key execute\" data-command=\"execute\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.EXECUTE)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key operator\" data-command=\"term\" data-param=\"ADD\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.ADD)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n    </div>\n</div>\n";
      return buffer;
      });
    function keyboardTpl(data, options, asString) {
      var html = Template(data, options);
      return (asString || true) ? html : $(html);
    }

    if (!Helpers0.__initialized) {
      Helpers0(Handlebars);
      Helpers0.__initialized = true;
    }
    var Template$1 = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
      this.compilerInfo = [4,'>= 1.0.0'];
    helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
      var buffer = "", stack1, helper, functionType="function";


      buffer += "<div class=\"calculator-screen simple-screen\">\n    <div class=\"screen-panel expression\">";
      if (helper = helpers.expression) { stack1 = helper.call(depth0, {hash:{},data:data}); }
      else { helper = (depth0 && depth0.expression); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</div>\n</div>";
      return buffer;
      });
    function screenTpl(data, options, asString) {
      var html = Template$1(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) 2018-2023 Open Assessment Technologies SA ;
     */

    /**
     * Creates a basic calculator component. Screen and keyboard layout are replaceable.
     * @param {Object} config - Some config entries (@see ui/dynamicComponent)
     * @param {Function} [config.keyboardLayout] - A Handlebars template for the keyboard
     * @param {Function} [config.screenLayout] - A Handlebars template for the screen
     * @param {Object} [config.calculator] - Config for the calculator (@see ui/maths/calculator/core/board)
     * @returns {dynamicComponent}
     */
    function basicCalculatorFactory(config) {
      // The plugins config is directly built here instead of using a module variable to ensure the object is unique
      // to the instance. This wil avoid global polluting by successive instances, as nested objects and arrays might
      // be simply copied.
      return defaultCalculatorFactory(_.merge({
        calculator: {
          plugins: {
            templateKeyboard: {
              layout: keyboardTpl
            },
            simpleScreen: {
              layout: screenTpl
            }
          }
        }
      }, config));
    }

    return basicCalculatorFactory;

});
