/*
 * 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 o from"@typo3/core/event/regular-event.js";var l;(function(t){t.primary="typo3:filelist:resource:action:primary",t.primaryContextmenu="typo3:filelist:resource:action:primaryContextmenu",t.show="typo3:filelist:resource:action:show",t.rename="typo3:filelist:resource:action:rename",t.select="typo3:filelist:resource:action:select",t.download="typo3:filelist:resource:action:download",t.updateOnlineMedia="typo3:filelist:resource:action:updateOnlineMedia"})(l||(l={}));var n;(function(t){t.elementSelector="[data-filelist-element]",t.actionSelector="[data-filelist-action]"})(n||(n={}));class r{static createResourceFromContextDataset(e){return{type:e.filecontextType,identifier:e.filecontextIdentifier,name:e.filecontextName,hasPreview:!1,uid:e.filecontextUid?parseInt(e.filecontextUid,10):null,metaUid:e.filecontextMetaUid?parseInt(e.filecontextMetaUid,10):null,url:e.filecontextUid?e.url:null}}static getResourceForElement(e){return{type:e.dataset.filelistType,identifier:e.dataset.filelistIdentifier,name:e.dataset.filelistName,hasPreview:"filelistPreview"in e.dataset&&e.dataset.filelistPreview.trim()==="true",uid:e.dataset.filelistUid?parseInt(e.dataset.filelistUid,10):null,metaUid:e.dataset.filelistMetaUid?parseInt(e.dataset.filelistMetaUid,10):null,url:e.dataset.filelistUid?e.dataset.filelistUrl:null}}}class d{constructor(){new o("contextmenu",(e,a)=>{e.preventDefault(),e.stopImmediatePropagation();const i=this.getActionDetail(e,a);switch(i.action){case"primary":document.dispatchEvent(new CustomEvent(l.primaryContextmenu,{detail:i}));break;default:break}}).delegateTo(document,n.actionSelector),new o("click",(e,a)=>{e.preventDefault();const i=this.getActionDetail(e,a);switch(i.action){case"primary":document.dispatchEvent(new CustomEvent(l.primary,{detail:i}));break;case"show":document.dispatchEvent(new CustomEvent(l.show,{detail:i}));break;case"select":document.dispatchEvent(new CustomEvent(l.select,{detail:i}));break;case"rename":document.dispatchEvent(new CustomEvent(l.rename,{detail:i}));break;case"download":document.dispatchEvent(new CustomEvent(l.download,{detail:i}));break;case"updateOnlineMedia":document.dispatchEvent(new CustomEvent(l.updateOnlineMedia,{detail:i}));break;default:break}}).delegateTo(document,n.actionSelector)}getActionDetail(e,a){const i=a.dataset.filelistAction,s=a.closest(n.elementSelector),c=r.getResourceForElement(s);return{event:e,trigger:a,action:i,resources:[c],url:a.dataset.filelistActionUrl??null,originalAction:null}}}var u=new d;export{l as FileListActionEvent,n as FileListActionSelector,r as FileListActionUtility,u as default};
