/*
 * 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=()=>{o.default(i.containerSelector).on("click",i.shortcutDeleteSelector,t=>{t.preventDefault(),t.stopImmediatePropagation(),this.deleteShortcut(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(o.default(t.currentTarget).closest(i.shortcutItemSelector))}).on("click",i.shortcutFormSaveSelector,t=>{t.preventDefault(),t.stopImmediatePropagation(),this.saveShortcutForm(o.default(t.currentTarget).closest(i.shortcutFormSelector))}).on("submit",i.shortcutFormSelector,t=>{t.preventDefault(),t.stopImmediatePropagation(),this.saveShortcutForm(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(),t.stopImmediatePropagation();const e=o.default(t.currentTarget).data("pageid");e&&n.ModuleStateStorage.updateWithCurrentMount("web",e,!0);const r=document.querySelector("typo3-backend-module-router");r.setAttribute("endpoint",o.default(t.currentTarget).attr("href")),r.setAttribute("module",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=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(),o.default(i.toolbarIconSelector,i.containerSelector).replaceWith(d),"object"==typeof n){const t=o.default(n).hasClass("dropdown-item"),e=new u.default;a.getIcon("actions-system-shortcut-active",a.sizes.small).then(r=>{o.default(n).html(r+(t?" "+e.encodeHtml(TYPO3.lang["labels.alreadyBookmarked"]):""))}),o.default(n).addClass(t?"disabled":"active"),o.default(n).attr("data-dispatch-disabled","disabled"),o.default(n).attr("title",TYPO3.lang["labels.alreadyBookmarked"])}}),o.default(c.currentTarget).trigger("modal-dismiss")}).on("confirm.button.cancel",t=>{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()}),o.default(e.currentTarget).trigger("modal-dismiss")}).on("confirm.button.cancel",t=>{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=>{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=>{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}));