import{r as t,c as o,h as i}from"./p-BIwHMk6j.js";import{L as e}from"./p-C_tMNOSt.js";import{b as r}from"./p-D5qhls4G.js";import{g as n}from"./p-BsH0YW6Z.js";import"./p-BgAfMcRA.js";import"./p-6PYziigk.js";const s=class{constructor(i){t(this,i),this.change=o(this,"change"),this.value={},this.type="component",this.configViewType="code",this.findConfigComponent=t=>{var o,i;return"component"===this.type?null===(o=this.registry.getAll().find((o=>o.name===t)))||void 0===o?void 0:o.configComponent:"command"===this.type?null===(i=this.commandbus.getAll().find((o=>o.id===t)))||void 0===i?void 0:i.configComponent:void 0},this.handleChangeMode=t=>{t.stopPropagation(),this.configViewType=t.detail.id},this.handleCodeEditorChange=t=>{t.stopPropagation();try{const o=JSON.parse(t.detail);this.change.emit(o)}catch(t){}}}componentWillLoad(){this.configComponent=this.getComponentName()}componentShouldUpdate(t,o,i){return"formInfo"!==i}watchFormInfo(){this.configComponent=this.getComponentName()}watchconfigComponent(t,o){t&&!o&&(this.configViewType="config"),t||(this.configViewType="code")}getComponentName(){var t,o,i;const e=[...null!==(o=null===(t=this.formInfo)||void 0===t?void 0:t.schemaPath.slice(0,-1))&&void 0!==o?o:[],this.getNameField()],r=n(null===(i=this.formInfo)||void 0===i?void 0:i.rootValue,e),s=this.findConfigComponent(r);if(s&&customElements.get(s.name))return s}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}]),i("limel-header",{icon:"edit_property",heading:this.label,subheading:this.helperText},i("limel-button-group",{slot:"actions",value:t,onChange:this.handleChangeMode}))}renderContent(){return"config"===this.configViewType?this.renderConfigComponent():this.renderCodeEditor()}renderCodeEditor(){return i("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,o;return i(e,{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===(o=this.configComponent)||void 0===o?void 0:o.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(r.WebComponentRegistry)}get commandbus(){return this.platform.get(r.CommandBus)}static get watchers(){return{formInfo:[{watchFormInfo:0}],configComponent:[{watchconfigComponent:0}]}}};s.style=":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))}";export{s as limebb_component_config}