/*
 * 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 f}from"lit";import{defaultConverter as v}from"@lit/reactive-element";import{property as a}from"lit/decorators.js";var i=function(u,t,e,r){var s=arguments.length,l=s<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,c;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")l=Reflect.decorate(u,t,e,r);else for(var b=u.length-1;b>=0;b--)(c=u[b])&&(l=(s<3?c(l):s>3?c(t,e,l):c(t,e))||l);return s>3&&l&&Object.defineProperty(t,e,l),l};const n=Symbol("internals"),h=Symbol("privateInternals"),p=Symbol("getFormValue"),d=Symbol("getFormState");class o extends f{constructor(){super(...arguments),this.readonly=!1,this.debug=!1}static{this.formAssociated=!0}createRenderRoot(){return this}get[n](){return this[h]||(this[h]=this.attachInternals()),this[h]}get form(){return this[n].form}get labels(){return this[n].labels}get name(){return this.getAttribute("name")??""}set name(t){this.setAttribute("name",t)}get disabled(){return this.hasAttribute("disabled")}set disabled(t){this.toggleAttribute("disabled",t)}attributeChangedCallback(t,e,r){if(t==="name"||t==="disabled"){const s=t==="disabled"?e!==null:e;this.requestUpdate(t,s);return}super.attributeChangedCallback(t,e,r)}requestUpdate(t,e,r){super.requestUpdate(t,e,r),t==="value"&&(this.dispatchEvent(new CustomEvent("typo3:setting:changed",{detail:{value:this.value}})),this[n].setFormValue(this[p](),this[d]()))}formDisabledCallback(t){this.disabled=t}formResetCallback(){const t=this.value,e=this.getAttribute("value");this.attributeChangedCallback("value",this.valueToString(t),null),this.attributeChangedCallback("value",null,e)}formStateRestoreCallback(t){if(typeof t=="string")this.attributeChangedCallback("value",this.valueToString(this.value),null),this.attributeChangedCallback("value",null,t);else throw new Error(`formStateRestoreCallback() needs to be implemented for <${this.localName}> for state type "${typeof t}"`)}[d](){return this[p]()}[p](){return this.valueToString(this.value)}valueToString(t){const r=this.constructor.getPropertyOptions("value");return(typeof r.converter=="object"&&typeof r.converter?.toAttribute=="function"?r.converter.toAttribute:v.toAttribute)(t,r.type)}}i([a({type:String})],o.prototype,"key",void 0),i([a({type:String})],o.prototype,"formid",void 0),i([a({type:Boolean})],o.prototype,"readonly",void 0),i([a({type:Object})],o.prototype,"enum",void 0),i([a({type:Boolean})],o.prototype,"debug",void 0),i([a({type:Object})],o.prototype,"options",void 0),i([a({noAccessor:!0})],o.prototype,"name",null),i([a({type:Boolean,noAccessor:!0})],o.prototype,"disabled",null);export{o as BaseElement,d as getFormState,p as getFormValue,n as internals};
