Liferay.Loader.define("layout-content-page-editor-web@2.0.166/page_editor/app/processors/HTMLProcessor", ['module', 'exports', 'require', 'frontend-js-web'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _frontendJsWeb = require("frontend-js-web");

    /**
     * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
     * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
     */

    /**
     * @param {HTMLElement} element HTMLElement where the editor
     *  should be applied to.
     * @param {function} changeCallback Function that should be called whenever the
     *  editor produces a change. It must receive a string with
     *  the new editable value.
     * @param {function} destroyCallback Function that should be called if
     *  the editor is destroyed for any internal reason. This function does NOT need
     *  to be called if the editor is destroyed with destroyEditor function.
     */
    function createEditor(element, changeCallback, destroyCallback) {
      var editor;
      (0, _frontendJsWeb.openModal)({
        bodyHTML: '<div class="editor-container" />',
        buttons: [{
          displayType: 'secondary',
          label: Liferay.Language.get('cancel'),
          type: 'cancel'
        }, {
          label: Liferay.Language.get('save'),
          onClick: function onClick() {
            var annotations = editor._editor.getSession().getAnnotations();

            var errorAnnotations = annotations.filter(function (annotation) {
              return annotation.type === 'error';
            });

            if (errorAnnotations.length) {
              var errorMessage = errorAnnotations.map(function (annotation) {
                return annotation.text;
              }).join('\n');
              (0, _frontendJsWeb.openToast)({
                message: errorMessage,
                type: 'danger'
              });
            } else {
              changeCallback(editor.get('value'));
              Liferay.fire('closeModal');
            }
          }
        }],
        onClose: function onClose() {
          return destroyCallback();
        },
        onOpen: function onOpen() {
          Liferay.Util.getTop().AUI().use('liferay-fullscreen-source-editor', function (A) {
            var editorContainer = document.querySelector('.liferay-modal .editor-container');

            if (editorContainer) {
              editor = new A.LiferayFullScreenSourceEditor({
                boundingBox: editorContainer,
                previewCssClass: 'alloy-editor',
                value: element.innerHTML
              }).render();
            }
          });
        },
        size: 'full-screen',
        title: Liferay.Language.get('edit-content')
      });
    }
    /**
     */

    function destroyEditor() {}
    /**
     * @param {HTMLElement} element HTMLElement that should be mutated with the
     *  given value.
     * @param {string} value Element content
     */

    function render(element, value) {
      if (value) {
        element.innerHTML = value;
      }
    }

    var _default = {
      createEditor: createEditor,
      destroyEditor: destroyEditor,
      render: render
    };
    exports.default = _default;
    //# sourceMappingURL=HTMLProcessor.js.map
  }
});
//# sourceMappingURL=HTMLProcessor.js.map