/* * 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{LitElement as h,html as n,nothing as a}from"lit";import{property as m,customElement as $}from"lit/decorators.js";import{until as k}from"lit/directives/until.js";import{unsafeHTML as u}from"lit/directives/unsafe-html.js";import{classMap as C}from"lit/directives/class-map.js";import y from"@typo3/core/ajax/ajax-request.js";import v from"@typo3/backend/notification.js";import"@typo3/backend/element/spinner-element.js";import"@typo3/backend/element/icon-element.js";var b=function(l,e,o,t){var r=arguments.length,i=r<3?e:t===null?t=Object.getOwnPropertyDescriptor(e,o):t,d;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(l,e,o,t);else for(var p=l.length-1;p>=0;p--)(d=l[p])&&(i=(r<3?d(i):r>3?d(e,o,i):d(e,o))||i);return r>3&&i&&Object.defineProperty(e,o,i),i},f,c;(function(l){l.cut="cut",l.copy="copy"})(c||(c={}));let s=f=class extends h{constructor(){super(...arguments),this.returnUrl="",this.table=""}static renderLoader(){return n`
`}createRenderRoot(){return this}render(){return n`${k(this.renderPanel(),f.renderLoader())}`}renderPanel(){return new y(top.TYPO3.settings.Clipboard.moduleUrl).withQueryArguments({action:"getClipboardData"}).post({table:this.table}).then(async e=>{const o=await e.resolve();if(o.success===!0&&o.data){const t=o.data;return n`
${t.labels.clipboard}
${t.tabs.map(r=>this.renderTab(r,t))}
`}else return n`
Clipboard data could not be fetched
`}).catch(()=>n`
An error occurred while fetching clipboard data
`)}renderTab(e,o){return n`${o.current!==e.identifier?a:n`
this.updateClipboard(t,{CB:{setCopyMode:"1"}})}> this.updateClipboard(t,{CB:{setCopyMode:"0"}})}>
${o.elementCount?n``:a}
`}${o.current===e.identifier&&e.items?e.items.map(t=>this.renderTabItem(t,e.identifier,o)):a}`}renderTabItem(e,o,t){return n`${u(e.icon)}${u(e.title)} ${o==="normal"?n`(${t.copyMode===c.copy?n`${t.labels.copy}`:n`${t.labels.cut}`})`:a} ${e.thumb?n`
${u(e.thumb)}
`:a}
${e.infoDataDispatch?n``:a} ${e.identifier?n``:a}
`}updateClipboard(e,o){e.preventDefault();const t=e.currentTarget;new y(top.TYPO3.settings.Clipboard.moduleUrl).post(o).then(async r=>{const i=await r.resolve();i.success===!0?(t.dataset.action&&t.dispatchEvent(new CustomEvent("typo3:clipboard:"+t.dataset.action,{detail:{payload:o,response:i},bubbles:!0,cancelable:!1})),this.reloadModule()):v.error("Clipboard data could not be updated")}).catch(()=>{v.error("An error occurred while updating clipboard data")})}reloadModule(){this.returnUrl?this.ownerDocument.location.href=this.returnUrl:this.ownerDocument.location.reload()}};b([m({type:String,attribute:"return-url"})],s.prototype,"returnUrl",void 0),b([m({type:String})],s.prototype,"table",void 0),s=f=b([$("typo3-backend-clipboard-panel")],s);export{s as ClipboardPanel};