Liferay.Loader.define("layout-seo-web@1.0.42/js/seo/openGraph.es", ['module', 'exports', 'require', 'frontend-js-web', './PreviewSeoEvents.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = _default;

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

    var _PreviewSeoEvents = require("./PreviewSeoEvents.es");

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * This library is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Lesser General Public License as published by the Free
     * Software Foundation; either version 2.1 of the License, or (at your option)
     * any later version.
     *
     * This library 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 Lesser General Public License for more
     * details.
     */
    function _default(_ref) {
      var namespace = _ref.namespace,
          uploadOpenGraphImageURL = _ref.uploadOpenGraphImageURL;
      var openGraphImageButton = document.getElementById("".concat(namespace, "openGraphImageButton"));
      var openGraphImageFileEntryId = document.getElementById("".concat(namespace, "openGraphImageFileEntryId"));
      var openGraphImageTitle = document.getElementById("".concat(namespace, "openGraphImageTitle"));
      var openGraphImageAltField = document.getElementById("".concat(namespace, "openGraphImageAlt"));
      var openGraphImageAltFieldDefaultLocale = document.getElementById("".concat(namespace, "openGraphImageAlt_").concat(Liferay.ThemeDisplay.getDefaultLanguageId()));
      var openGraphImageAltLabel = document.querySelector("[for=\"".concat(namespace, "openGraphImageAlt\""));
      openGraphImageButton.addEventListener('click', function () {
        (0, _frontendJsWeb.openSelectionModal)({
          onSelect: function onSelect(selectedItem) {
            if (selectedItem) {
              var itemValue = JSON.parse(selectedItem.value);
              openGraphImageFileEntryId.value = itemValue.fileEntryId;
              openGraphImageTitle.value = itemValue.title;
              (0, _PreviewSeoEvents.previewSeoFireChange)(namespace, {
                type: 'imgUrl',
                value: itemValue.url
              });
              (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltField, false);
              (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltFieldDefaultLocale, false);
              (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltLabel, false);
            }
          },
          selectEventName: "".concat(namespace, "openGraphImageSelectedItem"),
          title: Liferay.Language.get('open-graph-image'),
          url: uploadOpenGraphImageURL
        });
      });
      var openGraphClearImageButton = document.getElementById("".concat(namespace, "openGraphClearImageButton"));
      openGraphClearImageButton.addEventListener('click', function () {
        openGraphImageFileEntryId.value = '';
        openGraphImageTitle.value = '';
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltField, true);
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltFieldDefaultLocale, true);
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltLabel, true);
        (0, _PreviewSeoEvents.previewSeoFireChange)(namespace, {
          type: 'imgUrl',
          value: ''
        });
      });
      var openGraphTitleEnabledCheck = document.getElementById("".concat(namespace, "openGraphTitleEnabled"));
      var openGraphTitleField = document.getElementById("".concat(namespace, "openGraphTitle"));
      var openGraphTitleFieldDefaultLocale = document.getElementById("".concat(namespace, "openGraphTitle_").concat(Liferay.ThemeDisplay.getLanguageId()));
      openGraphTitleEnabledCheck.addEventListener('click', function (event) {
        var disabled = !event.target.checked;
        (0, _frontendJsWeb.toggleDisabled)(openGraphTitleField, disabled);
        (0, _frontendJsWeb.toggleDisabled)(openGraphTitleFieldDefaultLocale, disabled);
        (0, _PreviewSeoEvents.previewSeoFireChange)(namespace, {
          disabled: disabled,
          type: 'title',
          value: openGraphTitleField.value
        });
      });
      var openGraphDescriptionEnabledCheck = document.getElementById("".concat(namespace, "openGraphDescriptionEnabled"));
      var openGraphDescriptionField = document.getElementById("".concat(namespace, "openGraphDescription"));
      var openGraphDescriptionFieldDefaultLocale = document.getElementById("".concat(namespace, "openGraphDescription_").concat(Liferay.ThemeDisplay.getLanguageId()));
      openGraphDescriptionEnabledCheck.addEventListener('click', function (event) {
        var disabled = !event.target.checked;
        (0, _frontendJsWeb.toggleDisabled)(openGraphDescriptionField, disabled);
        (0, _frontendJsWeb.toggleDisabled)(openGraphDescriptionFieldDefaultLocale, disabled);
        (0, _PreviewSeoEvents.previewSeoFireChange)(namespace, {
          disabled: disabled,
          type: 'description',
          value: openGraphDescriptionField.value
        });
      });
    }
    //# sourceMappingURL=openGraph.es.js.map
  }
});
//# sourceMappingURL=openGraph.es.js.map