/*
 * 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{html as m,nothing as c}from"lit";import{property as u,customElement as g}from"lit/decorators.js";import{MessageUtility as y}from"@typo3/backend/utility/message-utility.js";import{BaseElement as h}from"@typo3/backend/settings/type/base.js";import d from"@typo3/backend/modal.js";import v from"~labels/backend.settingseditor";import"@typo3/backend/element/icon-element.js";var p=function(o,e,n,r){var i=arguments.length,t=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,n):r,s;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")t=Reflect.decorate(o,e,n,r);else for(var l=o.length-1;l>=0;l--)(s=o[l])&&(t=(i<3?s(t):i>3?s(e,n,t):s(e,n))||t);return i>3&&t&&Object.defineProperty(e,n,t),t};const f="typo3-backend-settings-type-page";let a=class extends h{constructor(){super(...arguments),this.elementBrowserListener=e=>{if(!y.verifyOrigin(e.origin))throw"Denied message sent by "+e.origin;if(e.data.actionName==="typo3:elementBrowser:elementAdded"){if(typeof e.data.fieldName>"u")throw"fieldName not defined in message";if(typeof e.data.value>"u")throw"value not defined in message";this.value=e.data.value.split("_").pop()}}}render(){return m`<div class=input-grouped><input type=number id=${this.formid} class=form-control ?readonly=${this.readonly} .value=${this.value} @change=${e=>this.value=parseInt(e.target.value,10)}> ${this.canUseElementBrowser()?m`<button type=button class="btn btn-default" @click=${()=>this.openElementBrowser()}><typo3-backend-icon identifier=apps-pagetree-page size=small></typo3-backend-icon>${v.get("settingseditor.type.page.button")||"Select page"}</button>`:c}</div>`}canUseElementBrowser(){return top.TYPO3.settings?.Wizards?.elementBrowserUrl!==void 0}openElementBrowser(){const e="db",n=new URLSearchParams({mode:e,fieldReference:this.formid,allowedTypes:"pages"}),r=d.advanced({type:d.types.iframe,content:top.TYPO3.settings.Wizards.elementBrowserUrl+"&"+n.toString(),size:d.sizes.large});window.addEventListener("message",this.elementBrowserListener),r.addEventListener("typo3-modal-hide",()=>{window.removeEventListener("message",this.elementBrowserListener)})}};p([u({type:Number})],a.prototype,"value",void 0),a=p([g(f)],a);export{a as PageTypeElement,f as componentName};
