var __decorate=this&&this.__decorate||function(t,e,i,n){var r,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(r=t[a])&&(s=(o<3?r(s):o>3?r(e,i,s):r(e,i))||s);return o>3&&s&&Object.defineProperty(e,i,s),s};import{InputType as t}from"@openremote/or-mwc-components/or-mwc-input";import{css as e,html as i}from"lit";import{customElement as n}from"lit/decorators.js";import{ControlBaseElement as r}from"./control-base-element";import{baseStyle as o}from"../styles";import{isBooleanControl as s,isEnumControl as a,isIntegerControl as p,isNumberControl as m,isOneOfEnumControl as l,isStringControl as h}from"@jsonforms/core";import{isEnumArray as u}from"../standard-renderers";let style=e`
    or-mwc-input {
        width: 100%;
    }
`,ControlInputElement=class extends r{static get styles(){return[o,style]}render(){var e;let n,r,o,d,c,y,f,g=this.uischema,T=this.schema,E=this.schema.format,O={rootSchema:this.rootSchema,config:this.config};this.inputType=t.TEXT;let S=!1,v=null!=(e=this.data)?e:T.default;return Array.isArray(T.type)?this.inputType=t.JSON:s(g,T,O)?this.inputType=t.CHECKBOX:m(g,T,O)||p(g,T,O)?(n=m(g,T,O)?.1:1,this.inputType=t.NUMBER,r=T.minimum,d=T.maximum,n=T.multipleOf||n,void 0!==r&&void 0!==d&&"or-range"===E&&(d-r)/n<=200&&(this.inputType=t.RANGE)):a(g,T,O)||l(g,T,O)||u(g,T,O)?(this.inputType=t.SELECT,a(g,T,O)?f=T.enum.map(t=>[JSON.stringify(t),String(t)]):l(g,T,O)?f=T.oneOf.map(t=>[JSON.stringify(t.const),String(t.const)]):(S=!0,f=T.items.oneOf?T.items.oneOf.map(t=>[JSON.stringify(t.const),String(t.const)]):T.items.enum.map(t=>[JSON.stringify(t),String(t)])),v=S?Array.isArray(v)?v.map(t=>JSON.stringify(t)):void 0!==v?[JSON.stringify(v)]:void 0:void 0!==v?JSON.stringify(v):void 0):h(g,T,O)&&(o=T.minLength,c=T.maxLength,y=T.pattern,"date-time"===E?this.inputType=t.DATETIME:"date"===E?this.inputType=t.DATE:"time"===E?this.inputType=t.TIME:"email"===E?this.inputType=t.EMAIL:"tel"===E?this.inputType=t.TELEPHONE:"or-multiline"===E?this.inputType=t.TEXTAREA:("or-password"===E||T.writeOnly)&&(this.inputType=t.PASSWORD)),i`<or-mwc-input
                .label="${this.label}"
                .type="${this.inputType}"
                .disabled="${!this.enabled}"
                .required="${!!this.required}"
                .id="${this.id}"
                .options="${f}"
                .multiple="${S}"
                @or-mwc-input-changed="${t=>this.onValueChanged(t)}"
                .maxLength="${c}"
                .minLength="${o}"
                .pattern="${y}"
                .validationMessage="${this.errors}"
                .step="${n}"
                .max="${d}"
                .min="${r}"
                .value="${v}"></or-mwc-input>`}onValueChanged(e){this.inputType===t.SELECT?Array.isArray(e.detail.value)?this.handleChange(this.path,e.detail.value.map(t=>JSON.parse(t))):this.handleChange(this.path,JSON.parse(e.detail.value)):this.handleChange(this.path,e.detail.value)}};ControlInputElement=__decorate([n("or-json-forms-input-control")],ControlInputElement);export{ControlInputElement};