var __decorate=this&&this.__decorate||function(e,t,r,o){var s,i=arguments.length,a=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,o);else for(var h=e.length-1;h>=0;h--)(s=e[h])&&(a=(i<3?s(a):i>3?s(t,r,a):s(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a};import{css as e,html as t,LitElement as r}from"lit";import{customElement as o,property as s,state as i}from"lit/decorators.js";import{Actions as a,configReducer as h,coreReducer as c,createAjv as d,createDefaultValue as n,generateDefaultUISchema as p,generateJsonSchema as m,mapStateToJsonFormsRendererProps as l,setConfig as u}from"@jsonforms/core";import{getTemplateWrapper as O,StandardRenderers as y}from"./standard-renderers";import{getLabel as _,getTemplateFromProps as f}from"./util";import{baseStyle as g}from"./styles";import{Util as v}from"@openremote/core";import{i18next as S,translate as F}from"@openremote/or-translate";export*from"@jsonforms/core";let styles=e`
    .delete-container {
        width: 0;
    }

    .item-container {
        margin: 0; /* Remove inherited margin */
    }
`,OrJSONForms=class extends F(S)(r){constructor(){super(...arguments),this.renderers=y,this.readonly=!1,this.required=!1,this.previousErrors=[]}static get styles(){return[g,styles]}checkValidity(){return 0===this.previousErrors.length}shouldUpdate(e){if(super.shouldUpdate(e),this.schema||(this.schema=void 0!==this.data?m(this.data):{}),this.data||(this.data=n(this.schema,this.schema)),this.uischema||(this.uischema=p(this.schema)),this.core||(this.core={ajv:d({useDefaults:!0,validateFormats:!1}),data:{},schema:this.schema,uischema:this.uischema},this.updateCore(a.init(this.data,this.schema,this.uischema)),this.config=h(void 0,u(this.config))),(e.has("data")||e.has("schema")||e.has("uischema"))&&this.updateCore(a.updateCore(this.data,this.schema,this.uischema)),(!this.contextValue||e.has("core")||e.has("renderers")||e.has("cells")||e.has("config")||e.has("readonly")||e.has("_language"))&&(this.contextValue={core:this.core,renderers:this.renderers,cells:this.cells,config:this.config,uischemas:this.uischemas,readonly:this.readonly,dispatch:e=>this.updateCore(e),i18n:{locale:this._language,translate:(e,t,{errors:[r]})=>{let o=t||(null==r?void 0:r.message)||"";return S.t(e,{defaultValue:o})||S.t(e,{defaultValue:o,lng:"en"})}}}),e.has("core")){let e=this.core.data,t=this.core.errors;this.onChange&&(!v.objectsEqual(e,this.previousData,!0)||t&&!v.objectsEqual(t,this.previousErrors,!0))&&(this.previousErrors=t||[],this.previousData=e,this.onChange({data:e,errors:t}))}return!0}updateCore(e){let t=c(this.core,e);return t!==this.core&&(this.core=t),e}render(){if(!this.contextValue)return t``;let e=Object.assign(Object.assign({},l({jsonforms:Object.assign({},this.contextValue)},this)),{label:_(this.schema,this.uischema,this.label,void 0)||"",required:this.required});return f(this.contextValue,e)||t``}};__decorate([s({type:Object})],OrJSONForms.prototype,"uischema",void 0),__decorate([s({type:Object})],OrJSONForms.prototype,"schema",void 0),__decorate([s({type:Object,attribute:!1})],OrJSONForms.prototype,"data",void 0),__decorate([s({type:Array})],OrJSONForms.prototype,"renderers",void 0),__decorate([s({type:Array})],OrJSONForms.prototype,"cells",void 0),__decorate([s({type:String,attribute:!1})],OrJSONForms.prototype,"onChange",void 0),__decorate([s({type:String,attribute:!1})],OrJSONForms.prototype,"config",void 0),__decorate([s({type:Array})],OrJSONForms.prototype,"uischemas",void 0),__decorate([s({type:Boolean})],OrJSONForms.prototype,"readonly",void 0),__decorate([s({type:String})],OrJSONForms.prototype,"label",void 0),__decorate([s({type:Boolean})],OrJSONForms.prototype,"required",void 0),__decorate([i()],OrJSONForms.prototype,"core",void 0),__decorate([i()],OrJSONForms.prototype,"contextValue",void 0),OrJSONForms=__decorate([o("or-json-forms")],OrJSONForms);export{y as StandardRenderers,O as getTemplateWrapper,OrJSONForms};