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