import{proxyCustomElement as t,HTMLElement as e,createEvent as o,h as n,transformTag as i}from"@stencil/core/internal/client";import{L as r}from"./web-component-template.js";import{b as s}from"./index.esm.js";import{g as l}from"./get.js";const c=t(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.change=o(this,"change",7),this.value={},this.type="component",this.configViewType="code",this.findConfigComponent=t=>{var e,o;return"component"===this.type?null===(e=this.registry.getAll().find((e=>e.name===t)))||void 0===e?void 0:e.configComponent:"command"===this.type?null===(o=this.commandbus.getAll().find((e=>e.id===t)))||void 0===o?void 0:o.configComponent:void 0},this.handleChangeMode=t=>{t.stopPropagation(),this.configViewType=t.detail.id},this.handleCodeEditorChange=t=>{t.stopPropagation();try{const e=JSON.parse(t.detail);this.change.emit(e)}catch(t){}}}componentWillLoad(){this.configComponent=this.getComponentName()}componentShouldUpdate(t,e,o){return"formInfo"!==o}watchFormInfo(){this.configComponent=this.getComponentName()}watchconfigComponent(t,e){t&&!e&&(this.configViewType="config"),t||(this.configViewType="code")}getComponentName(){var t,e,o;const n=[...null!==(e=null===(t=this.formInfo)||void 0===t?void 0:t.schemaPath.slice(0,-1))&&void 0!==e?e:[],this.getNameField()],i=l(null===(o=this.formInfo)||void 0===o?void 0:o.rootValue,n),r=this.findConfigComponent(i);if(r&&customElements.get(r.name))return r}render(){return[this.renderHeader(),this.renderContent()]}renderHeader(){let t=[];return this.configComponent&&(t=[{id:"config",title:"Config",selected:"config"===this.configViewType},{id:"code",title:"Code",selected:"code"===this.configViewType}]),n("limel-header",{icon:"edit_property",heading:this.label,subheading:this.helperText},n("limel-button-group",{slot:"actions",value:t,onChange:this.handleChangeMode}))}renderContent(){return"config"===this.configViewType?this.renderConfigComponent():this.renderCodeEditor()}renderCodeEditor(){return n("limel-code-editor",{value:JSON.stringify(this.value,null,"\t"),language:"json",readonly:this.readonly,lineNumbers:!0,fold:!0,lint:!0,onChange:this.handleCodeEditorChange})}renderConfigComponent(){var t,e;return n(r,{class:"config-component",platform:this.platform,context:this.context,name:null===(t=this.configComponent)||void 0===t?void 0:t.name,props:Object.assign(Object.assign({},null===(e=this.configComponent)||void 0===e?void 0:e.props),{value:this.value,required:this.required,readonly:this.readonly,disabled:this.disabled,label:this.label,helperText:this.helperText,formInfo:this.formInfo})})}getNameField(){return this.nameField?this.nameField:{component:"name",command:"id"}[this.type]}get registry(){return this.platform.get(s.WebComponentRegistry)}get commandbus(){return this.platform.get(s.CommandBus)}static get watchers(){return{formInfo:[{watchFormInfo:0}],configComponent:[{watchconfigComponent:0}]}}static get style(){return":host(*){--header-background-color:rgb(var(--contrast-600));display:flex;flex-direction:column;border:1px dashed rgb(var(--contrast-700));overflow:clip;border-radius:0.75rem;background-color:rgb(var(--contrast-500))}*{box-sizing:border-box}.label{margin-top:1rem;margin-bottom:1rem}.config-component{display:grid;column-gap:1rem;row-gap:1rem;margin:1rem;grid-template-columns:repeat(3, minmax(0, 1fr))}"}},[1,"limebb-component-config",{platform:[16],context:[16],value:[16],required:[4],readonly:[4],disabled:[4],label:[1],helperText:[1,"helper-text"],formInfo:[16],type:[1],nameField:[1,"name-field"],configComponent:[32],configViewType:[32]},void 0,{formInfo:[{watchFormInfo:0}],configComponent:[{watchconfigComponent:0}]}]),m=c,h=function(){"undefined"!=typeof customElements&&["limebb-component-config"].forEach((t=>{"limebb-component-config"===t&&(customElements.get(i(t))||customElements.define(i(t),c))}))};export{m as LimebbComponentConfig,h as defineCustomElement}