/*
 * 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!
 */
import{SeverityEnum as g}from"@typo3/backend/enum/severity.js";import f from"@typo3/backend/ajax-data-handler.js";import d from"@typo3/core/ajax/ajax-request.js";import U from"@typo3/backend/info-window.js";import l from"@typo3/backend/modal.js";import C from"@typo3/backend/module-menu.js";import m from"@typo3/backend/notification.js";import i from"@typo3/backend/viewport.js";import"@typo3/backend/new-record-wizard.js";import b from"@typo3/backend/utility.js";import{topLevelModuleImport as w}from"@typo3/backend/utility/top-level-module-import.js";import{html as h}from"lit";import p from"~labels/core.common";import c from"~labels/core.cache";import u from"~labels/core.mod_web_list";import R from"~labels/backend.layout";import{openPageWizardModal as v}from"@typo3/backend/page-wizard/helper/wizard-helper.js";class n{static getReturnUrl(){return encodeURIComponent(top.list_frame.document.location.pathname+top.list_frame.document.location.search)}static editRecord(t,o,e){const r=e.pagesLanguageUid;let a="";r&&(a="&overrideVals[pages][sys_language_uid]="+r),i.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+t+"]["+o+"]=edit"+a+"&module="+encodeURIComponent(top.TYPO3.ModuleMenu.App.getCurrentModule())+"&returnUrl="+n.getReturnUrl())}static viewRecord(t,o,e){const r=e.previewUrl;if(r){const a=window.open(r,"newTYPO3frontendWindow");a.focus(),b.urlsPointToSameServerSideResource(a.location.href,r)&&a.location.reload()}}static async showQrCode(t,o,e){const r=e.previewUrl;r&&(await w("@typo3/backend/element/qrcode-element.js"),l.advanced({title:R.get("showPageQrCode.modalTitle"),size:l.sizes.small,content:h`<div class=text-center><typo3-qrcode class=text-start content=${r} size=large show-url></typo3-qrcode></div>`,buttons:[{text:u.get("button.close"),btnClass:"btn-default",name:"close",trigger:(a,s)=>s.hideModal()}]}))}static openInfoPopUp(t,o){U.showItem(t,o)}static mountAsTreeRoot(t,o){if(t==="pages"){const e=new CustomEvent("typo3:pagetree:mountPoint",{detail:{pageId:o}});top.document.dispatchEvent(e)}}static newPageWizard(t,o,e){const r=e.pagesNewWizardUrl;i.ContentContainer.setUrl(r+"&returnUrl="+n.getReturnUrl())}static newContentWizard(t,o,e){let r=e.newWizardUrl;r&&(r+="&returnUrl="+n.getReturnUrl(),l.advanced({title:e.title,type:l.types.ajax,size:l.sizes.large,content:r,severity:g.notice}))}static newRecord(t,o){if(t==="pages"){v({positionData:{pageUid:parseInt(String(o),10),insertPosition:"inside"}});return}i.ContentContainer.setUrl(top.TYPO3.settings.FormEngine.moduleUrl+"&edit["+t+"]["+(t!=="pages"?"-":"")+o+"]=new&returnUrl="+n.getReturnUrl())}static openHistoryPopUp(t,o){i.ContentContainer.setUrl(top.TYPO3.settings.RecordHistory.moduleUrl+"&element="+t+":"+o+"&returnUrl="+n.getReturnUrl())}static openListModule(t,o,e){const r=t==="pages"?o:e.pageUid;C.App.showModule("records","id="+r)}static pagesSort(t,o,e){const r=e.pagesSortUrl;r&&i.ContentContainer.setUrl(r)}static openSiteSettings(t,o,e){const r=e.siteSettingsUrl;r&&i.ContentContainer.setUrl(r+"&returnUrl="+n.getReturnUrl())}static openSiteConfiguration(t,o,e){const r=e.siteConfigurationUrl;r&&i.ContentContainer.setUrl(r+"&returnUrl="+n.getReturnUrl())}static pagesNewMultiple(t,o,e){const r=e.pagesNewMultipleUrl;r&&i.ContentContainer.setUrl(r)}static disableRecord(t,o,e){const r=e.disableField||"hidden";i.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+t+"]["+o+"]["+r+"]=1&redirect="+n.getReturnUrl())}static enableRecord(t,o,e){const r=e.disableField||"hidden";i.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+t+"]["+o+"]["+r+"]=0&redirect="+n.getReturnUrl())}static showInMenus(t,o){i.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+t+"]["+o+"][nav_hide]=0&redirect="+n.getReturnUrl())}static hideInMenus(t,o){i.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+"&data["+t+"]["+o+"][nav_hide]=1&redirect="+n.getReturnUrl())}static deleteRecord(t,o,e){const r=l.confirm(e.title,e.message,g.warning,[{text:e.buttonCloseText||p.get("cancel"),active:!0,btnClass:"btn-default",name:"cancel"},{text:e.buttonOkText||u.get("button.delete"),btnClass:"btn-warning",name:"delete"}]);r.addEventListener("button.clicked",a=>{if(a.target.getAttribute("name")==="delete"){const s={component:"contextmenu",action:"delete",table:t,uid:o};f.process("cmd["+t+"]["+o+"][delete]=1",s).then(()=>{t==="pages"&&n.refreshPageTree(),n.triggerRefresh(i.ContentContainer.get().location.href)})}r.hideModal()})}static copy(t,o){const e=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+o+"]=1&CB[setCopyMode]=1";new d(e).get().finally(()=>{n.triggerRefresh(i.ContentContainer.get().location.href)})}static clipboardRelease(t,o){const e=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+o+"]=0";new d(e).get().finally(()=>{n.triggerRefresh(i.ContentContainer.get().location.href)})}static cut(t,o){const e=TYPO3.settings.ajaxUrls.contextmenu_clipboard+"&CB[el]["+t+"%7C"+o+"]=1&CB[setCopyMode]=0";new d(e).get().finally(()=>{n.triggerRefresh(i.ContentContainer.get().location.href)})}static triggerRefresh(t){t.includes("record%2Fedit")||i.ContentContainer.refresh()}static clearCache(t,o){new d(TYPO3.settings.ajaxUrls.clearcache_page).post({id:o}).then(async e=>{const r=await e.resolve();r?.success===!1?m.error(r.title??c.get("notification.error.title"),r.message??c.get("notification.error.message")):m.success(r?.title??c.get("notification.success.title"),r?.message??c.get("notification.success.message"))},()=>{m.error(c.get("notification.error.title"),c.get("notification.error.message"))})}static pasteAfter(t,o,e){n.pasteInto(t,-o,e)}static pasteInto(t,o,e){const r=()=>{const s="&CB[paste]="+t+"%7C"+o+"&CB[pad]=normal&redirect="+n.getReturnUrl();i.ContentContainer.setUrl(top.TYPO3.settings.RecordCommit.moduleUrl+s)};if(!e.title){r();return}const a=l.confirm(e.title,e.message,g.warning,[{text:e.buttonCloseText||p.get("cancel"),active:!0,btnClass:"btn-default",name:"cancel"},{text:e.buttonOkText||p.get("ok"),btnClass:"btn-warning",name:"ok"}]);a.addEventListener("button.clicked",s=>{s.target.getAttribute("name")==="ok"&&r(),a.hideModal()})}static refreshPageTree(){top.document.dispatchEvent(new CustomEvent("typo3:pagetree:refresh"))}}export{n as default};
