/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */
var __importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};define(["require","exports","jquery","TYPO3/CMS/Core/Ajax/AjaxRequest","../Icons","../Modal","../Notification","../Viewport","TYPO3/CMS/Core/SecurityUtility","TYPO3/CMS/Backend/Storage/ModuleStateStorage"],(function(t,e,o,r,a,c,s,l,u,n){"use strict";var i;o=__importDefault(o),u=__importDefault(u),function(t){t.containerSelector="#typo3-cms-backend-backend-toolbaritems-shortcuttoolbaritem",t.toolbarIconSelector=".dropdown-toggle span.icon",t.toolbarMenuSelector=".dropdown-menu",t.shortcutItemSelector=".t3js-topbar-shortcut",t.shortcutJumpSelector=".t3js-shortcut-jump",t.shortcutDeleteSelector=".t3js-shortcut-delete",t.shortcutEditSelector=".t3js-shortcut-edit",t.shortcutFormTitleSelector='input[name="shortcut-title"]',t.shortcutFormGroupSelector='select[name="shortcut-group"]',t.shortcutFormSaveSelector=".shortcut-form-save",t.shortcutFormCancelSelector=".shortcut-form-cancel",t.shortcutFormSelector=".shortcut-form"}(i||(i={}));class d{constructor(){this.initializeEvents=()=>{(0,o.default)(i.containerSelector).on("click",i.shortcutDeleteSelector,t=>{t.preventDefault(),t.stopImmediatePropagation(),this.deleteShortcut((0,o.default)(t.currentTarget).closest(i.shortcutItemSelector))}).on("click",i.shortcutFormGroupSelector,t=>{t.preventDefault(),t.stopImmediatePropagation()}).on("click",i.shortcutEditSelector,t=>{t.preventDefault(),t.stopImmediatePropagation(),this.editShortcut((0,o.default)(t.currentTarget).closest(i.shortcutItemSelector))}).on("click",i.shortcutFormSaveSelector,t=>{t.preventDefault(),t.stopImmediatePropagation(),this.saveShortcutForm((0,o.default)(t.currentTarget).closest(i.shortcutFormSelector))}).on("submit",i.shortcutFormSelector,t=>{t.preventDefault(),t.stopImmediatePropagation(),this.saveShortcutForm((0,o.default)(t.currentTarget).closest(i.shortcutFormSelector))}).on("click",i.shortcutFormCancelSelector,t=>{t.preventDefault(),t.stopImmediatePropagation(),this.refreshMenu()}).on("click",i.shortcutJumpSelector,t=>{t.preventDefault();const e=(0,o.default)(t.currentTarget).data("pageid");e&&n.ModuleStateStorage.updateWithCurrentMount("web",e,!0);const r=document.querySelector("typo3-backend-module-router");r.setAttribute("endpoint",(0,o.default)(t.currentTarget).attr("href")),r.setAttribute("module",(0,o.default)(t.currentTarget).data("module"))})},l.Topbar.Toolbar.registerEvent(this.initializeEvents)}createShortcut(t,e,s,l,n){void 0!==l&&c.confirm(TYPO3.lang["bookmark.create"],l).on("confirm.button.ok",c=>{const l=(0,o.default)(i.toolbarIconSelector,i.containerSelector),d=l.clone();a.getIcon("spinner-circle-light",a.sizes.small).then(t=>{l.replaceWith(t)}),new r(TYPO3.settings.ajaxUrls.shortcut_create).post({routeIdentifier:t,arguments:e,displayName:s}).then(()=>{if(this.refreshMenu(),(0,o.default)(i.toolbarIconSelector,i.containerSelector).replaceWith(d),"object"==typeof n){const t=(0,o.default)(n).hasClass("dropdown-item"),e=new u.default;a.getIcon("actions-system-shortcut-active",a.sizes.small).then(r=>{(0,o.default)(n).html(r+(t?" "+e.encodeHtml(TYPO3.lang["labels.alreadyBookmarked"]):""))}),(0,o.default)(n).addClass(t?"disabled":"active"),(0,o.default)(n).attr("data-dispatch-disabled","disabled"),(0,o.default)(n).attr("title",TYPO3.lang["labels.alreadyBookmarked"])}}),(0,o.default)(c.currentTarget).trigger("modal-dismiss")}).on("confirm.button.cancel",t=>{(0,o.default)(t.currentTarget).trigger("modal-dismiss")})}deleteShortcut(t){c.confirm(TYPO3.lang["bookmark.delete"],TYPO3.lang["bookmark.confirmDelete"]).on("confirm.button.ok",e=>{new r(TYPO3.settings.ajaxUrls.shortcut_remove).post({shortcutId:t.data("shortcutid")}).then(()=>{this.refreshMenu()}),(0,o.default)(e.currentTarget).trigger("modal-dismiss")}).on("confirm.button.cancel",t=>{(0,o.default)(t.currentTarget).trigger("modal-dismiss")})}editShortcut(t){new r(TYPO3.settings.ajaxUrls.shortcut_editform).withQueryArguments({shortcutId:t.data("shortcutid"),shortcutGroup:t.data("shortcutgroup")}).get({cache:"no-cache"}).then(async t=>{(0,o.default)(i.containerSelector).find(i.toolbarMenuSelector).html(await t.resolve())})}saveShortcutForm(t){new r(TYPO3.settings.ajaxUrls.shortcut_saveform).post({shortcutId:t.data("shortcutid"),shortcutTitle:t.find(i.shortcutFormTitleSelector).val(),shortcutGroup:t.find(i.shortcutFormGroupSelector).val()}).then(()=>{s.success(TYPO3.lang["bookmark.savedTitle"],TYPO3.lang["bookmark.savedMessage"]),this.refreshMenu()})}refreshMenu(){new r(TYPO3.settings.ajaxUrls.shortcut_list).get({cache:"no-cache"}).then(async t=>{(0,o.default)(i.toolbarMenuSelector,i.containerSelector).html(await t.resolve())})}}top.TYPO3.ShortcutMenu&&"object"==typeof top.TYPO3.ShortcutMenu||(top.TYPO3.ShortcutMenu=new d);return top.TYPO3.ShortcutMenu}));