define(['jquery', 'util/namespace', 'ui/maths/calculator/core/plugin', 'ui/maths/calculator/core/labels', 'handlebars', 'lib/handlebars/helpers'], function ($$1, nsHelper, pluginFactory, labels, Handlebars, Helpers0) { 'use strict';

    $$1 = $$1 && Object.prototype.hasOwnProperty.call($$1, 'default') ? $$1['default'] : $$1;
    nsHelper = nsHelper && Object.prototype.hasOwnProperty.call(nsHelper, 'default') ? nsHelper['default'] : nsHelper;
    pluginFactory = pluginFactory && Object.prototype.hasOwnProperty.call(pluginFactory, 'default') ? pluginFactory['default'] : pluginFactory;
    labels = labels && Object.prototype.hasOwnProperty.call(labels, 'default') ? labels['default'] : labels;
    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 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        <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 command\" data-command=\"clear\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.CLEAR)),typeof stack1 === functionType ? stack1.apply(depth0) : stack1);
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += "</span></button>\n        <button class=\"key command\" data-command=\"reset\"><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=\"CBRT\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.CBRT)),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=\"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 operator\" data-command=\"term\" data-param=\"POW NUM2\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.POW2)),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=\"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 operator\" data-command=\"term\" data-param=\"POW NUM3\"><span>";
      stack1 = ((stack1 = ((stack1 = (depth0 && depth0.labels)),stack1 == null || stack1 === false ? stack1 : stack1.POW3)),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=\"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 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 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 defaultKeyboardTpl(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) 2018-2023 Open Assessment Technologies SA ;
     */
    const pluginName = 'templateKeyboard';
    const defaultConfig = {
      layout: defaultKeyboardTpl
    };
    var templateKeyboard = pluginFactory({
      name: pluginName,
      /**
       * Called when the plugin should be initialized.
       */
      init() {
        // required by the plugin factory to validate this plugin
      },
      /**
       * Called when the plugin should be rendered.
       */
      render() {
        const calculator = this.getCalculator();
        const areaBroker = calculator.getAreaBroker();
        const pluginConfig = this.getConfig();
        const templateConfig = Object.assign({
          labels
        }, pluginConfig);
        if ('function' !== typeof pluginConfig.layout) {
          throw new TypeError('The keyboard plugin requires a template to render!');
        }
        this.$layout = $$1(pluginConfig.layout(templateConfig)).on(nsHelper.namespaceAll('click', pluginName), '.key', function onClick() {
          const $key = $$1(this).closest('.key');
          const command = $key.data('command');
          const param = $key.data('param');
          if (command) {
            calculator.useCommand(command, param);
          }
        });
        areaBroker.getKeyboardArea().append(this.$layout);
      },
      /**
       * Called when the plugin is destroyed. Mostly when the host is destroyed itself.
       */
      destroy() {
        if (this.$layout) {
          this.$layout.off(`.${pluginName}`).remove();
          this.$layout = null;
        }
        this.getCalculator().off(`.${pluginName}`);
      }
    }, defaultConfig);

    return templateKeyboard;

});
