define(['lodash', 'i18n', 'ui/dialog', 'handlebars', 'lib/handlebars/helpers'], function (_, __, dialog, Handlebars, Helpers0) { 'use strict';

    _ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
    __ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
    dialog = dialog && Object.prototype.hasOwnProperty.call(dialog, 'default') ? dialog['default'] : dialog;
    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); data = data || {};
      var buffer = "", stack1, helper, functionType="function", escapeExpression=this.escapeExpression, self=this;

    function program1(depth0,data) {
      
      
      return "checked";
      }

      buffer += "<label for=\"";
      if (helper = helpers.id) { stack1 = helper.call(depth0, {hash:{},data:data}); }
      else { helper = (depth0 && depth0.id); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
      buffer += escapeExpression(stack1)
        + "\">\n    <input type=\"checkbox\" id=\"";
      if (helper = helpers.id) { stack1 = helper.call(depth0, {hash:{},data:data}); }
      else { helper = (depth0 && depth0.id); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
      buffer += escapeExpression(stack1)
        + "\" name=\"";
      if (helper = helpers.id) { stack1 = helper.call(depth0, {hash:{},data:data}); }
      else { helper = (depth0 && depth0.id); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
      buffer += escapeExpression(stack1)
        + "\" ";
      stack1 = helpers['if'].call(depth0, (depth0 && depth0.checked), {hash:{},inverse:self.noop,fn:self.program(1, program1, data),data:data});
      if(stack1 || stack1 === 0) { buffer += stack1; }
      buffer += " />\n    <span class=\"icon-checkbox\"></span>\n    ";
      if (helper = helpers.text) { stack1 = helper.call(depth0, {hash:{},data:data}); }
      else { helper = (depth0 && depth0.text); stack1 = typeof helper === functionType ? helper.call(depth0, {hash:{},data:data}) : helper; }
      buffer += escapeExpression(stack1)
        + "\n</label>\n";
      return buffer;
      });
    function checkBoxTpl(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) 2020 (original work) Open Assessment Technologies SA ;
     */

    /**
     * Displays a confirm delete message with checkbox
     * @param {String} message - The displayed message
     * @param {Function} accept - An action called when the message is accepted
     * @param {Function} refuse - An action called when the message is refused
     * @param {Object} options - Dialog options
     * @param {Object} options.confirmationMessage - "I understand that this action is permanent." message
     * @param {Object} options.buttons - Dialog button options
     * @param {Object} options.buttons.labels - Dialog button labels
     * @param {String} options.buttons.labels.delete - "Delete" button label
     * @param {String} options.buttons.labels.cancel - "Cancel" button label
     * @returns {dialog} - Returns the dialog instance
     */
    const defaults = {
      buttons: {
        labels: {
          delete: __('Delete'),
          cancel: __('Cancel')
        }
      },
      confirmationMessage: __('I understand that this action is permanent.')
    };
    function dialogConfirmDelete(message, accept, refuse, options) {
      let accepted = false;
      options = _.defaults(options || {}, defaults);
      const dialogOptions = {
        message: message,
        content: checkBoxTpl({
          id: 'confirm',
          checked: false,
          text: options.confirmationMessage
        }),
        autoRender: true,
        autoDestroy: true,
        onDeleteBtn: function () {
          accepted = true;
          if (_.isFunction(accept)) {
            accept.call(this);
          }
        },
        buttons: {
          delete: {
            id: 'delete',
            type: 'info',
            label: options.buttons.labels.delete || defaults.buttons.labels.delete,
            close: true
          },
          cancel: {
            id: 'cancel',
            type: 'regular',
            label: options.buttons.labels.cancel || defaults.buttons.labels.cancel,
            close: true
          }
        }
      };
      const dlg = dialog(dialogOptions);
      const $html = dlg.getDom();
      const $deleteButton = $html.find('[data-control="delete"]');
      $deleteButton.prop('disabled', true);
      $html.find('#confirm').on('change', function () {
        $deleteButton.prop('disabled', !this.checked);
      });
      if (_.isFunction(refuse)) {
        dlg.on('closed.modal', function () {
          if (!accepted) {
            refuse.call(this);
          }
        });
      }
      return dlg;
    }

    return dialogConfirmDelete;

});
