Liferay.Loader.define("layout-seo-web@1.0.45/js/seo/openGraphSettings.es", ['module', 'exports', 'require', 'frontend-js-web'], 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");

    /**
     * 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 openGraphPreviewImage = document.getElementById("".concat(namespace, "openGraphPreviewImage"));
      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 (event) {
        event.preventDefault();
        (0, _frontendJsWeb.openSelectionModal)({
          buttonAddLabel: Liferay.Language.get('done'),
          onSelect: function onSelect(selectedItem) {
            if (selectedItem) {
              var itemValue = JSON.parse(selectedItem.value);
              openGraphImageFileEntryId.value = itemValue.fileEntryId;
              openGraphImageTitle.value = itemValue.title;
              openGraphPreviewImage.src = itemValue.url;
              openGraphPreviewImage.classList.remove('hide');
              (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 = '';
        openGraphPreviewImage.src = '';
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltField, true);
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltFieldDefaultLocale, true);
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltLabel, true);
        openGraphPreviewImage.classList.add('hide');
      });
      var openGraphEnabledCheck = document.getElementById("".concat(namespace, "openGraphEnabled"));
      var openGraphSettings = document.getElementById("".concat(namespace, "openGraphSettings"));
      openGraphEnabledCheck.addEventListener('click', function (event) {
        var disabled = !event.target.checked;
        var openGraphImageAltDisabled = disabled || !openGraphImageTitle.value;
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageTitle, disabled);
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageButton, disabled);
        (0, _frontendJsWeb.toggleDisabled)(openGraphClearImageButton, disabled);
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltField, openGraphImageAltDisabled);
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltFieldDefaultLocale, openGraphImageAltDisabled);
        (0, _frontendJsWeb.toggleDisabled)(openGraphImageAltLabel, openGraphImageAltDisabled);
        openGraphSettings.classList.toggle('disabled');
      });
    }
    //# sourceMappingURL=openGraphSettings.es.js.map
  }
});
//# sourceMappingURL=openGraphSettings.es.js.map