import{h as t,r as o,c as e}from"./p-BIwHMk6j.js";import{n as i}from"./p-B3U_Lxk4.js";import{g as n}from"./p-BsH0YW6Z.js";import"./p-BgAfMcRA.js";import"./p-6PYziigk.js";const r=(o,e)=>t(o.name,Object.assign({class:o.class},function(t){let o={};return t.props&&(o=Object.assign({},t.props)),Object.assign({context:t.context,platform:t.platform},o)}(o),{key:o.key}),e),s=class{constructor(t){o(this,t),this.change=e(this,"change"),this.value={},this.type="component",this.configViewType="code",this.findConfigComponent=t=>{var o,e;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===(e=this.commandbus.getAll().find((o=>o.id===t)))||void 0===e?void 0:e.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,e){return"formInfo"!==e}watchFormInfo(){this.configComponent=this.getComponentName()}watchconfigComponent(t,o){t&&!o&&(this.configViewType="config"),t||(this.configViewType="code")}getComponentName(){var t,o,e;const i=[...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===(e=this.formInfo)||void 0===e?void 0:e.rootValue,i),s=this.findConfigComponent(r);if(s&&customElements.get(s.name))return s}render(){return[this.renderHeader(),this.renderContent()]}renderHeader(){let o=[];return this.configComponent&&(o=[{id:"config",title:"Config",selected:"config"===this.configViewType},{id:"code",title:"Code",selected:"code"===this.configViewType}]),t("limel-header",{icon:"edit_property",heading:this.label,subheading:this.helperText},t("limel-button-group",{slot:"actions",value:o,onChange:this.handleChangeMode}))}renderContent(){return"config"===this.configViewType?this.renderConfigComponent():this.renderCodeEditor()}renderCodeEditor(){return t("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 o,e;return t(r,{class:"config-component",platform:this.platform,context:this.context,name:null===(o=this.configComponent)||void 0===o?void 0:o.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(i.WebComponentRegistry)}get commandbus(){return this.platform.get(i.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}