let defaultTz;var __decorate=this&&this.__decorate||function(t,e,i,n){var r,a=arguments.length,s=a<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 o=t.length-1;o>=0;o--)(r=t[o])&&(s=(a<3?r(s):a>3?r(e,i,s):r(e,i))||s);return a>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 a}from"../styles";import{isBooleanControl as s,isEnumControl as o,isIntegerControl as l,isNumberControl as p,isOneOfEnumControl as h,isStringControl as m}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[a,style]}render(){var e;let n,r,a,d,c,f,y,T,g,E=this.uischema,O=this.schema,v=this.schema.format,C={rootSchema:this.rootSchema,config:this.config};this.inputType=t.TEXT;let S=!1,$=null!=(e=this.data)?e:O.default,w=t=>this.onValueChanged(t);return Array.isArray(O.type)?this.inputType=t.JSON:s(E,O,C)?(this.inputType=t.CHECKBOX,"boolean"!=typeof this.data&&(this.data=!!this.data,this.handleChange(this.path,this.data))):p(E,O,C)||l(E,O,C)?(n=p(E,O,C)?.1:1,this.inputType=t.NUMBER,r=O.minimum,d=O.maximum,n=O.multipleOf||n,void 0!==r&&void 0!==d&&"or-range"===v&&(d-r)/n<=200&&(this.inputType=t.RANGE)):o(E,O,C)||h(E,O,C)||u(E,O,C)?(this.inputType=t.SELECT,o(E,O,C)?y=O.enum.map(t=>[JSON.stringify(t),String(t)]):h(E,O,C)?y=O.oneOf.map(t=>[JSON.stringify(t.const),String(t.const)]):(S=!0,y=O.items.oneOf?O.items.oneOf.map(t=>[JSON.stringify(t.const),String(t.const)]):O.items.enum.map(t=>[JSON.stringify(t),String(t)])),$=S?Array.isArray($)?$.map(t=>JSON.stringify(t)):void 0!==$?[JSON.stringify($)]:void 0:void 0!==$?JSON.stringify($):void 0):m(E,O,C)&&(a=O.minLength,c=O.maxLength,f=O.pattern,"date-time"===v?this.inputType=t.DATETIME:"date"===v?this.inputType=t.DATE:"time"===v?this.inputType=t.TIME:"email"===v?this.inputType=t.EMAIL:"tel"===v?this.inputType=t.TELEPHONE:"or-multiline"===v?this.inputType=t.TEXTAREA:"or-password"===v||O.writeOnly?this.inputType=t.PASSWORD:"timezone"===v&&(this.inputType=t.SELECT,y=Intl.supportedValuesOf("timeZone").map(t=>[t,t]),defaultTz&&$||(defaultTz=Intl.DateTimeFormat().resolvedOptions().timeZone,this.handleChange(this.path,defaultTz)),T=!0,w=t=>this.handleChange(this.path,t.detail.value),g=t=>t?null==y?void 0:y.filter(([,e])=>e.toLowerCase().includes(t.toLowerCase())):null==y?void 0:y.filter(([,t])=>t.toLowerCase().includes((null!=$?$:defaultTz).toLowerCase().split("/")[0])))),i`<or-mwc-input
                .label="${this.label}"
                .type="${this.inputType}"
                .disabled="${!this.enabled}"
                .required="${!!this.required}"
                .id="${this.id}"
                .options="${y}"
                .multiple="${S}"
                ?searchable="${T}"
                .searchProvider="${g}"
                @or-mwc-input-changed="${w}"
                .maxLength="${c}"
                .minLength="${a}"
                .pattern="${f}"
                .validationMessage="${this.errors}"
                .step="${n}"
                .max="${d}"
                .min="${r}"
                .value="${$}"></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};