iobroker.admin 7.4.13 → 7.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -6
- package/adminWww/asset-manifest.json +23 -26
- package/adminWww/index.html +1 -1
- package/adminWww/static/js/{1809.3970d4d2.chunk.js → 1809.797e6d9a.chunk.js} +3 -3
- package/adminWww/static/js/1809.797e6d9a.chunk.js.map +1 -0
- package/adminWww/static/js/288.b83253b7.chunk.js +2 -0
- package/adminWww/static/js/288.b83253b7.chunk.js.map +1 -0
- package/adminWww/static/js/3849.c8d3a754.chunk.js +2 -0
- package/adminWww/static/js/3849.c8d3a754.chunk.js.map +1 -0
- package/adminWww/static/js/4289.3fbd195d.chunk.js +2 -0
- package/adminWww/static/js/4289.3fbd195d.chunk.js.map +1 -0
- package/adminWww/static/js/471.c7298807.chunk.js +2 -0
- package/adminWww/static/js/471.c7298807.chunk.js.map +1 -0
- package/adminWww/static/js/6603.eaf9efa3.chunk.js +3 -0
- package/adminWww/static/js/6603.eaf9efa3.chunk.js.map +1 -0
- package/adminWww/static/js/{6853.1d96bb1c.chunk.js → 6853.c817c98e.chunk.js} +2 -2
- package/adminWww/static/js/6853.c817c98e.chunk.js.map +1 -0
- package/adminWww/static/js/7424.38cdae41.chunk.js +2 -0
- package/adminWww/static/js/7424.38cdae41.chunk.js.map +1 -0
- package/adminWww/static/js/7435.0f078b05.chunk.js +2 -0
- package/adminWww/static/js/7435.0f078b05.chunk.js.map +1 -0
- package/adminWww/static/js/8222.68da8b63.chunk.js +2 -0
- package/adminWww/static/js/8222.68da8b63.chunk.js.map +1 -0
- package/adminWww/static/js/{main.6be9bde2.js → main.d3c54b8f.js} +2 -2
- package/adminWww/static/js/{main.6be9bde2.js.map → main.d3c54b8f.js.map} +1 -1
- package/io-package.json +15 -15
- package/package.json +4 -4
- package/adminWww/static/js/1809.3970d4d2.chunk.js.map +0 -1
- package/adminWww/static/js/288.492f41ab.chunk.js +0 -2
- package/adminWww/static/js/288.492f41ab.chunk.js.map +0 -1
- package/adminWww/static/js/3849.363dd3ca.chunk.js +0 -2
- package/adminWww/static/js/3849.363dd3ca.chunk.js.map +0 -1
- package/adminWww/static/js/4289.6ac6a4bc.chunk.js +0 -2
- package/adminWww/static/js/4289.6ac6a4bc.chunk.js.map +0 -1
- package/adminWww/static/js/471.8a82d825.chunk.js +0 -2
- package/adminWww/static/js/471.8a82d825.chunk.js.map +0 -1
- package/adminWww/static/js/6603.51b36d23.chunk.js +0 -3
- package/adminWww/static/js/6603.51b36d23.chunk.js.map +0 -1
- package/adminWww/static/js/6853.1d96bb1c.chunk.js.map +0 -1
- package/adminWww/static/js/6858.7b3f28b9.chunk.js +0 -2
- package/adminWww/static/js/6858.7b3f28b9.chunk.js.map +0 -1
- package/adminWww/static/js/7424.a53c0d15.chunk.js +0 -2
- package/adminWww/static/js/7424.a53c0d15.chunk.js.map +0 -1
- package/adminWww/static/js/8222.399b9b24.chunk.js +0 -2
- package/adminWww/static/js/8222.399b9b24.chunk.js.map +0 -1
- package/adminWww/static/media/thread.78489b630e6b27d860ae133d9ccca0a6.svg +0 -4
- package/adminWww/static/media/z-wave.09176b331d7b6b4b101cffaddf3e441a.svg +0 -3
- package/adminWww/static/media/zigbee.0e17b818ea0c78a95e189da4dac70a6e.svg +0 -4
- /package/adminWww/static/js/{1809.3970d4d2.chunk.js.LICENSE.txt → 1809.797e6d9a.chunk.js.LICENSE.txt} +0 -0
- /package/adminWww/static/js/{6603.51b36d23.chunk.js.LICENSE.txt → 6603.eaf9efa3.chunk.js.LICENSE.txt} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(self.webpackChunksrc_rx=self.webpackChunksrc_rx||[]).push([[6853],{9995:(t,e,s)=>{"use strict";s.r(e),s.d(e,{ConfigGeneric:()=>x,ConfigPanel:()=>Ve,JsonConfig:()=>Ke,JsonConfigComponent:()=>Re});var i=s(89379),o=s(29183),a=s.n(o),n=s(77226),r=s.n(n),l=s(83931),h=s.n(l),p=s(89303),c=s(32075),d=s(16904),u=s(79159);const m=window.innerWidth<=600?12:void 0;function g(t){return"[object Object]"===Object.prototype.toString.call(t)}class x extends o.Component{constructor(t){super(t),this.defaultValue=void 0,this.isError=void 0,this.lang=void 0,this.defaultSendToDone=void 0,this.sendToTimeout=void 0,this.noPlaceRequired=void 0,this.onUpdate=t=>{const e=x.getValue(t||this.props.data,this.props.attr)||"";this.state.value!==e?this.setState({value:e}):this.forceUpdate()},this.state={confirmDialog:!1,confirmNewValue:null,confirmAttr:null,confirmData:null,confirmCallback:null},this.isError={},t.schema&&(t.custom?this.defaultValue=t.schema.defaultFunc?this.executeCustom(t.schema.defaultFunc,t.data,t.customObj,t.oContext.instanceObj,t.arrayIndex,t.globalData):t.schema.default:"state"!==t.schema.type&&(this.defaultValue=t.schema.defaultFunc?this.execute(t.schema.defaultFunc,t.schema.default,t.data,t.arrayIndex,t.globalData):t.schema.default)),this.lang=d.I18n.getLanguage()}componentDidMount(){this.props.oContext.registerOnForceUpdate&&this.props.oContext.registerOnForceUpdate(this.props.attr,this.onUpdate);const t=["select","autocomplete","autocompleteSendTo"];if(void 0!==this.defaultValue){const e=x.getValue(this.props.data,this.props.attr);(void 0===e||t.includes(this.props.schema.type)&&(""===e||null===e))&&setTimeout((()=>{this.props.custom?this.props.onChange(this.props.attr,this.defaultValue,(()=>setTimeout((()=>this.props.oContext.forceUpdate([this.props.attr],this.props.data)),100))):(x.setValue(this.props.data,this.props.attr,this.defaultValue),this.props.onChange(this.props.data,void 0,(()=>this.props.oContext.forceUpdate([this.props.attr],this.props.data))))}),100)}else this.props.schema.defaultSendTo&&this.sendTo()}sendTo(){if(this.props.alive){this.defaultSendToDone=!0;let e=this.props.schema.data;if(void 0===e&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,null,!0);try{e=JSON.parse(s)}catch(t){console.error("Cannot parse json data: ".concat(s))}}else e={attr:this.props.attr,value:x.getValue(this.props.data,this.props.attr)};void 0===e&&(e=null),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.defaultSendTo,e).then((t=>{null!==t&&void 0!==t&&(this.props.custom?this.props.onChange(this.props.attr,t,(()=>this.props.oContext.forceUpdate([this.props.attr],this.props.data))):(x.setValue(this.props.data,this.props.attr,t),this.props.onChange(this.props.data,void 0,(()=>this.props.oContext.forceUpdate([this.props.attr],this.props.data)))))}))}else this.defaultSendToDone=!1,this.props.schema.allowSaveWithError||this.onError(this.props.attr,d.I18n.t("ra_Instance %s is not alive",this.props.oContext.instance.toString()))}componentWillUnmount(){this.props.oContext.registerOnForceUpdate&&this.props.oContext.registerOnForceUpdate(this.props.attr),this.sendToTimeout&&(clearTimeout(this.sendToTimeout),this.sendToTimeout=null)}static getValue(t,e){if("string"===typeof e)return x.getValue(t,e.split("."));if(1===e.length)return t[e[0]];const s=e.shift();return"string"===typeof s&&"object"===typeof t[s]?x.getValue(t[s],e):void 0}static setValue(t,e,s){if("string"!==typeof e)if(1===e.length)null===s?delete t[e[0]]:t[e[0]]=s;else{const i=e.shift();if("string"!==typeof i)return;t[i]&&"object"!==typeof t[i]||(t[i]=t[i]||{}),x.setValue(t[i],e,s)}else x.setValue(t,e.split("."),s)}getText(t,e){if(!t)return"";if("string"===typeof t){const s=e?t:d.I18n.t(t);return s.includes("${")?this.getPattern(s,null,e):s}return g(t)?t.func?"object"===typeof t.func?this.getPattern(t.func[this.lang]||t.func.en||"",null,!0):this.getPattern(t.func,null,e):t[this.lang]||t.en||"":t.toString()}renderDialogConfirm(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,u.jsx)(c.Warning,{}):"error"===t.type?e=(0,u.jsx)(c.Error,{}):"info"===t.type&&(e=(0,u.jsx)(c.Info,{})),(0,u.jsx)(d.DialogConfirm,{title:this.getText(t.title)||d.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||d.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||d.I18n.t("ra_Cancel"),icon:e||void 0,onClose:t=>this.setState({confirmDialog:!1},(()=>{if(t){if(this.state.confirmCallback){const t=this.state.confirmCallback;return void this.setState({confirmCallback:null},(()=>t(!0)))}const t=JSON.parse(JSON.stringify(this.props.data));this.state.confirmDepAttr&&x.setValue(t,this.state.confirmDepAttr,this.state.confirmDepNewValue),x.setValue(t,this.state.confirmAttr,this.state.confirmNewValue),this.setState({confirmDialog:!1,confirmDepAttr:null,confirmDepNewValue:null,confirmNewValue:null,confirmAttr:null,confirmData:null},(()=>this.props.onChange(t)))}else{const t=this.state.confirmCallback;this.setState({confirmDialog:!1,confirmDepAttr:null,confirmDepNewValue:null,confirmNewValue:null,confirmAttr:null,confirmData:null,confirmCallback:null},(()=>{t&&t(!1)}))}}))})}getIcon(t){let e=null;return"auth"===(t=t||this.props.schema.icon)?e=(0,u.jsx)(c.Key,{}):"send"===t?e=(0,u.jsx)(c.Send,{}):"web"===t?e=(0,u.jsx)(c.Public,{}):"warning"===t?e=(0,u.jsx)(c.Warning,{}):"error"===t?e=(0,u.jsx)(c.Error,{}):"info"===t?e=(0,u.jsx)(c.Info,{}):"search"===t?e=(0,u.jsx)(c.Search,{}):"book"===t?e=(0,u.jsx)(c.MenuBook,{}):"help"===t?e=(0,u.jsx)(c.Help,{}):"upload"===t?e=(0,u.jsx)(c.UploadFile,{}):"edit"===t?e=(0,u.jsx)(c.Edit,{}):"user"===t?e=(0,u.jsx)(c.Person,{}):"group"===t?e=(0,u.jsx)(c.Group,{}):"delete"===t?e=(0,u.jsx)(c.Delete,{}):"refresh"===t?e=(0,u.jsx)(c.Refresh,{}):"add"===t?e=(0,u.jsx)(c.Add,{}):"unpair"===t?e=(0,u.jsx)(c.LinkOff,{}):"pair"===t?e=(0,u.jsx)(c.Link,{}):"save"===t?e=(0,u.jsx)(c.Save,{}):"open"===t?e=(0,u.jsx)(c.OpenInNew,{}):t&&((t.endsWith(".png")||t.endsWith(".svg")||t.endsWith(".jpg"))&&(t.startsWith("http://")||t.startsWith("https://")||(t="./adapter/".concat(this.props.oContext.adapterName,"/").concat(t))),e=(0,u.jsx)(d.Icon,{src:t,style:{width:22,height:22}})),e}onChangeAsync(t,e){return new Promise((s=>{const i=this.onChange(t,e,s);i instanceof Promise&&i.catch((t=>console.error("Cannot set value: ".concat(t))))}))}onChange(t,e,s){const i=JSON.parse(JSON.stringify(this.props.data));if(x.setValue(i,t,e),this.props.schema.confirm&&this.execute(this.props.schema.confirm.condition,!1,i,this.props.arrayIndex,this.props.globalData))return new Promise((i=>{this.setState({confirmDialog:!0,confirmNewValue:e,confirmAttr:t,confirmData:null},(()=>{"function"===typeof s?s():i()}))}));if(this.props.schema.confirmDependsOn)for(let a=0;a<this.props.schema.confirmDependsOn.length;a++){const o=this.props.schema.confirmDependsOn[a];if(o.confirm){const a=x.getValue(i,o.attr);if(this.execute(o.confirm.condition,!1,i,this.props.arrayIndex,this.props.globalData))return new Promise((i=>{this.setState({confirmDialog:!0,confirmNewValue:e,confirmAttr:t,confirmDepNewValue:a,confirmDepAttr:o.attr,confirmData:o.confirm},(()=>{"function"===typeof s?s():i()}))}))}}const o=[];if(this.props.schema.onChangeDependsOn)for(let a=0;a<this.props.schema.onChangeDependsOn.length;a++){const t=this.props.schema.onChangeDependsOn[a];if(t.onChange){const e=x.getValue(i,t.attr);let s;s=this.props.custom?this.executeCustom(t.onChange.calculateFunc,i,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):this.execute(t.onChange.calculateFunc,e,i,this.props.arrayIndex,this.props.globalData),s!==e&&(x.setValue(i,t.attr,s),o.push(t.attr))}}if(this.props.schema.hiddenDependsOn)for(let a=0;a<this.props.schema.hiddenDependsOn.length;a++){const t=this.props.schema.hiddenDependsOn[a];t.hidden&&o.push(t.attr)}if(this.props.schema.labelDependsOn)for(let a=0;a<this.props.schema.labelDependsOn.length;a++){const t=this.props.schema.labelDependsOn[a];t.hidden&&o.push(t.attr)}if(this.props.schema.helpDependsOn)for(let a=0;a<this.props.schema.helpDependsOn.length;a++){const t=this.props.schema.helpDependsOn[a];t.hidden&&o.push(t.attr)}if(this.props.schema.onChange&&!this.props.schema.onChange.ignoreOwnChanges){const t=x.getValue(i,this.props.attr),e=this.props.custom?this.executeCustom(this.props.schema.onChange.calculateFunc,i,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):this.execute(this.props.schema.onChange.calculateFunc,t,i,this.props.arrayIndex,this.props.globalData);e!==t&&x.setValue(i,this.props.attr,e)}return this.props.custom?(this.props.onChange(t,e,(()=>s&&s())),null!==o&&void 0!==o&&o.length&&o.forEach(((t,e)=>setTimeout((()=>this.props.onChange(t,x.getValue(i,t))),50*e)))):this.props.onChange(i,void 0,(()=>{o.length&&this.props.oContext.forceUpdate(o,i),s&&s()})),Promise.resolve()}execute(t,e,s,i,o){let a;if(g(t))a=t.func;else{if("string"!==typeof t)return t;a=t}if(!a)return e;try{return new Function("data","originalData","_system","_alive","_common","_socket","_instance","arrayIndex","globalData","_changed",a.includes("return")?a:"return ".concat(a))(s||this.props.data,this.props.originalData,this.props.oContext.systemConfig,this.props.alive,this.props.common,this.props.oContext.socket,this.props.oContext.instance,i,o,this.props.changed)}catch(n){return console.error("Cannot execute ".concat(JSON.stringify(t),": ").concat(n)),e}}executeCustom(t,e,s,i,o,a){let n;if(g(t))n=t.func;else{if("string"!==typeof t)return t;n=t}if(!n)return null;try{return new Function("data","originalData","_system","instanceObj","customObj","_socket","arrayIndex","globalData","_changed",n.includes("return")?n:"return ".concat(n))(e||this.props.data,this.props.originalData,this.props.oContext.systemConfig,i,s,this.props.oContext.socket,o,a,this.props.changed)}catch(r){return console.error("Cannot execute ".concat(n,": ").concat(r)),null}}calculate(t){let e,s,i,o;return this.props.custom?(e=!!t.validator&&!this.executeCustom(t.validator,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData),s=!0===t.disabled||!!t.disabled&&this.executeCustom(t.disabled,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData),i=!0===t.hidden||!!t.hidden&&this.executeCustom(t.hidden,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData),o=t.defaultFunc?this.executeCustom(t.defaultFunc,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):t.default):(e=!!t.validator&&!this.execute(t.validator,!1,this.props.data,this.props.arrayIndex,this.props.globalData),s=!0===t.disabled||!!t.disabled&&this.execute(t.disabled,!1,this.props.data,this.props.arrayIndex,this.props.globalData),i=!0===t.hidden||!!t.hidden&&this.execute(t.hidden,!1,this.props.data,this.props.arrayIndex,this.props.globalData),o=t.defaultFunc?this.execute(t.defaultFunc,t.default,this.props.data,this.props.arrayIndex,this.props.globalData):t.default),{error:e,disabled:s,hidden:i,defaultValue:o}}onError(t,e){e?this.isError[t]=e:delete this.isError[t],this.props.onError&&this.props.onError(t,e)}renderItem(t,e,s){return this.getText(this.props.schema.label)||this.getText(this.props.schema.text)}renderHelp(t,e,s){return e?(0,u.jsx)("a",{href:e,target:"_blank",rel:"noreferrer",style:{color:"dark"===this.props.oContext.themeType?"#a147ff":"#5b238f",textDecoration:"underline"},children:this.getText(t,s)}):(t=this.getText(t,s)||"")&&(t.includes("<a ")||t.includes("<br")||t.includes("<b>")||t.includes("<i>"))?d.Utils.renderTextWithA(t):t}static escapeString(t,e){return"string"!==typeof t?"":t=(t=t.replace(/`/g,"\\`")).replace(/\${([^}]+)}/g,((t,s)=>{if(s&&"string"===typeof s&&s.startsWith("data.")){const t=x.getValue(e,s.replace(/^data\./,""));if("string"===typeof t&&t.includes('"'))return"${".concat(s,".replace(/\"/g, '\\\\\"')}")}return t}))}getPattern(t,e,s){if(e=e||this.props.data,!t)return"";let i;"object"===typeof t?t.func?i=t.func:(console.log("Object must be stringified: ".concat(JSON.stringify(t))),i=JSON.stringify(t)):i=t;try{if(this.props.custom){return new Function("data","originalData","arrayIndex","globalData","_system","instanceObj","customObj","_socket","_changed","return `".concat(x.escapeString(i,e),"`"))(e,this.props.originalData,this.props.arrayIndex,this.props.globalData,this.props.oContext.systemConfig,this.props.oContext.instanceObj,this.props.customObj,this.props.oContext.socket,this.props.changed)}const t=new Function("data","originalData","arrayIndex","globalData","_system","_alive","_common","_socket","_changed","return `".concat(x.escapeString(i,e),"`"))(e,this.props.originalData,this.props.arrayIndex,this.props.globalData,this.props.oContext.systemConfig,this.props.alive,this.props.common,this.props.oContext.socket,this.props.changed);return s?t:d.I18n.t(t)}catch(o){return console.error("Cannot execute ".concat(i,": ").concat(o)),i}}render(){const t=this.props.schema;if(!t)return null;if(!1===this.props.oContext.expertMode&&t.expertMode)return null;this.props.alive&&!1===this.defaultSendToDone&&(this.sendToTimeout=setTimeout((()=>{this.sendToTimeout=null,this.sendTo()}),200));const{error:e,disabled:s,hidden:o,defaultValue:a}=this.calculate(t);if(o){if(Object.keys(this.isError).length&&(setTimeout((t=>Object.keys(t).forEach((t=>this.props.onError(t)))),100,JSON.parse(JSON.stringify(this.isError))),this.isError={}),t.hideOnlyControl){const e=(0,u.jsx)(p.Grid2,{size:{xs:t.xs||m,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},style:(0,i.A)((0,i.A)({marginBottom:0,textAlign:"left"},t.style),"dark"===this.props.oContext.themeType?t.darkStyle:{})});return t.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return null}t.validatorNoSaveOnError&&(e&&!Object.keys(this.isError).length?(this.isError={[this.props.attr]:!t.validatorErrorText||d.I18n.t(t.validatorErrorText)},setTimeout((t=>Object.keys(t).forEach((e=>this.props.onError(e,t[e])))),100,JSON.parse(JSON.stringify(this.isError)))):!e&&Object.keys(this.isError).length&&(setTimeout((t=>Object.keys(t).forEach((t=>this.props.onError(t)))),100,JSON.parse(JSON.stringify(this.isError))),this.isError={}));const n=this.renderItem(e,s||this.props.commandRunning||this.props.disabled,a);if(this.noPlaceRequired)return n;const r=(0,u.jsx)(p.Grid2,{title:this.getText(t.tooltip),size:{xs:t.xs||12,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},style:(0,i.A)((0,i.A)({marginBottom:0,textAlign:"left",width:"divider"===t.type||"header"===t.type?t.width||"100%":void 0},t.style),"dark"===this.props.oContext.themeType?t.darkStyle:{}),children:this.props.schema.defaultSendTo&&this.props.schema.button?(0,u.jsxs)(p.Grid2,{container:!0,style:{width:"100%"},children:[(0,u.jsx)(p.Grid2,{flex:1,children:n}),(0,u.jsx)(p.Grid2,{children:(0,u.jsx)(p.Button,{disabled:s,variant:"outlined",onClick:()=>this.sendTo(),title:this.props.schema.buttonTooltip?this.getText(this.props.schema.buttonTooltip,this.props.schema.buttonTooltipNoTranslation):d.I18n.t("ra_Request data by instance"),children:this.getText(this.props.schema.button)})})]}):n});return t.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),this.renderDialogConfirm(),r]}):this.state.confirmDialog?(0,u.jsxs)(u.Fragment,{children:[this.renderDialogConfirm(),r]}):r}}x.DIFFERENT_VALUE="__different__",x.DIFFERENT_LABEL="ra___different__",x.NONE_VALUE="",x.NONE_LABEL="ra_none";const v={fullWidth:{width:"100%"},accordionSummary:t=>({backgroundColor:"dark"===t.palette.mode?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.08)"}),accordionTitle:{},toolbar:t=>({backgroundColor:"dark"===t.palette.mode?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.08)",borderRadius:"3px"}),tooltip:{pointerEvents:"none"}};const f=class extends x{constructor(t){super(t),this.typingTimer=null,this.onDelete=t=>()=>{const e=JSON.parse(JSON.stringify(this.state.value));e.splice(t,1),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.onChangeWrapper(e)))},this.onClone=t=>()=>{const e=JSON.parse(JSON.stringify(this.state.value)),s=JSON.parse(JSON.stringify(e[t]));if("string"===typeof this.props.schema.clone&&"string"===typeof s[this.props.schema.clone]){let t=1,i=s[this.props.schema.clone];const o=i.match(/(\d+)$/);for(o?(i=i.replace(o[0],""),t=parseInt(o[0],10)+1):i+="_";e.find((e=>e[this.props.schema.clone]===i+t.toString()));)t++;s[this.props.schema.clone]="".concat(s[this.props.schema.clone],"_").concat(t)}e.splice(t,0,s),this.setState({value:e,activeIndex:-1,iteration:this.state.iteration+1e4},(()=>this.onChangeWrapper(e)))},this.onChangeWrapper=t=>{this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout((t=>{this.typingTimer=null;const e=this.onChange(this.props.attr,t);e instanceof Promise&&e.catch((t=>this.onError(t)))}),300,t)},this.onAdd=()=>{const{schema:t}=this.props,e=JSON.parse(JSON.stringify(this.state.value)),s=t.items&&t.items.reduce(((t,s)=>{let i;return i=s.defaultFunc?this.props.custom?s.defaultFunc?this.executeCustom(s.defaultFunc,this.props.data,this.props.customObj,this.props.oContext.instanceObj,e.length,this.props.data):this.props.schema.default:s.defaultFunc?this.execute(s.defaultFunc,this.props.schema.default,this.props.data,e.length,this.props.data):this.props.schema.default:void 0===s.default?null:s.default,t[s.attr]=i,t}),{});e.push(s),this.setState({value:e,activeIndex:e.length-1},(()=>this.onChangeWrapper(e)))},this.props.schema.items=this.props.schema.items||[]}componentDidMount(){super.componentDidMount();let t=x.getValue(this.props.data,this.props.attr)||[];Array.isArray(t)||(t=[]),this.setState({value:t,activeIndex:-1,iteration:0})}componentWillUnmount(){this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),super.componentWillUnmount()}itemAccordion(t,e){const{value:s}=this.state,{schema:i}=this.props,o={type:"panel",items:i.items.reduce(((t,e)=>(t[e.attr]=e,t)),{}),style:{marginLeft:"-8px",marginTop:"10px",marginBottom:"10px"}};return(0,u.jsx)(Ve,{oContext:this.props.oContext,index:e+this.state.iteration,arrayIndex:e,changed:this.props.changed,globalData:this.props.data,common:this.props.common,alive:this.props.alive,themeName:this.props.themeName,data:t,custom:!0,schema:o,originalData:this.props.originalData,onChange:(t,i)=>{const o=JSON.parse(JSON.stringify(s));o[e][t]=i,this.setState({value:o},(()=>this.onChangeWrapper(o)))},onError:(t,e)=>this.onError(t,e),table:this.props.table})}onMoveUp(t){const e=JSON.parse(JSON.stringify(this.state.value)),s=e[t];e.splice(t,1),e.splice(t-1,0,s);const i=this.state.activeIndex-1;this.setState({value:e,activeIndex:i,iteration:this.state.iteration+1e4},(()=>this.onChangeWrapper(e)))}onMoveDown(t){const e=JSON.parse(JSON.stringify(this.state.value)),s=e[t];e.splice(t,1),e.splice(t+1,0,s);const i=this.state.activeIndex+1;this.setState({value:e,activeIndex:i,iteration:this.state.iteration+1e4},(()=>this.onChangeWrapper(e)))}renderItem(){const{schema:t}=this.props,{value:e}=this.state;return e?(0,u.jsxs)(p.Paper,{children:[t.label||!t.noDelete?(0,u.jsxs)(p.Toolbar,{variant:"dense",children:[t.label?(0,u.jsx)(p.Typography,{variant:"h6",id:"tableTitle",component:"div",children:this.getText(t.label)}):null,t.noDelete?null:(0,u.jsx)(p.IconButton,{size:"small",color:"primary",onClick:this.onAdd,children:(0,u.jsx)(c.Add,{})})]}):null,e.map(((s,o)=>(0,u.jsxs)(p.Accordion,{expanded:this.state.activeIndex===o,onChange:(t,e)=>this.setState({activeIndex:e?o:-1}),children:[(0,u.jsx)(p.AccordionSummary,{expandIcon:(0,u.jsx)(c.ExpandMore,{}),sx:d.Utils.getStyle(this.props.oContext.theme,v.fullWidth,v.accordionSummary),children:(0,u.jsx)(p.Typography,{style:v.accordionTitle,children:s[t.titleAttr]})}),(0,u.jsxs)(p.AccordionDetails,{style:(0,i.A)((0,i.A)({},t.style),this.props.oContext.themeType?t.darkStyle:void 0),children:[this.itemAccordion(e[o],o),(0,u.jsxs)(p.Toolbar,{sx:v.toolbar,children:[o?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move up"),slotProps:{popper:{sx:v.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveUp(o),children:(0,u.jsx)(c.ArrowUpward,{})})}):(0,u.jsx)("div",{style:v.buttonEmpty}),o<e.length-1?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move down"),slotProps:{popper:{sx:v.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveDown(o),children:(0,u.jsx)(c.ArrowDownward,{})})}):(0,u.jsx)("div",{style:v.buttonEmpty}),t.noDelete?null:(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Delete current row"),slotProps:{popper:{sx:v.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onDelete(o),children:(0,u.jsx)(c.Delete,{})})}),t.clone?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Clone current row"),slotProps:{popper:{sx:v.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onClone(o),children:(0,u.jsx)(c.ContentCopy,{})})}):null]})]})]},"".concat(s,"_").concat(o)))),!t.noDelete&&e.length>0?(0,u.jsx)(p.Toolbar,{variant:"dense",sx:v.rootTool,children:(0,u.jsx)(p.IconButton,{size:"small",color:"primary",onClick:this.onAdd,children:(0,u.jsx)(c.Add,{})})}):null,t.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]}):null}},y={root:{width:"100%"},notAlive:{color:"#a30000"}};const b=class extends x{componentDidMount(){super.componentDidMount();const t=this.getInstance();this.props.oContext.socket.getState("".concat(t,".alive")).then((e=>this.setState({alive:!(!e||!e.val),instance:t})))}getInstance(){let t=this.props.schema.instance||"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance);return t.includes("${")&&(t=this.getPattern(t,null,!0)),t&&!t.startsWith("system.adapter.")&&(t="system.adapter.".concat(t)),t}renderItem(){if(this.getInstance()!==this.state.instance&&setTimeout((()=>{const t=this.getInstance();t?this.props.oContext.socket.getState("".concat(t,".alive")).then((e=>this.setState({alive:!(!e||!e.val),instance:t}))):this.setState({alive:null,instance:t})}),200),!1!==this.state.alive&&!0!==this.state.alive)return null;const t=this.state.instance.replace(/^system.adapter./,"");return(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},y.root),this.state.alive?void 0:y.notAlive),children:this.state.alive?void 0!==this.props.schema.textAlive?this.props.schema.textAlive?d.I18n.t(this.props.schema.textAlive,t):"":d.I18n.t("ra_Instance %s is alive",t):void 0!==this.props.schema.textNotAlive?this.props.schema.textNotAlive?d.I18n.t(this.props.schema.textNotAlive,t):"":d.I18n.t("ra_Instance %s is not alive",t)})}};const C=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr),e=this.props.schema.options.map((t=>"string"===typeof t?{label:t,value:t}:JSON.parse(JSON.stringify(t))));Array.isArray(t)?(e.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),this.setState({value:x.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}renderItem(t,e){if(!this.state.selectOptions)return null;let s;const o=JSON.parse(JSON.stringify(this.state.selectOptions));return Array.isArray(this.state.value)||this.state.value===x.DIFFERENT_VALUE?([...this.state.value].filter((t=>!o.find((e=>"object"===typeof e?e.value===t:e===t)))).forEach((t=>o.push({label:t.toString(),value:t}))),s={label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE},o.unshift(s)):(s=null!==this.state.value&&void 0!==this.state.value&&o.find((t=>"object"===typeof t?t.value==this.state.value:t==this.state.value)),null!==this.state.value&&void 0!==this.state.value&&!s&&this.props.schema.freeSolo&&(s={value:this.state.value,label:this.state.value},o.push(s))),(0,u.jsx)(p.Autocomplete,{fullWidth:!0,freeSolo:!!this.props.schema.freeSolo,value:s,options:o,isOptionEqualToValue:(t,e)=>t.value===e.value,filterOptions:(t,e)=>{const s=t.filter((t=>""===e.inputValue||(t.label.toLowerCase().includes(e.inputValue.toLowerCase())||t.value.toLowerCase().includes(e.inputValue.toLowerCase()))));return this.props.schema.freeSolo&&""!==e.inputValue&&s.push({label:e.inputValue,value:e.inputValue}),s},onInputChange:t=>{if(!t||!this.props.schema.freeSolo)return;const e=t.target.value;e!==this.state.value&&this.setState({value:e},(()=>this.onChange(this.props.attr,e)))},onChange:(t,e)=>{const s="object"===typeof e?e?e.value:"":e;s!==this.state.value&&this.setState({value:s},(()=>this.onChange(this.props.attr,s)))},getOptionLabel:t=>{var e;return"object"===typeof t&&null!==(e=null===t||void 0===t?void 0:t.label)&&void 0!==e?e:""},renderInput:s=>(0,u.jsx)(p.TextField,(0,i.A)((0,i.A)({variant:"standard"},s),{},{error:!!t,placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),disabled:e}))})}};const j=class extends x{constructor(){super(...arguments),this.initialized=!1,this.localContext=void 0}askInstance(){const t=x.getValue(this.props.data,this.props.attr),e=this.props.schema.options?this.props.schema.options.map((t=>"string"===typeof t?{label:t,value:t}:JSON.parse(JSON.stringify(t)))):[];if(this.props.alive){let i=this.props.schema.data;if(void 0===i&&this.props.schema.jsonData){const t=this.getPattern(this.props.schema.jsonData,null,!0);try{"string"===typeof t&&(i=JSON.parse(t))}catch(s){console.error("Cannot parse json data: ".concat(JSON.stringify(i)))}}void 0===i&&(i=null),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",i).then((s=>{s&&Array.isArray(s)&&s.forEach((t=>e.push("string"===typeof t?{label:t,value:t}:JSON.parse(JSON.stringify(t))))),Array.isArray(t)?(e.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),this.setState({value:x.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}))}else Array.isArray(t)?(e.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),this.setState({value:x.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}getContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=x.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(t,e){if(this.props.alive){const t=this.getContext();t===this.localContext&&this.initialized||(this.localContext=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}let s;const o=this.state.selectOptions?JSON.parse(JSON.stringify(this.state.selectOptions)):[];return Array.isArray(this.state.value)||this.state.value===x.DIFFERENT_LABEL?([...this.state.value].filter((t=>!o.find((e=>e.value===t)))).forEach((t=>o.push({label:t.toString(),value:t}))),s={label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE},o.unshift(s)):(s=null!==this.state.value&&void 0!==this.state.value&&o.find((t=>t.value==this.state.value)),null!==this.state.value&&void 0!==this.state.value&&!s&&this.props.schema.freeSolo&&(s={value:this.state.value,label:this.state.value},o.push(s)),s=s||null),o.length?(0,u.jsx)(p.Autocomplete,{value:s,fullWidth:!0,freeSolo:!!this.props.schema.freeSolo,options:o,isOptionEqualToValue:(t,e)=>t.value===e.value,filterOptions:(t,e)=>{const s=t.filter((t=>""===e.inputValue||(t.label.toLowerCase().includes(e.inputValue.toLowerCase())||t.value.toLowerCase().includes(e.inputValue.toLowerCase()))));return this.props.schema.freeSolo&&""!==e.inputValue&&s.push({label:e.inputValue,value:e.inputValue}),s},getOptionLabel:t=>{var e;return null!==(e=null===t||void 0===t?void 0:t.label)&&void 0!==e?e:""},onInputChange:t=>{if(!t||!this.props.schema.freeSolo)return;const e=t.target.value;e!==this.state.value&&this.setState({value:e},(()=>this.onChange(this.props.attr,e)))},onChange:(t,e)=>{const s="object"===typeof e?e?e.value:"":e;s!==this.state.value&&this.setState({value:s},(()=>this.onChange(this.props.attr,s)))},renderInput:s=>(0,u.jsx)(p.TextField,(0,i.A)((0,i.A)({variant:"standard"},s),{},{error:!!t,placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),disabled:e}))}):(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:null===this.state.value||void 0===this.state.value?"":this.state.value,error:!!t,disabled:e,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0}},onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,(e||"").trim())))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},w={fullWidth:{width:"100%"},flex:{display:"flex"},button:{height:48,marginLeft:4,minWidth:48}};const I=class extends x{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=x.getValue(t,e)||"";this.setState({value:s,showDialog:!1})}renderItem(t,e){const{schema:s,attr:i}=this.props,{value:o,showDialog:a}=this.state;return(0,u.jsxs)(p.FormControl,{style:w.fullWidth,variant:"standard",children:[s.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(s.label)}):null,(0,u.jsxs)("div",{style:w.flex,children:[(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:null!==o&&void 0!==o?o:"",error:!!t,disabled:e,placeholder:this.getText(s.placeholder),label:this.getText(s.label),helperText:this.renderHelp(s.help,s.helpLink,s.noTranslation),onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(i,e)))}}),(0,u.jsx)(p.Button,{color:"grey",disabled:e,style:w.button,size:"small",variant:"outlined",onClick:()=>this.setState({showDialog:!0}),children:"..."})]}),a?(0,u.jsx)(d.DialogCron,{title:d.I18n.t("ra_Define schedule"),simple:s.simple,complex:s.complex,cron:o,onClose:()=>this.setState({showDialog:!1}),cancel:d.I18n.t("ra_Cancel"),ok:d.I18n.t("ra_Ok"),theme:this.props.oContext.theme,onOk:t=>this.setState({showDialog:!1,value:t},(()=>this.onChange(i,t)))}):null]})}};const T=class extends x{async componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr),e=(await this.props.oContext.socket.getCertificates()).filter((t=>{const e=this.props.attr.toLowerCase();return!!e.includes(t.type)||(!("public"!==t.type||!e.includes("cert"))||(!("private"!==t.type||!e.includes("priv")&&!e.includes("key"))||!("chained"!==t.type||!e.includes("chain")&&!e.includes("ca"))))})).map((t=>({label:t.name,value:t.name})));e.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.setState({value:t,selectOptions:e})}renderItem(t,e){var s,i;if(!this.state.selectOptions)return null;const o=null===(s=this.state.selectOptions)||void 0===s?void 0:s.find((t=>t.value===this.state.value));return(0,u.jsxs)(p.FormControl,{style:{width:"100%"},variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:this.state.value,renderValue:()=>this.getText(null===o||void 0===o?void 0:o.label,!1!==this.props.schema.noTranslation),onChange:t=>this.setState({value:t.target.value},(()=>this.onChange(this.props.attr,this.state.value))),children:null===(i=this.state.selectOptions)||void 0===i?void 0:i.map((t=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label,!1!==this.props.schema.noTranslation)},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},S={fullWidth:{width:"100%"},leWidth:{width:620,marginBottom:10},certWidth:{width:200,marginRight:10}};const D=class extends x{async componentDidMount(){var t;super.componentDidMount();const e=await this.props.oContext.socket.getCertificates(),s=[],i=[],o=[];let a=[];const n=await this.props.oContext.socket.getObject("system.certificates");a=null!==n&&void 0!==n&&null!==(t=n.native)&&void 0!==t&&t.collections?Object.keys(n.native.collections):null,e.forEach((t=>{"public"===t.type?s.push({label:t.name,value:t.name}):"private"===t.type?i.push({label:t.name,value:t.name}):("chained"===t.type||(s.push({label:t.name,value:t.name}),i.push({label:t.name,value:t.name})),o.push({label:t.name,value:t.name}))})),s.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),i.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),o.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.setState({certsPublicOptions:s,certsChainOptions:o,certsPrivateOptions:i,collectionsOptions:a})}renderItem(t,e){var s,i,o,a,n,r,l;if(!this.state.certsPublicOptions||!this.state.certsPrivateOptions||!this.state.certsChainOptions)return null;const h=(x.getValue(this.props.data,this.props.schema.leCollectionName||"leCollection")||"false").toString(),c=x.getValue(this.props.data,this.props.schema.certPublicName||"certPublic"),m=x.getValue(this.props.data,this.props.schema.certPrivateName||"certPrivate"),g=x.getValue(this.props.data,this.props.schema.certChainedName||"certChained"),v=null===(s=this.state.certsPublicOptions)||void 0===s?void 0:s.find((t=>t.value===c)),f=null===(i=this.state.certsPrivateOptions)||void 0===i?void 0:i.find((t=>t.value===m)),y=null===(o=this.state.certsChainOptions)||void 0===o?void 0:o.find((t=>t.value===g));return(0,u.jsxs)("div",{style:S.fullWidth,children:[this.state.collectionsOptions?(0,u.jsxs)(p.FormControl,{style:S.leWidth,variant:"standard",children:[(0,u.jsx)(p.InputLabel,{shrink:!0,children:"Let's encrypt"}),(0,u.jsxs)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:h,onChange:t=>this.onChange(this.props.schema.leCollectionName||"leCollection","false"!==t.target.value&&("true"===t.target.value||t.target.value)),children:[(0,u.jsx)(p.MenuItem,{value:"false",style:{fontWeight:"bold"},children:d.I18n.t("ra_Do not use let's encrypt")},"_false"),(0,u.jsx)(p.MenuItem,{value:"true",style:{fontWeight:"bold"},children:d.I18n.t("ra_Use all available let's encrypt certificates")},"_true"),null===(a=this.state.collectionsOptions)||void 0===a?void 0:a.map((t=>(0,u.jsx)(p.MenuItem,{value:t,children:t},t)))]})]}):null,this.state.collectionsOptions?(0,u.jsx)("br",{}):null,this.state.collectionsOptions&&"false"!==h?(0,u.jsx)("div",{children:d.I18n.t("ra_Fallback custom certificates")}):null,(0,u.jsxs)(p.FormControl,{style:S.certWidth,variant:"standard",children:[(0,u.jsx)(p.InputLabel,{shrink:!0,children:d.I18n.t("ra_Public certificate")}),(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:c||"",renderValue:()=>this.getText(null===v||void 0===v?void 0:v.label),onChange:t=>this.onChange(this.props.schema.certPublicName||"certPublic",t.target.value),children:null===(n=this.state.certsPublicOptions)||void 0===n?void 0:n.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},"".concat(t.value,"_").concat(e))))})]}),(0,u.jsxs)(p.FormControl,{style:S.certWidth,variant:"standard",children:[(0,u.jsx)(p.InputLabel,{shrink:!0,children:d.I18n.t("ra_Private certificate")}),(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:m||"",renderValue:()=>this.getText(null===f||void 0===f?void 0:f.label),onChange:t=>this.onChange(this.props.schema.certPrivateName||"certPrivate",t.target.value),children:null===(r=this.state.certsPrivateOptions)||void 0===r?void 0:r.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},"".concat(t.value,"_").concat(e))))})]}),(0,u.jsxs)(p.FormControl,{style:S.certWidth,variant:"standard",children:[(0,u.jsx)(p.InputLabel,{shrink:!0,children:d.I18n.t("ra_Chained certificate")}),(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:g||"",renderValue:()=>this.getText(null===y||void 0===y?void 0:y.label),onChange:t=>this.onChange(this.props.schema.certChainedName||"certChained",t.target.value),children:null===(l=this.state.certsChainOptions)||void 0===l?void 0:l.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},"".concat(t.value,"_").concat(e))))})]})]})}};const k=class extends x{async componentDidMount(){var t;let e;super.componentDidMount();const s=await this.props.oContext.socket.getObject("system.certificates");e=null!==s&&void 0!==s&&null!==(t=s.native)&&void 0!==t&&t.collections?Object.keys(s.native.collections):[],this.setState({collectionsOptions:e})}renderItem(t,e){var s;if(!this.state.collectionsOptions)return null;const i=(x.getValue(this.props.data,this.props.schema.leCollectionName||"leCollection")||"false").toString();return(0,u.jsxs)(p.FormControl,{style:{width:"100%"},variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsxs)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:i,onChange:t=>this.onChange(this.props.schema.leCollectionName||"leCollection","false"!==t.target.value&&("true"===t.target.value||t.target.value)),children:[(0,u.jsx)(p.MenuItem,{value:"false",style:{fontWeight:"bold"},children:d.I18n.t("ra_Do not use let's encrypt")},"_false"),(0,u.jsx)(p.MenuItem,{value:"true",style:{fontWeight:"bold"},children:d.I18n.t("ra_Use all available let's encrypt certificates")},"_true"),null===(s=this.state.collectionsOptions)||void 0===s?void 0:s.map((t=>(0,u.jsx)(p.MenuItem,{value:t,children:t},t)))]}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},O={fullWidth:{width:"100%"},icon:{width:24,height:24,marginRight:4},licLabel:{fontWeight:"bold",minWidth:100,marginRight:10,textTransform:"capitalize",display:"inline-block"},licValue:{fontWeight:"normal"},errorTitle:t=>({color:"dark"===t.palette.mode?"#e39191":"#b62020"}),okTitle:t=>({color:"dark"===t.palette.mode?"#6fd56f":"#007c00"}),errorText:t=>({color:"dark"===t.palette.mode?"#e39191":"#b62020",mb:"30px"})};class _ extends x{componentDidMount(){super.componentDidMount(),this.setState({_error:"",running:!1,showLicenseData:null,foundSuitableLicense:!1,licenseOfflineCheck:!1,result:null,allLicenses:null,askForUpdate:!1,showLinkToProfile:!1})}renderErrorDialog(){if(this.state._error&&!this.state.showLicenseData){let t=this.state._error;return this.state.allLicenses&&(t=[(0,u.jsx)("div",{children:t},"error")],t.push((0,u.jsx)(p.Button,{variant:"contained",onClick:()=>window.open("https://iobroker.net/www/account/licenses","_blank"),children:d.I18n.t("iobroker.net")},"button")),this.state.allLicenses.length?t.push((0,u.jsx)(p.TableContainer,{children:(0,u.jsxs)(p.Table,{size:"small",children:[(0,u.jsx)(p.TableHead,{children:(0,u.jsxs)(p.TableRow,{children:[(0,u.jsx)(p.TableCell,{children:d.I18n.t("ra_Product")}),(0,u.jsx)(p.TableCell,{children:d.I18n.t("ra_Version")}),(0,u.jsx)(p.TableCell,{children:"UUID"}),(0,u.jsx)(p.TableCell,{children:d.I18n.t("ra_ValidTill")}),(0,u.jsx)(p.TableCell,{children:d.I18n.t("ra_Commercial")}),(0,u.jsx)(p.TableCell,{children:"ID"})]})}),(0,u.jsx)(p.TableBody,{children:this.state.allLicenses.map((t=>(0,u.jsxs)(p.TableRow,{children:[(0,u.jsx)(p.TableCell,{sx:t.validName?null:O.errorText,children:t.license.product}),(0,u.jsx)(p.TableCell,{sx:t.validVersion?null:O.errorText,children:t.license.version}),(0,u.jsx)(p.TableCell,{sx:t.validUuid?null:O.errorText,children:t.license.uuid||"--"}),(0,u.jsx)(p.TableCell,{sx:t.validTill?null:O.errorText,children:t.license.validTill&&"0000-00-00 00:00:00"!==t.license.validTill?new Date(t.license.validTill).toLocaleDateString():"--"}),(0,u.jsx)(p.TableCell,{children:"free"!==t.license.invoice?"MANUALLY_CREATED"===t.license.invoice?"\u2713":t.license.invoice:"-"}),(0,u.jsx)(p.TableCell,{children:t.id})]},t.id)))})]})},"table")):(t.push((0,u.jsx)("div",{children:d.I18n.t("ra_No one license found in license manager")},"text1")),t.push((0,u.jsx)("div",{children:d.I18n.t("ra_Please create license")},"text2")))),(0,u.jsxs)(p.Dialog,{open:!0,maxWidth:"xl",fullWidth:void 0===this.props.fullWidth||this.props.fullWidth,onClick:()=>this.setState({_error:"",allLicenses:null}),children:[(0,u.jsx)(p.DialogTitle,{children:d.I18n.t("ra_Error")}),(0,u.jsx)(p.DialogContent,{children:(0,u.jsx)(p.DialogContentText,{children:t})}),(0,u.jsx)(p.DialogActions,{children:(0,u.jsx)(p.Button,{variant:"contained",onClick:()=>this.setState({_error:"",allLicenses:null}),color:"primary",autoFocus:!0,startIcon:(0,u.jsx)(c.Check,{}),children:d.I18n.t("ra_Ok")})})]})}return null}renderMessageDialog(){if(this.state.showLicenseData){const t=[],e=this.state.showLicenseData;return Object.keys(e).forEach((s=>{if(null!==e[s]&&void 0!==e[s])if("object"===typeof e[s]){const i=e[s];Object.keys(i).forEach((e=>{null!==i[e]&&void 0!==i[e]&&("object"===typeof i[e]?t.push((0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{style:O.licLabel,children:[e,":"]}),JSON.stringify(i[e],null,2)]},e)):t.push((0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{style:O.licLabel,children:[s," -",e,":"]}),i[e].toString()]},e)))}))}else t.push((0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{style:O.licLabel,children:[s.replace(/_/g," "),":"]}),e[s].toString()]},s))})),t.push((0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{style:O.licLabel,children:[d.I18n.t("ra_Checked"),":"]}),this.state.licenseOfflineCheck?d.I18n.t("ra_locally"):d.I18n.t("ra_via internet")]},"checked")),(0,u.jsxs)(p.Dialog,{open:!0,onClose:()=>this.setState({showLicenseData:null}),children:[(0,u.jsx)(p.DialogTitle,{children:(0,u.jsx)(p.Box,{component:"span",sx:this.state.result?O.okTitle:O.errorTitle,children:d.I18n.t("ra_License %s",this.state.result?"OK":"INVALID")})}),(0,u.jsxs)(p.DialogContent,{children:[this.state.showLinkToProfile?(0,u.jsx)(p.Button,{variant:"contained",onClick:()=>window.open("https://iobroker.net/www/account/licenses","_blank"),children:"https://iobroker.net"}):null,this.state._error?(0,u.jsx)(p.Box,{component:"div",sx:O.errorText,children:this.state._error}):null,t]}),(0,u.jsx)(p.DialogActions,{children:(0,u.jsx)(p.Button,{onClick:()=>this.setState({showLicenseData:null,_error:""}),color:"primary",variant:"contained",children:d.I18n.t("ra_Close")})})]})}return null}static parseJwt(t){const e=t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),s=decodeURIComponent(atob(e).split("").map((t=>"%".concat("00".concat(t.charCodeAt(0).toString(16)).slice(-2)))).join(""));try{return JSON.parse(s)}catch(i){return null}}static isVersionValid(t,e,s,i){if(!e||!t)return!0;let o=!0;const[a]=t.split(".");return e.startsWith(">=")?o=parseInt(a,10)>=parseInt(e.substring(2,10)):e.startsWith("<=")?o=parseInt(a,10)<=parseInt(e.substring(2,10)):e.startsWith(">")?o=parseInt(a,10)>parseInt(e.substring(1,10)):e.startsWith("<")?o=parseInt(a,10)<parseInt(e.substring(1,10)):e.startsWith("=")?o=parseInt(a,10)===parseInt(e.substring(1,10)):e.startsWith("==")?o=parseInt(a,10)===parseInt(e.substring(2,10)):e.startsWith("===")&&(o=parseInt(a,10)===parseInt(e.substring(3,10))),!0}async findInLicenseManager(t){var e,s;const i=await this.props.oContext.socket.getObject("system.licenses"),o=[];if(null!==i&&void 0!==i&&null!==(e=i.native)&&void 0!==e&&null!==(s=e.licenses)&&void 0!==s&&s.length){let e=null;const s=Date.now();let r,l;if(this.props.schema.uuid){var a;const t=await this.props.oContext.socket.getObject("system.meta.uuid");r=null===t||void 0===t||null===(a=t.native)||void 0===a?void 0:a.uuid}if(this.props.schema.version){var n;const e=await this.props.oContext.socket.getObject("system.adapter.".concat(t));l=null===e||void 0===e||null===(n=e.common)||void 0===n?void 0:n.version}i.native.licenses.forEach((i=>{const a=!i.validTill||"0000-00-00 00:00:00"===i.validTill||new Date(i.validTill).getTime()>s,n=(i.product||"").split("."),h=n[1]===t||"vis-2"===t&&"vis"===n[1],p=!r||!i.uuid||i.uuid===r,c=_.isVersionValid(l,i.version,i.invoice,t);(!e||"free"!==i.invoice)&&a&&h&&p&&c&&(e=i),o.push({id:i.id,validName:h,validUuid:p,validVersion:c,validTill:a,license:i})})),e&&(o.find((t=>t.id===e.id)).used=!0)}return o}async checkLicense(t,e){let s,i;if(this.props.schema.uuid){var o;const t=await this.props.oContext.socket.getObject("system.meta.uuid");s=null===t||void 0===t||null===(o=t.native)||void 0===o?void 0:o.uuid}if(this.props.schema.version){var a;const t=await this.props.oContext.socket.getObject("system.adapter.".concat(e));i=null===t||void 0===t||null===(a=t.common)||void 0===a?void 0:a.version}const n=new AbortController;let r=setTimeout((()=>{r=null,n.abort()}),5e3);try{var l;const o=await window.fetch("https://iobroker.net/api/v1/public/cert/",{method:"POST",body:JSON.stringify({json:t,uuid:s}),headers:{"Content-Type":"text/plain"},signal:n.signal});r&&clearTimeout(r);const a=await o.text();let h;try{h=JSON.parse(a)}catch(p){}if(null===(l=h)||void 0===l||!l.error){let o=null;try{o=_.parseJwt(t)}catch(c){}if(h){const t=h.validTill||h.valid_till;if(t&&"0000-00-00 00:00:00"!==t&&new Date(t).getTime()<Date.now())return this.setState({_error:d.I18n.t("ra_License expired on %s",new Date(t).toLocaleString()),licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1});const a=(h.name||"").split(".");return a[1]===e||"vis"===a[1]&&"vis-2"===e?s&&!h.uuid&&"vis-2"===e?this.setState({_error:d.I18n.t("ra_License must be converted",h.uuid),showLinkToProfile:!0,licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1}):s&&h.uuid&&h.uuid!==s?this.setState({_error:d.I18n.t('ra_Serial number (UUID) "%s" in license is for other device.',h.uuid),licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1}):_.isVersionValid(i,h.version,h.invoice,e)?this.setState({licenseOfflineCheck:!1,showLicenseData:o,result:!0,running:!1}):this.setState({_error:d.I18n.t("ra_License is for version %s, but required version is %s",h.version,this.props.schema.version),licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1}):this.setState({_error:d.I18n.t('ra_License for other product "%s"',h.name),licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1})}throw new Error("ra_Invalid answer from server")}try{const e=_.parseJwt(t),s=d.I18n.t("ra_".concat(e.error||h.error||"Unknown error")).replace(/^ra_/,"");return this.setState({_error:s,licenseOfflineCheck:!1,showLicenseData:e,result:!1,running:!1})}catch(u){return console.log("Cannot parse license"),this.setState({_error:h.error,result:!1,running:!1})}}catch(m){var h;if(404===(null===m||void 0===m||null===(h=m.response)||void 0===h?void 0:h.status))return this.setState({_error:d.I18n.t("ra_License does not exist"),result:!1,running:!1});try{const o=_.parseJwt(t),a=(o.name||"").split(".");return o.valid_till&&"0000-00-00 00:00:00"!==o.valid_till&&new Date(o.valid_till).getTime()<Date.now()?this.setState({_error:d.I18n.t("ra_License expired on %s",new Date(o.valid_till).toLocaleString()),showLicenseData:o,licenseOfflineCheck:!0,running:!1,result:!1}):a[1]===e?s&&o.uuid&&o.uuid!==s?this.setState({_error:d.I18n.t('ra_Serial number (UUID) "%s" in license is for other device.',o.uuid),showLicenseData:o,licenseOfflineCheck:!0,result:!1,running:!1}):_.isVersionValid(i,o.version,o.invoice,e)?this.setState({running:!1,result:!0,licenseOfflineCheck:!0,showLicenseData:o}):this.setState({_error:d.I18n.t("ra_License is for version %s, but required version is %s",o.version,this.props.schema.version),licenseOfflineCheck:!0,showLicenseData:o,result:!1,running:!1}):this.setState({_error:d.I18n.t('ra_License for other product "%s"',o.name),licenseOfflineCheck:!0,showLicenseData:o,result:!1,running:!1})}catch(g){return this.setState({_error:d.I18n.t("ra_Cannot decode license"),result:!1,licenseOfflineCheck:!0,running:!1})}}}renderAskForUpdate(){return this.state.askForUpdate?(0,u.jsx)(d.DialogConfirm,{text:d.I18n.t("ra_License not found in license manager. Do you want to read licenses from iobroker.net?"),ok:d.I18n.t("ra_Yes"),onClose:async t=>{if(t){this.setState({askForUpdate:!1});try{await this.props.oContext.socket.updateLicenses(null,null)}catch(e){return void window.alert(d.I18n.t("ra_Cannot read licenses: %s",e))}await this._onClick(!0)}else this.setState({askForUpdate:!1,running:!1})}}):null}async _onClick(t){const e="vis-2"===this.props.oContext.adapterName?"vis":this.props.oContext.adapterName;let s,i;if(this.setState({running:!0}),this.props.data.useLicenseManager){if(i=await this.findInLicenseManager(e),s=i.find((t=>t.used)),s&&(s=s.license.json),!s&&!t)return void this.setState({askForUpdate:!0})}else s=this.props.data.license;s?await this.checkLicense(s,e):this.props.data.useLicenseManager?this.setState({_error:d.I18n.t("ra_Suitable license not found in license manager"),result:!1,running:!1,allLicenses:i}):this.setState({_error:d.I18n.t("ra_Please enter the license"),result:!1,running:!1})}renderItem(){return(0,u.jsxs)("div",{style:O.fullWidth,children:[(0,u.jsxs)(p.Button,{variant:this.props.schema.variant||"outlined",color:this.props.schema.color||"primary",style:O.fullWidth,disabled:!this.props.data.license&&!this.props.data.useLicenseManager||this.state.running,startIcon:(0,u.jsx)(c.Send,{}),onClick:()=>this._onClick(),children:[this.state.running?(0,u.jsx)(p.CircularProgress,{size:20,style:{marginRight:8}}):null,this.getText(this.props.schema.label||"ra_Check license",this.props.schema.noTranslation)]}),this.renderMessageDialog(),this.renderErrorDialog(),this.renderAskForUpdate()]})}}const A=_;const F=class extends x{renderItem(t,e){const s=x.getValue(this.props.data,this.props.attr),i=Array.isArray(s);return(0,u.jsxs)(p.FormControl,{style:{width:"100%"},variant:"standard",children:[(0,u.jsx)(p.FormControlLabel,{onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!e){const t=this.onChange(this.props.attr,!s);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}},control:(0,u.jsx)(p.Checkbox,{indeterminate:i,checked:!!s,onChange:t=>{let e;e=i?this.onChange(this.props.attr,!0):this.onChange(this.props.attr,t.target.checked),e instanceof Promise&&e.catch((t=>console.error("Cannot set value: ".concat(t))))},disabled:e||this.props.schema.readOnly}),label:this.getText(this.props.schema.label)}),(0,u.jsx)(p.FormHelperText,{style:{color:"red"},children:t?this.props.schema.validatorErrorText?d.I18n.t(this.props.schema.validatorErrorText):d.I18n.t("ra_Error"):null}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};var N=s(32619),E=s.n(N),L=s(99072),V=s(23106);const P={standard:p.Input,filled:L.A,outlined:p.OutlinedInput},W=t=>{const e="light"===t.palette.mode,s=e?"rgba(0, 0, 0, 0.42)":"rgba(255, 255, 255, 0.7)";return{root:{},inputRoot:{display:"inline-flex",flexWrap:"wrap",flex:1,marginTop:0,minWidth:70,"&.mui-variant-outlined,&.mui-variant-filled":{boxSizing:"border-box"},"&.mui-variant-outlined":{paddingTop:"14px"},"&.mui-variant-filled":{paddingTop:"28px"}},input:{display:"inline-block",textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",appearance:"none",WebkitTapHighlightColor:"rgba(0,0,0,0)",float:"left",flex:1},chipContainer:{display:"flex",flexFlow:"row wrap",alignItems:"center",cursor:"text",marginBottom:"-2px",minHeight:40},outlined:{"& input":{height:16,paddingTop:"4px",paddingBottom:"12px",marginTop:"4px",marginBottom:"4px"}},standard:{marginTop:"18px"},filled:{"& input":{height:22,marginBottom:"4px",marginTop:"4px",paddingTop:0},"$marginDense & input":{height:26}},labeled:{},label:{top:4,"&$outlined&:not($labelShrink)":{top:2,"$marginDense &":{top:5}},"&$filled&:not($labelShrink)":{top:15,"$marginDense &":{top:20}}},labelShrink:{top:0},helperText:{marginBottom:-20},focused:{},disabled:{},underline:{"&:after":{borderBottom:"2px solid ".concat(t.palette.primary[e?"dark":"light"]),left:0,bottom:0,content:'""',position:"absolute",right:0,transform:"scaleX(0)",transition:t.transitions.create("transform",{duration:t.transitions.duration.shorter,easing:t.transitions.easing.easeOut}),pointerEvents:"none"},"&$focused:after":{transform:"scaleX(1)"},"&$error:after":{borderBottomColor:t.palette.error.main,transform:"scaleX(1)"},"&:before":{borderBottom:"1px solid ".concat(s),left:0,bottom:0,content:'"\\00a0"',position:"absolute",right:0,transition:t.transitions.create("border-bottom-color",{duration:t.transitions.duration.shorter}),pointerEvents:"none"},"&:hover:not($disabled):not($focused):not($error):before":{borderBottom:"2px solid ".concat(t.palette.text.primary),"@media (hover: none)":{borderBottom:"1px solid ".concat(s)}},"&$disabled:before":{borderBottomStyle:"dotted"}},error:{"&:after":{backgroundColor:t.palette.error.main,transform:"scaleX(1)"}},chip:{margin:"0 8px 8px 0",float:"left"},marginDense:{}}},U=8,B=46,R=37,M=39,J=(t,e)=>{let{value:s,isFocused:o,isDisabled:a,isReadOnly:n,handleClick:r,handleDelete:l,style:h}=t;return(0,u.jsx)(p.Chip,{style:(0,i.A)((0,i.A)({},h),{},{pointerEvents:a||n?"none":void 0,backgroundColor:o?V.A[300]:void 0}),onClick:r,onDelete:l,label:s},e)};class z extends a().Component{constructor(t){super(t),this.labelRef=void 0,this.labelNode=null,this.input=void 0,this.newChipKeyCodes=void 0,this.newChipKeys=void 0,this.actualInput=null,this.inputBlurTimeout=null,this._keyPressed=void 0,this._preventChipCreation=void 0,this.styles={},this.styleTheme=null,this.focus=()=>{var t;null===(t=this.actualInput)||void 0===t||t.focus(),this.state.focusedChip&&this.setState({focusedChip:null})},this.handleInputBlur=t=>{this.props.onBlur&&this.props.onBlur(t),this.setState({isFocused:!1}),this.state.focusedChip&&this.setState({focusedChip:null});const e=t.target.value;let s;switch(this.props.blurBehavior||"clear"){case"add-or-clear":s={clearInputOnFail:!0};case"add":if(this.props.delayBeforeAdd){const t=(this.props.value||this.state.chips).length;this.inputBlurTimeout=setTimeout((()=>{const i=(this.props.value||this.state.chips).length;t===i?this.handleAddChip(e,s):this.clearInput()}),150)}else this.handleAddChip(e,s);break;case"clear":this.clearInput()}},this.handleInputFocus=t=>{this.setState({isFocused:!0}),this.props.onFocus&&this.props.onFocus(t)},this.handleKeyDown=t=>{const{focusedChip:e}=this.state;if(this._keyPressed=!1,this._preventChipCreation=!1,this.props.onKeyDown&&(this.props.onKeyDown(t),t.isDefaultPrevented()))return;const s=this.props.value||this.state.chips;if(this.newChipKeyCodes.includes(t.keyCode)||this.newChipKeys.includes(t.key)){!1!==this.handleAddChip(t.target.value)&&t.preventDefault()}else switch(t.keyCode){case U:""===t.target.value&&(e?(this.handleDeleteChip(s[e],e),e&&this.setState({focusedChip:e-1})):this.setState({focusedChip:s.length-1}));break;case B:""===t.target.value&&e&&(this.handleDeleteChip(s[e],e),e<=s.length-1&&this.setState({focusedChip:e}));break;case R:null===e&&""===t.target.value&&s.length?this.setState({focusedChip:s.length-1}):null!==e&&e>0&&this.setState({focusedChip:e-1});break;case M:null!==e&&e<s.length-1?this.setState({focusedChip:e+1}):this.setState({focusedChip:null});break;default:this.setState({focusedChip:null})}},this.handleKeyUp=t=>{!this._preventChipCreation&&(this.newChipKeyCodes.includes(t.keyCode)||this.newChipKeys.includes(t.key))&&this._keyPressed?this.clearInput():this.updateInput(t.target.value),this.props.onKeyUp&&this.props.onKeyUp(t)},this.handleUpdateInput=t=>{null!==this.props.inputValue&&void 0!==this.props.inputValue||this.updateInput(t.target.value),this.props.onUpdateInput&&this.props.onUpdateInput(t)},this.setActualInputRef=t=>{this.actualInput=t,this.props.inputRef&&this.props.inputRef(t)},this.state={chips:t.defaultValue||[],focusedChip:null,inputValue:"",isFocused:!1,chipsUpdated:!1,prevPropsValue:[],variant:this.props.variant||"standard"},this.newChipKeyCodes=t.newChipKeyCodes||[13],this.newChipKeys=t.newChipKeys||["Enter"],this.labelRef=a().createRef(),this.input=a().createRef()}componentDidMount(){"outlined"===this.state.variant&&(this.labelNode=E().findDOMNode(this.labelRef.current),this.forceUpdate())}componentWillUnmount(){this.inputBlurTimeout&&clearTimeout(this.inputBlurTimeout)}static getDerivedStateFromProps(t,e){let s=null;return t.value&&t.value.length!==e.prevPropsValue.length&&(s={prevPropsValue:t.value},t.clearInputValueOnChange&&(s.inputValue="")),t.clearInputValueOnChange&&t.value&&t.value.length!==e.prevPropsValue.length&&(s={prevPropsValue:t.value,inputValue:""}),t.disabled&&(s=(0,i.A)((0,i.A)({},s),{},{focusedChip:null})),!e.chipsUpdated&&t.defaultValue&&(s=(0,i.A)((0,i.A)({},s),{},{chips:t.defaultValue})),s}handleAddChip(t,e){if(this.props.onBeforeAdd&&!this.props.onBeforeAdd(t))return this._preventChipCreation=!0,e&&e.clearInputOnFail&&this.clearInput(),!1;this.clearInput();const s=this.props.value||this.state.chips;return!!t.trim().length&&(!this.props.allowDuplicates&&s.includes(t)||(this.props.value&&this.props.onAdd?this.props.onAdd(t):this.updateChips([...this.state.chips,t])),!0)}handleDeleteChip(t,e){if(this.props.value)this.props.onDelete&&this.props.onDelete(t,e);else{const t=this.state.chips.slice();if(t.splice(e,1)){let s=this.state.focusedChip;this.state.focusedChip===e?s=null:this.state.focusedChip>e&&(s=this.state.focusedChip-1),this.updateChips(t,{focusedChip:s})}}}updateChips(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.setState((0,i.A)({chips:t,chipsUpdated:!0},e)),this.props.onChange&&this.props.onChange(t)}clearInput(){this.updateInput("")}updateInput(t){this.setState({inputValue:t})}render(){const{alwaysShowPlaceholder:t,chipRenderer:e=J,className:s,disabled:o,disableUnderline:a,error:n,FormHelperTextProps:r,fullWidth:l,fullWidthInput:h,helperText:c,id:m,InputProps:g={},InputLabelProps:x={},inputValue:v,label:f,placeholder:y,readOnly:b,required:C,rootRef:j,value:w,margin:I}=this.props,T=this.state.variant;this.styleTheme!==this.props.theme.palette.mode&&(this.styleTheme=this.props.theme.palette.mode,this.styles=d.Utils.getStyle(this.props.theme,W));let S=w||this.state.chips||[];Array.isArray(S)||(S=(S||"").toString().split(/[,\s]+/).map((t=>t.trim())));const D=null!==v&&void 0!==v?v:this.state.inputValue,k=(this.props.value||D).length||D.length,O="boolean"===typeof x.shrink?x.shrink:null!==f&&(k||this.state.isFocused||S.length),_=S.map(((t,s)=>e({value:t,isDisabled:!!o,isReadOnly:b,isFocused:this.state.focusedChip===s,handleClick:()=>this.setState({focusedChip:s}),handleDelete:()=>this.handleDeleteChip(t,s),style:this.styles.chip},s.toString()))),A={};"outlined"===T&&(A.notched=!!O,A.labelWidth=O&&this.labelNode&&this.labelNode.offsetWidth||0),"standard"!==T?A.startAdornment=_:g.disableUnderline=!0;const F=P[T];return(0,u.jsxs)(p.FormControl,{ref:j,fullWidth:l,className:s,sx:(0,i.A)((0,i.A)({},this.styles.root),"dense"===I?this.styles.marginDense:{}),error:n,required:S.length>0?void 0:C,onClick:this.focus,disabled:o,variant:T,component:"div",margin:I,children:[f&&(0,u.jsx)(p.InputLabel,(0,i.A)((0,i.A)({htmlFor:m,sx:{"&.MuiInputLabel-root":this.styles.label,"&.MuiInputLabel-shrink":this.styles.labelShrink},shrink:!!O,focused:this.state.isFocused,variant:T,ref:this.labelRef,required:C,component:"label"},x),{},{children:f})),(0,u.jsxs)(p.Box,{component:"div",id:"input-chip-container",sx:(0,i.A)((0,i.A)((0,i.A)((0,i.A)((0,i.A)((0,i.A)((0,i.A)({},this.styles[T]),this.styles.chipContainer),this.state.isFocused?this.styles.focused:void 0),a||"standard"!==T?void 0:this.styles.underline),o?this.styles.disabled:void 0),f?this.styles.labeled:void 0),n?this.styles.error:void 0),children:["standard"===T&&_,(0,u.jsx)(F,(0,i.A)((0,i.A)({ref:this.input,className:"mui-variant-".concat(this.styles[T]," ").concat(f?"mui-chip-with-label":"mui-chip-no-label"),sx:{"&.MuiInputBase-input":(0,i.A)((0,i.A)({},this.styles.input),this.styles[T]),"&.MuiInputBase-root":(0,i.A)({},this.styles.inputRoot)},id:m,value:D,onChange:this.handleUpdateInput,onKeyDown:this.handleKeyDown,onKeyUp:this.handleKeyUp,onFocus:this.handleInputFocus,onBlur:this.handleInputBlur,inputRef:this.setActualInputRef,disabled:o,fullWidth:h,placeholder:!k&&(O||null===f||void 0===f)||t?y:null,readOnly:b},g),A))]}),c&&(0,u.jsx)(p.FormHelperText,(0,i.A)((0,i.A)({},r),{},{className:null===r||void 0===r?void 0:r.className,style:this.styles.helperText,children:c}))]})}}const H=z;const q=class extends x{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=x.getValue(t,e);if(this.props.schema.delimiter&&"string"===typeof s){const t=s.split(this.props.schema.delimiter).map((t=>t.trim())).filter((t=>t));this.setState({value:t})}else this.setState({value:s||[]})}renderItem(t,e){const{attr:s,schema:i}=this.props,{value:o}=this.state;return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[(0,u.jsx)(H,{value:o,disabled:!!e,label:this.getText(i.label),error:!!t,onAdd:t=>{const e=JSON.parse(JSON.stringify(o));e.push(t),this.setState({value:e},(()=>{let t;t=this.props.schema.delimiter?this.onChange(s,e.join("".concat(this.props.schema.delimiter," "))):this.onChange(s,e),t instanceof Promise&&t.catch((t=>console.error(t)))}))},theme:this.props.oContext.theme,onDelete:(t,e)=>{const i=JSON.parse(JSON.stringify(o));i.splice(e,1),this.setState({value:i},(()=>{let t;t=this.props.schema.delimiter?this.onChange(s,i.join("".concat(this.props.schema.delimiter," "))):this.onChange(s,i),t instanceof Promise&&t.catch((t=>console.error(t)))}))}}),(0,u.jsx)(p.FormHelperText,{children:d.I18n.t("ra_Press ENTER Key to add new item")}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};var K=s(4554);const $=class extends x{renderColorDialog(){return!!this.state.showColorDialog&&(0,u.jsx)(p.Dialog,{onClose:()=>this.setState({showColorDialog:!1}),open:this.state.showColorDialog,children:(0,u.jsx)(K.xk,{color:this.state.colorDialogValue,onChange:t=>this.setState({colorDialogValue:t.hex},(()=>this.onChange(this.props.attr,this.state.colorDialogValue)))})})}renderItem(t,e){const s=x.getValue(this.props.data,this.props.attr);let i=d.Utils.isUseBright(s,null);return null===i&&(i=void 0),(0,u.jsxs)(u.Fragment,{children:[this.renderColorDialog(),(0,u.jsx)(p.TextField,{variant:"standard",disabled:!!e,style:{minWidth:100,width:"calc(100% - 8px)"},label:this.getText(this.props.schema.label),value:s||"",onClick:()=>!this.props.schema.readOnly&&this.setState({showColorDialog:!0,colorDialogValue:s||""}),onChange:t=>{const e=t.target.value,s=this.onChange(this.props.attr,e);s instanceof Promise&&s.catch((t=>console.error("Cannot set value: ".concat(t))))},slotProps:{htmlInput:{style:{backgroundColor:s,color:i?"#FFF":"#000"},readOnly:this.props.schema.readOnly||!1},input:{endAdornment:this.props.schema.readOnly||!s||this.props.schema.noClearButton?void 0:(0,u.jsx)(p.IconButton,{size:"small",onClick:t=>{t.stopPropagation();const e=this.onChange(this.props.attr,"");e instanceof Promise&&e.catch((t=>console.error("Cannot set value: ".concat(t))))},children:(0,u.jsx)(c.Close,{})})},inputLabel:{shrink:!0}}})]})}},G={width:{width:"calc(100% - 85px)"},width50:{width:120,marginRight:5}};const Y=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t});const e={};if(this.props.schema.useSystemName&&(e.useSystem=!!x.getValue(this.props.data,this.props.schema.useSystemName)),this.props.schema.longitudeName&&this.props.schema.latitudeName)e.longitude=x.getValue(this.props.data,this.props.schema.longitudeName),e.latitude=x.getValue(this.props.data,this.props.schema.latitudeName),e.longitude||e.latitude||!this.props.schema.autoInit||setTimeout((()=>this.getCoordinates()),300);else{!x.getValue(this.props.data,this.props.attr)&&this.props.schema.autoInit&&setTimeout((()=>this.getCoordinates()),300)}Object.keys(e).length&&setTimeout((()=>this.setState(e)),50)}async getSystemCoordinates(){const t=await this.props.oContext.socket.getCompactSystemConfig();if(null!==t&&void 0!==t&&t.common&&(t.common.longitude||t.common.latitude))if(window.alert(d.I18n.t("ra_Used system settings")),this.props.schema.longitudeName&&this.props.schema.latitudeName)this.setState({longitude:t.common.longitude,latitude:t.common.latitude},(async()=>{await this.onChange(this.props.schema.longitudeName,t.common.longitude),await this.onChange(this.props.schema.latitudeName,t.common.latitude)}));else{const e=t.common.latitude+(this.props.schema.divider||",")+t.common.longitude;this.setState({value:e},(()=>{const t=this.onChange(this.props.attr,e);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}))}else window.alert(d.I18n.t("ra_Cannot determine position: System settings are empty and GPS detection is disabled in browser"))}getCoordinates(){navigator.geolocation?navigator.geolocation.getCurrentPosition((async t=>{if(null!==t&&void 0!==t&&t.coords)if(this.props.schema.longitudeName&&this.props.schema.latitudeName)this.setState({longitude:t.coords.longitude,latitude:t.coords.latitude},(async()=>{await this.onChange(this.props.schema.longitudeName,t.coords.longitude||""),await this.onChange(this.props.schema.latitudeName,t.coords.latitude||"")}));else{const e=t.coords.latitude+(this.props.schema.divider||",")+t.coords.longitude;this.setState({value:e},(()=>{const t=this.onChange(this.props.attr,e);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}))}else await this.getSystemCoordinates()}),(async t=>{console.error("Cannot determine coordinates from browser: ".concat(t.message)),await this.getSystemCoordinates()})):this.getSystemCoordinates().catch((t=>{console.error("Cannot determine coordinates: ".concat(t))}))}renderItem(t,e){var s,i;return(0,u.jsxs)(u.Fragment,{children:[this.props.schema.useSystemName?(0,u.jsx)(p.FormControlLabel,{control:(0,u.jsx)(p.Checkbox,{checked:!!this.state.useSystem,onChange:t=>{const e=t.target.checked;e&&this.getSystemCoordinates().catch((t=>console.error("Cannot determine coordinates: ".concat(t)))),this.setState({useSystem:e},(()=>this.onChange(this.props.schema.useSystemName,e)))}}),label:d.I18n.t("ra_Use system settings for position")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?(0,u.jsx)(p.TextField,{variant:"standard",style:G.width50,value:null!==(s=this.state.longitude)&&void 0!==s?s:"",error:!!t,disabled:this.state.useSystem||!!e,onChange:t=>{const e=t.target.value;this.setState({longitude:e},(()=>{const t=this.onChange(this.props.schema.longitudeName,(e||"").trim());t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}))},label:d.I18n.t("ra_Longitude")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?(0,u.jsx)(p.TextField,{variant:"standard",style:G.width50,value:null!==(i=this.state.latitude)&&void 0!==i?i:"",error:!!t,disabled:this.state.useSystem||!!e,onChange:t=>{const e=t.target.value;this.setState({latitude:e},(()=>this.onChange(this.props.schema.latitudeName,(e||"").trim())))},label:d.I18n.t("ra_Latitude")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?null:(0,u.jsx)(p.TextField,{variant:"standard",style:G.width,value:null===this.state.value||void 0===this.state.value?"":this.state.value,error:!!t,disabled:!!e,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:this.state.useSystem}},onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,(e||"").trim())))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}),this.state.useSystem?null:(0,u.jsx)(p.Fab,{size:"small",onClick:()=>this.getCoordinates(),title:d.I18n.t("ra_Take browser position"),style:{marginRight:4},children:(0,u.jsx)(c.LocationOn,{})}),this.state.useSystem?null:(0,u.jsx)(p.Fab,{size:"small",onClick:()=>this.getSystemCoordinates(),title:d.I18n.t("ra_Take position from system settings"),children:(0,u.jsx)(c.GpsFixed,{})})]})}};function Z(t,e,i,o){return async()=>{const a=await((t,e,i)=>new Promise(((o,a)=>{if(window[t])o(window[t]);else{const n=document.querySelector('script[data-webpack="'.concat(t,'"]')),r=async()=>{if(!window[t])return console.error("Cannot load ".concat(t)),void a(new Error("Cannot load ".concat(t)));window[t].__initialized||(await window[t].init(s.S[e]),window[t].__initialized=!0),o(window[t])};if(n)n.onload=r,n.onerror=a;else if(i){const e=document,s=e.createElement("script");s.type="text/javascript",s.setAttribute("data-webpack","".concat(t)),s.async=!0,s.onerror=a,s.onload=r,s.src=i,e.getElementsByTagName("head")[0].appendChild(s)}else a(new Error("Cannot Find Remote ".concat(t," to inject")))}})))(t,e,o);return(await a.get(i))()}}class Q extends x{constructor(t){super(t),Object.assign(this.state,{Component:null,error:""})}async componentDidMount(){if(!this.props.schema.url)return console.error("URL is empty. Cannot load custom component!"),void this.setState({error:"URL is empty. Cannot load custom component!"});let t;t=this.props.schema.url.startsWith("./")?"".concat(window.location.protocol,"//").concat(window.location.host).concat(this.props.schema.url.replace(/^\./,"")):"".concat(window.location.protocol,"//").concat(window.location.host,"/adapter/").concat(this.props.oContext.adapterName,"/").concat(this.props.schema.url);const[e,s,...i]=this.props.schema.name.split("/"),o=i.join("/");if(!t)return void console.error('Cannot find URL for custom component! Please define "url" as "custom/customComponents.js" in the schema');if(!e||!s||!o)return void console.error('Invalid format of "name"! Please define "name" as "ConfigCustomBackItUpSet/Components/AdapterExist" in the schema');let a=Q.runningLoads["".concat(t,"!").concat(s)];if(!(a instanceof Promise)){let i;if(!0===this.props.schema.i18n){const e=t.lastIndexOf("/");let s;s=-1!==e?t.substring(0,e):t;const o=d.I18n.getLanguage(),a="".concat(s,"/i18n/").concat(o,".json");i=fetch(a).then((t=>t.json())).then((t=>d.I18n.extendTranslations(t,o))).catch((t=>{"en"===o?console.log('Cannot load i18n "'.concat(a,'": ').concat(t)):fetch("".concat(s,"/i18n/en.json")).then((t=>t.json())).then((t=>d.I18n.extendTranslations(t,o))).catch((t=>console.log('Cannot load i18n "'.concat(a,'": ').concat(t))))}))}else if(this.props.schema.i18n&&"object"===typeof this.props.schema.i18n)try{d.I18n.extendTranslations(this.props.schema.i18n)}catch(n){console.error("Cannot import i18n: ".concat(n))}try{console.log(e,s,o),a=Z(e,"default","./".concat(s),t)(),i instanceof Promise&&(a=Promise.all([a,i]).then((t=>t[0]))),Q.runningLoads["".concat(t,"!").concat(s)]=a}catch(n){this.setState({error:"Cannot import from ".concat(this.props.schema.url,": ").concat(n)})}}try{const t=(await a).default;if(null!==t&&void 0!==t&&t[o])this.setState({Component:t[o]});else{const e=Object.keys(t||{});console.error("URL is empty. Cannot load custom component!"),this.setState({error:"Component ".concat(this.props.schema.name," not found in ").concat(this.props.schema.url,". Found: ").concat(e.join(", "))})}}catch(n){this.setState({error:"Cannot import from ".concat(this.props.schema.url,": ").concat(n)})}}render(){const t=this.state.Component,e=this.props.schema||{};let s=t?(0,u.jsx)(t,(0,i.A)((0,i.A)({},this.props),{},{socket:this.props.oContext.socket,theme:this.props.oContext.theme,themeType:this.props.oContext.themeType,instance:this.props.oContext.instance,adapterName:this.props.oContext.adapterName,systemConfig:this.props.oContext.systemConfig,forceUpdate:this.props.oContext.forceUpdate})):this.state.error?(0,u.jsx)("div",{children:this.state.error}):(0,u.jsx)(p.LinearProgress,{});return(e.xs||e.sm||e.md||e.lg||e.xl)&&(s=(0,u.jsx)(p.Grid2,{size:{xs:e.xs||12,sm:e.sm||void 0,md:e.md||void 0,lg:e.lg||void 0,xl:e.xl||void 0},style:(0,i.A)((0,i.A)({marginBottom:0,textAlign:"left"},e.style),"dark"===this.props.oContext.themeType?e.darkStyle:{}),children:s})),e.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),s]}):s}}Q.runningLoads={};var X=s(46567);const tt=class extends x{renderItem(){if(!this.props.schema)return null;if(this.props.oContext.DeviceManager){const t=this.props.oContext.DeviceManager;return(0,u.jsx)(t,{uploadImagesToInstance:"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),title:this.getText(this.props.schema.label),socket:this.props.oContext.socket,selectedInstance:"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),themeName:this.props.themeName,themeType:this.props.oContext.themeType,isFloatComma:this.props.oContext.isFloatComma,dateFormat:this.props.oContext.dateFormat})}return(0,u.jsx)("div",{children:"DeviceManager not found"})}};var et=s(51189),st=s.n(et);const it={fullWidth:{width:"100%"},fullWidthOneButton:{width:"calc(100% - 42px)"},fullWidthTwoButtons:{width:"calc(100% - 84px)"},fullWidthThreeButtons:{width:"calc(100% - 126x)"},dropZone:{width:"100%",height:"100%",position:"absolute"},dropZoneEmpty:{},image:{objectFit:"contain",margin:"auto",display:"flex",width:"100%",height:"100%"},uploadDiv:{position:"relative",width:"100%"},uploadDivDragging:{opacity:1,background:"rgba(128,255,128,0.1)"},uploadCenterDiv:{margin:5,border:"3px dashed grey",borderRadius:5,width:"100%",height:"100%",position:"absolute",display:"flex"},uploadCenterIcon:{paddingTop:10,width:48,height:48},uploadCenterText:{fontSize:16},uploadCenterTextAndIcon:{textAlign:"center",position:"absolute",top:0,bottom:0,left:0,right:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},disabledOpacity:{opacity:.3,cursor:"default"},error:{border:"2px solid red"},deleteButton:{},selectedImage:{height:40,width:40,display:"inline-block",marginRight:8}},ot=["jpg","jpeg","svg","png","webp","gif","apng","avif","webp"],at=["mp3","ogg","wav","aac"],nt=["avi","mp4","mov"],rt=["txt","log","html","htm"],lt=["json","js","ts"];class ht extends x{constructor(t){super(t),this.dropzoneRef=void 0,this.imagePrefix=void 0,this.objectID=void 0,this.path=void 0,this.dropzoneRef=a().createRef(),this.imagePrefix=void 0===this.props.oContext.imagePrefix?"./files":this.props.oContext.imagePrefix}componentDidMount(){super.componentDidMount(),this.objectID=(this.props.schema.objectID||"0_userdata.0").replace("%INSTANCE%",(this.props.oContext.instance||0).toString()),this.path=this.props.schema.upload,this.path&&("/"===this.path?this.path="":this.path.endsWith("/")||(this.path="".concat(this.path,"/"))),this.updateFiles().then((()=>{const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t})}))}updateFiles(){return this.readFiles(this.props.schema.pattern).then((t=>this.setState({files:t})))}async readFolder(t,e,s){try{const i=await this.props.oContext.socket.readDir(this.objectID,t.replace(/^\//,"")||null);for(let o=0;o<i.length;o++){const a=i[o];if(a.isDir)await this.readFolder("".concat(t+a.file,"/"),e,s);else{let i=!1;if("*.*"===s&&a.file.includes("."))i=!0;else if(s&&"*"!==s)if(".*"===s&&a.file.startsWith("."))i=!0;else{i=new RegExp("^".concat(s.replace(/\./g,"\\.").replace(/\*/g,".*"),"$")).test(a.file)}else i=!0;i&&e.push({name:t+a.file,size:a.stats?d.Utils.formatBytes(a.stats.size):"--"})}}}catch(i){console.error('Cannot read "'.concat(t,'": ').concat(i))}return e}async readFiles(t){const e=[];let s;(t=t||this.props.schema.pattern)||(t="**/*.*");const i=t.lastIndexOf("/");if(s=-1===i?t:t.substring(i+1),t.startsWith("**"))await this.readFolder("/",e,s);else{const i=t.lastIndexOf("/");if(-1===i)await this.readFolder("/",e,s);else{const o=t.substring(0,i+1);await this.readFolder(o,e,s)}}return e}onDrop(t){const e=t[0],s=new FileReader,i=this.props.schema.maxSize||2097152;s.onabort=()=>console.log("file reading was aborted"),s.onerror=()=>console.log("file reading has failed"),s.onload=()=>{let t="image/".concat(e.name.split(".").pop().toLowerCase());if("image/jpg"===t?t="image/jpeg":t.includes("svg")&&(t="image/svg+xml"),e.size>i)return void window.alert(d.I18n.t("File is too big. Max %sk allowed. Try use SVG.",Math.round(i/1024)));const o="data:".concat(t,";base64,").concat(btoa(new Uint8Array(s.result).reduce(((t,e)=>t+String.fromCharCode(e)),"")));this.props.oContext.socket.writeFile64(this.objectID,this.path+e.name,o).then((()=>this.updateFiles())).catch((t=>window.alert("Cannot upload file: ".concat(t))))},s.readAsArrayBuffer(e)}renderDeleteDialog(){return this.state.deleteFile?(0,u.jsx)(d.DialogConfirm,{title:d.I18n.t("ra_Are you sure?"),text:d.I18n.t("ra_File will be deleted"),ok:d.I18n.t("ra_Delete"),cancel:d.I18n.t("ra_Cancel"),onClose:t=>{const e=this.state.deleteFile;this.setState({deleteFile:""},(()=>{t&&this.props.oContext.socket.deleteFile(this.objectID,e).then((()=>this.updateFiles())).catch((t=>window.alert("Cannot delete file: ".concat(t))))}))}}):null}static base64ToArrayBuffer(t){const e=window.atob(t),s=e.length,i=new Uint8Array(s);for(let o=0;o<s;o++)i[o]=e.charCodeAt(o);return i.buffer}loadFile(){return this.props.oContext.socket.readFile(this.objectID,this.state.value,!0)}play(){this.loadFile().then((t=>{if("undefined"!==typeof AudioContext){const e=new AudioContext,s=ht.base64ToArrayBuffer(t.file);e.decodeAudioData(s,(t=>{const s=e.createBufferSource();s.buffer=t,s.connect(e.destination),s.start(0)}),(t=>window.alert("Cannot play: ".concat(t.message))))}}))}getFileIcon(t){return null!==t&&void 0!==t&&t.extension?ot.includes(t.extension)?(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},it.selectedImage),{},{backgroundImage:"url(".concat(this.imagePrefix,"/").concat(this.objectID,"/").concat(t.value,")"),backgroundSize:"contain",backgroundRepeat:"no-repeat"})}):at.includes(t.extension)?(0,u.jsx)(c.MusicNote,{}):rt.includes(t.extension)?(0,u.jsx)(c.Article,{}):nt.includes(t.extension)?(0,u.jsx)(c.Videocam,{}):lt.includes(t.extension)?(0,u.jsx)(c.Code,{}):null:null}renderItem(t,e){if(!this.state.files)return null;const s=[];this.props.schema.withFolder||this.state.files.forEach((t=>{const e=t.name.lastIndexOf("/");if(-1===e)s.includes("/")||s.push("/");else{const i=t.name.substring(0,e+1);s.includes(i)||s.push(i)}}));const o=this.state.files.map((t=>({value:t.name,label:this.props.schema.withFolder||1!==s.length?"".concat(t.name).concat(this.props.schema.noSize?"":"(".concat(t.size,")")):"".concat(t.name.substring(s[0].length)),extension:t.name.toLowerCase().split(".").pop()})));this.props.schema.noNone||o.unshift({label:d.I18n.t("ra_none"),value:""});const a=o.find((t=>t.value===this.state.value));let n=0;this.props.schema.upload&&n++,this.props.schema.refresh&&n++;const r=this.state.value&&(this.state.value.endsWith(".mp3")||this.state.value.endsWith(".ogg")||this.state.value.endsWith(".wav"));r&&n++;const l=(0,u.jsxs)("div",{style:it.fullWidth,children:[(0,u.jsxs)(p.FormControl,{variant:"standard",style:{width:"calc(100% - ".concat(42*n,"px)")},children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>(0,u.jsxs)(u.Fragment,{children:[this.getFileIcon(a),(0,u.jsx)("span",{children:(null===a||void 0===a?void 0:a.label)||""})]}),onChange:t=>{this.setState({value:"_"===t.target.value?"":t.target.value},(()=>this.onChange(this.props.attr,this.state.value)))},children:o.map((t=>(0,u.jsxs)(p.MenuItem,{value:t.value,children:[(0,u.jsx)(p.ListItemIcon,{children:this.getFileIcon(t)}),(0,u.jsx)(p.ListItemText,{children:t.label}),this.props.schema.delete&&a.value?(0,u.jsx)(p.IconButton,{style:it.deleteButton,size:"small",onClick:()=>this.setState({deleteFile:a.value}),children:(0,u.jsx)(c.Delete,{})}):null]},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]}),this.props.schema.refresh&&(0,u.jsx)(p.IconButton,{onClick:()=>this.updateFiles(),children:(0,u.jsx)(c.Refresh,{})}),this.props.schema.upload&&(0,u.jsx)(p.IconButton,{onClick:()=>{var t;return null===(t=this.dropzoneRef.current)||void 0===t?void 0:t.open()},children:(0,u.jsx)(c.UploadFile,{})}),r&&(0,u.jsx)(p.IconButton,{style:{color:"#00FF00"},onClick:()=>this.play(),children:(0,u.jsx)(c.PlayArrow,{})})]});if(!this.props.schema.upload)return(0,u.jsxs)(u.Fragment,{children:[l,this.renderDeleteDialog()]});let h={"*/*":[]};if("image"===this.props.schema.fileTypes?h={"image/*":[".png",".jpg",".svg",".gif",".apng",".avif",".webp"]}:"audio"===this.props.schema.fileTypes?h={"audio/*":[".mp3",".ogg",".wav",".mp4"]}:"text"===this.props.schema.fileTypes&&(h={"text/plain":[".txt"]}),this.props.schema.pattern){const t=this.props.schema.pattern.split("/").pop().toLowerCase().replace(/.*\./,"");h="png"===t||"jpg"===t||"svg"===t||"gif"===t||"apng"===t||"avif"===t||"webp"===t?{"image/*":[".png",".jpg",".svg",".gif",".apng",".avif",".webp"]}:"mp3"===t||"ogg"===t||"wav"===t?{"audio/*":[".mp3",".ogg",".wav",".mp4"]}:"ics"===t?{"text/calendar":[".ics"]}:"txt"===t?{"text/plain":[".txt"]}:"pem"===t?{"text/plain":[".pem"]}:{"*/*":[".".concat(t)]}}return(0,u.jsx)(st(),{ref:this.dropzoneRef,multiple:!1,accept:h,noKeyboard:!0,noClick:!0,maxSize:this.props.schema.maxSize||2097152,onDragEnter:()=>{this.setState({uploadFile:"dragging"})},onDragLeave:()=>this.setState({uploadFile:!0}),onDrop:(t,e)=>{this.setState({uploadFile:!1}),t.length?this.onDrop(t):window.alert(e&&e[0]&&e[0].errors&&e[0].errors[0]&&e[0].errors[0].message||d.I18n.t("Cannot upload"))},children:t=>{let{getRootProps:s,getInputProps:o}=t;return(0,u.jsxs)("div",(0,i.A)((0,i.A)({style:(0,i.A)((0,i.A)((0,i.A)({},it.uploadDiv),"dragging"===this.state.uploadFile?it.uploadDivDragging:void 0),e?it.disabledOpacity:void 0)},s()),{},{children:[(0,u.jsx)("input",(0,i.A)({},o())),"dragging"===this.state.uploadFile?(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},it.uploadCenterDiv),this.state.uploadError?it.error:void 0),children:(0,u.jsxs)("div",{style:it.uploadCenterTextAndIcon,children:[(0,u.jsx)(c.UploadFile,{style:it.uploadCenterIcon}),(0,u.jsx)("div",{style:it.uploadCenterText,children:"dragging"===this.state.uploadFile?d.I18n.t("ra_Drop file here"):d.I18n.t("ra_Place your files here or click here to open the browse dialog")})]})}):null,l,this.renderDeleteDialog()]}))}})}}const pt=ht,ct={fullWidth:{width:"100%"},fullWidthOneButton:{width:"calc(100% - 69px)",marginRight:4},fullWidthIcon:{width:"calc(100% - 119px)",marginRight:4},selectedImage:{height:40,width:40,display:"inline-block",marginRight:8}},dt=["jpg","jpeg","svg","png","webp","gif","apng","avif","webp"],ut=["mp3","ogg","wav","aac"],mt=["avi","mp4","mov"],gt=["txt","log","html","htm"],xt=["json","js","ts"];const vt=class extends x{constructor(){super(...arguments),this.imagePrefix="../.."}componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.imagePrefix=void 0===this.props.oContext.imagePrefix?"./files":this.props.oContext.imagePrefix,this.setState({value:null!==t&&void 0!==t?t:""})}static getDerivedStateFromProps(t,e){const s=x.getValue(t.data,t.attr);return null===s||void 0===s||s.toString().trim()!==(e.value||"").toString().trim()?{value:null!==s&&void 0!==s?s:""}:null}loadFile(){const t=this.state.value.indexOf("/");if(-1!==t){const e=this.state.value.substring(0,t),s=this.state.value.substring(t+1);return this.props.oContext.socket.readFile(e,s,!0)}return Promise.resolve(null)}play(){this.loadFile().then((t=>{if("undefined"!==typeof AudioContext&&null!==t&&void 0!==t&&t.file){const e=new AudioContext,s=pt.base64ToArrayBuffer(t.file);e.decodeAudioData(s,(t=>{const s=e.createBufferSource();s.buffer=t,s.connect(e.destination),s.start(0)}),(t=>window.alert("Cannot play: ".concat(t.message))))}}))}getIcon(){const t=this.state.value.split(".").pop().toLowerCase();return dt.includes(t)?(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},ct.selectedImage),{},{backgroundImage:"url(".concat(this.imagePrefix,"/").concat(this.state.value,")"),backgroundSize:"contain",backgroundRepeat:"no-repeat"})}):ut.includes(t)?(0,u.jsx)(p.IconButton,{style:{color:"#00FF00"},onClick:()=>this.play(),children:(0,u.jsx)(c.PlayArrow,{})}):gt.includes(t)?(0,u.jsx)(c.Article,{}):mt.includes(t)?(0,u.jsx)(c.Videocam,{}):xt.includes(t)?(0,u.jsx)(c.Code,{}):null}renderFileBrowser(){return this.state.showFileBrowser?(0,u.jsx)(d.DialogSelectFile,{imagePrefix:this.props.oContext.imagePrefix,socket:this.props.oContext.socket,selected:this.state.value,onClose:()=>this.setState({showFileBrowser:!1}),onOk:t=>{const e=Array.isArray(t)?t[0]:t;this.setState({value:e},(()=>this.onChange(this.props.attr,!1===this.props.schema.trim?e:(e||"").trim())))},selectOnlyFolders:this.props.schema.selectOnlyFolders,allowUpload:this.props.schema.allowUpload,allowDownload:this.props.schema.allowDownload,allowCreateFolder:this.props.schema.allowCreateFolder,allowView:this.props.schema.allowView,showToolbar:this.props.schema.showToolbar,limitPath:this.props.schema.limitPath,theme:this.props.oContext.theme}):null}renderItem(t,e){const s=this.getIcon();return(0,u.jsxs)("div",{style:ct.fullWidth,children:[s,(0,u.jsx)(p.TextField,{variant:"standard",style:s?ct.fullWidthIcon:ct.fullWidthOneButton,value:null===this.state.value||void 0===this.state.value?"":this.state.value,error:!!t,disabled:!!e,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:!!this.props.schema.disableEdit}},onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,!1===this.props.schema.trim?e:(e||"").trim())))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}),(0,u.jsx)(p.Button,{disabled:e,variant:"outlined",onClick:()=>this.setState({showFileBrowser:!0}),children:"..."}),this.renderFileBrowser()]})}};const ft=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.props.oContext.socket.getEnums("functions").then((e=>{const s=Object.keys(e).map((t=>({value:this.props.schema.short?t.replace("enum.functions.",""):t,label:this.getText(e[t].common.name),obj:e[t]})));!1!==this.props.schema.allowDeactivate&&s.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.setState({value:t,selectOptions:s})}))}renderItem(t,e){if(!this.state.selectOptions)return null;const s=this.state.selectOptions.find((t=>t.value===this.state.value));return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>s?s.obj?(0,u.jsx)(d.TextWithIcon,{value:s.obj,themeType:this.props.oContext.themeType,lang:d.I18n.getLanguage()}):s.label:"",onChange:t=>{this.setState({value:"_"===t.target.value?"":t.target.value},(()=>this.onChange(this.props.attr,this.state.value)))},children:this.state.selectOptions.map((t=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.DIFFERENT_VALUE?{opacity:.5}:{},children:t.obj?(0,u.jsx)(d.TextWithIcon,{value:t.obj,themeType:this.props.oContext.themeType,lang:d.I18n.getLanguage()}):t.label},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const yt=class extends x{componentDidMount(){super.componentDidMount(),this.props.oContext.socket.getHostByIp(this.props.common.host).then((t=>{this.props.schema.listenOnAllPorts||(t=t.filter((t=>"0.0.0.0"!==t.address&&"::"!==t.address))),this.props.schema.onlyIp4?t=t.filter((t=>"ipv4"===t.family)):this.props.schema.onlyIp6&&(t=t.filter((t=>"ipv6"===t.family))),this.props.schema.noInternal&&(t=t.filter((t=>!t.internal))),t.forEach((t=>{"0.0.0.0"===t.address?t.name="[IPv4] 0.0.0.0 - ".concat(d.I18n.t("ra_Listen on all IPs")):"::"===t.address&&(t.name="[IPv6] :: - ".concat(d.I18n.t("ra_Listen on all IPs")))})),this.setState({ips:t})})).catch((t=>console.error(t)))}renderItem(t,e){var s,i;const o=x.getValue(this.props.data,this.props.attr),a=null===(s=this.state.ips)||void 0===s?void 0:s.find((t=>t.address===o));return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[this.state.ips&&this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,this.state.ips?(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:o,renderValue:t=>(null===a||void 0===a?void 0:a.name)||t,onChange:t=>this.onChange(this.props.attr,t.target.value),children:null===(i=this.state.ips)||void 0===i?void 0:i.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.address,children:t.name},e)))}):(0,u.jsx)(p.TextField,{fullWidth:!0,variant:"standard",error:!!t,disabled:!!e,value:o,onChange:t=>this.onChange(this.props.attr,t.target.value),label:this.getText(this.props.schema.label)}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const bt=class extends x{constructor(){super(...arguments),this.initialized=!1,this.localContext=void 0}componentDidMount(){super.componentDidMount(),this.askInstance()}askInstance(){if(this.props.alive){let e=this.props.schema.data;if(void 0===e&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,null,!0);if(s)try{e=JSON.parse(s)}catch(t){console.error("Cannot parse json data: ".concat(JSON.stringify(e)))}}void 0===e&&(e=null),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",e).then((t=>this.setState({image:t||""})))}}getContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=x.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(){if(this.props.alive){const t=this.getContext();t===this.localContext&&this.initialized||(this.localContext=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}return void 0===this.state.image?null:(0,u.jsx)("img",{alt:"dynamic content",src:this.state.image,style:{width:this.props.schema.width||"100%",height:this.props.schema.height}})}};const Ct=class extends x{constructor(t){super(t),this.index=void 0,this.index=Date.now()}componentDidMount(){if(super.componentDidMount(),this.props.schema.base64){const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t})}else this.props.oContext.socket.fileExists("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.attr).then((t=>t&&this.loadImage()))}_getUrl(t){t&&(this.index=Date.now());let e="files/".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance,"/").concat(this.props.attr,"?t=").concat(this.index);return"3000"===window.location.port&&(e="".concat(window.location.protocol,"//").concat(window.location.hostname,":8081/").concat(e)),e}loadImage(){fetch(this._getUrl()).then((t=>t.blob())).then((t=>{const e=new FileReader;e.onload=()=>{this.setState({value:e.result})},e.readAsDataURL(t)})).catch((t=>console.error(t)))}renderItem(t,e){return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(d.UploadImage,{error:!!t,disabled:e,accept:this.props.schema.accept,crop:this.props.schema.crop,maxSize:this.props.schema.maxSize||262144,icon:this.state.value||void 0,removeIconFunc:()=>this.setState({value:null},(()=>{if(this.props.schema.base64){const t=this.onChange(this.props.attr,this.state.value);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}else this.props.oContext.socket.deleteFile("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.attr).catch((t=>console.error(t)))})),onChange:t=>this.setState({value:t},(()=>{if(this.props.schema.base64){const t=this.onChange(this.props.attr,this.state.value);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}else t.startsWith("data")&&(t=t.split(",")[1]);this.props.oContext.socket.writeFile64("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.attr,t).catch((t=>console.error(t)))}))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},jt={icon:{width:20,height:20,marginRight:4}};const wt=class extends x{constructor(){super(...arguments),this.onInstancesUpdate=(t,e)=>{if(!t.match(/^system\.adapter\.[-_a-z\d]+\.\d+$/))return;const s=this.props.schema.long?t:this.props.schema.short?t.split(".").pop():t.replace(/^system\.adapter\./,""),i=this.state.selectOptions.findIndex((t=>t.value===s));if(e){if("_dataSources"===this.props.schema.adapter&&(!e.common||!e.common.getHistory))return;if(-1===i){const t=JSON.parse(JSON.stringify(this.state.selectOptions)),s="object"===typeof e.common.name?e.common.name[d.I18n.getLanguage()]||e.common.name.en:e.common.name;t.push({value:this.props.schema.long?e._id:this.props.schema.short?e._id.split(".").pop():e._id.replace(/^system\.adapter\./,""),label:"".concat(s," [").concat(e._id.replace(/^system\.adapter\./,""),"]"),icon:"adapter/".concat(s,"/").concat(e.common.icon)}),t.sort(((t,e)=>t.label>e.label?1:t.label<e.label?-1:0)),this.setState({selectOptions:t})}}else if(-1!==i){const t=JSON.parse(JSON.stringify(this.state.selectOptions)),e={};this.state.value===t[i].value&&(e.value=x.NONE_VALUE),t.splice(i,1),e.selectOptions=t,this.setState(e)}}}componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);let e=this.props.schema.adapter;"_dataSources"===e&&(e=void 0),this.props.oContext.socket.getAdapterInstances(e,!0).then((async s=>{"_dataSources"===this.props.schema.adapter?s=s.filter((t=>{var e;return null===t||void 0===t||null===(e=t.common)||void 0===e?void 0:e.getHistory})):this.props.schema.adapter?s=s.filter((t=>null===t||void 0===t?void 0:t._id.startsWith("system.adapter.".concat(this.props.schema.adapter,".")))):this.props.schema.adapters&&Array.isArray(this.props.schema.adapters)&&(s=s.filter((t=>{var e;return this.props.schema.adapters.includes(null===t||void 0===t||null===(e=t.common)||void 0===e?void 0:e.name)}))),this.props.schema.onlyEnabled&&(s=s.filter((t=>{var e;return null===t||void 0===t||null===(e=t.common)||void 0===e?void 0:e.enabled})));const i=s.map((t=>({value:this.props.schema.long?t._id:this.props.schema.short?t._id.split(".").pop():t._id.replace(/^system\.adapter\./,""),label:"".concat(t.common.name," [").concat(t._id.replace(/^system\.adapter\./,""),"]"),icon:"adapter/".concat(t.common.name,"/").concat(t.common.icon)})));i.sort(((t,e)=>t.value>e.value?1:t.value<e.value?-1:0)),!1!==this.props.schema.allowDeactivate&&i.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.props.schema.all&&i.unshift({label:d.I18n.t("sch_all"),value:"*"}),this.setState({value:t||"",selectOptions:i}),await this.props.oContext.socket.subscribeObject("system.adapter.".concat(e?"".concat(e,"."):"","*"),this.onInstancesUpdate)})).catch((t=>console.error("Cannot get instances: ".concat(t))))}componentWillUnmount(){this.props.oContext.socket.unsubscribeObject("system.adapter.*",this.onInstancesUpdate).then((()=>{})),super.componentWillUnmount()}renderItem(t,e){var s;if(!this.state.selectOptions)return null;const i=null===(s=this.state.selectOptions)||void 0===s?void 0:s.find((t=>t.value===this.state.value));return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:this.state.value,renderValue:()=>(0,u.jsxs)("span",{style:{display:"flex"},children:[null!==i&&void 0!==i&&i.icon?(0,u.jsx)("img",{src:"./".concat(i.icon),alt:i.value,style:jt.icon}):null,this.getText(null===i||void 0===i?void 0:i.label,!0)]}),onChange:t=>this.setState({value:t.target.value},(()=>this.onChange(this.props.attr,this.state.value))),children:this.state.selectOptions.map((t=>(0,u.jsxs)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:[t.icon?(0,u.jsx)("img",{src:"./".concat(t.icon),alt:t.value,style:jt.icon}):null,this.getText(t.label,!0)]},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]},this.props.attr)}},It={address:{fontSize:"smaller",opacity:.5,marginLeft:8}};const Tt=class extends x{componentDidMount(){super.componentDidMount(),this.props.oContext.socket.getObject("system.host.".concat(this.props.common.host)).then((t=>{var e,s;const i=[];if(null!==t&&void 0!==t&&null!==(e=t.native)&&void 0!==e&&null!==(s=e.hardware)&&void 0!==s&&s.networkInterfaces){const e=t.native.hardware.networkInterfaces;Object.keys(e).forEach((t=>{if(this.props.schema.ignoreInternal&&!e[t].find((t=>!t.internal)))return;if(this.props.schema.ignoreLoopback&&e[t].find((t=>"127.0.0.1"===t.address||"::1"===t.address)))return;let s=e[t].find((t=>"IPv4"===t.family));s=s||e[t].find((t=>"IPv6"===t.family)),i.push({value:t,address:s.address})}))}this.setState({interfaces:i})})).catch((t=>window.alert("Cannot read interfaces: ".concat(t))))}renderItem(t,e){var s,i,o;const a=x.getValue(this.props.data,this.props.attr),n=null===(s=this.state.interfaces)||void 0===s?void 0:s.find((t=>t.value===a));return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[null!==(i=this.state.interfaces)&&void 0!==i&&i.length&&this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,null!==(o=this.state.interfaces)&&void 0!==o&&o.length?(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:a,renderValue:t=>n?(0,u.jsxs)("span",{children:[n.value,(0,u.jsx)("span",{style:It.address,children:n.address})]}):t,onChange:t=>this.onChange(this.props.attr,t.target.value),children:this.state.interfaces.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.value,children:(0,u.jsxs)("span",{children:[t.value,(0,u.jsx)("span",{style:It.address,children:t.address})]})},e)))}):(0,u.jsx)(p.TextField,{fullWidth:!0,variant:"standard",error:!!t,disabled:!!e,value:a,onChange:t=>this.onChange(this.props.attr,t.target.value),label:this.getText(this.props.schema.label)}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},St={modalDialog:{minWidth:400,maxWidth:800},overflowHidden:{display:"flex",overflow:"hidden"},titleIcon:{marginRight:5},content:{fontSize:16},languageButton:{position:"absolute",right:8,top:8},languageButtonActive:{color:"primary.main"}},Dt=t=>{let{toggleTranslation:e,noTranslation:s,title:a,fullWidth:n,help:r,maxWidth:l,progress:h,icon:m,applyDisabled:g,applyButton:x,onClose:v,children:f,titleButtonApply:y,titleButtonClose:b,onApply:C,textInput:j,defaultValue:w,overflowHidden:I}=t;const[T,S]=(0,o.useState)(w);(0,o.useEffect)((()=>{S(w)}),[w]);let D=null;return m&&(D=m),(0,u.jsxs)(p.Dialog,{open:!0,maxWidth:l||"md",fullWidth:!!n,disableEscapeKeyDown:!1,onClose:v,sx:{"& .MuiPaper-root":St.modalDialog},children:[a&&(0,u.jsxs)(p.DialogTitle,{children:[m?(0,u.jsx)(D,{style:St.titleIcon}):null,a,"en"!==d.I18n.getLanguage()&&e?(0,u.jsx)(p.IconButton,{size:"large",style:(0,i.A)((0,i.A)({},St.languageButton),s?St.languageButtonActive:{}),onClick:()=>e(),title:d.I18n.t("Disable/Enable translation"),children:(0,u.jsx)(c.Language,{})}):null]}),(0,u.jsxs)(p.DialogContent,{sx:(0,i.A)((0,i.A)({},I?St.overflowHidden:{}),St.content),style:{paddingTop:8},children:[j&&(0,u.jsx)(p.TextField,{autoComplete:"off",fullWidth:!0,autoFocus:!0,variant:"outlined",size:"medium",multiline:!0,value:T,onChange:t=>S(t.target.value)}),f,r?(0,u.jsx)("div",{children:r}):null]}),(0,u.jsxs)(p.DialogActions,{children:[!1!==x&&(0,u.jsx)(p.Button,{startIcon:(0,u.jsx)(c.Check,{}),disabled:h||g&&w===T,onClick:()=>C&&C(j?T:""),variant:"contained",color:"primary",children:d.I18n.t(y||"Ok")}),(0,u.jsx)(p.Button,{color:"grey",onClick:()=>v&&v(),disabled:h,variant:"contained",startIcon:(0,u.jsx)(c.Close,{}),children:d.I18n.t(b||"Cancel")})]})]})};var kt=s(2091),Ot=s.n(kt);s(77563),s(78172),s(67244),s(85781),s(21571);const _t={jsonError:{border:"1px solid red",minHeight:200},jsonNoError:{border:"1px solid #00000000",minHeight:200}};const At=function(t){return(0,u.jsx)(Ot(),{style:!0===t.error?_t.jsonError:!1===t.error?_t.jsonNoError:void 0,mode:t.mode||"json",width:"100%",height:"100%",showPrintMargin:t.editValueMode,showGutter:t.editValueMode,highlightActiveLine:t.editValueMode,defaultValue:t.defaultValue,theme:"dark"===t.themeType?"clouds_midnight":"chrome",value:t.value,readOnly:!t.onChange,onChange:e=>t.onChange(e),name:t.name||"UNIQUE_ID_OF_DIV1",fontSize:t.fontSize||14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0,showLineNumbers:t.editValueMode,tabSize:t.editValueMode?2:void 0},editorProps:{$blockScrolling:!0}})},Ft={fullWidth:{width:"100%"},flex:{display:"flex"},button:{height:48,minWidth:48},wrapper:{width:"calc(100vw - 40px)",height:"calc(100vh - 188px)"}};const Nt=class extends x{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=x.getValue(t,e)||{};this.setState({value:s,initialized:!0,jsonError:this.validateJson(s)})}validateJson(t){let e=!1;if(!1!==this.props.schema.validateJson&&(t||!this.props.schema.allowEmpty))try{JSON.parse(t)}catch(s){console.log("Error in JSON",s),e=!0}return e}renderItem(t,e){if(!this.state.initialized)return null;const{schema:s,data:o,attr:a}=this.props,{value:n,showSelectId:r}=this.state;return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[(0,u.jsx)("div",{style:Ft.flex,children:(0,u.jsx)(p.Button,{color:"grey",disabled:e,style:Ft.button,size:"small",variant:"outlined",onClick:()=>this.setState({showSelectId:!0}),children:d.I18n.t("ra_JSON editor")})}),r?(0,u.jsx)(Dt,{title:this.getText(s.label),overflowHidden:!0,onClose:()=>this.setState({showSelectId:!1,value:x.getValue(o,a)||{}}),onApply:()=>this.setState({showSelectId:!1},(()=>this.onChange(a,n))),children:(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},Ft.wrapper),this.state.jsonError?{}:void 0),children:(0,u.jsx)(At,{value:"object"===typeof n?JSON.stringify(n):n,onChange:t=>this.setState({value:t,jsonError:this.validateJson(t)}),name:"ConfigJsonEditor",themeType:this.props.oContext.themeType})})}):null,s.help||this.state.jsonError?(0,u.jsx)(p.FormHelperText,{children:this.state.jsonError?d.I18n.t("ra_Invalid JSON"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},Et=[{value:"en",label:"English"},{value:"de",label:"Deutsch"},{value:"ru",label:"\u0440\u0443\u0441\u0441\u043a\u0438\u0439"},{value:"pt",label:"Portugues"},{value:"nl",label:"Nederlands"},{value:"fr",label:"fran\xe7ais"},{value:"it",label:"Italiano"},{value:"es",label:"Espanol"},{value:"pl",label:"Polski"},{value:"uk",label:"\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0438\u0439"},{value:"zh-cn",label:"\u7b80\u4f53\u4e2d\u6587"}];const Lt=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr),e=[...Et];this.props.schema.system?e.unshift({value:"",label:d.I18n.t("ra_System language")}):e.unshift({value:"",label:d.I18n.t("ra_none")}),this.setState({value:this.props.schema.system?t||"":t||d.I18n.getLanguage(),selectOptions:e})}renderItem(t,e){var s,i;if(!this.state.selectOptions)return null;const o=null===(s=this.state.selectOptions)||void 0===s?void 0:s.find((t=>t.value===this.state.value||!t.value&&!this.state.value));return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:e,value:this.state.value||"_",renderValue:()=>this.getText(null===o||void 0===o?void 0:o.label,this.props.schema.noTranslation),onChange:t=>{let{value:e}=t.target;"_"===e&&(e=""),this.setState({value:e},(()=>{const t=this.onChange(this.props.attr,e);if(t instanceof Promise&&t.catch((t=>console.error(t))),this.props.schema.changeGuiLanguage)if(e){if(e===d.I18n.getLanguage())return;d.I18n.setLanguage(e),this.props.oContext.changeLanguage&&this.props.oContext.changeLanguage()}else this.props.oContext.socket.getSystemConfig().then((t=>{t.common.language!==d.I18n.getLanguage()&&t.common.language&&(d.I18n.setLanguage(t.common.language),this.props.oContext.changeLanguage&&this.props.oContext.changeLanguage())})).catch((t=>console.error("Cannot read system config: ".concat(t))))}))},children:null===(i=this.state.selectOptions)||void 0===i?void 0:i.map((t=>(0,u.jsx)(p.MenuItem,{value:t.value,children:t.label},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const Vt=class extends x{constructor(t){super(t),this.scrollRef=void 0,this.scrollRef=a().createRef()}scrolledDown(){return!!this.scrollRef.current&&this.scrollRef.current.offsetHeight+this.scrollRef.current.scrollTop>=this.scrollRef.current.scrollHeight}componentDidMount(){super.componentDidMount(),x.getValue(this.props.data,this.props.attr)||(this.props.schema.licenseUrl?(this.setState({showLicenseDialog:!0,loading:!0,scrolledDown:!1}),fetch(this.props.schema.licenseUrl).then((t=>t.text())).then((t=>this.setState({license:t,loading:!1}))).catch((t=>this.setState({license:t.toString(),loading:!1,error:!0,scrolledDown:!1})))):this.setState({showLicenseDialog:!0,scrolledDown:!1}),setTimeout((()=>{if(this.scrollRef.current){this.scrolledDown()?this.setState({scrolledDown:!0}):this.scrollRef.current.addEventListener("scroll",(()=>{!this.state.scrolledDown&&this.scrolledDown()&&this.setState({scrolledDown:!0})}))}}),1e3))}renderItem(t,e){return this.state.showLicenseDialog?(0,u.jsxs)(p.Dialog,{maxWidth:"lg",open:!0,onClose:(t,e)=>{"escapeKeyDown"!==e&&"backdropClick"!==e&&this.setState({showLicenseDialog:!1})},children:[(0,u.jsx)(p.DialogTitle,{children:this.props.schema.title?d.I18n.t(this.props.schema.title):d.I18n.t("ra_License agreement")}),(0,u.jsxs)(p.DialogContent,{children:[this.props.schema.licenseUrl?(0,u.jsxs)(u.Fragment,{children:[this.state.loading?(0,u.jsx)(p.LinearProgress,{}):null,(0,u.jsx)("pre",{ref:this.scrollRef,style:{width:"100%",height:"100%",overflowY:"auto",fontSize:14},children:this.state.license})]}):null,!this.props.schema.licenseUrl&&this.props.schema.texts?(0,u.jsx)("div",{ref:this.scrollRef,style:{width:"100%",height:"100%",overflowY:"auto",fontSize:14},children:this.props.schema.texts.map(((t,e)=>this.props.schema.noTranslation?(0,u.jsx)("p",{children:t},e):(0,u.jsx)("p",{children:d.I18n.t(t)},e)))}):null]}),(0,u.jsxs)(p.DialogActions,{children:[this.props.schema.checkBox?(0,u.jsx)(p.FormControlLabel,{control:(0,u.jsx)(p.Checkbox,{disabled:e,checked:!!this.state.licenseChecked,onClick:()=>this.setState({licenseChecked:!this.state.licenseChecked})}),label:d.I18n.t(this.props.schema.checkBox)}):null,(0,u.jsx)(p.Button,{disabled:e||this.state.loading||this.state.error||this.props.schema.checkBox&&!this.state.licenseChecked||!this.state.scrolledDown,onClick:()=>{this.setState({showLicenseDialog:!1});const t=this.onChange(this.props.attr,!0);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))},color:"primary",variant:"contained",startIcon:(0,u.jsx)(c.Check,{}),children:this.props.schema.agreeText?d.I18n.t(this.props.schema.agreeText):d.I18n.t("ra_Accept license")}),(0,u.jsx)(p.Button,{onClick:()=>{this.setState({showLicenseDialog:!1}),setTimeout((()=>this.setState({showLicenseDialog:!0})),2e3)},color:"grey",variant:"contained",startIcon:(0,u.jsx)(c.Close,{}),children:d.I18n.t("ra_Close")})]})]}):null}},Pt={indeterminate:{opacity:.5},control:{flexDirection:"row",width:"100%"}};const Wt=class extends x{constructor(){super(...arguments),this.updateTimeout=void 0}componentDidMount(){super.componentDidMount();let t=x.getValue(this.props.data,this.props.attr);if(null!==t&&void 0!==t||(t=""),Array.isArray(t)&&this.props.oContext.multiEdit)return t=x.DIFFERENT_VALUE,void this.setState({_value:t,oldValue:t});this.setState({_value:t.toString(),oldValue:t.toString()})}static getDerivedStateFromProps(t,e){if(void 0!==t.schema.min&&t.schema.min<0||void 0!==t.schema.max&&t.schema.max<0)return null;const s=x.getValue(t.data,t.attr);return t.oContext.multiEdit&&e._value===x.DIFFERENT_VALUE?{_value:x.DIFFERENT_VALUE}:null===s||void 0===s||null===e.oldValue||void 0===e.oldValue||s.toString()!==parseFloat(e._value).toString()&&s.toString()!==e.oldValue.toString()?{_value:s}:null}checkValue(t){if(null===t||void 0===t)return null;const e=""===(t=t.toString().trim())?0:parseFloat(t);return""!==t&&Number.isNaN(e)?"ra_Not a number":""!==t&&window.isFinite(e)?void 0!==this.props.schema.min&&e<this.props.schema.min?"ra_Too small":void 0!==this.props.schema.max&&e>this.props.schema.max?"ra_Too big":""===t||"-"===t||Number.isNaN(e)?"ra_Not a number":null:"ra_Not a number"}renderItem(t,e){const s=Array.isArray(this.state._value)||this.state._value===x.DIFFERENT_VALUE;if(null!==this.state.oldValue&&void 0!==this.state.oldValue?(this.updateTimeout&&clearTimeout(this.updateTimeout),this.updateTimeout=setTimeout((()=>{this.updateTimeout=void 0,this.setState({oldValue:null})}),30)):this.updateTimeout&&(clearTimeout(this.updateTimeout),this.updateTimeout=void 0),s){const s=x.getValue(this.props.data,this.props.attr),o=(null===s||void 0===s?void 0:s.filter((t=>t||0===t)).map((t=>({label:t.toString(),value:t}))))||[];return o.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),(0,u.jsx)(p.Autocomplete,{style:Pt.indeterminate,fullWidth:!0,freeSolo:!0,value:o[0],getOptionSelected:(t,e)=>t.label===e.label,onChange:(t,e)=>{const s=this.onChange(this.props.attr,null===e||void 0===e?void 0:e.value,(()=>{this.setState({_value:null===e||void 0===e?void 0:e.value,oldValue:this.state._value})}));s instanceof Promise&&s.catch((t=>console.error(t)))},options:o,getOptionLabel:t=>t.label,renderInput:s=>(0,u.jsx)(p.TextField,(0,i.A)((0,i.A)({},s),{},{label:this.getText(this.props.schema.label),variant:"standard",slotProps:{htmlInput:(0,i.A)((0,i.A)({},s.inputProps),{},{readOnly:this.props.schema.readOnly||!1}),input:{endAdornment:this.props.schema.unit?this.getText(this.props.schema.unit,this.props.schema.noTranslation):void 0}},error:!!t,placeholder:this.getText(this.props.schema.placeholder),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),disabled:!!e}))})}return!t&&null!==this.state._value&&void 0!==this.state._value&&this.state._value&&(t=this.checkValue(this.state._value))&&(t=d.I18n.t(t)),(0,u.jsx)(p.FormControl,{variant:"standard",style:Pt.control,children:(0,u.jsx)(p.TextField,{variant:"standard",type:"number",fullWidth:!0,slotProps:{htmlInput:{min:this.props.schema.min,max:this.props.schema.max,step:this.props.schema.step,readOnly:this.props.schema.readOnly||!1},input:{endAdornment:this.props.schema.unit?this.getText(this.props.schema.unit,this.props.schema.noTranslation):void 0}},value:null===this.state._value||void 0===this.state._value?"":this.state._value,error:!!t,disabled:!!e,onChange:t=>{const e=t.target.value,s=this.checkValue(e);s?this.onError(this.props.attr,d.I18n.t(s)):this.onError(this.props.attr),this.setState({_value:e,oldValue:this.state._value},(()=>this.onChange(this.props.attr,parseFloat(e))))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:t&&"string"===typeof t?t:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})})}},Ut={flex:{display:"flex"},button:{height:48,marginLeft:4,minWidth:48}};const Bt=class extends x{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=x.getValue(t,e)||"";this.setState({value:s,initialized:!0})}renderItem(t,e){if(!this.state.initialized)return null;const s=this.props.oContext.socket,{schema:i,attr:o}=this.props,{value:a,showSelectId:n}=this.state;return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[i.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(i.label)}):null,(0,u.jsxs)("div",{style:Ut.flex,children:[(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:a,error:!!t,disabled:e,placeholder:this.getText(i.placeholder),label:this.getText(i.label),helperText:this.renderHelp(i.help,i.helpLink,i.noTranslation),onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(o,e)))}}),(0,u.jsx)(p.Button,{color:"grey",disabled:e,style:Ut.button,size:"small",variant:"outlined",onClick:()=>this.setState({showSelectId:!0}),children:"..."})]}),n?(0,u.jsx)(d.DialogSelectID,{imagePrefix:void 0===this.props.oContext.imagePrefix?"../..":this.props.oContext.imagePrefix,dialogName:"admin.".concat(this.props.oContext.adapterName),filterFunc:i.filterFunc,themeType:this.props.oContext.themeType,theme:this.props.oContext.theme,types:i.types?Array.isArray(i.types)?i.types:[i.types]:void 0,customFilter:i.customFilter,filters:i.filters,socket:s,selected:a,root:i.root,onClose:()=>this.setState({showSelectId:!1}),onOk:t=>this.setState({showSelectId:!1,value:t},(()=>this.onChange(o,t)))}):null]})}},Rt={fullWidth:{width:"100%",display:"inline-block"},halfWidth1:{width:"calc(50% - 5px)",display:"inline-block",marginRight:8},halfWidth2:{width:"calc(50% - 5px)",display:"inline-block"}},Mt="____ppp____";const Jt=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({_repeat:t?Mt:"",_visible:!1,value:t?Mt:"",_notEqual:!1})}onChangePassword(t,e){void 0===t&&(t=this.state.value),void 0===e&&(e=this.state._repeat);const s=!!this.props.schema.repeat&&e!==t;this.setState({value:t,_repeat:e,_notEqual:s},(()=>{if(s)this.onError(this.props.attr,d.I18n.t("ra_Passwords are not equal!"));else{this.onError(this.props.attr);const e=this.onChange(this.props.attr,t);e instanceof Promise&&e.catch((t=>this.onError(this.props.attr,t)))}}))}renderItem(t,e){if(void 0===this.state._notEqual)return null;const s=(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,type:this.state._visible&&this.state.value!==Mt?"text":"password",value:this.state.value,error:!!t||this.state._notEqual,disabled:!!e,onChange:t=>this.onChangePassword(t.target.value),label:this.getText(this.props.schema.label),slotProps:{input:{autoComplete:"new-password",endAdornment:this.state.value&&this.state.value!==Mt&&this.props.schema.visible&&!e&&!this.props.schema.readOnly?(0,u.jsx)(p.InputAdornment,{position:"end",children:(0,u.jsx)(p.IconButton,{size:"large",tabIndex:-1,onClick:t=>{t.preventDefault(),t.stopPropagation(),this.setState({_visible:!this.state._visible})},edge:"end",children:this.state._visible?(0,u.jsx)(c.VisibilityOff,{}):(0,u.jsx)(c.Visibility,{})})}):void 0},htmlInput:{autoComplete:"new-password",form:{autoComplete:"off"},maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:this.props.schema.readOnly||!1}},helperText:this.state._notEqual?d.I18n.t("ra_Passwords are not equal!"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)});if(this.props.schema.repeat&&!this.props.schema.readOnly){const i=this.state._visible?null:(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,type:"password",value:this.state._repeat,error:!!t||this.state._notEqual,disabled:!!e,onChange:t=>this.onChangePassword(void 0,t.target.value),label:"".concat(this.getText(this.props.schema.label)," (").concat(d.I18n.t("ra_repeat"),")"),slotProps:{input:{autoComplete:"new-password"},htmlInput:{autoComplete:"new-password",form:{autoComplete:"off"},maxLength:this.props.schema.maxLength||this.props.schema.max||void 0}},helperText:this.state._notEqual?d.I18n.t("ra_Passwords are not equal!"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)});return(0,u.jsxs)("div",{style:Rt.fullWidth,children:[(0,u.jsx)("div",{style:Rt.halfWidth1,children:s}),(0,u.jsx)("div",{style:Rt.halfWidth2,children:i})]})}return s}};const zt=class extends x{renderItem(t,e){return(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,disabled:!!e,slotProps:{input:{endAdornment:this.props.schema.copyToClipboard?(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>{d.Utils.copyToClipboard(this.getPattern(this.props.schema.pattern,null,this.props.schema.noTranslation)),window.alert(d.I18n.t("ra_Copied"))},children:(0,u.jsx)(d.IconCopy,{})}):void 0}},value:this.getPattern(this.props.schema.pattern,null,!0),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},Ht={warning:{"& .Mui-error":{color:"orange"}}};const qt=class extends x{constructor(){super(...arguments),this.updateTimeout=void 0}async componentDidMount(){super.componentDidMount();let t=x.getValue(this.props.data,this.props.attr);null!==t&&void 0!==t||(t=""),this.setState({_value:t.toString(),oldValue:t.toString()});const e=await this.props.oContext.socket.getAdapterInstances(),s="system.adapter.".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),i=await this.props.oContext.socket.getObject(s),o=null===i||void 0===i?void 0:i.common.host,a=[];e.forEach((t=>{var e,i;if(!t||t._id===s||t.common.host!==o)return;if(null===(e=t.native)||void 0===e||!e.bind)return;if(null!==t&&void 0!==t&&t.native&&t.native.secure&&t.native.leEnabled&&t.native.leUpdate){const e=parseInt(t.native.leCheckPort||t.native.lePort,10);var n;if(e)a.push({name:"".concat(t._id.replace("system.adapter.","")," (LE)"),port:e,v6bind:t.native.bind.includes(":")?t.native.bind:t.native.v6bind,bind:t.native.bind,enabled:!(null===(n=t.common)||void 0===n||!n.enabled)})}const r=parseInt(null===t||void 0===t||null===(i=t.native)||void 0===i?void 0:i.port,10);var l;r&&a.push({name:t._id.replace("system.adapter.",""),bind:t.native.bind,v6bind:t.native.bind.includes(":")?t.native.bind:t.native.v6bind,port:r,enabled:!(null===(l=t.common)||void 0===l||!l.enabled)})})),this.setState({ports:a})}static getDerivedStateFromProps(t,e){const s=x.getValue(t.data,t.attr);return null===s||void 0===s||null===e.oldValue||void 0===e.oldValue||s.toString()!==parseInt(e._value,10).toString()&&s.toString()!==e.oldValue.toString()?{_value:s}:null}checkValue(t){if(null===t||void 0===t)return null;const e=void 0===this.props.schema.min?20:this.props.schema.min,s=this.props.schema.max||65535,i=""===(t=t.toString().trim())?0:parseInt(t,10);return""!==t&&Number.isNaN(i)?"ra_Not a number":""!==t&&window.isFinite(Number(t))?i<e?"ra_Too small":i>s?"ra_Too big":""===t||"-"===t||Number.isNaN(i)?"ra_Not a number":null:"ra_Not a number"}renderItem(t,e){null!==this.state.oldValue&&void 0!==this.state.oldValue?(this.updateTimeout&&clearTimeout(this.updateTimeout),this.updateTimeout=setTimeout((()=>{this.updateTimeout=void 0,this.setState({oldValue:null})}),30)):this.updateTimeout&&(clearTimeout(this.updateTimeout),this.updateTimeout=void 0);const s=void 0===this.props.schema.min?20:this.props.schema.min,i=this.props.schema.max||65535;let o;if(this.state.ports){const e=parseInt(this.state._value,10);if(e){const s=this.state.ports.filter((t=>!this.props.data.bind||this.props.data.bind===t.bind||"0.0.0.0"===this.props.data.bind||"0.0.0.0"===t.bind));let i=s.findIndex((t=>t.port===e&&t.enabled));-1!==i?t=d.I18n.t("ra_Port is already used by %s",this.state.ports[i].name):(i=s.findIndex((t=>t.port===e&&!t.enabled)),-1!==i&&(o=!0,t=d.I18n.t("ra_Port could be used by %s",this.state.ports[i].name)))}}return t||null===this.state._value||void 0===this.state._value||"string"===typeof(t=this.checkValue(this.state._value))&&(t=d.I18n.t(t)),(0,u.jsx)(p.TextField,{variant:"standard",type:"number",fullWidth:!0,slotProps:{htmlInput:{min:s,max:i,readOnly:this.props.schema.readOnly||!1}},value:null===this.state._value||void 0===this.state._value?"":this.state._value,error:!!t,disabled:!!e,sx:o?Ht.warning:void 0,onChange:t=>{const e=Number(t.target.value.toString().replace(/[^0-9]/g,"")).toString(),s=this.checkValue(e);s?this.onError(this.props.attr,d.I18n.t(s)):this.onError(this.props.attr),this.setState({_value:e,oldValue:this.state._value},(()=>{if(e.trim()===parseInt(e,10).toString()){const t=this.onChange(this.props.attr,parseInt(e,10)||0);t instanceof Promise&&t.catch((t=>{console.error("Cannot set value for ".concat(this.props.attr,": ").concat(t))}))}}))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:t&&"string"===typeof t?t:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}};const Kt=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.props.oContext.socket.getEnums("rooms").then((e=>{const s=Object.keys(e).map((t=>({value:this.props.schema.short?t.replace("enum.rooms.",""):t,label:this.getText(e[t].common.name),obj:e[t]})));!1!==this.props.schema.allowDeactivate&&s.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.setState({value:t,selectOptions:s})})).catch((t=>console.error("Cannot get enums: ".concat(t))))}renderItem(t,e){if(!this.state.selectOptions)return null;const s=this.state.selectOptions.find((t=>t.value===this.state.value));return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>s?s.obj?(0,u.jsx)(d.TextWithIcon,{value:s.obj,themeType:this.props.oContext.themeType,lang:d.I18n.getLanguage()}):s.label:"",onChange:t=>{this.setState({value:"_"===t.target.value?"":t.target.value},(()=>this.onChange(this.props.attr,this.state.value)))},children:this.state.selectOptions.map((t=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.DIFFERENT_VALUE?{opacity:.5}:{},children:t.obj?(0,u.jsx)(d.TextWithIcon,{value:t.obj,themeType:this.props.oContext.themeType,lang:d.I18n.getLanguage()}):t.label},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},$t={fullWidth:{width:"100%"},noMargin:{"&>div":{marginTop:0}}};const Gt=class extends x{constructor(){super(...arguments),this.initialValue=""}componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr),e=[];(this.props.schema.options||[]).forEach((t=>{const s=t;Array.isArray(s.items)?(e.push({label:this.getText(t.label),value:t.value,group:!0}),s.items.forEach((t=>e.push({label:this.getText(t.label),value:t.value,hidden:t.hidden})))):e.push({label:this.getText(t.label),value:t.value,hidden:t.hidden})})),Array.isArray(t)?(this.initialValue=[...t],e.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),this.setState({value:x.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}renderItem(t,e){if(!this.state.selectOptions)return null;const s=(this.state.selectOptions||[]).filter((t=>!t.hidden||(this.props.custom?!this.executeCustom(t.hidden,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):!this.execute(t.hidden,this.props.schema.default,this.props.data,this.props.arrayIndex,this.props.globalData)))),i=s.find((t=>t.value==this.state.value));return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,sx:void 0!==this.props.table&&$t.noMargin,id:"jsonSelect_".concat(this.props.attr,"_").concat(this.props.index||0===this.props.index?this.props.index:""),children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>this.getText(null===i||void 0===i?void 0:i.label,this.props.schema.noTranslation),onChange:t=>{this.setState({value:"_"===t.target.value?"":t.target.value},(()=>{let t;t=this.state.value===x.DIFFERENT_VALUE?this.onChange(this.props.attr,this.initialValue):this.onChange(this.props.attr,this.state.value),t instanceof Promise&&t.catch((t=>console.error(t)))}))},children:s.map(((t,e)=>t.group?(0,u.jsx)(p.ListSubheader,{children:this.getText(t.label,this.props.schema.noTranslation)},e):(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.DIFFERENT_VALUE?{opacity:.5}:{},children:this.getText(t.label,this.props.schema.noTranslation)},e)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},Yt={menuPaper:{maxHeight:800}};const Zt=class extends x{constructor(){super(...arguments),this.initialized=!1,this.localContext=void 0}askInstance(){if(this.props.alive){let e=this.props.schema.data;if(void 0===e&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,null,!0);try{e=JSON.parse(s)}catch(t){console.error("Cannot parse json data: ".concat(s))}}void 0===e&&(e=null),this.setState({running:!0},(()=>{this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",e).then((t=>this.setState({list:t,running:!1}))).catch((t=>{console.error("Cannot send command: ".concat(t))}))}))}else{const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t,running:!1})}}getContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=x.getValue(this.props.data,e))),JSON.stringify(t)}_getValue(){let t=null===this.state.value||void 0===this.state.value?x.getValue(this.props.data,this.props.attr):this.state.value;return this.props.schema.multiple&&("string"===typeof t?t=[t]:null!==t&&void 0!==t||(t=[])),t}renderItem(t,e){var s;if(this.props.alive){const t=this.getContext();t===this.localContext&&this.initialized||(this.localContext=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}const i=this._getValue();if(!this.props.alive||!this.state.running&&(null===(s=this.state.list)||void 0===s||!s.length))return this.props.schema.multiple||!1===this.props.schema.manual?d.I18n.t("ra_Cannot retrieve options, as instance is offline"):(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:i,error:!!t,disabled:!!e,onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,(e||"").trim())))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),slotProps:{input:{endAdornment:this.state.value&&!this.props.schema.noClearButton?(0,u.jsx)(p.InputAdornment,{position:"end",children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.setState({value:""},(()=>this.onChange(this.props.attr,""))),children:(0,u.jsx)(c.Close,{})})}):null}}});if(this.state.running)return(0,u.jsx)(p.CircularProgress,{size:"24"});const o=this.state.list.filter((t=>!t.hidden||(this.props.custom?!this.executeCustom(t.hidden,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):!this.execute(t.hidden,this.props.schema.default,this.props.data,this.props.arrayIndex,this.props.globalData)))),a=o.find((t=>t.value===i));return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,multiple:this.props.schema.multiple,disabled:!!e,sx:{"&.MuiSelect-paper":this.props.schema.multiple?Yt.menuPaper:void 0},value:i,renderValue:t=>this.props.schema.multiple?(0,u.jsx)(p.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:t.map((t=>{const e=o.find((e=>e.value===t));if(e||!1!==this.props.schema.showAllValues){const s=(null===e||void 0===e?void 0:e.label)||t;return(0,u.jsx)(p.Chip,{label:s},t)}return null}))}):(null===a||void 0===a?void 0:a.label)||t,onChange:t=>{const e=this.onChange(this.props.attr,t.target.value);e instanceof Promise&&e.catch((t=>console.error("Cannot set value: ".concat(t))))},children:o.map(((t,e)=>(0,u.jsxs)(p.MenuItem,{value:t.value,children:[this.props.schema.multiple?(0,u.jsx)(p.Checkbox,{checked:i.includes(t.value),onClick:()=>{const e=JSON.parse(JSON.stringify(this._getValue())),s=i.indexOf(t.value);-1!==s?e.splice(s,1):(e.push(t.value),e.sort()),this.setState({value:e},(()=>this.onChange(this.props.attr,e)))}}):null,(0,u.jsx)(p.ListItemText,{primary:t.label})]},e)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},Qt={fullWidth:{width:"100%"}};function Xt(t){return t.split(".").reduce(((t,e)=>(t<<8)+parseInt(e,10)),0)>>>0}const te=class extends x{async componentDidMount(){super.componentDidMount();let t=window.location.hostname;if(this.props.schema.openUrl){const s=await this.props.oContext.socket.getCurrentInstance(),i=await this.props.oContext.socket.getObject("system.adapter.".concat(s));if(i){var e;const s=await this.props.oContext.socket.getObject("system.host.".concat(null===i||void 0===i||null===(e=i.common)||void 0===e?void 0:e.host));if(s){const e=function(t,e){var s,i;const o=null===t||void 0===t||null===(s=t.native)||void 0===s||null===(i=s.hardware)||void 0===i?void 0:i.networkInterfaces;if(!o)return null;let a;return Object.keys(o).forEach((t=>o[t].forEach((t=>{t.internal||e.includes(":")&&"IPv6"!==t.family||e.includes(".")&&!e.match(/[^.\d]/)&&"IPv4"!==t.family||("IPv4"!==t.family||t.address.startsWith("172")||"127.0.0.0"!==e&&"localhost"!==e&&!e.match(/[^.\d]/)?a||("IPv4"===t.family&&e.includes(".")&&(Xt(e),Xt(t.netmask),Xt(t.address),Xt(t.netmask)),a=t.address):a=t.address)})))),a||Object.keys(o).forEach((t=>o[t].forEach((t=>{t.internal||e.includes(":")&&"IPv6"!==t.family||e.includes(".")&&!e.match(/[^.\d]/)&&"IPv4"!==t.family||("IPv6"!==t.family||"127.0.0.0"!==e&&"localhost"!==e&&!e.match(/[^.\d]/)?a||("IPv4"===t.family&&e.includes(".")&&(Xt(e),Xt(t.netmask),Xt(t.address),Xt(t.netmask)),a=t.address):a=t.address)})))),a||Object.keys(o).forEach((t=>{o[t].forEach((t=>{t.internal||e.includes(":")&&"IPv6"!==t.family||e.includes(".")&&!e.match(/[^.\d]/)&&"IPv4"!==t.family||("127.0.0.0"===e||"localhost"===e||e.match(/[^.\d]/),a=t.address)}))})),a||Object.keys(o).forEach((t=>{o[t].forEach((t=>{t.internal||(a=t.address)}))})),a}(s,window.location.hostname);if(!e)return void console.warn("Cannot find suitable IP in host ".concat(i.common.host," for ").concat(i._id));t="".concat(e,":").concat(window.location.port)}}}await new Promise((e=>{this.setState({_error:"",_message:"",hostname:t},e)})),this.props.schema.onLoaded&&this._onClick()}renderErrorDialog(){return this.state._error?(0,u.jsx)(d.DialogError,{text:this.state._error,onClose:()=>this.setState({_error:""})}):null}renderMessageDialog(){return this.state._message?(0,u.jsx)(d.DialogMessage,{text:this.state._message,onClose:()=>this.setState({_message:""})}):null}_onClick(){this.props.oContext.onCommandRunning(!0),this.setState({running:!0});const t="".concat(window.location.protocol,"//").concat(window.location.host).concat(window.location.pathname.replace(/\/index\.html$/,"")),e="".concat(window.location.protocol,"//").concat(this.state.hostname.split(":").length>3?"[".concat(this.state.hostname,"]"):this.state.hostname).concat(window.location.pathname.replace(/\/index\.html$/,""));let s,o=this.props.schema.data;if(void 0===o&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,(0,i.A)({_origin:t,_originIp:e},this.props.data),!0);try{o=JSON.parse(s)}catch(a){console.error("Cannot parse json data: ".concat(s))}}void 0===o&&(o=null),this.props.schema.openUrl&&!o&&(o={_origin:t,_originIp:e}),this.props.schema.timeout&&(s=setTimeout((()=>{this.props.oContext.onCommandRunning(!1),this.setState({_error:d.I18n.t("ra_Request timed out"),running:!1})}),parseInt(this.props.schema.timeout,10)||1e4)),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",o).then((async t=>{if(s&&(clearTimeout(s),s=void 0),null!==t&&void 0!==t&&t.error)if(this.props.schema.error&&this.props.schema.error[t.error]){let e=this.getText(this.props.schema.error[t.error]);t.args&&t.args.forEach((t=>e=e.replace("%s",t))),this.setState({_error:e})}else this.setState({_error:t.error?d.I18n.t(t.error):d.I18n.t("ra_Error")});else{if(null!==t&&void 0!==t&&t.command)return void(this.props.oContext.onBackEndCommand&&this.props.oContext.onBackEndCommand(t.command));if(null!==t&&void 0!==t&&t.reloadBrowser&&this.props.schema.reloadBrowser)window.location.reload();else if(null!==t&&void 0!==t&&t.openUrl&&this.props.schema.openUrl)window.open(t.openUrl,t.window||this.props.schema.window||"_blank");else if(null!==t&&void 0!==t&&t.result&&this.props.schema.result&&this.props.schema.result[t.result]){let e=this.getText(this.props.schema.result[t.result]);t.args&&t.args.forEach((t=>e=e.replace("%s",t))),window.alert(e)}if(null!==t&&void 0!==t&&t.native&&this.props.schema.useNative){for(const[e,s]of Object.entries(t.native))await this.onChangeAsync(e,s);setTimeout((()=>this.props.oContext.forceUpdate(Object.keys(t.native),this.props.data)),300)}else null!==t&&void 0!==t&&t.result?window.alert("object"===typeof t.result?JSON.stringify(t.result):t.result):window.alert(d.I18n.t("ra_Ok"));null!==t&&void 0!==t&&t.saveConfig&&this.props.onChange(null,null,null,!0)}})).catch((t=>{this.props.schema.error&&this.props.schema.error[t.toString()]?this.setState({_error:this.getText(this.props.schema.error[t.toString()])}):this.setState({_error:d.I18n.t(t.toString())||d.I18n.t("ra_Error")})})).then((()=>{this.props.oContext.onCommandRunning(!1),this.setState({running:!1})}))}renderDialogConfirm(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,u.jsx)(c.Warning,{}):"error"===t.type?e=(0,u.jsx)(c.Error,{}):"info"===t.type&&(e=(0,u.jsx)(c.Info,{})),(0,u.jsx)(d.DialogConfirm,{title:this.getText(t.title)||d.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||d.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||d.I18n.t("ra_Cancel"),icon:e||void 0,onClose:t=>this.setState({confirmDialog:!1},(()=>t&&this._onClick()))})}renderItem(t,e){const s=this.getIcon();return(0,u.jsxs)("div",{style:Qt.fullWidth,children:[(0,u.jsxs)(p.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:(0,i.A)((0,i.A)({},Qt.fullWidth),this.props.schema.controlStyle||void 0),disabled:e||!this.props.alive,startIcon:s,title:this.props.alive?this.getText(this.props.schema.title)||"":d.I18n.t("ra_Instance is not alive"),onClick:()=>{this.props.schema.confirm?this.setState({confirmDialog:!0}):this._onClick()},children:[this.props.schema.showProcess&&this.state.running?(0,u.jsx)(p.CircularProgress,{size:20,style:{marginRight:8}}):null,this.getText(this.props.schema.label,this.props.schema.noTranslation)]}),this.renderErrorDialog(),this.renderMessageDialog()]})}},ee={fullWidth:{width:"100%"},icon:{width:24,height:24,marginRight:4}};const se=class extends x{async _onClick(){let t=this.props.schema.val;if("string"===typeof t&&t.includes("${")){var e,s;t=this.getPattern(t,null,!0);const i=await this.props.oContext.socket.getObject(this.props.schema.id);"number"===(null===i||void 0===i||null===(e=i.common)||void 0===e?void 0:e.type)?t=parseFloat(t):"boolean"===(null===i||void 0===i||null===(s=i.common)||void 0===s?void 0:s.type)&&(t="true"===t||!0===t||"1"===t||1===t)}const i=(this.props.schema.id||"").replace(/%INSTANCE%/g,(this.props.oContext.instance||0).toString());try{await this.props.oContext.socket.setState(i,{val:t,ack:!!this.props.schema.ack}),this.props.schema.okText&&window.alert(this.getText(this.props.schema.okText))}catch(o){this.props.schema.error&&this.props.schema.error[o.toString()]?window.alert(this.getText(this.props.schema.error[o.toString()])):window.alert(d.I18n.t(o.toString())||d.I18n.t("ra_Error"))}}renderDialogConfirm(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,u.jsx)(c.Warning,{}):"error"===t.type?e=(0,u.jsx)(c.Error,{}):"info"===t.type&&(e=(0,u.jsx)(c.Info,{})),(0,u.jsx)(d.DialogConfirm,{title:this.getText(t.title)||d.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||d.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||d.I18n.t("ra_Cancel"),icon:e,onClose:t=>this.setState({confirmDialog:!1},(()=>t&&this._onClick()))})}renderItem(t,e){return(0,u.jsxs)(p.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:ee.fullWidth,disabled:e,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0}):await this._onClick()},children:[this.props.schema.icon?(0,u.jsx)(d.Icon,{src:this.props.schema.icon,style:ee.icon}):null,this.getText(this.props.schema.label,this.props.schema.noTranslation)]})}},ie={fullWidth:{width:"100%"},slider:{marginLeft:10,marginRight:10,width:"calc(100% - 20px)"}};const oe=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({_value:t})}static getDerivedStateFromProps(t,e){if(void 0!==t.schema.min&&t.schema.min<0||void 0!==t.schema.max&&t.schema.max<0)return null;const s=x.getValue(t.data,t.attr);return null===s||void 0===s||s.toString()!==parseFloat(e._value).toString()?{_value:s}:null}renderItem(t,e){const s=this.props.schema.min||0,i=this.props.schema.max||100,o=this.props.schema.unit?this.getText(this.props.schema.unit,this.props.schema.noTranslation):"",a=[{value:s,label:s+o},{value:i,label:i+o}];return(0,u.jsxs)(p.Box,{style:ie.fullWidth,children:[this.props.schema.label?(0,u.jsx)(p.Typography,{gutterBottom:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Slider,{style:ie.slider,value:this.state._value,getAriaValueText:t=>t+o,step:this.props.schema.step||(i-s)/100,valueLabelDisplay:"auto",marks:a,min:s,max:i,disabled:!!e,onChange:t=>{const e=t.target.value;this.setState({_value:e},(()=>this.onChange(this.props.attr,e)))}}),this.props.schema.help?(0,u.jsx)(p.Typography,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};function ae(t,e){return"edit"===t||"rename"===t?(0,u.jsx)(c.Edit,{style:e}):"delete"===t?(0,u.jsx)(c.Delete,{style:e}):"refresh"===t?(0,u.jsx)(c.Refresh,{style:e}):"newDevice"===t||"new"===t||"add"===t?(0,u.jsx)(c.Add,{style:e}):"discover"===t||"search"===t?(0,u.jsx)(c.Search,{style:e}):"unpairDevice"===t||"unpair"===t?(0,u.jsx)(c.LinkOff,{style:e}):"pairDevice"===t||"pair"===t?(0,u.jsx)(c.Link,{style:e}):"identify"===t?(0,u.jsx)(c.NotListedLocation,{style:e}):"play"===t?(0,u.jsx)(c.PlayArrow,{style:e}):"stop"===t?(0,u.jsx)(c.Stop,{style:e}):"pause"===t?(0,u.jsx)(c.Pause,{style:e}):"forward"===t||"next"===t?(0,u.jsx)(c.FastForward,{style:e}):"rewind"===t||"previous"===t?(0,u.jsx)(c.FastRewind,{style:e}):"lamp"===t||"light"===t?(0,u.jsx)(c.Lightbulb,{style:e}):"backlight"===t?(0,u.jsx)(c.Fluorescent,{style:e}):"dimmer"===t?(0,u.jsx)(c.WbIncandescent,{style:e}):"socket"===t?(0,u.jsx)(c.Power,{style:e}):"settings"===t?(0,u.jsx)(c.Settings,{style:e}):"users"===t||"group"===t?(0,u.jsx)(c.Group,{style:e}):"user"===t?(0,u.jsx)(c.Person,{style:e}):"qrcode"===t?(0,u.jsx)(c.QrCode,{style:e}):"connection"===t?(0,u.jsx)(c.Wifi,{style:e}):"no-connection"===t?(0,u.jsx)(c.WifiOff,{style:e}):"visible"===t?(0,u.jsx)(c.Visibility,{style:e}):null}const ne=class extends x{constructor(){super(...arguments),this.controlTimeout=null,this.delayedUpdate={timer:null,value:null},this.onStateChanged=(t,e)=>{let s=e?e.val:null;"button"===this.state.controlType||"switch"===this.state.controlType?(s=!!s,this.state.stateValue!==s&&this.setState({stateValue:s})):null===s||"slider"!==this.state.controlType&&"number"!==this.state.controlType?this.state.stateValue.toString()!==s.toString()&&this.setState({stateValue:s}):(s=parseFloat(s),console.log("".concat(Date.now()," Received new value: ").concat(s)),s!==this.state.stateValue?(this.delayedUpdate.timer&&(clearTimeout(this.delayedUpdate.timer),this.delayedUpdate.timer=null),this.delayedUpdate.value=s,this.delayedUpdate.timer=setTimeout((()=>{this.setState({stateValue:this.delayedUpdate.value})}),500)):this.delayedUpdate.timer&&(clearTimeout(this.delayedUpdate.timer),this.delayedUpdate.timer=null))}}getObjectID(){return this.props.schema.foreign?this.props.schema.oid:"".concat(this.props.schema.system?"system.adapter.":"").concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance,".").concat(this.props.schema.oid)}async componentDidMount(){super.componentDidMount();const t=await this.props.oContext.socket.getObject(this.getObjectID()),e=this.props.schema.control||this.detectType(t),s=await this.props.oContext.socket.getState(this.getObjectID());this.setState({stateValue:s?s.val:null,controlType:e,obj:t},(async()=>{await this.props.oContext.socket.subscribeState(this.getObjectID(),this.onStateChanged)}))}componentWillUnmount(){super.componentWillUnmount(),this.props.oContext.socket.unsubscribeState(this.getObjectID(),this.onStateChanged),this.delayedUpdate.timer&&(clearTimeout(this.delayedUpdate.timer),this.delayedUpdate.timer=null),this.controlTimeout&&(clearTimeout(this.controlTimeout),this.controlTimeout=null,this.props.oContext.socket.setState(this.getObjectID(),this.state.stateValue,!1).catch((t=>console.error("Cannot control value: ".concat(t)))))}detectType(t){if((t=t||{}).common=t.common||{},"boolean"===t.common.type){if(!1!==this.props.schema.controlled){if(!1===t.common.read||!0===this.props.schema.controlled)return"button";if(t.common.write||!0===this.props.schema.controlled)return"switch"}return"text"}return"number"===t.common.type&&!1!==this.props.schema.controlled?t.common.write||!0===this.props.schema.controlled?void 0!==t.common.max?"slider":"input":"text":t.common.write&&!1!==this.props.schema.controlled?"input":"text"}renderItem(t,e){if(!this.state.obj)return null;let s;if("button"===this.state.controlType){let t=null;this.props.schema.falseImage&&(t=ae(this.props.schema.falseImage));const i=this.getText(this.props.schema.falseText||this.props.schema.label,this.props.schema.noTranslation);s=!i&&t?(0,u.jsx)(p.IconButton,{style:this.props.schema.falseTextStyle,disabled:!!this.props.schema.readOnly,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.oContext.socket.setState(this.getObjectID(),!0,!1)}}):await this.props.oContext.socket.setState(this.getObjectID(),!0,!1)},children:t}):(0,u.jsx)(p.Button,{variant:this.props.schema.variant||"contained",startIcon:t,style:this.props.schema.falseTextStyle,disabled:e||!!this.props.schema.readOnly,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.oContext.socket.setState(this.getObjectID(),!0,!1)}}):await this.props.oContext.socket.setState(this.getObjectID(),!0,!1)},children:i||this.getObjectID().split(".").pop()})}else if("input"===this.state.controlType)s=(0,u.jsx)(p.TextField,{style:{width:"100%"},value:this.state.stateValue,variant:"standard",slotProps:{input:{endAdornment:this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit||void 0},htmlInput:{readOnly:!!this.props.schema.readOnly}},onChange:t=>{this.setState({stateValue:t.target.value},(()=>{this.controlTimeout&&clearTimeout(this.controlTimeout),this.controlTimeout=setTimeout((async()=>{this.controlTimeout=null,await this.props.oContext.socket.setState(this.getObjectID(),this.state.stateValue,!1)}),this.props.schema.controlDelay||0)}))},label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)});else if("number"===this.state.obj.common.type){const t=void 0===this.props.schema.min?this.state.obj.common.min||0:this.props.schema.min,e=void 0===this.props.schema.max?void 0===this.state.obj.common.max?100:this.state.obj.common.max:this.props.schema.max,i=void 0===this.props.schema.step?this.state.obj.common.step||1:this.props.schema.step;s=(0,u.jsx)(p.TextField,{variant:"standard",style:{width:"100%"},value:this.state.stateValue,type:"number",slotProps:{htmlInput:{min:t,max:e,step:i,readOnly:!!this.props.schema.readOnly},input:{endAdornment:this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit||void 0}},onChange:t=>{this.setState({stateValue:t.target.value},(()=>{this.controlTimeout&&clearTimeout(this.controlTimeout),this.controlTimeout=setTimeout((async()=>{this.controlTimeout=null;const t=parseFloat(this.state.stateValue);await this.props.oContext.socket.setState(this.getObjectID(),t,!1)}),this.props.schema.controlDelay||0)}))},label:this.getText(this.props.schema.label,this.props.schema.noTranslation),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}else{let t;"normal"===this.props.schema.size?t=16:"large"===this.props.schema.size?t=20:"number"===typeof this.props.schema.size&&(t=this.props.schema.size);let e=this.getText(this.props.schema.label,this.props.schema.noTranslation);const n={display:"flex",alignItems:"center",fontSize:t||"1rem",gap:8};let r,l,h;if(this.props.schema.narrow||(n.width="100%",n.justifyContent="space-between"),e.trim()&&!e.trim().endsWith(":")&&this.props.schema.addColon&&(e="".concat(e.trim(),":")),this.props.schema.blinkOnUpdate&&(o=this.props.oContext.theme,r="string"===typeof(a=this.props.schema.blinkOnUpdate)?{"@keyframes newStateAnimationOnceColor":{"0%":{color:a},"100%":{color:"dark"===o.palette.mode?"#fff":"#000"}},animation:"newStateAnimationOnceColor 2s ease-in-out"}:{"@keyframes newStateAnimationOnce":{"0%":{color:"#00f900"},"80%":{color:"dark"===o.palette.mode?"#518851":"#008000"},"100%":{color:"dark"===o.palette.mode?"#fff":"#000"}},animation:"newStateAnimationOnce 2s ease-in-out"}),this.props.schema.labelIcon&&(l=(0,u.jsx)(d.Icon,{src:this.props.schema.labelIcon,style:{marginRight:4}})),e&&l?h=(0,u.jsxs)("div",{style:{whiteSpace:"nowrap"},children:[l,e]}):e?h=(0,u.jsx)("div",{style:{whiteSpace:"nowrap"},children:e}):l&&(h=l),"switch"===this.state.controlType){let t=null;const e=this.getText(this.props.schema.falseText,this.props.schema.noTranslation);this.props.schema.falseImage&&(t=ae(this.props.schema.falseImage,e?{marginLeft:8}:void 0));let i=null;const o=this.getText(this.props.schema.trueText,this.props.schema.noTranslation);this.props.schema.trueImage&&(i=ae(this.props.schema.trueImage,o?{marginRight:8}:void 0)),s=(0,u.jsx)(p.Switch,{checked:!!this.state.stateValue,disabled:!!this.props.schema.readOnly,onChange:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.oContext.socket.setState(this.getObjectID(),!this.state.stateValue,!1)}}):await this.props.oContext.socket.setState(this.getObjectID(),!this.state.stateValue,!1)}}),(e||t||o||i)&&(s=(0,u.jsxs)("div",{style:{display:"flex",alignItems:"center",fontSize:14},children:[(0,u.jsxs)("span",{style:this.props.schema.falseTextStyle,children:[e,t]}),s,(0,u.jsxs)("span",{style:this.props.schema.trueTextStyle,children:[i,o]})]})),h&&(s=(0,u.jsxs)("div",{style:n,children:[h,s]}))}else if("slider"===this.state.controlType){let t=null;const e=this.getText(this.props.schema.falseText,this.props.schema.noTranslation);this.props.schema.falseImage&&(t=ae(this.props.schema.falseImage,e?{marginLeft:8}:void 0));let o=null;const a=this.getText(this.props.schema.trueText,this.props.schema.noTranslation);this.props.schema.trueImage&&(o=ae(this.props.schema.trueImage,a?{marginRight:8}:void 0));const r=void 0===this.props.schema.min?this.state.obj.common.min||0:this.props.schema.min,l=void 0===this.props.schema.max?void 0===this.state.obj.common.max?100:this.state.obj.common.max:this.props.schema.max,c=void 0===this.props.schema.step?this.state.obj.common.step||1:this.props.schema.step;s=(0,u.jsx)(p.Slider,{style:{width:"100%",flexGrow:1},min:r,max:l,disabled:!!this.props.schema.readOnly,step:c,value:this.state.stateValue,valueLabelDisplay:"auto",valueLabelFormat:t=>"".concat(t).concat(this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit||""),onChange:(t,e)=>{this.setState({stateValue:e},(()=>{this.controlTimeout&&clearTimeout(this.controlTimeout),this.controlTimeout=setTimeout((async()=>{console.log("".concat(Date.now()," Send new value: ").concat(this.state.stateValue)),this.controlTimeout=null,await this.props.oContext.socket.setState(this.getObjectID(),this.state.stateValue,!1)}),this.props.schema.controlDelay||0)}))}}),(e||t||a||o)&&(s=(0,u.jsxs)("div",{style:{display:"flex",width:"100%",flexGrow:1,alignItems:"center"},children:[(0,u.jsxs)("span",{style:(0,i.A)({marginRight:16},this.props.schema.falseTextStyle),children:[e,t]}),s,(0,u.jsxs)("span",{style:(0,i.A)({marginLeft:16},this.props.schema.trueTextStyle),children:[o,a]})]})),h&&(s=(0,u.jsxs)("div",{style:n,children:[h,s]}))}else if("boolean"===this.state.obj.common.type){let t,e,i=null;this.state.stateValue?(t=this.getText(this.props.schema.trueText,this.props.schema.noTranslation),this.props.schema.trueImage&&(i=ae(this.props.schema.falseImage,t?{marginRight:8}:void 0)),e=this.props.schema.trueTextStyle):(t=this.getText(this.props.schema.falseText,this.props.schema.noTranslation),this.props.schema.falseImage&&(i=ae(this.props.schema.falseImage,t?{marginLeft:8}:void 0)),e=this.props.schema.falseTextStyle),e=Object.assign(n,e),s=(0,u.jsxs)("div",{style:e,children:[h,(0,u.jsxs)(p.Box,{style:{display:"flex",alignItems:"center",gap:8},sx:r,children:[i,t||(this.state.stateValue?d.I18n.t("ra_true"):d.I18n.t("ra_false"))]},this.props.schema.blinkOnUpdate?t:void 0)]})}else{const t=this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit;let e,i;"html"===this.state.controlType?(i=(this.state.stateValue||"").toString(),e=(0,u.jsx)("span",{dangerouslySetInnerHTML:{__html:this.state.stateValue}})):null===this.state.stateValue?(e="null",i=e):void 0===this.state.stateValue?(e="undefined",i=e):(e=this.state.stateValue.toString(),i=e),s=(0,u.jsxs)("div",{style:n,children:[h,(0,u.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:4},children:[(0,u.jsx)(p.Box,{sx:r,children:e},this.props.schema.blinkOnUpdate?i:void 0),t?(0,u.jsx)("span",{style:{opacity:.7,fontSize:"smaller"},children:t}):null]})]})}}var o,a;return s}},re={fullWidth:t=>({width:"100%",backgroundColor:"dark"===t.palette.mode?"#FFF":"#000",borderStyle:"hidden"}),primary:t=>({backgroundColor:t.palette.primary.main}),secondary:t=>({backgroundColor:t.palette.secondary.main})};const le=class extends x{renderItem(){return(0,u.jsx)(p.Box,{component:"hr",sx:d.Utils.getStyle(this.props.oContext.theme,re.fullWidth,"primary"===this.props.schema.color?re.primary:"secondary"===this.props.schema.color?re.secondary:{backgroundColor:this.props.schema.color||("dark"===this.props.oContext.themeType?"#333":"#ddd")},{height:this.props.schema.color?this.props.schema.height||2:this.props.schema.height||1})})}},he={header:t=>({width:"100%",background:t.palette.primary.main,color:t.palette.primary.contrastText,padding:"4px !important",borderRadius:"3px",marginBlockEnd:0,marginBlockStart:0})};const pe=class extends x{renderItem(){let t="h5";switch((this.props.schema.size||5).toString()){case"1":t="h1";break;case"2":t="h2";break;case"3":t="h3";break;case"4":t="h4";break;default:t="h5"}return(0,u.jsx)(p.Box,{component:t,sx:he.header,children:this.getText(this.props.schema.label||this.props.schema.text,this.props.schema.noTranslation)})}};const ce=class extends x{renderItem(){let t=this.props.schema.src;return!t||t.startsWith(".")||t.startsWith("http")||t.startsWith("adapter/".concat(this.props.oContext.adapterName,"/"))||t.startsWith("./adapter/".concat(this.props.oContext.adapterName,"/"))||(t="adapter/".concat(this.props.oContext.adapterName,"/").concat(t)),(0,u.jsx)("img",{src:t,style:{cursor:this.props.schema.href?"pointer":void 0,width:"100%",height:"100%"},onClick:this.props.schema.href?()=>this.props.schema.href&&window.open(this.props.schema.href,"_blank"):null,alt:""})}};function de(t,e,s){return"string"===typeof s?{"@keyframes newValueAnimationOnceColor":{"0%":{color:e?"".concat(s," !important"):s},"100%":{color:"dark"===t.palette.mode?e?"#fff !important":"#fff":e?"#000 !important":"#000"}},animation:"newValueAnimationOnceColor 2s ease-in-out"}:{"@keyframes newValueAnimationOnce":{"0%":{color:e?"#00f900 !important":"#00f900"},"80%":{color:"dark"===t.palette.mode?e?"#518851 !important":"#518851":e?"#008000 !important":"#008000"},"100%":{color:"dark"===t.palette.mode?e?"#fff !important":"#fff":e?"#000 !important":"#000"}},animation:"newValueAnimationOnce 2s ease-in-out"}}function ue(t,e){return"string"===typeof e?{"@keyframes blinkAnimationColor":{"0%":{color:e},"100%":{color:"dark"===t.palette.mode?"#fff":"#000"}},animation:"blinkAnimationColor 2s ease-in-out infinite"}:{"@keyframes blinkAnimation":{"0%":{color:"#00f900"},"80%":{color:"dark"===t.palette.mode?"#518851":"#008000"},"100%":{color:"dark"===t.palette.mode?"#fff":"#000"}},animation:"blinkAnimation 2s ease-in-out infinite"}}const me={label:{fontWeight:"bold",whiteSpace:"nowrap"},valueImage:{maxHeight:"100%"},valueAndUnit:{display:"flex",gap:4,alignItems:"baseline"},value:{},unit:{fontSize:"smaller",opacity:.7}};const ge=class extends x{renderItem(t){let e,s=this.getText(this.props.schema.text||this.props.schema.label,this.props.schema.noTranslation);this.props.schema.addColon&&"string"===typeof s&&!s.trim().endsWith(":")&&(s="".concat(s.trim(),":")),s&&(s.includes("<a ")||s.includes("<br")||s.includes("<b>")||s.includes("<i>"))&&(s=d.Utils.renderTextWithA(s)),"normal"===this.props.schema.size?e=16:"large"===this.props.schema.size?e=20:"number"===typeof this.props.schema.size&&(e=this.props.schema.size);const o={width:"100%",height:"100%",display:"flex",alignItems:"center",position:"relative",fontSize:e};let a,n;this.props.schema.narrow?o.gap=8:o.justifyContent="space-between",this.props.schema.data&&"object"===typeof this.props.schema.data&&this.props.schema.data.en?n=this.getText(this.props.schema.data):"object"===typeof this.props.schema.data||void 0===this.props.schema.data||null===this.props.schema.data?n=JSON.stringify(this.props.schema.data):"number"===typeof this.props.schema.data?(n=this.props.schema.data.toString(),this.props.oContext.isFloatComma&&(n=n.replace(".",","))):this.props.schema.booleanAsCheckbox&&"boolean"===typeof this.props.schema.data||(n=this.props.schema.data.toString());let r,l,h=!1;if(this.props.schema.booleanAsCheckbox&&"boolean"===typeof this.props.schema.data)a=(0,u.jsx)(p.Checkbox,{checked:!!a,disabled:!0,size:"small"===this.props.schema.size?"small":"large"===this.props.schema.size?"large":void 0});else if(n.startsWith("data:image/"))a=(0,u.jsx)("div",{style:(0,i.A)((0,i.A)((0,i.A)({},me.value),me.valueImage),this.props.schema.styleValue||void 0),children:(0,u.jsx)(d.Icon,{src:n})});else{const t=(0,i.A)((0,i.A)({},me.value),this.props.schema.styleValue||void 0);this.props.schema.html?a=(0,u.jsx)("div",{style:t,dangerouslySetInnerHTML:{__html:n}}):Array.isArray(this.props.schema.data)?(h=!0,a=(0,u.jsx)("div",{style:t,children:this.props.schema.data.map(((t,e)=>(0,u.jsx)("div",{children:"object"===typeof t||null===t||void 0===t?JSON.stringify(t):t},e)))})):n.includes("\n")?(h=!0,a=(0,u.jsx)("div",{style:t,children:d.Utils.renderTextWithA(n)})):a=(0,u.jsx)("div",{style:t,children:n})}if(this.props.schema.blinkOnUpdate&&this.props.schema.blink){const t=de(this.props.oContext.theme,!0,this.props.schema.blinkOnUpdate),e=ue(this.props.oContext.theme,this.props.schema.blink);a=(0,u.jsx)(p.Box,{sx:(0,i.A)((0,i.A)({},t),e),children:a},n)}else if(this.props.schema.blinkOnUpdate){const t=de(this.props.oContext.theme,!1,this.props.schema.blinkOnUpdate);a=(0,u.jsx)(p.Box,{sx:t,children:a},n)}else if(this.props.schema.blink){const t=ue(this.props.oContext.theme,this.props.schema.blink);a=(0,u.jsx)(p.Box,{sx:t,children:a})}this.props.schema.unit&&(a=(0,u.jsxs)("div",{style:me.valueAndUnit,children:[a,(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},me.unit),this.props.schema.styleUnit||void 0),children:this.getText(this.props.schema.unit,this.props.schema.noTranslation)})]})),this.props.schema.labelIcon&&(r=(0,u.jsx)(d.Icon,{src:this.props.schema.labelIcon,style:{marginRight:4}})),this.props.schema.copyToClipboard&&(l=(0,u.jsx)(c.ContentCopy,{className:"staticCopyButton",style:{position:"absolute",top:"calc(50% - 12px)",right:0,cursor:"pointer"},onClick:()=>{d.Utils.copyToClipboard(n),window.alert(d.I18n.t("ra_Copied"))}}));const m={"& .staticCopyButton":{display:"none"},"& .staticCopyButton:action":{transform:"scale(0.9)"},"&:hover .staticCopyButton":{display:"block"}};return this.props.schema.highlight&&(m["&:hover"]={backgroundColor:"dark"===this.props.oContext.themeType?"#51515180":"#b8b8b880"}),h&&(o.alignItems="top"),(0,u.jsxs)(p.Box,{component:"div",style:o,sx:m,children:[(0,u.jsxs)("div",{style:(0,i.A)((0,i.A)({},me.label),this.props.schema.styleLabel||void 0),children:[r,s]}),a,l]})}},xe={fullWidth:{height:"100%",width:"100%"},link:t=>({textDecoration:"underline",color:"dark"===t.palette.mode?"#4dabf5":"#254e72",cursor:"pointer"})};function ve(t,e,s){let i,o="";t?t.toString().startsWith("#")||t.toString().startsWith("/")?(i=e||"_self",o=t):t.startsWith("http://")||t.startsWith("https://")?(i=e||"_blank",o=t):(o="#tab-instances/config/".concat(s,"/").concat(t),i=e||"_self"):(o="#tab-instances/config/".concat(s),i=e||"_self"),"_self"===i?setTimeout((t=>{t.startsWith("#")?window.location.hash=t:t.startsWith("/")?o="".concat(window.location.protocol,":").concat(window.location.host).concat(o):(t.startsWith("http://")||t.startsWith("https://"))&&(window.location.href=t)}),100,o):(o.startsWith("#")?o="".concat(window.location.protocol,":").concat(window.location.host).concat(window.location.pathname).concat(o):o.startsWith("/")&&(o="".concat(window.location.protocol,":").concat(window.location.host).concat(o)),window.open(o,i))}const fe=class extends x{renderItem(t,e){if(this.props.schema.button){const t=this.getIcon();return(0,u.jsx)(p.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:(0,i.A)((0,i.A)({},xe.fullWidth),this.props.schema.controlStyle||void 0),disabled:e,startIcon:t,onClick:this.props.schema.href?()=>{const t=this.props.schema.href?this.getText(this.props.schema.href,!0):null;t&&(this.props.oContext.onBackEndCommand?this.props.oContext.onBackEndCommand({command:"link",url:t,target:this.props.schema.target,close:this.props.schema.close}):ve(t,this.props.schema.target,"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance)))}:null,children:this.getText(this.props.schema.text||this.props.schema.label,this.props.schema.noTranslation)})}let s=this.getText(this.props.schema.text||this.props.schema.label,this.props.schema.noTranslation);return s&&(s.includes("<a ")||s.includes("<br")||s.includes("<b>")||s.includes("<i>"))&&(s=d.Utils.renderTextWithA(s)),(0,u.jsx)(p.Box,{component:"span",style:(0,i.A)({},this.props.schema.controlStyle||void 0),sx:this.props.schema.href?xe.link:void 0,onClick:this.props.schema.href?()=>{const t=this.props.schema.href?this.getText(this.props.schema.href,!0):null;t&&(this.props.oContext.onBackEndCommand?this.props.oContext.onBackEndCommand({command:"link",url:t,target:this.props.schema.target||"_blank",close:this.props.schema.close}):ve(t,this.props.schema.target||"_blank","".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance)))}:null,children:s})}},ye=1048576,be={fullWidth:{width:"100%"},root:{width:"100%"},paper:{width:"100%",marginBottom:16,backgroundColor:"rgba(255, 255, 255, 0.1)"},headerText:{width:"100%"},table:{minWidth:750},visuallyHidden:{border:0,clip:"rect(0 0 0 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",top:20,width:1},label:{display:"flex",justifyContent:"space-between"},title:{flex:"1 1 100%"},rootTool:{paddingLeft:16,paddingRight:8},silver:{opacity:.2},flex:{display:"flex",alignItems:"baseline"},filteredOut:{padding:10,display:"flex",textAlign:"center"},buttonEmpty:{width:34,display:"inline-block"},buttonCell:{whiteSpace:"nowrap"},dropZone:{width:"100%",height:100,position:"relative"},dropZoneEmpty:{},uploadDiv:{position:"relative",width:"100%",minHeight:300,opacity:.9,marginTop:30,cursor:"pointer",outline:"none"},uploadDivDragging:{opacity:1,background:"rgba(128,255,128,0.1)"},image:{objectFit:"contain",margin:"auto",display:"flex",width:"100%",height:"100%"},uploadCenterDiv:{margin:5,border:"3px dashed grey",borderRadius:5,width:"calc(100% - 10px)",height:"calc(100% - 10px)",minHeight:300,position:"relative",display:"flex"},uploadCenterIcon:{paddingTop:10,width:48,height:48},uploadCenterText:{fontSize:16},uploadCenterTextAndIcon:{textAlign:"center",position:"absolute",top:0,bottom:0,left:0,right:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},buttonRemoveWrapper:{position:"absolute",zIndex:222,right:0},error:{border:"2px solid red",boxSizing:"border-box"},tooltip:{pointerEvents:"none"}};function Ce(t,e,s){e=e||"key";const i={};return t.forEach((t=>{let o=t[e];null!==o&&void 0!==o||(o=""),delete t[e],i[o]=s?t[s]:t})),i}class je extends x{constructor(t){var e;super(t),e=this,this.filterRefs=void 0,this.typingTimer=null,this.secret="Zgfr56gFe87jJOM",this.handleRequestSort=function(t){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{order:i,orderBy:o}=e.state;if(o){const a=s?i:o===t&&"asc"===i?"desc":"asc",n=e.stableSort(a,t);e.setState({order:a,orderBy:t,iteration:e.state.iteration+1e4},(()=>e.applyFilter(!1,n)))}},this.stableSort=(t,e)=>{const{value:s}=this.state,i=je.getComparator(t,e),o=s.map(((t,e)=>({el:t,index:e})));return o.sort(((t,e)=>{const s=i(t.el,e.el);return 0!==s?s:t.index-e.index})),o.map((t=>t.el))},this.onDelete=t=>()=>{const e=JSON.parse(JSON.stringify(this.state.value));e.splice(t,1),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(e)))))},this.onClone=t=>()=>{const e=JSON.parse(JSON.stringify(this.state.value)),s=JSON.parse(JSON.stringify(e[t]));if("string"===typeof this.props.schema.clone&&"string"===typeof s[this.props.schema.clone]){let t=1,i=s[this.props.schema.clone];const o=i.match(/(\d+)$/);for(o?(i=i.replace(o[0],""),t=parseInt(o[0],10)+1):i+="_";e.find((e=>e[this.props.schema.clone]===i+t.toString()));)t++;s[this.props.schema.clone]="".concat(s[this.props.schema.clone],"_").concat(t)}e.splice(t,0,s),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(e)))))},this.onChangeWrapper=(t,e)=>{this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(((t,e)=>{let s;if(this.typingTimer=null,this.props.schema.encryptedAttributes){const e=JSON.parse(JSON.stringify(t));if(e.forEach((t=>{this.props.schema.encryptedAttributes.forEach((e=>{t[e]&&(t[e]=function(t,e){let s="";for(let i=0;i<e.length;i++)s+=String.fromCharCode(t[i%t.length].charCodeAt(0)^e.charCodeAt(i));return s}(this.secret,t[e]))}))})),this.props.schema.objKeyName){const t=Ce(e,this.props.schema.objKeyName,this.props.schema.objValueName);s=this.onChange(this.props.attr,t)}else s=this.onChange(this.props.attr,e)}else if(this.props.schema.objKeyName){const e=Ce(JSON.parse(JSON.stringify(t)),this.props.schema.objKeyName,this.props.schema.objValueName);s=this.onChange(this.props.attr,e)}else s=this.onChange(this.props.attr,t);s instanceof Promise&&s.catch((t=>console.error("Cannot save: ".concat(t)))),e&&(this.applyFilter(!1,t),this.handleRequestSort(this.state.orderBy,!0))}),300,t,e)},this.onAdd=()=>{var t;const{schema:e}=this.props,s=JSON.parse(JSON.stringify(this.state.value)),i=null===(t=e.items)||void 0===t?void 0:t.reduce(((t,e)=>{let i;return i=e.defaultFunc?this.props.custom?e.defaultFunc?this.executeCustom(e.defaultFunc,this.props.data,this.props.customObj,this.props.oContext.instanceObj,s.length,this.props.data):this.props.schema.default:e.defaultFunc?this.execute(e.defaultFunc,this.props.schema.default,this.props.data,s.length,this.props.data):this.props.schema.default:void 0===e.default?null:e.default,t[e.attr]=i,t}),{});s.push(i),this.setState({value:s},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(s)))))},this.applyFilter=(t,e,s)=>{let i=(e=e||this.state.value).map(((t,e)=>e));Object.keys(this.filterRefs).forEach((s=>{let o=je.getFilterValue(this.filterRefs[s]);!t&&o?(o=o.toLowerCase(),i=i.filter((t=>e[t]&&e[t][s]&&e[t][s].toLowerCase().includes(o)))):this.filterRefs[s].current&&je.setFilterValue(this.filterRefs[s],"")})),i.length===e.length&&(i=null),(null!==i||null!==this.state.visibleValue)&&JSON.stringify(i)!==JSON.stringify(this.state.visibleValue)?this.setState({visibleValue:i},(()=>s&&s())):s&&s()},this.filterRefs={},this.props.schema.items=this.props.schema.items||[],this.props.schema.items.forEach((t=>{t.filter&&(this.filterRefs[t.attr]=(0,o.createRef)())}))}async componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr)||[];let e;if(e=this.props.schema.objKeyName?function(t,e,s){e=e||"key";const i=[];return Object.keys(t).forEach((o=>{const a={};a[e]=o,s?(a[s]=t[o],i.push(a)):i.push(Object.assign(a,t[o]))})),i}(t,this.props.schema.objKeyName,this.props.schema.objValueName):t,Array.isArray(e)||(e=[]),this.props.schema.encryptedAttributes){const e=await this.props.oContext.socket.getCompactSystemConfig();this.secret=(null===e||void 0===e?void 0:e.native.secret)||this.secret,t.forEach((t=>{this.props.schema.encryptedAttributes.forEach((e=>{t[e]&&(t[e]=function(t,e){let s="";for(let i=0;i<e.length;i++)s+=String.fromCharCode(t[i%t.length].charCodeAt(0)^e.charCodeAt(i));return s}(this.secret,t[e]))}))}))}this.setState({value:e,visibleValue:null,orderBy:"",order:"asc",iteration:0,filterOn:[]},(()=>this.validateUniqueProps()))}componentWillUnmount(){this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),super.componentWillUnmount()}itemTable(t,e,s){const{schema:i}=this.props,o=i.items&&i.items.find((e=>e.attr===t));if(!o)return null;const a={items:{[t]:o}};return(0,u.jsx)(Ve,{oContext:this.props.oContext,alive:this.props.alive,arrayIndex:s,changed:this.props.changed,common:this.props.common,custom:!0,data:e,globalData:this.props.data,index:s+this.state.iteration,onChange:(t,e)=>{const i=JSON.parse(JSON.stringify(this.state.value));i[s][t]=e,this.setState({value:i},(()=>{this.validateUniqueProps(),this.onChangeWrapper(i,!0)}))},onError:(t,e)=>this.onError(t,e),originalData:this.props.originalData,schema:a,table:!0,themeName:this.props.themeName})}validateUniqueProps(){if(this.props.schema.uniqueColumns)for(const t of this.props.schema.uniqueColumns){const e=[];this.state.value.find((s=>{const i=s[t];return e.includes(i)?(this.onError(t,"is not unique"),this.setState({errorMessage:d.I18n.t('Non-allowed duplicate entry "%s" in column "%s"',i,t)}),!0):(e.push(i),!1)}))||(this.onError(t,null),this.setState({errorMessage:""}))}}static descendingComparator(t,e,s){return e[s]<t[s]?-1:e[s]>t[s]?1:0}static getComparator(t,e){return"desc"===t?(t,s)=>je.descendingComparator(t,s,e):(t,s)=>-je.descendingComparator(t,s,e)}static getFilterValue(t){var e,s,i;return null===t||void 0===t||null===(e=t.current)||void 0===e||null===(s=e.children[0])||void 0===s||null===(i=s.children[0])||void 0===i?void 0:i.value}static setFilterValue(t,e){return t.current.children[0].children[0].value=e}enhancedTableHead(t,e){const{schema:s}=this.props,{order:o,orderBy:a}=this.state;return(0,u.jsx)(p.TableHead,{children:(0,u.jsxs)(p.TableRow,{children:[s.items&&s.items.map(((t,n)=>(0,u.jsx)(p.TableCell,{style:{width:("string"===typeof t.width&&t.width.endsWith("%"),t.width)},align:"left",sortDirection:a===t.attr&&o,children:(0,u.jsxs)("div",{style:(0,i.A)((0,i.A)({},be.flex),s.showFirstAddOnTop?{flexDirection:"column"}:void 0),children:[n||s.noDelete?null:(0,u.jsx)(p.Tooltip,{title:e?d.I18n.t("ra_Cannot add items with set filter"):d.I18n.t("ra_Add row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)("span",{children:(0,u.jsx)(p.IconButton,{size:"small",color:"primary",disabled:!!e&&!this.props.schema.allowAddByFilter,onClick:this.onAdd,children:(0,u.jsx)(c.Add,{})})})}),t.sort&&(0,u.jsx)(p.TableSortLabel,{active:!0,style:a!==t.attr?be.silver:void 0,direction:a===t.attr?o:"asc",onClick:()=>this.handleRequestSort(t.attr)}),t.filter&&this.state.filterOn.includes(t.attr)?(0,u.jsx)(p.TextField,{variant:"standard",ref:this.filterRefs[t.attr],onChange:()=>this.applyFilter(),title:d.I18n.t("ra_You can filter entries by entering here some text"),slotProps:{input:{endAdornment:je.getFilterValue(this.filterRefs[t.attr])&&(0,u.jsx)(p.InputAdornment,{position:"end",children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>{je.setFilterValue(this.filterRefs[t.attr],""),this.applyFilter()},children:(0,u.jsx)(c.Close,{})})})}},fullWidth:!0,placeholder:this.getText(t.title)}):(0,u.jsx)("span",{style:be.headerText,children:this.getText(t.title)}),t.filter?(0,u.jsx)(p.IconButton,{title:d.I18n.t("ra_Show/hide filter input"),size:"small",onClick:()=>{const e=[...this.state.filterOn],s=this.state.filterOn.indexOf(t.attr);-1===s?e.push(t.attr):e.splice(s,1),this.setState({filterOn:e},(()=>{s&&je.getFilterValue(this.filterRefs[t.attr])&&(je.setFilterValue(this.filterRefs[t.attr],""),this.applyFilter())}))},children:this.state.filterOn.includes(t.attr)?(0,u.jsx)(c.FilterAltOff,{}):(0,u.jsx)(c.FilterAlt,{})}):null]})},"".concat(t.attr,"_").concat(n)))),!s.noDelete&&(0,u.jsxs)(p.TableCell,{style:{paddingLeft:20,paddingRight:20,width:t,textAlign:"right"},padding:"checkbox",children:[s.import?(0,u.jsx)(p.IconButton,{style:{marginRight:10},size:"small",onClick:()=>this.setState({showImportDialog:!0}),title:d.I18n.t("ra_import data from %s file","CSV"),children:(0,u.jsx)(c.UploadFile,{})}):null,s.export?(0,u.jsx)(p.IconButton,{style:{marginRight:10},size:"small",onClick:()=>this.onExport(),title:d.I18n.t("ra_Export data to %s file","CSV"),children:(0,u.jsx)(c.Download,{})}):null,(0,u.jsx)(p.IconButton,{disabled:!0,size:"small",children:(0,u.jsx)(c.Delete,{})})]})]})})}onExport(){const{schema:t}=this.props,{value:e}=this.state,s=[t.items.map((t=>t.attr)).join(";")];e.forEach((e=>{const i=[];t.items.forEach((t=>{var s;null!==(s=e[t.attr])&&void 0!==s&&s.includes(";")?i.push('"'.concat(e[t.attr],'"')):i.push(void 0===e[t.attr]||null===e[t.attr]?"":e[t.attr])})),s.push(i.join(";"))}));const i=document.createElement("a");i.setAttribute("href","data:text/csv;charset=utf-8,".concat(encodeURIComponent(s.join("\n"))));const o=new Date;i.setAttribute("download","".concat(o.getFullYear(),"_").concat((o.getMonth()+1).toString().padStart(2,"0"),"_").concat(o.getDate().toString().padStart(2,"0"),"_").concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance,"_").concat(this.props.attr,".csv")),i.style.display="none",document.body.appendChild(i),i.click(),document.body.removeChild(i)}onImport(t){const e=t.split("\n").map((t=>t.replace("\r","").trim())),{schema:s}=this.props,i=e.shift().split(";").filter((t=>t&&s.items.find((e=>e.attr===t)))),o=[];var a;(e.forEach((t=>{const e=t.split(";"),s={};for(let o=0;o<e.length;o++){let t=e[o];if(t.startsWith('"')){for(t=t.substring(1);o<e.length&&!t.endsWith('"');)t+=";".concat(e[++o]);t=t.substring(0,t.length-1)}let a=t;if("true"===t)a=!0;else if("false"===t)a=!1;else if(window.isFinite(t)){const e=this.props.schema.items.find((t=>t.attr===i[o]));a=e&&"number"===e.type?parseFloat(t):t}else a=t;s[i[o]]=a}o.push(s)})),o.length)?null!==(a=this.state.value)&&void 0!==a&&a.length?this.setState({showTypeOfImportDialog:o,showImportDialog:!1}):this.setState({value:o,showImportDialog:!1}):window.alert("ra_No data found in file")}isAnyFilterSet(){return!!Object.keys(this.filterRefs).find((t=>je.getFilterValue(this.filterRefs[t])))}onMoveUp(t){const e=JSON.parse(JSON.stringify(this.state.value)),s=e[t];e.splice(t,1),e.splice(t-1,0,s),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(e)))))}onMoveDown(t){const e=JSON.parse(JSON.stringify(this.state.value)),s=e[t];e.splice(t,1),e.splice(t+1,0,s),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(e)))))}onDrop(t){const e=t[0],s=new FileReader;s.onabort=()=>console.log("file reading was aborted"),s.onerror=()=>console.log("file reading has failed"),s.onload=()=>{if(e.size>ye)return void window.alert(d.I18n.t("ra_File is too big. Max %sk allowed. Try use SVG.",Math.round(1024)));const t=new Uint8Array(s.result).reduce(((t,e)=>t+String.fromCharCode(e)),"");this.onImport(t)},s.readAsArrayBuffer(e)}showTypeOfImportDialog(){return this.state.showTypeOfImportDialog?(0,u.jsxs)(p.Dialog,{open:!0,onClose:()=>this.setState({showTypeOfImportDialog:!1}),maxWidth:"md",children:[(0,u.jsx)(p.DialogTitle,{children:d.I18n.t("ra_Append or replace?")}),(0,u.jsx)(p.DialogContent,{children:d.I18n.t("ra_Append %s entries or replace existing?",this.state.showTypeOfImportDialog.length)}),(0,u.jsxs)(p.DialogActions,{children:[(0,u.jsx)(p.Button,{variant:"contained",color:"primary",autoFocus:!0,onClick:()=>{const t=JSON.parse(JSON.stringify(this.state.value));this.state.showTypeOfImportDialog.forEach((e=>t.push(e))),this.setState({value:t,iteration:this.state.iteration+1e4,showTypeOfImportDialog:!1},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(t)))))},children:d.I18n.t("ra_Append")}),(0,u.jsx)(p.Button,{variant:"contained",color:"secondary",autoFocus:!0,onClick:()=>{const t=this.state.showTypeOfImportDialog;this.setState({value:t,iteration:this.state.iteration+1e4,showTypeOfImportDialog:!1},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(t)))))},children:d.I18n.t("ra_Replace")})]})]}):null}showImportDialog(){return this.state.showImportDialog?(0,u.jsxs)(p.Dialog,{open:!0,onClose:()=>this.setState({showImportDialog:!1}),sx:{"& .MuiDialog-paper":{minHeight:500}},maxWidth:"md",fullWidth:!0,children:[(0,u.jsx)(p.DialogTitle,{children:d.I18n.t("ra_Import from %s","CSV")}),(0,u.jsx)(p.DialogContent,{children:(0,u.jsx)(st(),{multiple:!1,accept:{"text/csv":[".csv"]},maxSize:ye,onDragEnter:()=>this.setState({uploadFile:"dragging"}),onDragLeave:()=>this.setState({uploadFile:!0}),onDrop:(t,e)=>{this.setState({uploadFile:!1}),t.length?this.onDrop(t):window.alert(e&&e[0]&&e[0].errors&&e[0].errors[0]&&e[0].errors[0].message||d.I18n.t("ra_Cannot upload"))},children:t=>{let{getRootProps:e,getInputProps:s}=t;return(0,u.jsxs)("div",(0,i.A)((0,i.A)({style:(0,i.A)((0,i.A)((0,i.A)((0,i.A)({},be.uploadDiv),"dragging"===this.state.uploadFile?be.uploadDivDragging:void 0),be.dropZone),this.state.icon?void 0:be.dropZoneEmpty)},e()),{},{children:[(0,u.jsx)("input",(0,i.A)({},s())),(0,u.jsx)("div",{style:be.uploadCenterDiv,children:(0,u.jsxs)("div",{style:be.uploadCenterTextAndIcon,children:[(0,u.jsx)(c.UploadFile,{style:be.uploadCenterIcon}),(0,u.jsx)("div",{style:be.uploadCenterText,children:"dragging"===this.state.uploadFile?d.I18n.t("ra_Drop file here"):d.I18n.t("ra_Place your files here or click here to open the browse dialog")})]})})]}))}})}),(0,u.jsx)(p.DialogActions,{children:(0,u.jsx)(p.Button,{variant:"contained",onClick:()=>this.setState({showImportDialog:!1}),color:"primary",startIcon:(0,u.jsx)(c.Close,{}),children:d.I18n.t("Cancel")})})]}):null}renderItem(){const{schema:t}=this.props;let{visibleValue:e}=this.state;if(!this.state.value||!Array.isArray(this.state.value))return null;e=e||this.state.value.map(((t,e)=>e));const s=this.isAnyFilterSet();let o;return this.props.schema.compact&&(o={paddingTop:1,paddingBottom:1}),(0,u.jsxs)(p.Paper,{style:be.paper,children:[this.showImportDialog(),this.showTypeOfImportDialog(),t.label?(0,u.jsx)("div",{style:be.label,children:(0,u.jsx)(p.Toolbar,{variant:"dense",style:be.rootTool,children:(0,u.jsx)(p.Typography,{style:be.title,variant:"h6",id:"tableTitle",component:"div",children:this.getText(t.label)})})}):null,(0,u.jsxs)(p.TableContainer,{children:[(0,u.jsxs)(p.Table,{style:be.table,size:"small",children:[this.enhancedTableHead(s||this.state.orderBy?64:120,s),(0,u.jsxs)(p.TableBody,{children:[e.map(((a,n)=>(0,u.jsxs)(p.TableRow,{hover:!0,children:[t.items&&t.items.map((t=>(0,u.jsx)(p.TableCell,{align:"left",style:o,children:this.itemTable(t.attr,this.state.value[a],a)},"".concat(t.attr,"_").concat(a)))),!t.noDelete&&(0,u.jsxs)(p.TableCell,{align:"left",style:(0,i.A)((0,i.A)({},o),be.buttonCell),children:[s||this.state.orderBy?null:n?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move up"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveUp(a),children:(0,u.jsx)(c.ArrowUpward,{})})}):(0,u.jsx)("div",{style:be.buttonEmpty}),s||this.state.orderBy?null:n<e.length-1?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move down"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveDown(a),children:(0,u.jsx)(c.ArrowDownward,{})})}):(0,u.jsx)("div",{style:be.buttonEmpty}),(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Delete current row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onDelete(a),children:(0,u.jsx)(c.Delete,{})})}),this.props.schema.clone?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Clone current row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onClone(a),children:(0,u.jsx)(c.ContentCopy,{})})}):null]})]},"".concat(a,"_").concat(n)))),!t.noDelete&&e.length>=(t.showSecondAddAt||5)?(0,u.jsx)(p.TableRow,{children:(0,u.jsx)(p.TableCell,{colSpan:t.items.length+1,style:(0,i.A)({},o),children:(0,u.jsx)(p.Tooltip,{title:s?d.I18n.t("ra_Cannot add items with set filter"):d.I18n.t("ra_Add row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)("span",{children:(0,u.jsx)(p.IconButton,{size:"small",color:"primary",disabled:!!s&&!this.props.schema.allowAddByFilter,onClick:this.onAdd,children:(0,u.jsx)(c.Add,{})})})})})}):null]})]}),!e.length&&this.state.value.length?(0,u.jsx)("div",{style:be.filteredOut,children:(0,u.jsxs)(p.Typography,{style:be.title,variant:"h6",id:"tableTitle",component:"div",children:[d.I18n.t("ra_All items are filtered out"),(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.applyFilter(!0),children:(0,u.jsx)(c.Close,{})})]})}):null]}),t.help?(0,u.jsx)(p.FormHelperText,{style:{paddingLeft:16},children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null,this.state.errorMessage?(0,u.jsxs)("div",{style:{display:"flex",padding:"5px"},children:[(0,u.jsx)(c.Warning,{color:"error"}),(0,u.jsx)("span",{style:{color:"red",alignSelf:"center"},children:this.state.errorMessage})]}):null]})}}const we=je,Ie={indeterminate:{opacity:.5},label:{width:"100%",fontSize:14,marginBottom:2},helper:{width:"100%",fontSize:12},error:{width:"100%",fontSize:12,color:"#FF0000"}};const Te=class extends x{constructor(){super(...arguments),this.updateTimeout=null}componentDidMount(){super.componentDidMount();let t=x.getValue(this.props.data,this.props.attr);if(Array.isArray(t)&&this.props.oContext.multiEdit)return t=x.DIFFERENT_VALUE,void this.setState({value:t,oldValue:t,jsonError:!1});this.setState({value:t,oldValue:t,jsonError:this.validateJson(t)})}validateJson(t){let e=!1;if(this.props.schema.validateJson&&(t||!this.props.schema.allowEmpty))try{JSON.parse(t)}catch(s){console.log("Error in JSON",s),e=!0}return e}static getDerivedStateFromProps(t,e){if(t.oContext.multiEdit&&e.value===x.DIFFERENT_VALUE)return{value:x.DIFFERENT_VALUE};let s=x.getValue(t.data,t.attr);return null!==s&&void 0!==s&&(s=s.toString()),null===s||void 0===s||s!==e.value&&s!==e.oldValue?{value:s}:null}renderItem(t,e){const s=Array.isArray(this.state.value)||this.state.value===x.DIFFERENT_VALUE;if(this.props.schema.time){let s="";return"number"===typeof this.state.value?s=this.state.value&&this.state.value<9466596e5?new Date(1e3*this.state.value).toLocaleString():new Date(this.state.value).toLocaleString():"string"===typeof this.state.value&&(s=new Date(this.state.value).toLocaleString()),(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:s,error:!!t||!!this.state.jsonError,disabled:!!e,slotProps:{htmlInput:{readOnly:!0}},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}if(null!==this.state.oldValue&&void 0!==this.state.oldValue?(this.updateTimeout&&clearTimeout(this.updateTimeout),this.updateTimeout=setTimeout((()=>{this.updateTimeout=null,this.setState({oldValue:null})}),30)):this.updateTimeout&&(clearTimeout(this.updateTimeout),this.updateTimeout=null),s){const s=x.getValue(this.props.data,this.props.attr),o=(null===s||void 0===s?void 0:s.filter((t=>t||0===t)).map((t=>({label:t.toString()||"",value:t}))))||[];return o.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),(0,u.jsx)(p.Autocomplete,{style:Ie.indeterminate,fullWidth:!0,value:o[0],onChange:(t,e)=>{const s=e?e.value:"",i=this.onChange(this.props.attr,s,(()=>{this.setState({value:s,oldValue:s,jsonError:this.validateJson(e)})}));i instanceof Promise&&i.catch((t=>console.error("Cannot set value: ".concat(t))))},options:o,getOptionLabel:t=>t.label,renderInput:s=>(0,u.jsx)(p.TextField,(0,i.A)((0,i.A)({variant:"standard"},s),{},{error:!!t,placeholder:this.getText(this.props.schema.placeholder),slotProps:{htmlInput:(0,i.A)((0,i.A)({},s.inputProps),{},{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:this.props.schema.readOnly||!1})},label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),disabled:!!e}))})}let o,a;if((this.props.schema.readOnly||e)&&this.props.schema.copyToClipboard?(this.props.schema.minRows>1&&(a={position:"absolute",right:3,top:20,zIndex:1e3}),o=(0,u.jsx)(p.IconButton,{style:a,size:"small",onClick:()=>{d.Utils.copyToClipboard(this.state.value),window.alert(d.I18n.t("ra_Copied"))},children:(0,u.jsx)(d.IconCopy,{})})):this.props.schema.readOnly||e||!this.state.value||this.props.schema.noClearButton||(this.props.schema.minRows>1&&(a={position:"absolute",right:3,top:20,zIndex:1e3}),o=(0,u.jsx)(p.IconButton,{style:a,size:"small",onClick:()=>this.setState({value:"",oldValue:this.state.value},(()=>this.onChange(this.props.attr,""))),children:(0,u.jsx)(c.Close,{})}),this.props.schema.minRows<=1&&(o=(0,u.jsx)(p.InputAdornment,{position:"end",children:o}))),this.props.schema.minRows>1){const s=this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation);return(0,u.jsxs)("div",{style:{width:"100%",position:"relative"},children:[this.props.schema.label?(0,u.jsx)("div",{style:Ie.label,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.TextareaAutosize,{style:{width:"100%",resize:"vertical",backgroundColor:"dark"===this.props.oContext.themeType?"#363636":"#cccccc",color:"dark"===this.props.oContext.themeType?"#fff":"#111"},minRows:this.props.schema.minRows,maxRows:this.props.schema.maxRows,value:null===this.state.value||void 0===this.state.value?"":this.state.value,disabled:!!e,readOnly:this.props.schema.readOnly||!1,onChange:t=>{const e=t.target.value;this.setState({value:e,oldValue:this.state.value,jsonError:this.validateJson(e)},(()=>this.onChange(this.props.attr,e||"")))},placeholder:this.getText(this.props.schema.placeholder)}),s||t||this.state.jsonError?(0,u.jsx)("div",{style:t?Ie.error:Ie.helper,children:t||(this.state.jsonError?d.I18n.t("ra_Invalid JSON"):s)}):null]})}return(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:null===this.state.value||void 0===this.state.value?"":this.state.value,error:!!t||!!this.state.jsonError,disabled:!!e,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:this.props.schema.readOnly||!1},input:{endAdornment:o}},onChange:t=>{const e=t.target.value;this.setState({value:e,oldValue:this.state.value,jsonError:this.validateJson(e)},(()=>this.onChange(this.props.attr,e)))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.state.jsonError?d.I18n.t("ra_Invalid JSON"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},Se={width:"100%"};const De=class extends x{constructor(){super(...arguments),this.initialized=!1,this.localContext=void 0}askInstance(){if(this.props.alive){let e=this.props.schema.data;if(void 0===e&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,null,!0);try{e=JSON.parse(s)}catch(t){console.error("Cannot parse json data: ".concat(s))}}void 0===e&&(e=null),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",e).then((t=>{if("object"===typeof t){const e=t;this.setState({text:e.text||"",style:e.style,icon:e.icon,iconStyle:e.iconStyle})}else"string"===typeof t&&this.setState({text:t||""})})).catch((t=>console.error("Cannot send command: ".concat(t))))}}getLocalContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=x.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(){if(this.props.alive){const t=this.getLocalContext();t===this.localContext&&this.initialized||(this.localContext=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}if(void 0===this.state.text)return null;let t=null;return this.state.icon&&(t=ae(this.state.icon,(0,i.A)({marginRight:this.state.text?8:void 0},this.state.iconStyle||void 0)),t||(t=(0,u.jsx)(d.Icon,{src:this.state.icon,style:(0,i.A)({marginRight:this.state.text?8:void 0},this.state.iconStyle||void 0)}))),"text"===this.props.schema.container?(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,slotProps:{input:{endAdornment:this.props.schema.copyToClipboard?(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>{d.Utils.copyToClipboard(this.state.text),window.alert(d.I18n.t("ra_Copied"))},children:(0,u.jsx)(d.IconCopy,{})}):void 0}},value:this.state.text,label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):(0,u.jsxs)("div",{style:(0,i.A)((0,i.A)({},Se),this.state.style||void 0),children:[t,"html"===this.props.schema.container?(0,u.jsx)("span",{dangerouslySetInnerHTML:{__html:this.state.text||""}}):this.state.text]})}};const ke=class extends x{componentDidMount(){var t;super.componentDidMount();const e=x.getValue(this.props.data,this.props.attr);if(!e&&null!==(t=this.props.customObj)&&void 0!==t&&t._id){const t=function(t,e){let s;return s=e&&t.substring(0,e.length)===e?t.substring(e.length+1):t,s=s.replace(/\./g,"/").replace(/_/g," "),s}(this.props.customObj._id,"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance));this.setState({value:t})}else this.setState({value:e||""})}renderItem(t,e){return(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0}},value:this.state.value,error:!!t,disabled:e,placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,e)))}})}};const Oe=class extends x{async componentDidMount(){var t;super.componentDidMount();const e=await this.props.oContext.socket.getObject("system.meta.uuid");this.setState({uuid:(null===e||void 0===e||null===(t=e.native)||void 0===t?void 0:t.uuid)||"unknown"})}renderItem(t,e){return(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,error:!!t,disabled:!!e,slotProps:{htmlInput:{readOnly:!0},input:{endAdornment:(0,u.jsx)(p.IconButton,{onClick:()=>{d.Utils.copyToClipboard(this.state.uuid),window.alert(d.I18n.t("ra_Copied %s",this.state.uuid))},children:(0,u.jsx)(c.ContentCopy,{})})}},value:this.state.uuid||"",label:this.getText(this.props.schema.label)||d.I18n.t("ra_Serial number (UUID)"),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},_e={icon:{width:16,height:16,marginRight:8}};const Ae=class extends x{componentDidMount(){super.componentDidMount(),this.props.oContext.socket.getUsers().then((t=>{const e={},s=d.I18n.getLanguage();this.props.schema.short?t.forEach((t=>{var i,o;return e[t._id]={color:null===(i=t.common)||void 0===i?void 0:i.color,icon:null===(o=t.common)||void 0===o?void 0:o.icon,name:d.Utils.getObjectNameFromObj(t,s)}})):t.forEach((t=>{var i,o;return e[t._id.replace(/^system\.user\./,"")]={color:null===(i=t.common)||void 0===i?void 0:i.color,icon:null===(o=t.common)||void 0===o?void 0:o.icon,name:d.Utils.getObjectNameFromObj(t,s)}})),this.setState({users:e})})).catch((t=>console.error("Cannot get users: ".concat(t))))}renderItem(t,e){var s,i;const o=x.getValue(this.props.data,this.props.attr);return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,children:[this.state.users&&this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,this.state.users?(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:o,renderValue:t=>{var e,s,i;return(0,u.jsxs)("span",{children:[this.state.users&&null!==(e=this.state.users[t])&&void 0!==e&&e.icon?(0,u.jsx)(d.Icon,{src:this.state.users&&(null===(s=this.state.users[t])||void 0===s?void 0:s.icon),style:_e.icon}):null,this.state.users&&(null===(i=this.state.users[t])||void 0===i?void 0:i.name)||t||""]})},style:{color:this.state.users&&(null===(s=this.state.users[o])||void 0===s?void 0:s.color)||void 0,backgroundColor:d.Utils.getInvertedColor(this.state.users&&(null===(i=this.state.users[o])||void 0===i?void 0:i.color),this.props.oContext.themeType)},onChange:t=>this.onChange(this.props.attr,t.target.value),children:this.state.users&&Object.keys(this.state.users).map((t=>(0,u.jsxs)(p.MenuItem,{style:{color:this.state.users[t].color||void 0,backgroundColor:d.Utils.getInvertedColor(this.state.users[t].color,this.props.oContext.themeType)},value:t,children:[this.state.users[t].icon?(0,u.jsx)(d.Icon,{src:this.state.users[t].icon,style:_e.icon}):null,this.state.users[t].name]},t)))}):(0,u.jsx)(p.TextField,{variant:"standard",error:!!t,disabled:!!e,value:o,onChange:t=>this.onChange(this.props.attr,t.target.value),label:this.getText(this.props.schema.label)}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const Fe=class extends x{async componentDidMount(){super.componentDidMount();const t=await s.e(7249).then(s.bind(s,47249));this.setState({QRCode:t.default})}renderItem(){const t=this.state.QRCode;return t?(0,u.jsx)(t,{value:this.props.schema.data,size:this.props.schema.size,fgColor:this.props.schema.fgColor,bgColor:this.props.schema.bgColor,level:this.props.schema.level}):null}},Ne={accordion:f,alive:b,autocomplete:C,autocompleteSendTo:j,certCollection:k,certificate:T,certificates:D,checkbox:F,checkLicense:A,chip:q,chips:q,color:$,coordinates:Y,cron:I,custom:Q,datePicker:class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t})}renderItem(t,e){return(0,u.jsx)(X.DatePicker,{sx:t=>({width:"100%",borderBottom:"1px solid ".concat(t.palette.text.primary),"& fieldset":{display:"none"},"& input":{padding:"".concat(t.spacing(1.5)," 0 4px 0")},"& .MuiInputAdornment-root":{marginLeft:0,marginTop:1},"& label":{transform:"translate(0px, -9px) scale(0.75)"}}),format:this.props.oContext.systemConfig.dateFormat.toLowerCase().replace("mm","MM"),disabled:!!e,value:this.state.value,onChange:t=>{this.setState({value:t},(()=>this.onChange(this.props.attr,this.state.value)))},label:this.getText(this.props.schema.label)})}},deviceManager:tt,divider:le,file:vt,fileSelector:pt,func:ft,header:pe,image:Ct,imageSendTo:bt,instance:wt,interface:Tt,ip:yt,jsonEditor:Nt,language:Lt,license:Vt,number:Wt,objectId:Bt,password:Jt,pattern:zt,port:qt,qrCode:Fe,room:Kt,select:Gt,selectSendTo:Zt,sendto:te,sendTo:te,setState:se,slider:oe,state:ne,staticImage:ce,staticInfo:ge,staticLink:fe,staticText:fe,table:we,text:Te,textSendTo:De,timePicker:class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t})}renderItem(t,e){const s="HH:mm:ss"!==this.props.schema.returnFormat,i=new Date(Date.parse("Thu, 01 Jan 1970 ".concat(this.state.value||"00:00:00")));return(0,u.jsx)(X.TimePicker,{sx:t=>({width:"100%",borderBottom:"1px solid ".concat(t.palette.text.primary),"& fieldset":{display:"none"},"& input":{padding:"".concat(t.spacing(1.5)," 0 4px 0")},"& .MuiInputAdornment-root":{marginLeft:0,marginTop:1},"& label":{transform:"translate(0px, -9px) scale(0.75)"}}),ampm:this.props.oContext.systemConfig.dateFormat.includes("/"),timeSteps:this.props.schema.timeSteps||this.props.schema.timesteps||{hours:1,minutes:5,seconds:5},format:this.props.schema.format||"HH:mm:ss",disabled:!!e,value:i,onChange:t=>{let e;e=t instanceof Date?t.toTimeString().split(" ")[0]:t.toTimeString(),s&&(e=e.split(":").slice(0,2).join(":")),this.setState({value:e},(()=>this.onChange(this.props.attr,this.state.value)))},views:this.props.schema.views||["hours","minutes","seconds"],label:this.getText(this.props.schema.label)})}},topic:ke,uuid:Oe,user:Ae},Ee={fullWidth:{width:"100%"},paper:{margin:1,width:"auto !important",overflowY:"auto",paddingBottom:1},paperWithIcons:{height:"calc(100vh - 259px) !important"},paperWithoutIcons:{height:"calc(100vh - 235px) !important"},padding:{padding:"10px"},heading:{},primary:t=>({backgroundColor:t.palette.primary.main,color:"dark"===t.palette.mode?"inherit":"#FFF"}),secondary:t=>({backgroundColor:t.palette.secondary.main})};class Le extends x{componentDidMount(){super.componentDidMount(),this.props.schema&&this.props.schema.collapsable&&this.setState({expanded:"true"===(window._localStorage||window.localStorage).getItem("".concat(this.props.oContext.adapterName,".").concat(this.props.attr))})}renderItems(t,e){return t?Object.keys(t).map((s=>{if(this.props.oContext.multiEdit&&t[s].noMultiEdit)return null;const i=t[s].type||"panel";let o,a="Use this.props.oContext.socket!";return"custom"===i?(t[s].url?o=Q:this.props.oContext.customs&&this.props.oContext.customs[t[s].component]?o=this.props.oContext.customs[t[s].component]:(console.error("Cannot find custom component: ".concat(t[s].component)),o=x),a=this.props.oContext.socket):o="panel"===i?Le:Ne[i]||x,(0,u.jsx)(o,{socket:a,globalData:this.props.globalData,oContext:this.props.oContext,index:this.props.index,changed:this.props.changed,arrayIndex:this.props.arrayIndex,commandRunning:this.props.commandRunning,style:Ee.panel,common:this.props.common,alive:this.props.alive,themeName:this.props.themeName,data:this.props.data,originalData:this.props.originalData,onError:this.props.onError,onChange:this.props.onChange,disabled:e,customObj:this.props.customObj,custom:this.props.custom,schema:t[s],attr:s,table:this.props.table},"".concat(s,"_").concat(void 0===this.props.index?"":this.props.index))})):null}render(){const t=this.props.schema;if(!t)return null;const{disabled:e,hidden:s}=this.calculate(t),o=this.props.schema.items,a=this.props.schema.style||{};if(s){if(t.hideOnlyControl){const e=(0,u.jsx)(p.Grid2,{size:{xs:t.xs||void 0,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},sx:d.Utils.getStyle(this.props.oContext.theme,{marginBottom:0,textAlign:"left"},a,"dark"===this.props.oContext.themeType&&t.darkStyle)});return t.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return null}if(this.props.table)return this.renderItems(o,e);if(this.props.custom)return(0,u.jsx)(p.Grid2,{container:!0,style:Ee.fullWidth,columnSpacing:2,rowSpacing:1,sx:a,children:this.renderItems(o,e)},"".concat(this.props.attr,"_").concat(this.props.index));let n;if(n=t.collapsable?(0,u.jsxs)(p.Accordion,{style:Ee.fullWidth,expanded:!!this.state.expanded,onChange:()=>{(window._localStorage||window.localStorage).setItem("".concat(this.props.oContext.adapterName,".").concat(this.props.attr),this.state.expanded?"false":"true"),this.setState({expanded:!this.state.expanded})},children:[(0,u.jsx)(p.AccordionSummary,{expandIcon:(0,u.jsx)(c.ExpandMore,{}),sx:d.Utils.getStyle(this.props.oContext.theme,a,this.props.oContext.themeType&&t.darkStyle,"primary"===t.color?Ee.primary:"secondary"===t.color&&Ee.secondary,{width:"100%"}),children:(0,u.jsx)(p.Typography,{style:Ee.heading,children:this.getText(t.label)})}),(0,u.jsx)(p.AccordionDetails,{children:(0,u.jsx)(p.Grid2,{container:!0,columnSpacing:2,rowSpacing:1,sx:(0,i.A)((0,i.A)({},a),{},{width:"100%",padding:"10px"}),children:this.renderItems(o,e)})})]},"".concat(this.props.attr,"_").concat(this.props.index)):(0,u.jsx)(p.Box,{component:"div",className:this.props.className,sx:d.Utils.getStyle(this.props.oContext.theme,this.props.style,a,{width:"100%"},this.props.isParentTab&&Ee.paper,this.props.isParentTab&&(this.props.withIcons?Ee.paperWithIcons:Ee.paperWithoutIcons)),children:(0,u.jsx)(p.Grid2,{container:!0,columnSpacing:2,rowSpacing:1,sx:d.Utils.getStyle(this.props.oContext.theme,{width:"100%"},this.props.isParentTab&&Ee.padding,this.props.schema.innerStyle),children:this.renderItems(o,e)})},"".concat(this.props.attr,"_").concat(this.props.index)),!this.props.isParentTab){const e=(0,u.jsx)(p.Grid2,{title:this.getText(t.tooltip),size:{xs:t.xs||void 0,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},sx:(0,i.A)({marginBottom:0,textAlign:"left"},a),children:n});return t.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return n}}const Ve=Le,Pe={tabs:{height:"100%",width:"100%"},panel:{width:"100%",display:"block"},panelWithIcons:{height:"calc(100% - 72px)"},panelWithoutIcons:{height:"calc(100% - 48px)"}};const We=class extends x{constructor(t){let e;if(super(t),this.onHashTabsChanged=()=>{const t=(window.location.hash||"").replace(/^#/,"").split("/");if(t.length>3&&"config"===t[1]){const e=t[3],s=parseInt(e,10);let i;s.toString()===e?s>=0&&s<Object.keys(this.props.schema.items).length&&(i=Object.keys(this.props.schema.items)[s]):Object.keys(this.props.schema.items).includes(e)&&(i=e),void 0!==i&&i!==this.state.tab&&((window._localStorage||window.localStorage).setItem("".concat(this.props.dialogName||"App",".").concat(this.props.oContext.adapterName),i),this.setState({tab:i}))}},this.props.root){const t=(window.location.hash||"").replace(/^#/,"").split("/");if(t.length>=3&&"config"===t[1]){const s=t[3],i=parseInt(s,10);s&&i.toString()===s?i>=0&&i<Object.keys(this.props.schema.items).length&&(e=Object.keys(this.props.schema.items)[i]):s&&Object.keys(this.props.schema.items).includes(s)&&(e=s),window.addEventListener("hashchange",this.onHashTabsChanged,!1)}}void 0===e&&(e=(window._localStorage||window.localStorage).getItem("".concat(this.props.dialogName||"App",".").concat(this.props.oContext.adapterName))||Object.keys(this.props.schema.items)[0],Object.keys(this.props.schema.items).includes(e)||(e=Object.keys(this.props.schema.items)[0])),Object.assign(this.state,{tab:e})}componentWillUnmount(){window.removeEventListener("hashchange",this.onHashTabsChanged,!1),super.componentWillUnmount()}render(){const t=this.props.schema.items;let e=!1;return(0,u.jsxs)("div",{style:Pe.tabs,children:[(0,u.jsx)(p.Tabs,{variant:"scrollable",scrollButtons:"auto",style:this.props.schema.tabsStyle,value:this.state.tab,onChange:(t,e)=>{(window._localStorage||window.localStorage).setItem("".concat(this.props.dialogName||"App",".").concat(this.props.oContext.adapterName),e),this.setState({tab:e},(()=>{if(this.props.root){const t=(window.location.hash||"").split("/");t.length>=3&&"config"===t[1]&&(t[3]=this.state.tab,window.location.hash=t.join("/"))}}))},children:Object.keys(t).map((s=>{let i;if(this.props.custom){if(this.executeCustom(t[s].hidden,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.index,this.props.globalData))return null;i=this.executeCustom(t[s].disabled,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.index,this.props.globalData)}else{if(this.execute(t[s].hidden,!1,this.props.data,this.props.index,this.props.globalData))return null;i=this.execute(t[s].disabled,!1,this.props.data,this.props.index,this.props.globalData)}const o=this.getIcon(t[s].icon);return e=e||!!o,(0,u.jsx)(p.Tab,{id:s,wrapped:!0,disabled:i,value:s,iconPosition:this.props.schema.iconPosition||"start",icon:o,label:this.getText(t[s].label)},s)}))}),(0,u.jsx)(Ve,{oContext:this.props.oContext,isParentTab:!0,changed:this.props.changed,index:1001,arrayIndex:this.props.arrayIndex,globalData:this.props.globalData,commandRunning:this.props.commandRunning,style:(0,i.A)((0,i.A)({},Pe.panel),e?Pe.panelWithIcons:Pe.panelWithoutIcons),common:this.props.common,alive:this.props.alive,themeName:this.props.themeName,data:this.props.data,originalData:this.props.originalData,onChange:this.props.onChange,onError:this.props.onError,customObj:this.props.customObj,custom:this.props.custom,schema:t[this.state.tab],table:this.props.table,withIcons:e},this.state.tab)]})}},Ue={root:{width:"100%",height:"100%"}};class Be extends o.Component{constructor(t){super(t),this.forceUpdateHandlers=void 0,this.errorTimeout=null,this.errorCached=null,this.oContext=void 0,this.onCommandRunning=t=>this.setState({commandRunning:t}),this.onAlive=(t,e)=>{!(null===e||void 0===e||!e.val)!==this.state.alive&&this.setState({alive:!(null===e||void 0===e||!e.val)})},this.onChange=(t,e,s,i)=>{if(this.props.onValueChange)this.props.onValueChange(t,e,i),s&&s();else if(t&&this.props.onChange){const e={changed:JSON.stringify(t)!==this.state.originalData};this.setState(e,(()=>{this.props.onChange(t,e.changed,i),s&&s()}))}else i&&this.props.onChange(null,null,i)},this.onError=(t,e)=>{this.errorCached=this.errorCached||JSON.parse(JSON.stringify(this.state.errors));const s=this.errorCached;e?s[t]=e:delete s[t],this.errorTimeout&&clearTimeout(this.errorTimeout),JSON.stringify(s)!==JSON.stringify(this.state.errors)?this.errorTimeout=setTimeout((()=>this.setState({errors:this.errorCached},(()=>{this.errorTimeout=null,this.errorCached=null,this.props.onError(!!Object.keys(this.state.errors).length)}))),50):this.errorCached=null},this.changeLanguage=()=>{this.forceUpdate()},this.forceAttrUpdate=(t,e)=>{Array.isArray(t)?t.forEach((t=>this.forceUpdateHandlers[t]&&this.forceUpdateHandlers[t](e))):this.forceUpdateHandlers[t]&&this.forceUpdateHandlers[t](e)},this.registerOnForceUpdate=(t,e)=>{e?this.forceUpdateHandlers[t]=e:this.forceUpdateHandlers[t]&&delete this.forceUpdateHandlers[t]},this.state={originalData:JSON.stringify(this.props.data),changed:!1,errors:{},updateData:this.props.updateData||0,systemConfig:null,alive:!1,commandRunning:!1,schema:JSON.parse(JSON.stringify(this.props.schema))},this.forceUpdateHandlers={},this.buildDependencies(this.state.schema),this.readData()}static getDerivedStateFromProps(t,e){return t.updateData!==e.updateData?{updateData:t.updateData,originalData:JSON.stringify(t.data),schema:JSON.parse(JSON.stringify(t.schema))}:null}static async loadI18n(t,e,s){if(!0===e||e&&"string"===typeof e){const o=d.I18n.getLanguage(),a="string"===typeof e?e:"i18n";let n,r=await t.fileExists("".concat(s,".admin"),"".concat(a,"/").concat(o,".json"));if(r?n="".concat(a,"/").concat(o,".json"):(r=await t.fileExists("".concat(s,".admin"),"".concat(a,"/").concat(o,"/translations.json")),r?n="".concat(a,"/").concat(o,"/translations.json"):"en"!==o&&(r=await t.fileExists("".concat(s,".admin"),"".concat(a,"/en.json")),r?n="".concat(a,"/en.json"):(r=await t.fileExists("".concat(s,".admin"),"".concat(a,"/en/translations.json")),r&&(n="".concat(a,"/en/translations.json"))))),n){const e=await t.readFile("".concat(s,".admin"),n);let a;a=void 0!==e.file?e.file:e;try{const t=JSON.parse(a);d.I18n.extendTranslations(t,o)}catch(i){return console.error('Cannot parse language file "'.concat(s,".admin/").concat(n,": ").concat(i)),""}return n}return console.warn("Cannot find i18n for ".concat(s," / ").concat(n)),""}return e&&"object"===typeof e?(d.I18n.extendTranslations(e),""):""}readData(){this.props.socket.getCompactSystemConfig().then((t=>this.props.socket.getState("system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance,".alive")).then((e=>this.setState({systemConfig:t.common,alive:!(!e||!e.val)},(()=>{this.updateContext(!0),this.props.custom||this.props.socket.subscribeState("system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance,".alive"),this.onAlive)})))))).catch((t=>console.error("Cannot read system config: ".concat(t))))}flatten(t,e){return e=e||{},t.items&&Object.keys(t.items).forEach((s=>{e[s]=t.items[s],this.flatten(t.items[s],e)})),e}buildDependencies(t){const e=this.flatten(t);Object.keys(e).forEach((t=>{var s,o,a,n,r,l,h,p,c,d;null!==(s=e[t].confirm)&&void 0!==s&&s.alsoDependsOn&&(null===(l=e[t].confirm)||void 0===l||l.alsoDependsOn.forEach((s=>{if(e[s]){e[s].confirmDependsOn=e[s].confirmDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});o.confirm&&(o.confirm.cancel="Undo"),e[s].confirmDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));null!==(o=e[t].onChange)&&void 0!==o&&o.alsoDependsOn&&(null===(h=e[t].onChange)||void 0===h||h.alsoDependsOn.forEach((s=>{if(e[s]){e[s].onChangeDependsOn=e[s].onChangeDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});e[s].onChangeDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));null!==(a=e[t].hidden)&&void 0!==a&&a.alsoDependsOn&&(null===(p=e[t].hidden)||void 0===p||p.alsoDependsOn.forEach((s=>{if(e[s]){e[s].hiddenDependsOn=e[s].hiddenDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});e[s].hiddenDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));null!==(n=e[t].label)&&void 0!==n&&n.alsoDependsOn&&(null===(c=e[t].label)||void 0===c||c.alsoDependsOn.forEach((s=>{if(e[s]){e[s].labelDependsOn=e[s].labelDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});e[s].labelDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));null!==(r=e[t].help)&&void 0!==r&&r.alsoDependsOn&&(null===(d=e[t].help)||void 0===d||d.alsoDependsOn.forEach((s=>{if(e[s]){e[s].helpDependsOn=e[s].helpDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});e[s].helpDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})))}))}updateContext(t){this.oContext={DeviceManager:this.props.DeviceManager,adapterName:this.props.adapterName,changeLanguage:this.changeLanguage,common:this.props.common,customs:this.props.customs,dateFormat:this.props.dateFormat,embedded:this.props.embedded,expertMode:this.props.expertMode,forceUpdate:this.forceAttrUpdate,imagePrefix:this.props.imagePrefix,instance:this.props.instance,instanceObj:this.props.instanceObj,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,onBackEndCommand:this.props.onBackEndCommand,onCommandRunning:this.onCommandRunning,onValueChange:this.props.onValueChange,registerOnForceUpdate:this.registerOnForceUpdate,socket:this.props.socket,systemConfig:this.state.systemConfig,theme:this.props.theme,themeType:this.props.themeType,_themeName:this.props.themeName,updateData:this.state.updateData},t&&this.forceUpdate()}renderItem(t){return"tabs"===t.type?(0,u.jsx)(We,{oContext:this.oContext,alive:this.state.alive,changed:this.state.changed,commandRunning:this.state.commandRunning,common:this.props.common,custom:this.props.custom,customObj:this.props.customObj,data:this.props.data,onChange:this.onChange,onError:(t,e)=>this.onError(t,e),originalData:JSON.parse(this.state.originalData),root:!0,schema:t,themeName:this.props.themeName}):"panel"!==t.type&&t.type?(console.error("Unknown item type in root: ".concat(JSON.stringify(t))),null):(0,u.jsx)(Ve,{oContext:this.oContext,alive:this.state.alive,changed:this.state.changed,commandRunning:this.state.commandRunning,common:this.props.common,custom:this.props.custom,customObj:this.props.customObj,data:this.props.data,index:1e3,isParentTab:!this.props.embedded,onChange:this.onChange,onError:(t,e)=>this.onError(t,e),originalData:JSON.parse(this.state.originalData),root:!0,schema:t,themeName:this.props.themeName})}render(){return this.state.systemConfig&&this.oContext?(this.oContext._themeName!==this.props.themeName&&(this.oContext._themeName=this.props.themeName,setTimeout((()=>this.updateContext(!0)),0)),(0,u.jsx)("div",{style:(0,i.A)((0,i.A)((0,i.A)({},this.props.embedded?void 0:Ue.root),this.props.style),this.state.schema.style),children:this.renderItem(this.state.schema)})):(0,u.jsx)(p.LinearProgress,{})}}const Re=Be,Me={root:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},scroll:{height:"calc(100% - 48px)",overflowY:"auto"},exportImportButtons:{position:"absolute",top:5,right:0,zIndex:3},button:{marginRight:"5px"},tooltip:{pointerEvents:"none"}};function Je(t,e){if("string"!==typeof e)return e;if(!e.startsWith("$/aes-192-cbc:")||!/^[0-9a-f]{48}$/.test(t))return function(t,e){let s="";for(let i=0;i<e.length;i++)s+=String.fromCharCode(t[i%t.length].charCodeAt(0)^e.charCodeAt(i));return s}(t,e);const s=e.split(":",3),i=window.CryptoJS.enc.Hex.parse(t),o=window.CryptoJS.enc.Hex.parse(s[1]),a=window.CryptoJS.lib.CipherParams.create({ciphertext:window.CryptoJS.enc.Hex.parse(s[2])}),n=window.CryptoJS.AES.decrypt(a,i,{iv:o});return window.CryptoJS.enc.Utf8.stringify(n)}function ze(t,e,s){if("string"!==typeof e)return e;if(!/^[0-9a-f]{48}$/.test(t))return function(t,e){let s="";for(let i=0;i<e.length;i++)s+=String.fromCharCode(t[i%t.length].charCodeAt(0)^e.charCodeAt(i));return s}(t,e);let i;i=s?window.CryptoJS.enc.Hex.parse(s):window.CryptoJS.lib.WordArray.random(16);const o=window.CryptoJS.enc.Hex.parse(t),a=window.CryptoJS.AES.encrypt(e,o,{iv:i}).ciphertext;return"$/aes-192-cbc:".concat(window.CryptoJS.enc.Hex.stringify(i),":").concat(a)}function He(t,e){var s;return e&&document.getElementById(e)?null===(s=document.getElementById(e))||void 0===s?void 0:s.onload:new Promise((s=>{const i=document.createElement("script");i.setAttribute("id",e),i.onload=s,i.src=t,document.getElementsByTagName("head")[0].appendChild(i)}))}class qe extends d.Router{constructor(t){super(t),this.fileSubscribed=[],this.fileLangSubscribed="",this.secret=void 0,this.handleFileSelect=t=>{const e=t.target.files[0];if(e){const t=new FileReader;t.onload=t=>{if(!t.target)return;const e=t.target.result;try{const t=JSON.parse(e);this.setState({data:t,changed:JSON.stringify(t)!==JSON.stringify(this.state.originalData)})}catch(s){window.alert(d.I18n.t("[JsonConfig] Failed to parse JSON file"))}},t.readAsText(e)}else window.alert(d.I18n.t("[JsonConfig] Failed to open JSON File"))},this.onFileChange=async(t,e,s)=>{if(t==="".concat(this.props.adapterName,".admin")&&s)if(e===this.fileLangSubscribed)try{var i;await Re.loadI18n(this.props.socket,null===(i=this.state.schema)||void 0===i?void 0:i.i18n,this.props.adapterName),this.setState({hash:"".concat(this.state.hash,"1")})}catch(o){}else if(this.fileSubscribed.includes(e))try{const t=await this.getConfigFile(this.fileSubscribed[0]);this.setState({schema:t,hash:h()(JSON.stringify(t)).toString()})}catch(a){}},this.state={updateData:0,changed:!1,confirmDialog:!1,theme:(0,d.Theme)(t.themeName),saveConfigDialog:!1,hash:"_"},this.secret=t.secret||"",this.getInstanceObject().then((t=>this.getConfigFile().then((e=>Re.loadI18n(this.props.socket,null===e||void 0===e?void 0:e.i18n,this.props.adapterName).then((s=>{s&&(this.fileLangSubscribed||(this.fileLangSubscribed=s,this.props.socket.subscribeFiles("".concat(this.props.adapterName,".admin"),this.fileLangSubscribed,this.onFileChange))),t?this.setState({schema:e,data:t.native,common:t.common,hash:h()(JSON.stringify(e)).toString()}):window.alert("Instance system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance," not found!"))}))))))}componentWillUnmount(){super.componentWillUnmount(),this.fileSubscribed.length&&(this.props.socket.unsubscribeFiles("".concat(this.props.adapterName,".admin"),this.fileSubscribed,this.onFileChange),this.fileSubscribed=[]),this.fileLangSubscribed&&(this.props.socket.unsubscribeFiles("".concat(this.props.adapterName,".admin"),this.fileLangSubscribed,this.onFileChange),this.fileLangSubscribed="")}getExportImportButtons(){return(0,u.jsxs)("div",{style:Me.exportImportButtons,children:[(0,u.jsx)(p.Tooltip,{title:this.props.t("Import settings from JSON file"),slotProps:{popper:{sx:Me.tooltip}},children:(0,u.jsx)(p.Fab,{size:"small",sx:{"&.MuiFab-root":Me.button},onClick:()=>{const t=document.createElement("input");t.setAttribute("type","file"),t.setAttribute("id","files"),t.setAttribute("opacity",0),t.addEventListener("change",(t=>this.handleFileSelect(t)),!1),t.click()},children:(0,u.jsx)(c.Publish,{})})}),(0,u.jsx)(p.Tooltip,{title:this.props.t("Export setting to JSON file"),slotProps:{popper:{sx:Me.tooltip}},children:(0,u.jsx)(p.Fab,{size:"small",sx:{"&.MuiFab-root":Me.button},onClick:()=>{this.state.data&&d.Utils.generateFile("".concat(this.props.adapterName,".").concat(this.props.instance,".json"),this.state.data)},children:(0,u.jsx)(c.Publish,{style:{transform:"rotate(180deg)"}})})})]})}async getInstanceObject(){try{const e=await this.props.socket.getObject("system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance));if(Array.isArray(e.encryptedNative)){var t;if(!this.secret){const t=await this.props.socket.getSystemConfig();await He("../../lib/js/crypto-js/crypto-js.js","crypto-js"),this.secret=t.native.secret}return null===(t=e.encryptedNative)||void 0===t||t.forEach((t=>{e.native[t]&&(e.native[t]=Je(this.secret,e.native[t]))})),e}return e}catch(e){window.alert("[JsonConfig] Cannot read instance object: ".concat(e))}return null}renderDialogConfirm(){return this.state.confirmDialog?(0,u.jsx)(d.DialogConfirm,{title:d.I18n.t("ra_Please confirm"),text:d.I18n.t("ra_Some data are not stored. Discard?"),ok:d.I18n.t("ra_Discard"),cancel:d.I18n.t("ra_Cancel"),onClose:t=>this.setState({confirmDialog:!1},(()=>t&&d.Router.doNavigate(null)))}):null}async scanForInclude(t,e){if("string"===typeof t["#include"]){const s=await this._getConfigFile(t["#include"],[...e]);return delete t["#include"],s&&(t=(0,i.A)((0,i.A)({},t),s)),t}const s=Object.keys(t);for(let i=0;i<s.length;i++)t[s[i]]&&"object"===typeof t[s[i]]&&(t[s[i]]=await this.scanForInclude(t[s[i]],e));return t}async getConfigFile(t){return this._getConfigFile(t)}async _getConfigFile(t,e){if(t=t||"jsonConfig.json5",(e=e||[]).includes(t))return window.alert("[JsonConfig] Circular reference in file: ".concat(t," => ").concat(e.join(" => "))),null;e.push(t);try{await this.props.socket.fileExists("".concat(this.props.adapterName,".admin"),t)||(t="jsonConfig.json");const i=await this.props.socket.readFile("".concat(this.props.adapterName,".admin"),t);let o="",a="";if(void 0!==i.file&&(a=i.file),"string"===typeof a)o=a;else if("Buffer"===a.type){let t="";const e=new Uint8Array(a.data),s=e.byteLength;for(let i=0;i<s;i++)t+=String.fromCharCode(e[i]);o=t}this.fileSubscribed.includes(t)||(this.fileSubscribed.push(t),await this.props.socket.subscribeFiles("".concat(this.props.adapterName,".admin"),t,this.onFileChange));try{return await this.scanForInclude(r().parse(o),e)}catch(s){window.alert("[JsonConfig] Cannot parse json5 config!"),console.log(s)}}catch(i){this.state.schema||window.alert('[JsonConfig] Cannot read file "'.concat(t,": ").concat(i))}return null}renderSaveConfigDialog(){return this.state.saveConfigDialog?(0,u.jsx)(d.DialogConfirm,{title:d.I18n.t("ra_Please confirm"),text:d.I18n.t("Save configuration?"),ok:d.I18n.t("ra_Save"),cancel:d.I18n.t("ra_Cancel"),onClose:t=>this.setState({saveConfigDialog:!1},(()=>t&&this.onSave(!0)))}):null}findAttr(t,e){var s;if(null!==(s=e=e||this.state.schema)&&void 0!==s&&s.items){if(t in e.items)return e.items[t];for(const s of Object.values(e.items)){const e=this.findAttr(t,s);if(e)return e}}return null}postProcessing(t,e,s){if(s=s||this.state.schema,!t)return void console.error("Data is empty in postProcessing: ".concat(e,", ").concat(JSON.stringify(s)));const i=t[e];if(s.items)if("table"===s.type){const t=i;if(!Array.isArray(t))return;for(const e of t)for(const t of s.items)this.postProcessing(e,t.attr,t)}else for(const[o,a]of Object.entries(s.items)){if("panel"===a.type||"tabs"===a.type||"accordion"===a.type)return;this.postProcessing(t,o,a)}else if(e&&"string"===typeof i)if("text"===s.type)!1!==s.trim&&(t[e]=i.trim());else if("ip"===s.type)t[e]=i.trim();else if("number"===s.type){const o=parseFloat(i.toString().replace(",","."));void 0!==s.min&&o<s.min?t[e]=s.min:void 0!==s.max&&o>s.max?t[e]=s.max:t[e]=o}else if("port"===s.type){const o=parseInt(i.toString(),10);void 0!==s.min&&o<s.min?t[e]=s.min:void 0!==s.max&&o>s.max&&(t[e]=s.max),0!==t[e]&&o<20?t[e]=20:t[e]=o>65535?65535:o}else"checkbox"===s.type&&(t[e]=!0===t[e]||"true"===t[e]||"on"===t[e]||1===t[e]||"1"===t[e])}async onSave(t,e){if(t){const t=await this.getInstanceObject();if(!t)return console.error("Something went wrong: may be no connection?"),void window.alert("Something went wrong: may be no connection?");if(!this.state.data||!this.state.schema)return;const o={};for(const e of Object.keys(this.state.data)){const s=this.findAttr(e);s&&s.doNotSave&&"state"!==s.type||e.startsWith("_")?(x.setValue(t.native,e,null),o[e]=this.state.data[e]):x.setValue(t.native,e,this.state.data[e])}try{const e=JSON.parse(JSON.stringify(t));if(Array.isArray(e.encryptedNative)){await He("../../lib/js/crypto-js/crypto-js.js","crypto-js");for(const t of e.encryptedNative)e.native[t]&&(e.native[t]=ze(this.secret,e.native[t]))}await this.props.socket.setObject(e._id,e)}catch(s){window.alert("[JsonConfig] Cannot set object: ".concat(s))}const a=(0,i.A)((0,i.A)({},t.native),o);console.log(a),this.setState({changed:!1,data:a,updateData:this.state.updateData+1,originalData:a},(()=>e&&d.Router.doNavigate(null)))}else this.state.changed?this.setState({confirmDialog:!0}):d.Router.doNavigate(null)}componentDidUpdate(t,e){e.changed!==this.state.changed&&this.props.configStored(!this.state.changed)}async componentDidMount(){const t="".concat(window.location.protocol,"//").concat(window.location.host).concat(window.location.pathname,"validate_config/").concat(this.props.adapterName);console.log("fetch ".concat(t)),await fetch(t)}render(){return this.state.data&&this.state.schema?(0,u.jsxs)("div",{style:Me.root,children:[this.renderDialogConfirm(),this.getExportImportButtons(),this.renderSaveConfigDialog(),(0,u.jsx)(Re,{style:Me.scroll,socket:this.props.socket,themeName:this.props.themeName,themeType:this.props.themeType,adapterName:this.props.adapterName,instance:this.props.instance,isFloatComma:this.props.isFloatComma,dateFormat:this.props.dateFormat,schema:this.state.schema,common:this.state.common,expertMode:this.props.expertMode,data:this.state.data,updateData:this.state.updateData,onError:t=>this.setState({error:t}),onChange:(t,e,s)=>{s&&this.state.error&&(window.alert(d.I18n.t("Cannot save configuration because of error in configuration")),s=!1),!s||this.state.changed||e||(s=!1),t?this.setState({data:t,changed:e,saveConfigDialog:s}):void 0!==s&&this.setState({saveConfigDialog:s})},DeviceManager:this.props.DeviceManager,theme:this.state.theme},this.state.hash),(0,u.jsx)(d.SaveCloseButtons,{isIFrame:!1,dense:!0,paddingLeft:0,newReact:!0,theme:this.state.theme,noTextOnButtons:"xs"===this.props.width||"sm"===this.props.width||"md"===this.props.width,changed:!(!this.state.error&&!this.state.changed),error:!!this.state.error,onSave:t=>this.onSave(!0,t),onClose:()=>this.onSave(!1)})]}):(0,u.jsx)(p.LinearProgress,{})}}const Ke=qe},75443:()=>{}}]);
|
|
2
|
-
//# sourceMappingURL=6853.
|
|
1
|
+
(self.webpackChunksrc_rx=self.webpackChunksrc_rx||[]).push([[6853],{9995:(t,e,s)=>{"use strict";s.r(e),s.d(e,{ConfigGeneric:()=>x,ConfigPanel:()=>Ve,JsonConfig:()=>Ke,JsonConfigComponent:()=>Me});var i=s(89379),o=s(29183),a=s.n(o),n=s(77226),r=s.n(n),l=s(83931),h=s.n(l),p=s(89303),c=s(32075),d=s(16904),u=s(79159);const m=window.innerWidth<=600?12:void 0;function g(t){return"[object Object]"===Object.prototype.toString.call(t)}class x extends o.Component{constructor(t){super(t),this.defaultValue=void 0,this.isError=void 0,this.lang=void 0,this.defaultSendToDone=void 0,this.sendToTimeout=void 0,this.noPlaceRequired=void 0,this.onUpdate=t=>{const e=x.getValue(t||this.props.data,this.props.attr)||"";this.state.value!==e?this.setState({value:e}):this.forceUpdate()},this.state={confirmDialog:!1,confirmNewValue:null,confirmAttr:null,confirmData:null,confirmCallback:null},this.isError={},t.schema&&(t.custom?this.defaultValue=t.schema.defaultFunc?this.executeCustom(t.schema.defaultFunc,t.data,t.customObj,t.oContext.instanceObj,t.arrayIndex,t.globalData):t.schema.default:"state"!==t.schema.type&&(this.defaultValue=t.schema.defaultFunc?this.execute(t.schema.defaultFunc,t.schema.default,t.data,t.arrayIndex,t.globalData):t.schema.default)),this.lang=d.I18n.getLanguage()}componentDidMount(){this.props.oContext.registerOnForceUpdate&&this.props.oContext.registerOnForceUpdate(this.props.attr,this.onUpdate);const t=["select","autocomplete","autocompleteSendTo"];if(void 0!==this.defaultValue){const e=x.getValue(this.props.data,this.props.attr);(void 0===e||t.includes(this.props.schema.type)&&(""===e||null===e))&&setTimeout((()=>{this.props.custom?this.props.onChange(this.props.attr,this.defaultValue,(()=>setTimeout((()=>this.props.oContext.forceUpdate([this.props.attr],this.props.data)),100))):(x.setValue(this.props.data,this.props.attr,this.defaultValue),this.props.onChange(this.props.data,void 0,(()=>this.props.oContext.forceUpdate([this.props.attr],this.props.data))))}),100)}else this.props.schema.defaultSendTo&&this.sendTo()}sendTo(){if(this.props.alive){this.defaultSendToDone=!0;let e=this.props.schema.data;if(void 0===e&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,null,!0);try{e=JSON.parse(s)}catch(t){console.error("Cannot parse json data: ".concat(s))}}else e={attr:this.props.attr,value:x.getValue(this.props.data,this.props.attr)};void 0===e&&(e=null),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.defaultSendTo,e).then((t=>{null!==t&&void 0!==t&&(this.props.custom?this.props.onChange(this.props.attr,t,(()=>this.props.oContext.forceUpdate([this.props.attr],this.props.data))):(x.setValue(this.props.data,this.props.attr,t),this.props.onChange(this.props.data,void 0,(()=>this.props.oContext.forceUpdate([this.props.attr],this.props.data)))))}))}else this.defaultSendToDone=!1,this.props.schema.allowSaveWithError||this.onError(this.props.attr,d.I18n.t("ra_Instance %s is not alive",this.props.oContext.instance.toString()))}componentWillUnmount(){this.props.oContext.registerOnForceUpdate&&this.props.oContext.registerOnForceUpdate(this.props.attr),this.sendToTimeout&&(clearTimeout(this.sendToTimeout),this.sendToTimeout=null)}static getValue(t,e){if("string"===typeof e)return x.getValue(t,e.split("."));if(1===e.length)return t[e[0]];const s=e.shift();return"string"===typeof s&&"object"===typeof t[s]?x.getValue(t[s],e):void 0}static setValue(t,e,s){if("string"!==typeof e)if(1===e.length)null===s?delete t[e[0]]:t[e[0]]=s;else{const i=e.shift();if("string"!==typeof i)return;t[i]&&"object"!==typeof t[i]||(t[i]=t[i]||{}),x.setValue(t[i],e,s)}else x.setValue(t,e.split("."),s)}getText(t,e){if(!t)return"";if("string"===typeof t){const s=e?t:d.I18n.t(t);return s.includes("${")?this.getPattern(s,null,e):s}return g(t)?t.func?"object"===typeof t.func?this.getPattern(t.func[this.lang]||t.func.en||"",null,!0):this.getPattern(t.func,null,e):t[this.lang]||t.en||"":t.toString()}renderDialogConfirm(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,u.jsx)(c.Warning,{}):"error"===t.type?e=(0,u.jsx)(c.Error,{}):"info"===t.type&&(e=(0,u.jsx)(c.Info,{})),(0,u.jsx)(d.DialogConfirm,{title:this.getText(t.title)||d.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||d.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||d.I18n.t("ra_Cancel"),icon:e||void 0,onClose:t=>this.setState({confirmDialog:!1},(()=>{if(t){if(this.state.confirmCallback){const t=this.state.confirmCallback;return void this.setState({confirmCallback:null},(()=>t(!0)))}const t=JSON.parse(JSON.stringify(this.props.data));this.state.confirmDepAttr&&x.setValue(t,this.state.confirmDepAttr,this.state.confirmDepNewValue),x.setValue(t,this.state.confirmAttr,this.state.confirmNewValue),this.setState({confirmDialog:!1,confirmDepAttr:null,confirmDepNewValue:null,confirmNewValue:null,confirmAttr:null,confirmData:null},(()=>this.props.onChange(t)))}else{const t=this.state.confirmCallback;this.setState({confirmDialog:!1,confirmDepAttr:null,confirmDepNewValue:null,confirmNewValue:null,confirmAttr:null,confirmData:null,confirmCallback:null},(()=>{t&&t(!1)}))}}))})}getIcon(t){let e=null;return"auth"===(t=t||this.props.schema.icon)?e=(0,u.jsx)(c.Key,{}):"send"===t?e=(0,u.jsx)(c.Send,{}):"web"===t?e=(0,u.jsx)(c.Public,{}):"warning"===t?e=(0,u.jsx)(c.Warning,{}):"error"===t?e=(0,u.jsx)(c.Error,{}):"info"===t?e=(0,u.jsx)(c.Info,{}):"search"===t?e=(0,u.jsx)(c.Search,{}):"book"===t?e=(0,u.jsx)(c.MenuBook,{}):"help"===t?e=(0,u.jsx)(c.Help,{}):"upload"===t?e=(0,u.jsx)(c.UploadFile,{}):"edit"===t?e=(0,u.jsx)(c.Edit,{}):"user"===t?e=(0,u.jsx)(c.Person,{}):"group"===t?e=(0,u.jsx)(c.Group,{}):"delete"===t?e=(0,u.jsx)(c.Delete,{}):"refresh"===t?e=(0,u.jsx)(c.Refresh,{}):"add"===t?e=(0,u.jsx)(c.Add,{}):"unpair"===t?e=(0,u.jsx)(c.LinkOff,{}):"pair"===t?e=(0,u.jsx)(c.Link,{}):"save"===t?e=(0,u.jsx)(c.Save,{}):"open"===t?e=(0,u.jsx)(c.OpenInNew,{}):t&&((t.endsWith(".png")||t.endsWith(".svg")||t.endsWith(".jpg"))&&(t.startsWith("http://")||t.startsWith("https://")||(t="./adapter/".concat(this.props.oContext.adapterName,"/").concat(t))),e=(0,u.jsx)(d.Icon,{src:t,style:{width:22,height:22}})),e}onChangeAsync(t,e){return new Promise((s=>{const i=this.onChange(t,e,s);i instanceof Promise&&i.catch((t=>console.error("Cannot set value: ".concat(t))))}))}onChange(t,e,s){const i=JSON.parse(JSON.stringify(this.props.data));if(x.setValue(i,t,e),this.props.schema.confirm&&this.execute(this.props.schema.confirm.condition,!1,i,this.props.arrayIndex,this.props.globalData))return new Promise((i=>{this.setState({confirmDialog:!0,confirmNewValue:e,confirmAttr:t,confirmData:null},(()=>{"function"===typeof s?s():i()}))}));if(this.props.schema.confirmDependsOn)for(let a=0;a<this.props.schema.confirmDependsOn.length;a++){const o=this.props.schema.confirmDependsOn[a];if(o.confirm){const a=x.getValue(i,o.attr);if(this.execute(o.confirm.condition,!1,i,this.props.arrayIndex,this.props.globalData))return new Promise((i=>{this.setState({confirmDialog:!0,confirmNewValue:e,confirmAttr:t,confirmDepNewValue:a,confirmDepAttr:o.attr,confirmData:o.confirm},(()=>{"function"===typeof s?s():i()}))}))}}const o=[];if(this.props.schema.onChangeDependsOn)for(let a=0;a<this.props.schema.onChangeDependsOn.length;a++){const t=this.props.schema.onChangeDependsOn[a];if(t.onChange){const e=x.getValue(i,t.attr);let s;s=this.props.custom?this.executeCustom(t.onChange.calculateFunc,i,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):this.execute(t.onChange.calculateFunc,e,i,this.props.arrayIndex,this.props.globalData),s!==e&&(x.setValue(i,t.attr,s),o.push(t.attr))}}if(this.props.schema.hiddenDependsOn)for(let a=0;a<this.props.schema.hiddenDependsOn.length;a++){const t=this.props.schema.hiddenDependsOn[a];t.hidden&&o.push(t.attr)}if(this.props.schema.labelDependsOn)for(let a=0;a<this.props.schema.labelDependsOn.length;a++){const t=this.props.schema.labelDependsOn[a];t.hidden&&o.push(t.attr)}if(this.props.schema.helpDependsOn)for(let a=0;a<this.props.schema.helpDependsOn.length;a++){const t=this.props.schema.helpDependsOn[a];t.hidden&&o.push(t.attr)}if(this.props.schema.onChange&&!this.props.schema.onChange.ignoreOwnChanges){const t=x.getValue(i,this.props.attr),e=this.props.custom?this.executeCustom(this.props.schema.onChange.calculateFunc,i,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):this.execute(this.props.schema.onChange.calculateFunc,t,i,this.props.arrayIndex,this.props.globalData);e!==t&&x.setValue(i,this.props.attr,e)}return this.props.custom?(this.props.onChange(t,e,(()=>s&&s())),null!==o&&void 0!==o&&o.length&&o.forEach(((t,e)=>setTimeout((()=>this.props.onChange(t,x.getValue(i,t))),50*e)))):this.props.onChange(i,void 0,(()=>{o.length&&this.props.oContext.forceUpdate(o,i),s&&s()})),Promise.resolve()}execute(t,e,s,i,o){let a;if(g(t))a=t.func;else{if("string"!==typeof t)return t;a=t}if(!a)return e;try{return new Function("data","originalData","_system","_alive","_common","_socket","_instance","arrayIndex","globalData","_changed",a.includes("return")?a:"return ".concat(a))(s||this.props.data,this.props.originalData,this.props.oContext.systemConfig,this.props.alive,this.props.common,this.props.oContext.socket,this.props.oContext.instance,i,o,this.props.changed)}catch(n){return console.error("Cannot execute ".concat(JSON.stringify(t),": ").concat(n)),e}}executeCustom(t,e,s,i,o,a){let n;if(g(t))n=t.func;else{if("string"!==typeof t)return t;n=t}if(!n)return null;try{return new Function("data","originalData","_system","instanceObj","customObj","_socket","arrayIndex","globalData","_changed",n.includes("return")?n:"return ".concat(n))(e||this.props.data,this.props.originalData,this.props.oContext.systemConfig,i,s,this.props.oContext.socket,o,a,this.props.changed)}catch(r){return console.error("Cannot execute ".concat(n,": ").concat(r)),null}}calculate(t){let e,s,i,o;return this.props.custom?(e=!!t.validator&&!this.executeCustom(t.validator,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData),s=!0===t.disabled||!!t.disabled&&this.executeCustom(t.disabled,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData),i=!0===t.hidden||!!t.hidden&&this.executeCustom(t.hidden,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData),o=t.defaultFunc?this.executeCustom(t.defaultFunc,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):t.default):(e=!!t.validator&&!this.execute(t.validator,!1,this.props.data,this.props.arrayIndex,this.props.globalData),s=!0===t.disabled||!!t.disabled&&this.execute(t.disabled,!1,this.props.data,this.props.arrayIndex,this.props.globalData),i=!0===t.hidden||!!t.hidden&&this.execute(t.hidden,!1,this.props.data,this.props.arrayIndex,this.props.globalData),o=t.defaultFunc?this.execute(t.defaultFunc,t.default,this.props.data,this.props.arrayIndex,this.props.globalData):t.default),{error:e,disabled:s,hidden:i,defaultValue:o}}onError(t,e){e?this.isError[t]=e:delete this.isError[t],this.props.onError&&this.props.onError(t,e)}renderItem(t,e,s){return this.getText(this.props.schema.label)||this.getText(this.props.schema.text)}renderHelp(t,e,s){return e?(0,u.jsx)("a",{href:e,target:"_blank",rel:"noreferrer",style:{color:"dark"===this.props.oContext.themeType?"#a147ff":"#5b238f",textDecoration:"underline"},children:this.getText(t,s)}):(t=this.getText(t,s)||"")&&(t.includes("<a ")||t.includes("<br")||t.includes("<b>")||t.includes("<i>"))?d.Utils.renderTextWithA(t):t}static escapeString(t,e){return"string"!==typeof t?"":t=(t=t.replace(/`/g,"\\`")).replace(/\${([^}]+)}/g,((t,s)=>{if(s&&"string"===typeof s&&s.startsWith("data.")){const t=x.getValue(e,s.replace(/^data\./,""));if("string"===typeof t&&t.includes('"'))return"${".concat(s,".replace(/\"/g, '\\\\\"')}")}return t}))}getPattern(t,e,s){if(e=e||this.props.data,!t)return"";let i;"object"===typeof t?t.func?i=t.func:(console.log("Object must be stringified: ".concat(JSON.stringify(t))),i=JSON.stringify(t)):i=t;try{if(this.props.custom){return new Function("data","originalData","arrayIndex","globalData","_system","instanceObj","customObj","_socket","_changed","return `".concat(x.escapeString(i,e),"`"))(e,this.props.originalData,this.props.arrayIndex,this.props.globalData,this.props.oContext.systemConfig,this.props.oContext.instanceObj,this.props.customObj,this.props.oContext.socket,this.props.changed)}const t=new Function("data","originalData","arrayIndex","globalData","_system","_alive","_common","_socket","_changed","return `".concat(x.escapeString(i,e),"`"))(e,this.props.originalData,this.props.arrayIndex,this.props.globalData,this.props.oContext.systemConfig,this.props.alive,this.props.common,this.props.oContext.socket,this.props.changed);return s?t:d.I18n.t(t)}catch(o){return console.error("Cannot execute ".concat(i,": ").concat(o)),i}}render(){const t=this.props.schema;if(!t)return null;if(!1===this.props.oContext.expertMode&&t.expertMode)return null;this.props.alive&&!1===this.defaultSendToDone&&(this.sendToTimeout=setTimeout((()=>{this.sendToTimeout=null,this.sendTo()}),200));const{error:e,disabled:s,hidden:o,defaultValue:a}=this.calculate(t);if(o){if(Object.keys(this.isError).length&&(setTimeout((t=>Object.keys(t).forEach((t=>this.props.onError(t)))),100,JSON.parse(JSON.stringify(this.isError))),this.isError={}),t.hideOnlyControl){const e=(0,u.jsx)(p.Grid2,{size:{xs:t.xs||m,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},style:(0,i.A)((0,i.A)({marginBottom:0,textAlign:"left"},t.style),"dark"===this.props.oContext.themeType?t.darkStyle:{})});return t.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return null}t.validatorNoSaveOnError&&(e&&!Object.keys(this.isError).length?(this.isError={[this.props.attr]:!t.validatorErrorText||d.I18n.t(t.validatorErrorText)},setTimeout((t=>Object.keys(t).forEach((e=>this.props.onError(e,t[e])))),100,JSON.parse(JSON.stringify(this.isError)))):!e&&Object.keys(this.isError).length&&(setTimeout((t=>Object.keys(t).forEach((t=>this.props.onError(t)))),100,JSON.parse(JSON.stringify(this.isError))),this.isError={}));const n=this.renderItem(e,s||this.props.commandRunning||this.props.disabled,a);if(this.noPlaceRequired)return n;const r=(0,u.jsx)(p.Grid2,{title:this.getText(t.tooltip),size:{xs:t.xs||12,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},style:(0,i.A)((0,i.A)({marginBottom:0,textAlign:"left",width:"divider"===t.type||"header"===t.type?t.width||"100%":void 0},t.style),"dark"===this.props.oContext.themeType?t.darkStyle:{}),children:this.props.schema.defaultSendTo&&this.props.schema.button?(0,u.jsxs)(p.Grid2,{container:!0,style:{width:"100%"},children:[(0,u.jsx)(p.Grid2,{flex:1,children:n}),(0,u.jsx)(p.Grid2,{children:(0,u.jsx)(p.Button,{disabled:s,variant:"outlined",onClick:()=>this.sendTo(),title:this.props.schema.buttonTooltip?this.getText(this.props.schema.buttonTooltip,this.props.schema.buttonTooltipNoTranslation):d.I18n.t("ra_Request data by instance"),children:this.getText(this.props.schema.button)})})]}):n});return t.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),this.renderDialogConfirm(),r]}):this.state.confirmDialog?(0,u.jsxs)(u.Fragment,{children:[this.renderDialogConfirm(),r]}):r}}x.DIFFERENT_VALUE="__different__",x.DIFFERENT_LABEL="ra___different__",x.NONE_VALUE="",x.NONE_LABEL="ra_none";const v={fullWidth:{width:"100%"},accordionSummary:t=>({backgroundColor:"dark"===t.palette.mode?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.08)"}),accordionTitle:{},toolbar:t=>({backgroundColor:"dark"===t.palette.mode?"rgba(255, 255, 255, 0.08)":"rgba(0, 0, 0, 0.08)",borderRadius:"3px"}),tooltip:{pointerEvents:"none"}};const f=class extends x{constructor(t){super(t),this.typingTimer=null,this.onDelete=t=>()=>{const e=JSON.parse(JSON.stringify(this.state.value));e.splice(t,1),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.onChangeWrapper(e)))},this.onClone=t=>()=>{const e=JSON.parse(JSON.stringify(this.state.value)),s=JSON.parse(JSON.stringify(e[t]));if("string"===typeof this.props.schema.clone&&"string"===typeof s[this.props.schema.clone]){let t=1,i=s[this.props.schema.clone];const o=i.match(/(\d+)$/);for(o?(i=i.replace(o[0],""),t=parseInt(o[0],10)+1):i+="_";e.find((e=>e[this.props.schema.clone]===i+t.toString()));)t++;s[this.props.schema.clone]="".concat(s[this.props.schema.clone],"_").concat(t)}e.splice(t,0,s),this.setState({value:e,activeIndex:-1,iteration:this.state.iteration+1e4},(()=>this.onChangeWrapper(e)))},this.onChangeWrapper=t=>{this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout((t=>{this.typingTimer=null;const e=this.onChange(this.props.attr,t);e instanceof Promise&&e.catch((t=>this.onError(t)))}),300,t)},this.onAdd=()=>{const{schema:t}=this.props,e=JSON.parse(JSON.stringify(this.state.value)),s=t.items&&t.items.reduce(((t,s)=>{let i;return i=s.defaultFunc?this.props.custom?s.defaultFunc?this.executeCustom(s.defaultFunc,this.props.data,this.props.customObj,this.props.oContext.instanceObj,e.length,this.props.data):this.props.schema.default:s.defaultFunc?this.execute(s.defaultFunc,this.props.schema.default,this.props.data,e.length,this.props.data):this.props.schema.default:void 0===s.default?null:s.default,t[s.attr]=i,t}),{});e.push(s),this.setState({value:e,activeIndex:e.length-1},(()=>this.onChangeWrapper(e)))},this.props.schema.items=this.props.schema.items||[]}componentDidMount(){super.componentDidMount();let t=x.getValue(this.props.data,this.props.attr)||[];Array.isArray(t)||(t=[]),this.setState({value:t,activeIndex:-1,iteration:0})}componentWillUnmount(){this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),super.componentWillUnmount()}itemAccordion(t,e){const{value:s}=this.state,{schema:i}=this.props,o={type:"panel",items:i.items.reduce(((t,e)=>(t[e.attr]=e,t)),{}),style:{marginLeft:"-8px",marginTop:"10px",marginBottom:"10px"}};return(0,u.jsx)(Ve,{oContext:this.props.oContext,index:e+this.state.iteration,arrayIndex:e,changed:this.props.changed,globalData:this.props.data,common:this.props.common,alive:this.props.alive,themeName:this.props.themeName,data:t,custom:!0,schema:o,originalData:this.props.originalData,onChange:(t,i)=>{const o=JSON.parse(JSON.stringify(s));o[e][t]=i,this.setState({value:o},(()=>this.onChangeWrapper(o)))},onError:(t,e)=>this.onError(t,e),table:this.props.table})}onMoveUp(t){const e=JSON.parse(JSON.stringify(this.state.value)),s=e[t];e.splice(t,1),e.splice(t-1,0,s);const i=this.state.activeIndex-1;this.setState({value:e,activeIndex:i,iteration:this.state.iteration+1e4},(()=>this.onChangeWrapper(e)))}onMoveDown(t){const e=JSON.parse(JSON.stringify(this.state.value)),s=e[t];e.splice(t,1),e.splice(t+1,0,s);const i=this.state.activeIndex+1;this.setState({value:e,activeIndex:i,iteration:this.state.iteration+1e4},(()=>this.onChangeWrapper(e)))}renderItem(){const{schema:t}=this.props,{value:e}=this.state;return e?(0,u.jsxs)(p.Paper,{children:[t.label||!t.noDelete?(0,u.jsxs)(p.Toolbar,{variant:"dense",children:[t.label?(0,u.jsx)(p.Typography,{variant:"h6",id:"tableTitle",component:"div",children:this.getText(t.label)}):null,t.noDelete?null:(0,u.jsx)(p.IconButton,{size:"small",color:"primary",onClick:this.onAdd,children:(0,u.jsx)(c.Add,{})})]}):null,e.map(((s,o)=>(0,u.jsxs)(p.Accordion,{expanded:this.state.activeIndex===o,onChange:(t,e)=>this.setState({activeIndex:e?o:-1}),children:[(0,u.jsx)(p.AccordionSummary,{expandIcon:(0,u.jsx)(c.ExpandMore,{}),sx:d.Utils.getStyle(this.props.oContext.theme,v.fullWidth,v.accordionSummary),children:(0,u.jsx)(p.Typography,{style:v.accordionTitle,children:s[t.titleAttr]})}),(0,u.jsxs)(p.AccordionDetails,{style:(0,i.A)((0,i.A)({},t.style),this.props.oContext.themeType?t.darkStyle:void 0),children:[this.itemAccordion(e[o],o),(0,u.jsxs)(p.Toolbar,{sx:v.toolbar,children:[o?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move up"),slotProps:{popper:{sx:v.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveUp(o),children:(0,u.jsx)(c.ArrowUpward,{})})}):(0,u.jsx)("div",{style:v.buttonEmpty}),o<e.length-1?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move down"),slotProps:{popper:{sx:v.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveDown(o),children:(0,u.jsx)(c.ArrowDownward,{})})}):(0,u.jsx)("div",{style:v.buttonEmpty}),t.noDelete?null:(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Delete current row"),slotProps:{popper:{sx:v.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onDelete(o),children:(0,u.jsx)(c.Delete,{})})}),t.clone?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Clone current row"),slotProps:{popper:{sx:v.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onClone(o),children:(0,u.jsx)(c.ContentCopy,{})})}):null]})]})]},"".concat(s,"_").concat(o)))),!t.noDelete&&e.length>0?(0,u.jsx)(p.Toolbar,{variant:"dense",sx:v.rootTool,children:(0,u.jsx)(p.IconButton,{size:"small",color:"primary",onClick:this.onAdd,children:(0,u.jsx)(c.Add,{})})}):null,t.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]}):null}},y={root:{width:"100%"},notAlive:{color:"#a30000"}};const b=class extends x{componentDidMount(){super.componentDidMount();const t=this.getInstance();this.props.oContext.socket.getState("".concat(t,".alive")).then((e=>this.setState({alive:!(!e||!e.val),instance:t})))}getInstance(){let t=this.props.schema.instance||"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance);return t.includes("${")&&(t=this.getPattern(t,null,!0)),t&&!t.startsWith("system.adapter.")&&(t="system.adapter.".concat(t)),t}renderItem(){if(this.getInstance()!==this.state.instance&&setTimeout((()=>{const t=this.getInstance();t?this.props.oContext.socket.getState("".concat(t,".alive")).then((e=>this.setState({alive:!(!e||!e.val),instance:t}))):this.setState({alive:null,instance:t})}),200),!1!==this.state.alive&&!0!==this.state.alive)return null;const t=this.state.instance.replace(/^system.adapter./,"");return(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},y.root),this.state.alive?void 0:y.notAlive),children:this.state.alive?void 0!==this.props.schema.textAlive?this.props.schema.textAlive?d.I18n.t(this.props.schema.textAlive,t):"":d.I18n.t("ra_Instance %s is alive",t):void 0!==this.props.schema.textNotAlive?this.props.schema.textNotAlive?d.I18n.t(this.props.schema.textNotAlive,t):"":d.I18n.t("ra_Instance %s is not alive",t)})}};const C=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr),e=this.props.schema.options.map((t=>"string"===typeof t?{label:t,value:t}:JSON.parse(JSON.stringify(t))));Array.isArray(t)?(e.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),this.setState({value:x.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}renderItem(t,e){if(!this.state.selectOptions)return null;let s;const o=JSON.parse(JSON.stringify(this.state.selectOptions));return Array.isArray(this.state.value)||this.state.value===x.DIFFERENT_VALUE?([...this.state.value].filter((t=>!o.find((e=>"object"===typeof e?e.value===t:e===t)))).forEach((t=>o.push({label:t.toString(),value:t}))),s={label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE},o.unshift(s)):(s=null!==this.state.value&&void 0!==this.state.value&&o.find((t=>"object"===typeof t?t.value==this.state.value:t==this.state.value)),null!==this.state.value&&void 0!==this.state.value&&!s&&this.props.schema.freeSolo&&(s={value:this.state.value,label:this.state.value},o.push(s))),(0,u.jsx)(p.Autocomplete,{fullWidth:!0,freeSolo:!!this.props.schema.freeSolo,value:s,options:o,isOptionEqualToValue:(t,e)=>t.value===e.value,filterOptions:(t,e)=>{const s=t.filter((t=>""===e.inputValue||(t.label.toLowerCase().includes(e.inputValue.toLowerCase())||t.value.toLowerCase().includes(e.inputValue.toLowerCase()))));return this.props.schema.freeSolo&&""!==e.inputValue&&s.push({label:e.inputValue,value:e.inputValue}),s},onInputChange:t=>{if(!t||!this.props.schema.freeSolo)return;const e=t.target.value;e!==this.state.value&&this.setState({value:e},(()=>this.onChange(this.props.attr,e)))},onChange:(t,e)=>{const s="object"===typeof e?e?e.value:"":e;s!==this.state.value&&this.setState({value:s},(()=>this.onChange(this.props.attr,s)))},getOptionLabel:t=>{var e;return"object"===typeof t&&null!==(e=null===t||void 0===t?void 0:t.label)&&void 0!==e?e:""},renderInput:s=>(0,u.jsx)(p.TextField,(0,i.A)((0,i.A)({variant:"standard"},s),{},{error:!!t,placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),disabled:e}))})}};const j=class extends x{constructor(){super(...arguments),this.initialized=!1,this.localContext=void 0}askInstance(){const t=x.getValue(this.props.data,this.props.attr),e=this.props.schema.options?this.props.schema.options.map((t=>"string"===typeof t?{label:t,value:t}:JSON.parse(JSON.stringify(t)))):[];if(this.props.alive){let i=this.props.schema.data;if(void 0===i&&this.props.schema.jsonData){const t=this.getPattern(this.props.schema.jsonData,null,!0);try{"string"===typeof t&&(i=JSON.parse(t))}catch(s){console.error("Cannot parse json data: ".concat(JSON.stringify(i)))}}void 0===i&&(i=null),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",i).then((s=>{s&&Array.isArray(s)&&s.forEach((t=>e.push("string"===typeof t?{label:t,value:t}:JSON.parse(JSON.stringify(t))))),Array.isArray(t)?(e.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),this.setState({value:x.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}))}else Array.isArray(t)?(e.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),this.setState({value:x.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}getContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=x.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(t,e){if(this.props.alive){const t=this.getContext();t===this.localContext&&this.initialized||(this.localContext=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}let s;const o=this.state.selectOptions?JSON.parse(JSON.stringify(this.state.selectOptions)):[];return Array.isArray(this.state.value)||this.state.value===x.DIFFERENT_LABEL?([...this.state.value].filter((t=>!o.find((e=>e.value===t)))).forEach((t=>o.push({label:t.toString(),value:t}))),s={label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE},o.unshift(s)):(s=null!==this.state.value&&void 0!==this.state.value&&o.find((t=>t.value==this.state.value)),null!==this.state.value&&void 0!==this.state.value&&!s&&this.props.schema.freeSolo&&(s={value:this.state.value,label:this.state.value},o.push(s)),s=s||null),o.length?(0,u.jsx)(p.Autocomplete,{value:s,fullWidth:!0,freeSolo:!!this.props.schema.freeSolo,options:o,isOptionEqualToValue:(t,e)=>t.value===e.value,filterOptions:(t,e)=>{const s=t.filter((t=>""===e.inputValue||(t.label.toLowerCase().includes(e.inputValue.toLowerCase())||t.value.toLowerCase().includes(e.inputValue.toLowerCase()))));return this.props.schema.freeSolo&&""!==e.inputValue&&s.push({label:e.inputValue,value:e.inputValue}),s},getOptionLabel:t=>{var e;return null!==(e=null===t||void 0===t?void 0:t.label)&&void 0!==e?e:""},onInputChange:t=>{if(!t||!this.props.schema.freeSolo)return;const e=t.target.value;e!==this.state.value&&this.setState({value:e},(()=>this.onChange(this.props.attr,e)))},onChange:(t,e)=>{const s="object"===typeof e?e?e.value:"":e;s!==this.state.value&&this.setState({value:s},(()=>this.onChange(this.props.attr,s)))},renderInput:s=>(0,u.jsx)(p.TextField,(0,i.A)((0,i.A)({variant:"standard"},s),{},{error:!!t,placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),disabled:e}))}):(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:null===this.state.value||void 0===this.state.value?"":this.state.value,error:!!t,disabled:e,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0}},onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,(e||"").trim())))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},w={fullWidth:{width:"100%"},flex:{display:"flex"},button:{height:48,marginLeft:4,minWidth:48}};const T=class extends x{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=x.getValue(t,e)||"";this.setState({value:s,showDialog:!1})}renderItem(t,e){const{schema:s,attr:i}=this.props,{value:o,showDialog:a}=this.state;return(0,u.jsxs)(p.FormControl,{style:w.fullWidth,variant:"standard",children:[s.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(s.label)}):null,(0,u.jsxs)("div",{style:w.flex,children:[(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:null!==o&&void 0!==o?o:"",error:!!t,disabled:e,placeholder:this.getText(s.placeholder),label:this.getText(s.label),helperText:this.renderHelp(s.help,s.helpLink,s.noTranslation),onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(i,e)))}}),(0,u.jsx)(p.Button,{color:"grey",disabled:e,style:w.button,size:"small",variant:"outlined",onClick:()=>this.setState({showDialog:!0}),children:"..."})]}),a?(0,u.jsx)(d.DialogCron,{title:d.I18n.t("ra_Define schedule"),simple:s.simple,complex:s.complex,cron:o,onClose:()=>this.setState({showDialog:!1}),cancel:d.I18n.t("ra_Cancel"),ok:d.I18n.t("ra_Ok"),theme:this.props.oContext.theme,onOk:t=>this.setState({showDialog:!1,value:t},(()=>this.onChange(i,t)))}):null]})}};const I=class extends x{async componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr),e=(await this.props.oContext.socket.getCertificates()).filter((t=>{const e=this.props.attr.toLowerCase();return!!e.includes(t.type)||(!("public"!==t.type||!e.includes("cert"))||(!("private"!==t.type||!e.includes("priv")&&!e.includes("key"))||!("chained"!==t.type||!e.includes("chain")&&!e.includes("ca"))))})).map((t=>({label:t.name,value:t.name})));e.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.setState({value:t,selectOptions:e})}renderItem(t,e){var s,i;if(!this.state.selectOptions)return null;const o=null===(s=this.state.selectOptions)||void 0===s?void 0:s.find((t=>t.value===this.state.value));return(0,u.jsxs)(p.FormControl,{style:{width:"100%"},variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:this.state.value,renderValue:()=>this.getText(null===o||void 0===o?void 0:o.label,!1!==this.props.schema.noTranslation),onChange:t=>this.setState({value:t.target.value},(()=>this.onChange(this.props.attr,this.state.value))),children:null===(i=this.state.selectOptions)||void 0===i?void 0:i.map((t=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label,!1!==this.props.schema.noTranslation)},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},S={fullWidth:{width:"100%"},leWidth:{width:620,marginBottom:10},certWidth:{width:200,marginRight:10}};const D=class extends x{async componentDidMount(){var t;super.componentDidMount();const e=await this.props.oContext.socket.getCertificates(),s=[],i=[],o=[];let a=[];const n=await this.props.oContext.socket.getObject("system.certificates");a=null!==n&&void 0!==n&&null!==(t=n.native)&&void 0!==t&&t.collections?Object.keys(n.native.collections):null,e.forEach((t=>{"public"===t.type?s.push({label:t.name,value:t.name}):"private"===t.type?i.push({label:t.name,value:t.name}):("chained"===t.type||(s.push({label:t.name,value:t.name}),i.push({label:t.name,value:t.name})),o.push({label:t.name,value:t.name}))})),s.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),i.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),o.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.setState({certsPublicOptions:s,certsChainOptions:o,certsPrivateOptions:i,collectionsOptions:a})}renderItem(t,e){var s,i,o,a,n,r,l;if(!this.state.certsPublicOptions||!this.state.certsPrivateOptions||!this.state.certsChainOptions)return null;const h=(x.getValue(this.props.data,this.props.schema.leCollectionName||"leCollection")||"false").toString(),c=x.getValue(this.props.data,this.props.schema.certPublicName||"certPublic"),m=x.getValue(this.props.data,this.props.schema.certPrivateName||"certPrivate"),g=x.getValue(this.props.data,this.props.schema.certChainedName||"certChained"),v=null===(s=this.state.certsPublicOptions)||void 0===s?void 0:s.find((t=>t.value===c)),f=null===(i=this.state.certsPrivateOptions)||void 0===i?void 0:i.find((t=>t.value===m)),y=null===(o=this.state.certsChainOptions)||void 0===o?void 0:o.find((t=>t.value===g));return(0,u.jsxs)("div",{style:S.fullWidth,children:[this.state.collectionsOptions?(0,u.jsxs)(p.FormControl,{style:S.leWidth,variant:"standard",children:[(0,u.jsx)(p.InputLabel,{shrink:!0,children:"Let's encrypt"}),(0,u.jsxs)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:h,onChange:t=>this.onChange(this.props.schema.leCollectionName||"leCollection","false"!==t.target.value&&("true"===t.target.value||t.target.value)),children:[(0,u.jsx)(p.MenuItem,{value:"false",style:{fontWeight:"bold"},children:d.I18n.t("ra_Do not use let's encrypt")},"_false"),(0,u.jsx)(p.MenuItem,{value:"true",style:{fontWeight:"bold"},children:d.I18n.t("ra_Use all available let's encrypt certificates")},"_true"),null===(a=this.state.collectionsOptions)||void 0===a?void 0:a.map((t=>(0,u.jsx)(p.MenuItem,{value:t,children:t},t)))]})]}):null,this.state.collectionsOptions?(0,u.jsx)("br",{}):null,this.state.collectionsOptions&&"false"!==h?(0,u.jsx)("div",{children:d.I18n.t("ra_Fallback custom certificates")}):null,(0,u.jsxs)(p.FormControl,{style:S.certWidth,variant:"standard",children:[(0,u.jsx)(p.InputLabel,{shrink:!0,children:d.I18n.t("ra_Public certificate")}),(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:c||"",renderValue:()=>this.getText(null===v||void 0===v?void 0:v.label),onChange:t=>this.onChange(this.props.schema.certPublicName||"certPublic",t.target.value),children:null===(n=this.state.certsPublicOptions)||void 0===n?void 0:n.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},"".concat(t.value,"_").concat(e))))})]}),(0,u.jsxs)(p.FormControl,{style:S.certWidth,variant:"standard",children:[(0,u.jsx)(p.InputLabel,{shrink:!0,children:d.I18n.t("ra_Private certificate")}),(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:m||"",renderValue:()=>this.getText(null===f||void 0===f?void 0:f.label),onChange:t=>this.onChange(this.props.schema.certPrivateName||"certPrivate",t.target.value),children:null===(r=this.state.certsPrivateOptions)||void 0===r?void 0:r.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},"".concat(t.value,"_").concat(e))))})]}),(0,u.jsxs)(p.FormControl,{style:S.certWidth,variant:"standard",children:[(0,u.jsx)(p.InputLabel,{shrink:!0,children:d.I18n.t("ra_Chained certificate")}),(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:g||"",renderValue:()=>this.getText(null===y||void 0===y?void 0:y.label),onChange:t=>this.onChange(this.props.schema.certChainedName||"certChained",t.target.value),children:null===(l=this.state.certsChainOptions)||void 0===l?void 0:l.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},"".concat(t.value,"_").concat(e))))})]})]})}};const k=class extends x{async componentDidMount(){var t;let e;super.componentDidMount();const s=await this.props.oContext.socket.getObject("system.certificates");e=null!==s&&void 0!==s&&null!==(t=s.native)&&void 0!==t&&t.collections?Object.keys(s.native.collections):[],this.setState({collectionsOptions:e})}renderItem(t,e){var s;if(!this.state.collectionsOptions)return null;const i=(x.getValue(this.props.data,this.props.schema.leCollectionName||"leCollection")||"false").toString();return(0,u.jsxs)(p.FormControl,{style:{width:"100%"},variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsxs)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:i,onChange:t=>this.onChange(this.props.schema.leCollectionName||"leCollection","false"!==t.target.value&&("true"===t.target.value||t.target.value)),children:[(0,u.jsx)(p.MenuItem,{value:"false",style:{fontWeight:"bold"},children:d.I18n.t("ra_Do not use let's encrypt")},"_false"),(0,u.jsx)(p.MenuItem,{value:"true",style:{fontWeight:"bold"},children:d.I18n.t("ra_Use all available let's encrypt certificates")},"_true"),null===(s=this.state.collectionsOptions)||void 0===s?void 0:s.map((t=>(0,u.jsx)(p.MenuItem,{value:t,children:t},t)))]}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},O={fullWidth:{width:"100%"},icon:{width:24,height:24,marginRight:4},licLabel:{fontWeight:"bold",minWidth:100,marginRight:10,textTransform:"capitalize",display:"inline-block"},licValue:{fontWeight:"normal"},errorTitle:t=>({color:"dark"===t.palette.mode?"#e39191":"#b62020"}),okTitle:t=>({color:"dark"===t.palette.mode?"#6fd56f":"#007c00"}),errorText:t=>({color:"dark"===t.palette.mode?"#e39191":"#b62020",mb:"30px"})};class A extends x{componentDidMount(){super.componentDidMount(),this.setState({_error:"",running:!1,showLicenseData:null,foundSuitableLicense:!1,licenseOfflineCheck:!1,result:null,allLicenses:null,askForUpdate:!1,showLinkToProfile:!1})}renderErrorDialog(){if(this.state._error&&!this.state.showLicenseData){let t=this.state._error;return this.state.allLicenses&&(t=[(0,u.jsx)("div",{children:t},"error")],t.push((0,u.jsx)(p.Button,{variant:"contained",onClick:()=>window.open("https://iobroker.net/www/account/licenses","_blank"),children:d.I18n.t("iobroker.net")},"button")),this.state.allLicenses.length?t.push((0,u.jsx)(p.TableContainer,{children:(0,u.jsxs)(p.Table,{size:"small",children:[(0,u.jsx)(p.TableHead,{children:(0,u.jsxs)(p.TableRow,{children:[(0,u.jsx)(p.TableCell,{children:d.I18n.t("ra_Product")}),(0,u.jsx)(p.TableCell,{children:d.I18n.t("ra_Version")}),(0,u.jsx)(p.TableCell,{children:"UUID"}),(0,u.jsx)(p.TableCell,{children:d.I18n.t("ra_ValidTill")}),(0,u.jsx)(p.TableCell,{children:d.I18n.t("ra_Commercial")}),(0,u.jsx)(p.TableCell,{children:"ID"})]})}),(0,u.jsx)(p.TableBody,{children:this.state.allLicenses.map((t=>(0,u.jsxs)(p.TableRow,{children:[(0,u.jsx)(p.TableCell,{sx:t.validName?null:O.errorText,children:t.license.product}),(0,u.jsx)(p.TableCell,{sx:t.validVersion?null:O.errorText,children:t.license.version}),(0,u.jsx)(p.TableCell,{sx:t.validUuid?null:O.errorText,children:t.license.uuid||"--"}),(0,u.jsx)(p.TableCell,{sx:t.validTill?null:O.errorText,children:t.license.validTill&&"0000-00-00 00:00:00"!==t.license.validTill?new Date(t.license.validTill).toLocaleDateString():"--"}),(0,u.jsx)(p.TableCell,{children:"free"!==t.license.invoice?"MANUALLY_CREATED"===t.license.invoice?"\u2713":t.license.invoice:"-"}),(0,u.jsx)(p.TableCell,{children:t.id})]},t.id)))})]})},"table")):(t.push((0,u.jsx)("div",{children:d.I18n.t("ra_No one license found in license manager")},"text1")),t.push((0,u.jsx)("div",{children:d.I18n.t("ra_Please create license")},"text2")))),(0,u.jsxs)(p.Dialog,{open:!0,maxWidth:"xl",fullWidth:void 0===this.props.fullWidth||this.props.fullWidth,onClick:()=>this.setState({_error:"",allLicenses:null}),children:[(0,u.jsx)(p.DialogTitle,{children:d.I18n.t("ra_Error")}),(0,u.jsx)(p.DialogContent,{children:(0,u.jsx)(p.DialogContentText,{children:t})}),(0,u.jsx)(p.DialogActions,{children:(0,u.jsx)(p.Button,{variant:"contained",onClick:()=>this.setState({_error:"",allLicenses:null}),color:"primary",autoFocus:!0,startIcon:(0,u.jsx)(c.Check,{}),children:d.I18n.t("ra_Ok")})})]})}return null}renderMessageDialog(){if(this.state.showLicenseData){const t=[],e=this.state.showLicenseData;return Object.keys(e).forEach((s=>{if(null!==e[s]&&void 0!==e[s])if("object"===typeof e[s]){const i=e[s];Object.keys(i).forEach((e=>{null!==i[e]&&void 0!==i[e]&&("object"===typeof i[e]?t.push((0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{style:O.licLabel,children:[e,":"]}),JSON.stringify(i[e],null,2)]},e)):t.push((0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{style:O.licLabel,children:[s," -",e,":"]}),i[e].toString()]},e)))}))}else t.push((0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{style:O.licLabel,children:[s.replace(/_/g," "),":"]}),e[s].toString()]},s))})),t.push((0,u.jsxs)("div",{children:[(0,u.jsxs)("div",{style:O.licLabel,children:[d.I18n.t("ra_Checked"),":"]}),this.state.licenseOfflineCheck?d.I18n.t("ra_locally"):d.I18n.t("ra_via internet")]},"checked")),(0,u.jsxs)(p.Dialog,{open:!0,onClose:()=>this.setState({showLicenseData:null}),children:[(0,u.jsx)(p.DialogTitle,{children:(0,u.jsx)(p.Box,{component:"span",sx:this.state.result?O.okTitle:O.errorTitle,children:d.I18n.t("ra_License %s",this.state.result?"OK":"INVALID")})}),(0,u.jsxs)(p.DialogContent,{children:[this.state.showLinkToProfile?(0,u.jsx)(p.Button,{variant:"contained",onClick:()=>window.open("https://iobroker.net/www/account/licenses","_blank"),children:"https://iobroker.net"}):null,this.state._error?(0,u.jsx)(p.Box,{component:"div",sx:O.errorText,children:this.state._error}):null,t]}),(0,u.jsx)(p.DialogActions,{children:(0,u.jsx)(p.Button,{onClick:()=>this.setState({showLicenseData:null,_error:""}),color:"primary",variant:"contained",children:d.I18n.t("ra_Close")})})]})}return null}static parseJwt(t){const e=t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),s=decodeURIComponent(atob(e).split("").map((t=>"%".concat("00".concat(t.charCodeAt(0).toString(16)).slice(-2)))).join(""));try{return JSON.parse(s)}catch(i){return null}}static isVersionValid(t,e,s,i){if(!e||!t)return!0;let o=!0;const[a]=t.split(".");return e.startsWith(">=")?o=parseInt(a,10)>=parseInt(e.substring(2,10)):e.startsWith("<=")?o=parseInt(a,10)<=parseInt(e.substring(2,10)):e.startsWith(">")?o=parseInt(a,10)>parseInt(e.substring(1,10)):e.startsWith("<")?o=parseInt(a,10)<parseInt(e.substring(1,10)):e.startsWith("=")?o=parseInt(a,10)===parseInt(e.substring(1,10)):e.startsWith("==")?o=parseInt(a,10)===parseInt(e.substring(2,10)):e.startsWith("===")&&(o=parseInt(a,10)===parseInt(e.substring(3,10))),!0}async findInLicenseManager(t){var e,s;const i=await this.props.oContext.socket.getObject("system.licenses"),o=[];if(null!==i&&void 0!==i&&null!==(e=i.native)&&void 0!==e&&null!==(s=e.licenses)&&void 0!==s&&s.length){let e=null;const s=Date.now();let r,l;if(this.props.schema.uuid){var a;const t=await this.props.oContext.socket.getObject("system.meta.uuid");r=null===t||void 0===t||null===(a=t.native)||void 0===a?void 0:a.uuid}if(this.props.schema.version){var n;const e=await this.props.oContext.socket.getObject("system.adapter.".concat(t));l=null===e||void 0===e||null===(n=e.common)||void 0===n?void 0:n.version}i.native.licenses.forEach((i=>{const a=!i.validTill||"0000-00-00 00:00:00"===i.validTill||new Date(i.validTill).getTime()>s,n=(i.product||"").split("."),h=n[1]===t||"vis-2"===t&&"vis"===n[1],p=!r||!i.uuid||i.uuid===r,c=A.isVersionValid(l,i.version,i.invoice,t);(!e||"free"!==i.invoice)&&a&&h&&p&&c&&(e=i),o.push({id:i.id,validName:h,validUuid:p,validVersion:c,validTill:a,license:i})})),e&&(o.find((t=>t.id===e.id)).used=!0)}return o}async checkLicense(t,e){let s,i;if(this.props.schema.uuid){var o;const t=await this.props.oContext.socket.getObject("system.meta.uuid");s=null===t||void 0===t||null===(o=t.native)||void 0===o?void 0:o.uuid}if(this.props.schema.version){var a;const t=await this.props.oContext.socket.getObject("system.adapter.".concat(e));i=null===t||void 0===t||null===(a=t.common)||void 0===a?void 0:a.version}const n=new AbortController;let r=setTimeout((()=>{r=null,n.abort()}),5e3);try{var l;const o=await window.fetch("https://iobroker.net/api/v1/public/cert/",{method:"POST",body:JSON.stringify({json:t,uuid:s}),headers:{"Content-Type":"text/plain"},signal:n.signal});r&&clearTimeout(r);const a=await o.text();let h;try{h=JSON.parse(a)}catch(p){}if(null===(l=h)||void 0===l||!l.error){let o=null;try{o=A.parseJwt(t)}catch(c){}if(h){const t=h.validTill||h.valid_till;if(t&&"0000-00-00 00:00:00"!==t&&new Date(t).getTime()<Date.now())return this.setState({_error:d.I18n.t("ra_License expired on %s",new Date(t).toLocaleString()),licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1});const a=(h.name||"").split(".");return a[1]===e||"vis"===a[1]&&"vis-2"===e?s&&!h.uuid&&"vis-2"===e?this.setState({_error:d.I18n.t("ra_License must be converted",h.uuid),showLinkToProfile:!0,licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1}):s&&h.uuid&&h.uuid!==s?this.setState({_error:d.I18n.t('ra_Serial number (UUID) "%s" in license is for other device.',h.uuid),licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1}):A.isVersionValid(i,h.version,h.invoice,e)?this.setState({licenseOfflineCheck:!1,showLicenseData:o,result:!0,running:!1}):this.setState({_error:d.I18n.t("ra_License is for version %s, but required version is %s",h.version,this.props.schema.version),licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1}):this.setState({_error:d.I18n.t('ra_License for other product "%s"',h.name),licenseOfflineCheck:!1,showLicenseData:o,result:!1,running:!1})}throw new Error("ra_Invalid answer from server")}try{const e=A.parseJwt(t),s=d.I18n.t("ra_".concat(e.error||h.error||"Unknown error")).replace(/^ra_/,"");return this.setState({_error:s,licenseOfflineCheck:!1,showLicenseData:e,result:!1,running:!1})}catch(u){return console.log("Cannot parse license"),this.setState({_error:h.error,result:!1,running:!1})}}catch(m){var h;if(404===(null===m||void 0===m||null===(h=m.response)||void 0===h?void 0:h.status))return this.setState({_error:d.I18n.t("ra_License does not exist"),result:!1,running:!1});try{const o=A.parseJwt(t),a=(o.name||"").split(".");return o.valid_till&&"0000-00-00 00:00:00"!==o.valid_till&&new Date(o.valid_till).getTime()<Date.now()?this.setState({_error:d.I18n.t("ra_License expired on %s",new Date(o.valid_till).toLocaleString()),showLicenseData:o,licenseOfflineCheck:!0,running:!1,result:!1}):a[1]===e?s&&o.uuid&&o.uuid!==s?this.setState({_error:d.I18n.t('ra_Serial number (UUID) "%s" in license is for other device.',o.uuid),showLicenseData:o,licenseOfflineCheck:!0,result:!1,running:!1}):A.isVersionValid(i,o.version,o.invoice,e)?this.setState({running:!1,result:!0,licenseOfflineCheck:!0,showLicenseData:o}):this.setState({_error:d.I18n.t("ra_License is for version %s, but required version is %s",o.version,this.props.schema.version),licenseOfflineCheck:!0,showLicenseData:o,result:!1,running:!1}):this.setState({_error:d.I18n.t('ra_License for other product "%s"',o.name),licenseOfflineCheck:!0,showLicenseData:o,result:!1,running:!1})}catch(g){return this.setState({_error:d.I18n.t("ra_Cannot decode license"),result:!1,licenseOfflineCheck:!0,running:!1})}}}renderAskForUpdate(){return this.state.askForUpdate?(0,u.jsx)(d.DialogConfirm,{text:d.I18n.t("ra_License not found in license manager. Do you want to read licenses from iobroker.net?"),ok:d.I18n.t("ra_Yes"),onClose:async t=>{if(t){this.setState({askForUpdate:!1});try{await this.props.oContext.socket.updateLicenses(null,null)}catch(e){return void window.alert(d.I18n.t("ra_Cannot read licenses: %s",e))}await this._onClick(!0)}else this.setState({askForUpdate:!1,running:!1})}}):null}async _onClick(t){const e="vis-2"===this.props.oContext.adapterName?"vis":this.props.oContext.adapterName;let s,i;if(this.setState({running:!0}),this.props.data.useLicenseManager){if(i=await this.findInLicenseManager(e),s=i.find((t=>t.used)),s&&(s=s.license.json),!s&&!t)return void this.setState({askForUpdate:!0})}else s=this.props.data.license;s?await this.checkLicense(s,e):this.props.data.useLicenseManager?this.setState({_error:d.I18n.t("ra_Suitable license not found in license manager"),result:!1,running:!1,allLicenses:i}):this.setState({_error:d.I18n.t("ra_Please enter the license"),result:!1,running:!1})}renderItem(){return(0,u.jsxs)("div",{style:O.fullWidth,children:[(0,u.jsxs)(p.Button,{variant:this.props.schema.variant||"outlined",color:this.props.schema.color||"primary",style:O.fullWidth,disabled:!this.props.data.license&&!this.props.data.useLicenseManager||this.state.running,startIcon:(0,u.jsx)(c.Send,{}),onClick:()=>this._onClick(),children:[this.state.running?(0,u.jsx)(p.CircularProgress,{size:20,style:{marginRight:8}}):null,this.getText(this.props.schema.label||"ra_Check license",this.props.schema.noTranslation)]}),this.renderMessageDialog(),this.renderErrorDialog(),this.renderAskForUpdate()]})}}const _=A;const F=class extends x{renderItem(t,e){const s=x.getValue(this.props.data,this.props.attr),i=Array.isArray(s);return(0,u.jsxs)(p.FormControl,{style:{width:"100%"},variant:"standard",children:[(0,u.jsx)(p.FormControlLabel,{onClick:t=>{if(t.preventDefault(),t.stopPropagation(),!e){const t=this.onChange(this.props.attr,!s);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}},control:(0,u.jsx)(p.Checkbox,{indeterminate:i,checked:!!s,onChange:t=>{let e;e=i?this.onChange(this.props.attr,!0):this.onChange(this.props.attr,t.target.checked),e instanceof Promise&&e.catch((t=>console.error("Cannot set value: ".concat(t))))},disabled:e||this.props.schema.readOnly}),label:this.getText(this.props.schema.label)}),(0,u.jsx)(p.FormHelperText,{style:{color:"red"},children:t?this.props.schema.validatorErrorText?d.I18n.t(this.props.schema.validatorErrorText):d.I18n.t("ra_Error"):null}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};var N=s(32619),E=s.n(N),L=s(99072),V=s(23106);const P={standard:p.Input,filled:L.A,outlined:p.OutlinedInput},B=t=>{const e="light"===t.palette.mode,s=e?"rgba(0, 0, 0, 0.42)":"rgba(255, 255, 255, 0.7)";return{root:{},inputRoot:{display:"inline-flex",flexWrap:"wrap",flex:1,marginTop:0,minWidth:70,"&.mui-variant-outlined,&.mui-variant-filled":{boxSizing:"border-box"},"&.mui-variant-outlined":{paddingTop:"14px"},"&.mui-variant-filled":{paddingTop:"28px"}},input:{display:"inline-block",textOverflow:"ellipsis",overflow:"hidden",whiteSpace:"nowrap",appearance:"none",WebkitTapHighlightColor:"rgba(0,0,0,0)",float:"left",flex:1},chipContainer:{display:"flex",flexFlow:"row wrap",alignItems:"center",cursor:"text",marginBottom:"-2px",minHeight:40},outlined:{"& input":{height:16,paddingTop:"4px",paddingBottom:"12px",marginTop:"4px",marginBottom:"4px"}},standard:{marginTop:"18px"},filled:{"& input":{height:22,marginBottom:"4px",marginTop:"4px",paddingTop:0},"$marginDense & input":{height:26}},labeled:{},label:{top:4,"&$outlined&:not($labelShrink)":{top:2,"$marginDense &":{top:5}},"&$filled&:not($labelShrink)":{top:15,"$marginDense &":{top:20}}},labelShrink:{top:0},helperText:{marginBottom:-20},focused:{},disabled:{},underline:{"&:after":{borderBottom:"2px solid ".concat(t.palette.primary[e?"dark":"light"]),left:0,bottom:0,content:'""',position:"absolute",right:0,transform:"scaleX(0)",transition:t.transitions.create("transform",{duration:t.transitions.duration.shorter,easing:t.transitions.easing.easeOut}),pointerEvents:"none"},"&$focused:after":{transform:"scaleX(1)"},"&$error:after":{borderBottomColor:t.palette.error.main,transform:"scaleX(1)"},"&:before":{borderBottom:"1px solid ".concat(s),left:0,bottom:0,content:'"\\00a0"',position:"absolute",right:0,transition:t.transitions.create("border-bottom-color",{duration:t.transitions.duration.shorter}),pointerEvents:"none"},"&:hover:not($disabled):not($focused):not($error):before":{borderBottom:"2px solid ".concat(t.palette.text.primary),"@media (hover: none)":{borderBottom:"1px solid ".concat(s)}},"&$disabled:before":{borderBottomStyle:"dotted"}},error:{"&:after":{backgroundColor:t.palette.error.main,transform:"scaleX(1)"}},chip:{margin:"0 8px 8px 0",float:"left"},marginDense:{}}},W=8,U=46,M=37,R=39,J=(t,e)=>{let{value:s,isFocused:o,isDisabled:a,isReadOnly:n,handleClick:r,handleDelete:l,style:h}=t;return(0,u.jsx)(p.Chip,{style:(0,i.A)((0,i.A)({},h),{},{pointerEvents:a||n?"none":void 0,backgroundColor:o?V.A[300]:void 0}),onClick:r,onDelete:l,label:s},e)};class z extends a().Component{constructor(t){super(t),this.labelRef=void 0,this.labelNode=null,this.input=void 0,this.newChipKeyCodes=void 0,this.newChipKeys=void 0,this.actualInput=null,this.inputBlurTimeout=null,this._keyPressed=void 0,this._preventChipCreation=void 0,this.styles={},this.styleTheme=null,this.focus=()=>{var t;null===(t=this.actualInput)||void 0===t||t.focus(),this.state.focusedChip&&this.setState({focusedChip:null})},this.handleInputBlur=t=>{this.props.onBlur&&this.props.onBlur(t),this.setState({isFocused:!1}),this.state.focusedChip&&this.setState({focusedChip:null});const e=t.target.value;let s;switch(this.props.blurBehavior||"clear"){case"add-or-clear":s={clearInputOnFail:!0};case"add":if(this.props.delayBeforeAdd){const t=(this.props.value||this.state.chips).length;this.inputBlurTimeout=setTimeout((()=>{const i=(this.props.value||this.state.chips).length;t===i?this.handleAddChip(e,s):this.clearInput()}),150)}else this.handleAddChip(e,s);break;case"clear":this.clearInput()}},this.handleInputFocus=t=>{this.setState({isFocused:!0}),this.props.onFocus&&this.props.onFocus(t)},this.handleKeyDown=t=>{const{focusedChip:e}=this.state;if(this._keyPressed=!1,this._preventChipCreation=!1,this.props.onKeyDown&&(this.props.onKeyDown(t),t.isDefaultPrevented()))return;const s=this.props.value||this.state.chips;if(this.newChipKeyCodes.includes(t.keyCode)||this.newChipKeys.includes(t.key)){!1!==this.handleAddChip(t.target.value)&&t.preventDefault()}else switch(t.keyCode){case W:""===t.target.value&&(e?(this.handleDeleteChip(s[e],e),e&&this.setState({focusedChip:e-1})):this.setState({focusedChip:s.length-1}));break;case U:""===t.target.value&&e&&(this.handleDeleteChip(s[e],e),e<=s.length-1&&this.setState({focusedChip:e}));break;case M:null===e&&""===t.target.value&&s.length?this.setState({focusedChip:s.length-1}):null!==e&&e>0&&this.setState({focusedChip:e-1});break;case R:null!==e&&e<s.length-1?this.setState({focusedChip:e+1}):this.setState({focusedChip:null});break;default:this.setState({focusedChip:null})}},this.handleKeyUp=t=>{!this._preventChipCreation&&(this.newChipKeyCodes.includes(t.keyCode)||this.newChipKeys.includes(t.key))&&this._keyPressed?this.clearInput():this.updateInput(t.target.value),this.props.onKeyUp&&this.props.onKeyUp(t)},this.handleUpdateInput=t=>{null!==this.props.inputValue&&void 0!==this.props.inputValue||this.updateInput(t.target.value),this.props.onUpdateInput&&this.props.onUpdateInput(t)},this.setActualInputRef=t=>{this.actualInput=t,this.props.inputRef&&this.props.inputRef(t)},this.state={chips:t.defaultValue||[],focusedChip:null,inputValue:"",isFocused:!1,chipsUpdated:!1,prevPropsValue:[],variant:this.props.variant||"standard"},this.newChipKeyCodes=t.newChipKeyCodes||[13],this.newChipKeys=t.newChipKeys||["Enter"],this.labelRef=a().createRef(),this.input=a().createRef()}componentDidMount(){"outlined"===this.state.variant&&(this.labelNode=E().findDOMNode(this.labelRef.current),this.forceUpdate())}componentWillUnmount(){this.inputBlurTimeout&&clearTimeout(this.inputBlurTimeout)}static getDerivedStateFromProps(t,e){let s=null;return t.value&&t.value.length!==e.prevPropsValue.length&&(s={prevPropsValue:t.value},t.clearInputValueOnChange&&(s.inputValue="")),t.clearInputValueOnChange&&t.value&&t.value.length!==e.prevPropsValue.length&&(s={prevPropsValue:t.value,inputValue:""}),t.disabled&&(s=(0,i.A)((0,i.A)({},s),{},{focusedChip:null})),!e.chipsUpdated&&t.defaultValue&&(s=(0,i.A)((0,i.A)({},s),{},{chips:t.defaultValue})),s}handleAddChip(t,e){if(this.props.onBeforeAdd&&!this.props.onBeforeAdd(t))return this._preventChipCreation=!0,e&&e.clearInputOnFail&&this.clearInput(),!1;this.clearInput();const s=this.props.value||this.state.chips;return!!t.trim().length&&(!this.props.allowDuplicates&&s.includes(t)||(this.props.value&&this.props.onAdd?this.props.onAdd(t):this.updateChips([...this.state.chips,t])),!0)}handleDeleteChip(t,e){if(this.props.value)this.props.onDelete&&this.props.onDelete(t,e);else{const t=this.state.chips.slice();if(t.splice(e,1)){let s=this.state.focusedChip;this.state.focusedChip===e?s=null:this.state.focusedChip>e&&(s=this.state.focusedChip-1),this.updateChips(t,{focusedChip:s})}}}updateChips(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.setState((0,i.A)({chips:t,chipsUpdated:!0},e)),this.props.onChange&&this.props.onChange(t)}clearInput(){this.updateInput("")}updateInput(t){this.setState({inputValue:t})}render(){const{alwaysShowPlaceholder:t,chipRenderer:e=J,className:s,disabled:o,disableUnderline:a,error:n,FormHelperTextProps:r,fullWidth:l,fullWidthInput:h,helperText:c,id:m,InputProps:g={},InputLabelProps:x={},inputValue:v,label:f,placeholder:y,readOnly:b,required:C,rootRef:j,value:w,margin:T}=this.props,I=this.state.variant;this.styleTheme!==this.props.theme.palette.mode&&(this.styleTheme=this.props.theme.palette.mode,this.styles=d.Utils.getStyle(this.props.theme,B));let S=w||this.state.chips||[];Array.isArray(S)||(S=(S||"").toString().split(/[,\s]+/).map((t=>t.trim())));const D=null!==v&&void 0!==v?v:this.state.inputValue,k=(this.props.value||D).length||D.length,O="boolean"===typeof x.shrink?x.shrink:null!==f&&(k||this.state.isFocused||S.length),A=S.map(((t,s)=>e({value:t,isDisabled:!!o,isReadOnly:b,isFocused:this.state.focusedChip===s,handleClick:()=>this.setState({focusedChip:s}),handleDelete:()=>this.handleDeleteChip(t,s),style:this.styles.chip},s.toString()))),_={};"outlined"===I&&(_.notched=!!O,_.labelWidth=O&&this.labelNode&&this.labelNode.offsetWidth||0),"standard"!==I?_.startAdornment=A:g.disableUnderline=!0;const F=P[I];return(0,u.jsxs)(p.FormControl,{ref:j,fullWidth:l,className:s,sx:(0,i.A)((0,i.A)({},this.styles.root),"dense"===T?this.styles.marginDense:{}),error:n,required:S.length>0?void 0:C,onClick:this.focus,disabled:o,variant:I,component:"div",margin:T,children:[f&&(0,u.jsx)(p.InputLabel,(0,i.A)((0,i.A)({htmlFor:m,sx:{"&.MuiInputLabel-root":this.styles.label,"&.MuiInputLabel-shrink":this.styles.labelShrink},shrink:!!O,focused:this.state.isFocused,variant:I,ref:this.labelRef,required:C,component:"label"},x),{},{children:f})),(0,u.jsxs)(p.Box,{component:"div",id:"input-chip-container",sx:(0,i.A)((0,i.A)((0,i.A)((0,i.A)((0,i.A)((0,i.A)((0,i.A)({},this.styles[I]),this.styles.chipContainer),this.state.isFocused?this.styles.focused:void 0),a||"standard"!==I?void 0:this.styles.underline),o?this.styles.disabled:void 0),f?this.styles.labeled:void 0),n?this.styles.error:void 0),children:["standard"===I&&A,(0,u.jsx)(F,(0,i.A)((0,i.A)({ref:this.input,className:"mui-variant-".concat(this.styles[I]," ").concat(f?"mui-chip-with-label":"mui-chip-no-label"),sx:{"&.MuiInputBase-input":(0,i.A)((0,i.A)({},this.styles.input),this.styles[I]),"&.MuiInputBase-root":(0,i.A)({},this.styles.inputRoot)},id:m,value:D,onChange:this.handleUpdateInput,onKeyDown:this.handleKeyDown,onKeyUp:this.handleKeyUp,onFocus:this.handleInputFocus,onBlur:this.handleInputBlur,inputRef:this.setActualInputRef,disabled:o,fullWidth:h,placeholder:!k&&(O||null===f||void 0===f)||t?y:null,readOnly:b},g),_))]}),c&&(0,u.jsx)(p.FormHelperText,(0,i.A)((0,i.A)({},r),{},{className:null===r||void 0===r?void 0:r.className,style:this.styles.helperText,children:c}))]})}}const H=z;const q=class extends x{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=x.getValue(t,e);if(this.props.schema.delimiter&&"string"===typeof s){const t=s.split(this.props.schema.delimiter).map((t=>t.trim())).filter((t=>t));this.setState({value:t})}else this.setState({value:s||[]})}renderItem(t,e){const{attr:s,schema:i}=this.props,{value:o}=this.state;return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[(0,u.jsx)(H,{value:o,disabled:!!e,label:this.getText(i.label),error:!!t,onAdd:t=>{const e=JSON.parse(JSON.stringify(o));e.push(t),this.setState({value:e},(()=>{let t;t=this.props.schema.delimiter?this.onChange(s,e.join("".concat(this.props.schema.delimiter," "))):this.onChange(s,e),t instanceof Promise&&t.catch((t=>console.error(t)))}))},theme:this.props.oContext.theme,onDelete:(t,e)=>{const i=JSON.parse(JSON.stringify(o));i.splice(e,1),this.setState({value:i},(()=>{let t;t=this.props.schema.delimiter?this.onChange(s,i.join("".concat(this.props.schema.delimiter," "))):this.onChange(s,i),t instanceof Promise&&t.catch((t=>console.error(t)))}))}}),(0,u.jsx)(p.FormHelperText,{children:d.I18n.t("ra_Press ENTER Key to add new item")}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};var K=s(4554);const $=class extends x{renderColorDialog(){return!!this.state.showColorDialog&&(0,u.jsx)(p.Dialog,{onClose:()=>this.setState({showColorDialog:!1}),open:this.state.showColorDialog,children:(0,u.jsx)(K.xk,{color:this.state.colorDialogValue,onChange:t=>this.setState({colorDialogValue:t.hex},(()=>this.onChange(this.props.attr,this.state.colorDialogValue)))})})}renderItem(t,e){const s=x.getValue(this.props.data,this.props.attr);let i=d.Utils.isUseBright(s,null);return null===i&&(i=void 0),(0,u.jsxs)(u.Fragment,{children:[this.renderColorDialog(),(0,u.jsx)(p.TextField,{variant:"standard",disabled:!!e,style:{minWidth:100,width:"calc(100% - 8px)"},label:this.getText(this.props.schema.label),value:s||"",onClick:()=>!this.props.schema.readOnly&&this.setState({showColorDialog:!0,colorDialogValue:s||""}),onChange:t=>{const e=t.target.value,s=this.onChange(this.props.attr,e);s instanceof Promise&&s.catch((t=>console.error("Cannot set value: ".concat(t))))},slotProps:{htmlInput:{style:{backgroundColor:s,color:i?"#FFF":"#000"},readOnly:this.props.schema.readOnly||!1},input:{endAdornment:this.props.schema.readOnly||!s||this.props.schema.noClearButton?void 0:(0,u.jsx)(p.IconButton,{size:"small",onClick:t=>{t.stopPropagation();const e=this.onChange(this.props.attr,"");e instanceof Promise&&e.catch((t=>console.error("Cannot set value: ".concat(t))))},children:(0,u.jsx)(c.Close,{})})},inputLabel:{shrink:!0}}})]})}},G={width:{width:"calc(100% - 85px)"},width50:{width:120,marginRight:5}};const Y=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t});const e={};if(this.props.schema.useSystemName&&(e.useSystem=!!x.getValue(this.props.data,this.props.schema.useSystemName)),this.props.schema.longitudeName&&this.props.schema.latitudeName)e.longitude=x.getValue(this.props.data,this.props.schema.longitudeName),e.latitude=x.getValue(this.props.data,this.props.schema.latitudeName),e.longitude||e.latitude||!this.props.schema.autoInit||setTimeout((()=>this.getCoordinates()),300);else{!x.getValue(this.props.data,this.props.attr)&&this.props.schema.autoInit&&setTimeout((()=>this.getCoordinates()),300)}Object.keys(e).length&&setTimeout((()=>this.setState(e)),50)}async getSystemCoordinates(){const t=await this.props.oContext.socket.getCompactSystemConfig();if(null!==t&&void 0!==t&&t.common&&(t.common.longitude||t.common.latitude))if(window.alert(d.I18n.t("ra_Used system settings")),this.props.schema.longitudeName&&this.props.schema.latitudeName)this.setState({longitude:t.common.longitude,latitude:t.common.latitude},(async()=>{await this.onChange(this.props.schema.longitudeName,t.common.longitude),await this.onChange(this.props.schema.latitudeName,t.common.latitude)}));else{const e=t.common.latitude+(this.props.schema.divider||",")+t.common.longitude;this.setState({value:e},(()=>{const t=this.onChange(this.props.attr,e);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}))}else window.alert(d.I18n.t("ra_Cannot determine position: System settings are empty and GPS detection is disabled in browser"))}getCoordinates(){navigator.geolocation?navigator.geolocation.getCurrentPosition((async t=>{if(null!==t&&void 0!==t&&t.coords)if(this.props.schema.longitudeName&&this.props.schema.latitudeName)this.setState({longitude:t.coords.longitude,latitude:t.coords.latitude},(async()=>{await this.onChange(this.props.schema.longitudeName,t.coords.longitude||""),await this.onChange(this.props.schema.latitudeName,t.coords.latitude||"")}));else{const e=t.coords.latitude+(this.props.schema.divider||",")+t.coords.longitude;this.setState({value:e},(()=>{const t=this.onChange(this.props.attr,e);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}))}else await this.getSystemCoordinates()}),(async t=>{console.error("Cannot determine coordinates from browser: ".concat(t.message)),await this.getSystemCoordinates()})):this.getSystemCoordinates().catch((t=>{console.error("Cannot determine coordinates: ".concat(t))}))}renderItem(t,e){var s,i;return(0,u.jsxs)(u.Fragment,{children:[this.props.schema.useSystemName?(0,u.jsx)(p.FormControlLabel,{control:(0,u.jsx)(p.Checkbox,{checked:!!this.state.useSystem,onChange:t=>{const e=t.target.checked;e&&this.getSystemCoordinates().catch((t=>console.error("Cannot determine coordinates: ".concat(t)))),this.setState({useSystem:e},(()=>this.onChange(this.props.schema.useSystemName,e)))}}),label:d.I18n.t("ra_Use system settings for position")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?(0,u.jsx)(p.TextField,{variant:"standard",style:G.width50,value:null!==(s=this.state.longitude)&&void 0!==s?s:"",error:!!t,disabled:this.state.useSystem||!!e,onChange:t=>{const e=t.target.value;this.setState({longitude:e},(()=>{const t=this.onChange(this.props.schema.longitudeName,(e||"").trim());t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}))},label:d.I18n.t("ra_Longitude")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?(0,u.jsx)(p.TextField,{variant:"standard",style:G.width50,value:null!==(i=this.state.latitude)&&void 0!==i?i:"",error:!!t,disabled:this.state.useSystem||!!e,onChange:t=>{const e=t.target.value;this.setState({latitude:e},(()=>this.onChange(this.props.schema.latitudeName,(e||"").trim())))},label:d.I18n.t("ra_Latitude")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?null:(0,u.jsx)(p.TextField,{variant:"standard",style:G.width,value:null===this.state.value||void 0===this.state.value?"":this.state.value,error:!!t,disabled:!!e,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:this.state.useSystem}},onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,(e||"").trim())))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}),this.state.useSystem?null:(0,u.jsx)(p.Fab,{size:"small",onClick:()=>this.getCoordinates(),title:d.I18n.t("ra_Take browser position"),style:{marginRight:4},children:(0,u.jsx)(c.LocationOn,{})}),this.state.useSystem?null:(0,u.jsx)(p.Fab,{size:"small",onClick:()=>this.getSystemCoordinates(),title:d.I18n.t("ra_Take position from system settings"),children:(0,u.jsx)(c.GpsFixed,{})})]})}};function Z(t,e,i,o){return async()=>{const a=await((t,e,i)=>new Promise(((o,a)=>{if(window[t])o(window[t]);else{const n=document.querySelector('script[data-webpack="'.concat(t,'"]')),r=async()=>{if(!window[t])return console.error("Cannot load ".concat(t)),void a(new Error("Cannot load ".concat(t)));window[t].__initialized||(await window[t].init(s.S[e]),window[t].__initialized=!0),o(window[t])};if(n)n.onload=r,n.onerror=a;else if(i){const e=document,s=e.createElement("script");s.type="text/javascript",s.setAttribute("data-webpack","".concat(t)),s.async=!0,s.onerror=a,s.onload=r,s.src=i,e.getElementsByTagName("head")[0].appendChild(s)}else a(new Error("Cannot Find Remote ".concat(t," to inject")))}})))(t,e,o);return(await a.get(i))()}}class Q extends x{constructor(t){super(t),Object.assign(this.state,{Component:null,error:""})}async componentDidMount(){if(!this.props.schema.url)return console.error("URL is empty. Cannot load custom component!"),void this.setState({error:"URL is empty. Cannot load custom component!"});let t;t=this.props.schema.url.startsWith("./")?"".concat(window.location.protocol,"//").concat(window.location.host).concat(this.props.schema.url.replace(/^\./,"")):"".concat(window.location.protocol,"//").concat(window.location.host,"/adapter/").concat(this.props.oContext.adapterName,"/").concat(this.props.schema.url);const[e,s,...i]=this.props.schema.name.split("/"),o=i.join("/");if(!t)return void console.error('Cannot find URL for custom component! Please define "url" as "custom/customComponents.js" in the schema');if(!e||!s||!o)return void console.error('Invalid format of "name"! Please define "name" as "ConfigCustomBackItUpSet/Components/AdapterExist" in the schema');let a=Q.runningLoads["".concat(t,"!").concat(s)];if(!(a instanceof Promise)){let i;if(!0===this.props.schema.i18n){const e=t.lastIndexOf("/");let s;s=-1!==e?t.substring(0,e):t;const o=d.I18n.getLanguage(),a="".concat(s,"/i18n/").concat(o,".json");i=fetch(a).then((t=>t.json())).then((t=>d.I18n.extendTranslations(t,o))).catch((t=>{"en"===o?console.log('Cannot load i18n "'.concat(a,'": ').concat(t)):fetch("".concat(s,"/i18n/en.json")).then((t=>t.json())).then((t=>d.I18n.extendTranslations(t,o))).catch((t=>console.log('Cannot load i18n "'.concat(a,'": ').concat(t))))}))}else if(this.props.schema.i18n&&"object"===typeof this.props.schema.i18n)try{d.I18n.extendTranslations(this.props.schema.i18n)}catch(n){console.error("Cannot import i18n: ".concat(n))}try{console.log(e,s,o),a=Z(e,"default","./".concat(s),t)(),i instanceof Promise&&(a=Promise.all([a,i]).then((t=>t[0]))),Q.runningLoads["".concat(t,"!").concat(s)]=a}catch(n){this.setState({error:"Cannot import from ".concat(this.props.schema.url,": ").concat(n)})}}try{const t=(await a).default;if(null!==t&&void 0!==t&&t[o])this.setState({Component:t[o]});else{const e=Object.keys(t||{});console.error("URL is empty. Cannot load custom component!"),this.setState({error:"Component ".concat(this.props.schema.name," not found in ").concat(this.props.schema.url,". Found: ").concat(e.join(", "))})}}catch(n){this.setState({error:"Cannot import from ".concat(this.props.schema.url,": ").concat(n)})}}render(){const t=this.state.Component,e=this.props.schema||{};let s=t?(0,u.jsx)(t,(0,i.A)((0,i.A)({},this.props),{},{socket:this.props.oContext.socket,theme:this.props.oContext.theme,themeType:this.props.oContext.themeType,instance:this.props.oContext.instance,adapterName:this.props.oContext.adapterName,systemConfig:this.props.oContext.systemConfig,forceUpdate:this.props.oContext.forceUpdate})):this.state.error?(0,u.jsx)("div",{children:this.state.error}):(0,u.jsx)(p.LinearProgress,{});return(e.xs||e.sm||e.md||e.lg||e.xl)&&(s=(0,u.jsx)(p.Grid2,{size:{xs:e.xs||12,sm:e.sm||void 0,md:e.md||void 0,lg:e.lg||void 0,xl:e.xl||void 0},style:(0,i.A)((0,i.A)({marginBottom:0,textAlign:"left"},e.style),"dark"===this.props.oContext.themeType?e.darkStyle:{}),children:s})),e.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),s]}):s}}Q.runningLoads={};var X=s(46567);const tt=class extends x{renderItem(){if(!this.props.schema)return null;if(this.props.oContext.DeviceManager){const t=this.props.oContext.DeviceManager;return(0,u.jsx)(t,{uploadImagesToInstance:"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),title:this.getText(this.props.schema.label),socket:this.props.oContext.socket,selectedInstance:"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),themeName:this.props.themeName,themeType:this.props.oContext.themeType,isFloatComma:this.props.oContext.isFloatComma,dateFormat:this.props.oContext.dateFormat})}return(0,u.jsx)("div",{children:"DeviceManager not found"})}};var et=s(51189),st=s.n(et);const it={fullWidth:{width:"100%"},fullWidthOneButton:{width:"calc(100% - 42px)"},fullWidthTwoButtons:{width:"calc(100% - 84px)"},fullWidthThreeButtons:{width:"calc(100% - 126x)"},dropZone:{width:"100%",height:"100%",position:"absolute"},dropZoneEmpty:{},image:{objectFit:"contain",margin:"auto",display:"flex",width:"100%",height:"100%"},uploadDiv:{position:"relative",width:"100%"},uploadDivDragging:{opacity:1,background:"rgba(128,255,128,0.1)"},uploadCenterDiv:{margin:5,border:"3px dashed grey",borderRadius:5,width:"100%",height:"100%",position:"absolute",display:"flex"},uploadCenterIcon:{paddingTop:10,width:48,height:48},uploadCenterText:{fontSize:16},uploadCenterTextAndIcon:{textAlign:"center",position:"absolute",top:0,bottom:0,left:0,right:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},disabledOpacity:{opacity:.3,cursor:"default"},error:{border:"2px solid red"},deleteButton:{},selectedImage:{height:40,width:40,display:"inline-block",marginRight:8}},ot=["jpg","jpeg","svg","png","webp","gif","apng","avif","webp"],at=["mp3","ogg","wav","aac"],nt=["avi","mp4","mov"],rt=["txt","log","html","htm"],lt=["json","js","ts"];class ht extends x{constructor(t){super(t),this.dropzoneRef=void 0,this.imagePrefix=void 0,this.objectID=void 0,this.path=void 0,this.dropzoneRef=a().createRef(),this.imagePrefix=void 0===this.props.oContext.imagePrefix?"./files":this.props.oContext.imagePrefix}componentDidMount(){super.componentDidMount(),this.objectID=(this.props.schema.objectID||"0_userdata.0").replace("%INSTANCE%",(this.props.oContext.instance||0).toString()),this.path=this.props.schema.upload,this.path&&("/"===this.path?this.path="":this.path.endsWith("/")||(this.path="".concat(this.path,"/"))),this.updateFiles().then((()=>{const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t})}))}updateFiles(){return this.readFiles(this.props.schema.pattern).then((t=>this.setState({files:t})))}async readFolder(t,e,s){try{const i=await this.props.oContext.socket.readDir(this.objectID,t.replace(/^\//,"")||null);for(let o=0;o<i.length;o++){const a=i[o];if(a.isDir)await this.readFolder("".concat(t+a.file,"/"),e,s);else{let i=!1;if("*.*"===s&&a.file.includes("."))i=!0;else if(s&&"*"!==s)if(".*"===s&&a.file.startsWith("."))i=!0;else{i=new RegExp("^".concat(s.replace(/\./g,"\\.").replace(/\*/g,".*"),"$")).test(a.file)}else i=!0;i&&e.push({name:t+a.file,size:a.stats?d.Utils.formatBytes(a.stats.size):"--"})}}}catch(i){console.error('Cannot read "'.concat(t,'": ').concat(i))}return e}async readFiles(t){const e=[];let s;(t=t||this.props.schema.pattern)||(t="**/*.*");const i=t.lastIndexOf("/");if(s=-1===i?t:t.substring(i+1),t.startsWith("**"))await this.readFolder("/",e,s);else{const i=t.lastIndexOf("/");if(-1===i)await this.readFolder("/",e,s);else{const o=t.substring(0,i+1);await this.readFolder(o,e,s)}}return e}onDrop(t){const e=t[0],s=new FileReader,i=this.props.schema.maxSize||2097152;s.onabort=()=>console.log("file reading was aborted"),s.onerror=()=>console.log("file reading has failed"),s.onload=()=>{let t="image/".concat(e.name.split(".").pop().toLowerCase());if("image/jpg"===t?t="image/jpeg":t.includes("svg")&&(t="image/svg+xml"),e.size>i)return void window.alert(d.I18n.t("File is too big. Max %sk allowed. Try use SVG.",Math.round(i/1024)));const o="data:".concat(t,";base64,").concat(btoa(new Uint8Array(s.result).reduce(((t,e)=>t+String.fromCharCode(e)),"")));this.props.oContext.socket.writeFile64(this.objectID,this.path+e.name,o).then((()=>this.updateFiles())).catch((t=>window.alert("Cannot upload file: ".concat(t))))},s.readAsArrayBuffer(e)}renderDeleteDialog(){return this.state.deleteFile?(0,u.jsx)(d.DialogConfirm,{title:d.I18n.t("ra_Are you sure?"),text:d.I18n.t("ra_File will be deleted"),ok:d.I18n.t("ra_Delete"),cancel:d.I18n.t("ra_Cancel"),onClose:t=>{const e=this.state.deleteFile;this.setState({deleteFile:""},(()=>{t&&this.props.oContext.socket.deleteFile(this.objectID,e).then((()=>this.updateFiles())).catch((t=>window.alert("Cannot delete file: ".concat(t))))}))}}):null}static base64ToArrayBuffer(t){const e=window.atob(t),s=e.length,i=new Uint8Array(s);for(let o=0;o<s;o++)i[o]=e.charCodeAt(o);return i.buffer}loadFile(){return this.props.oContext.socket.readFile(this.objectID,this.state.value,!0)}play(){this.loadFile().then((t=>{if("undefined"!==typeof AudioContext){const e=new AudioContext,s=ht.base64ToArrayBuffer(t.file);e.decodeAudioData(s,(t=>{const s=e.createBufferSource();s.buffer=t,s.connect(e.destination),s.start(0)}),(t=>window.alert("Cannot play: ".concat(t.message))))}}))}getFileIcon(t){return null!==t&&void 0!==t&&t.extension?ot.includes(t.extension)?(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},it.selectedImage),{},{backgroundImage:"url(".concat(this.imagePrefix,"/").concat(this.objectID,"/").concat(t.value,")"),backgroundSize:"contain",backgroundRepeat:"no-repeat"})}):at.includes(t.extension)?(0,u.jsx)(c.MusicNote,{}):rt.includes(t.extension)?(0,u.jsx)(c.Article,{}):nt.includes(t.extension)?(0,u.jsx)(c.Videocam,{}):lt.includes(t.extension)?(0,u.jsx)(c.Code,{}):null:null}renderItem(t,e){if(!this.state.files)return null;const s=[];this.props.schema.withFolder||this.state.files.forEach((t=>{const e=t.name.lastIndexOf("/");if(-1===e)s.includes("/")||s.push("/");else{const i=t.name.substring(0,e+1);s.includes(i)||s.push(i)}}));const o=this.state.files.map((t=>({value:t.name,label:this.props.schema.withFolder||1!==s.length?"".concat(t.name).concat(this.props.schema.noSize?"":"(".concat(t.size,")")):"".concat(t.name.substring(s[0].length)),extension:t.name.toLowerCase().split(".").pop()})));this.props.schema.noNone||o.unshift({label:d.I18n.t("ra_none"),value:""});const a=o.find((t=>t.value===this.state.value));let n=0;this.props.schema.upload&&n++,this.props.schema.refresh&&n++;const r=this.state.value&&(this.state.value.endsWith(".mp3")||this.state.value.endsWith(".ogg")||this.state.value.endsWith(".wav"));r&&n++;const l=(0,u.jsxs)("div",{style:it.fullWidth,children:[(0,u.jsxs)(p.FormControl,{variant:"standard",style:{width:"calc(100% - ".concat(42*n,"px)")},children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>(0,u.jsxs)(u.Fragment,{children:[this.getFileIcon(a),(0,u.jsx)("span",{children:(null===a||void 0===a?void 0:a.label)||""})]}),onChange:t=>{this.setState({value:"_"===t.target.value?"":t.target.value},(()=>this.onChange(this.props.attr,this.state.value)))},children:o.map((t=>(0,u.jsxs)(p.MenuItem,{value:t.value,children:[(0,u.jsx)(p.ListItemIcon,{children:this.getFileIcon(t)}),(0,u.jsx)(p.ListItemText,{children:t.label}),this.props.schema.delete&&a.value?(0,u.jsx)(p.IconButton,{style:it.deleteButton,size:"small",onClick:()=>this.setState({deleteFile:a.value}),children:(0,u.jsx)(c.Delete,{})}):null]},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]}),this.props.schema.refresh&&(0,u.jsx)(p.IconButton,{onClick:()=>this.updateFiles(),children:(0,u.jsx)(c.Refresh,{})}),this.props.schema.upload&&(0,u.jsx)(p.IconButton,{onClick:()=>{var t;return null===(t=this.dropzoneRef.current)||void 0===t?void 0:t.open()},children:(0,u.jsx)(c.UploadFile,{})}),r&&(0,u.jsx)(p.IconButton,{style:{color:"#00FF00"},onClick:()=>this.play(),children:(0,u.jsx)(c.PlayArrow,{})})]});if(!this.props.schema.upload)return(0,u.jsxs)(u.Fragment,{children:[l,this.renderDeleteDialog()]});let h={"*/*":[]};if("image"===this.props.schema.fileTypes?h={"image/*":[".png",".jpg",".svg",".gif",".apng",".avif",".webp"]}:"audio"===this.props.schema.fileTypes?h={"audio/*":[".mp3",".ogg",".wav",".mp4"]}:"text"===this.props.schema.fileTypes&&(h={"text/plain":[".txt"]}),this.props.schema.pattern){const t=this.props.schema.pattern.split("/").pop().toLowerCase().replace(/.*\./,"");h="png"===t||"jpg"===t||"svg"===t||"gif"===t||"apng"===t||"avif"===t||"webp"===t?{"image/*":[".png",".jpg",".svg",".gif",".apng",".avif",".webp"]}:"mp3"===t||"ogg"===t||"wav"===t?{"audio/*":[".mp3",".ogg",".wav",".mp4"]}:"ics"===t?{"text/calendar":[".ics"]}:"txt"===t?{"text/plain":[".txt"]}:"pem"===t?{"text/plain":[".pem"]}:{"*/*":[".".concat(t)]}}return(0,u.jsx)(st(),{ref:this.dropzoneRef,multiple:!1,accept:h,noKeyboard:!0,noClick:!0,maxSize:this.props.schema.maxSize||2097152,onDragEnter:()=>{this.setState({uploadFile:"dragging"})},onDragLeave:()=>this.setState({uploadFile:!0}),onDrop:(t,e)=>{this.setState({uploadFile:!1}),t.length?this.onDrop(t):window.alert(e&&e[0]&&e[0].errors&&e[0].errors[0]&&e[0].errors[0].message||d.I18n.t("Cannot upload"))},children:t=>{let{getRootProps:s,getInputProps:o}=t;return(0,u.jsxs)("div",(0,i.A)((0,i.A)({style:(0,i.A)((0,i.A)((0,i.A)({},it.uploadDiv),"dragging"===this.state.uploadFile?it.uploadDivDragging:void 0),e?it.disabledOpacity:void 0)},s()),{},{children:[(0,u.jsx)("input",(0,i.A)({},o())),"dragging"===this.state.uploadFile?(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},it.uploadCenterDiv),this.state.uploadError?it.error:void 0),children:(0,u.jsxs)("div",{style:it.uploadCenterTextAndIcon,children:[(0,u.jsx)(c.UploadFile,{style:it.uploadCenterIcon}),(0,u.jsx)("div",{style:it.uploadCenterText,children:"dragging"===this.state.uploadFile?d.I18n.t("ra_Drop file here"):d.I18n.t("ra_Place your files here or click here to open the browse dialog")})]})}):null,l,this.renderDeleteDialog()]}))}})}}const pt=ht,ct={fullWidth:{width:"100%"},fullWidthOneButton:{width:"calc(100% - 69px)",marginRight:4},fullWidthIcon:{width:"calc(100% - 119px)",marginRight:4},selectedImage:{height:40,width:40,display:"inline-block",marginRight:8}},dt=["jpg","jpeg","svg","png","webp","gif","apng","avif","webp"],ut=["mp3","ogg","wav","aac"],mt=["avi","mp4","mov"],gt=["txt","log","html","htm"],xt=["json","js","ts"];const vt=class extends x{constructor(){super(...arguments),this.imagePrefix="../.."}componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.imagePrefix=void 0===this.props.oContext.imagePrefix?"./files":this.props.oContext.imagePrefix,this.setState({value:null!==t&&void 0!==t?t:""})}static getDerivedStateFromProps(t,e){const s=x.getValue(t.data,t.attr);return null===s||void 0===s||s.toString().trim()!==(e.value||"").toString().trim()?{value:null!==s&&void 0!==s?s:""}:null}loadFile(){const t=this.state.value.indexOf("/");if(-1!==t){const e=this.state.value.substring(0,t),s=this.state.value.substring(t+1);return this.props.oContext.socket.readFile(e,s,!0)}return Promise.resolve(null)}play(){this.loadFile().then((t=>{if("undefined"!==typeof AudioContext&&null!==t&&void 0!==t&&t.file){const e=new AudioContext,s=pt.base64ToArrayBuffer(t.file);e.decodeAudioData(s,(t=>{const s=e.createBufferSource();s.buffer=t,s.connect(e.destination),s.start(0)}),(t=>window.alert("Cannot play: ".concat(t.message))))}}))}getIcon(){const t=this.state.value.split(".").pop().toLowerCase();return dt.includes(t)?(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},ct.selectedImage),{},{backgroundImage:"url(".concat(this.imagePrefix,"/").concat(this.state.value,")"),backgroundSize:"contain",backgroundRepeat:"no-repeat"})}):ut.includes(t)?(0,u.jsx)(p.IconButton,{style:{color:"#00FF00"},onClick:()=>this.play(),children:(0,u.jsx)(c.PlayArrow,{})}):gt.includes(t)?(0,u.jsx)(c.Article,{}):mt.includes(t)?(0,u.jsx)(c.Videocam,{}):xt.includes(t)?(0,u.jsx)(c.Code,{}):null}renderFileBrowser(){return this.state.showFileBrowser?(0,u.jsx)(d.DialogSelectFile,{imagePrefix:this.props.oContext.imagePrefix,socket:this.props.oContext.socket,selected:this.state.value,onClose:()=>this.setState({showFileBrowser:!1}),onOk:t=>{const e=Array.isArray(t)?t[0]:t;this.setState({value:e},(()=>this.onChange(this.props.attr,!1===this.props.schema.trim?e:(e||"").trim())))},selectOnlyFolders:this.props.schema.selectOnlyFolders,allowUpload:this.props.schema.allowUpload,allowDownload:this.props.schema.allowDownload,allowCreateFolder:this.props.schema.allowCreateFolder,allowView:this.props.schema.allowView,showToolbar:this.props.schema.showToolbar,limitPath:this.props.schema.limitPath,theme:this.props.oContext.theme}):null}renderItem(t,e){const s=this.getIcon();return(0,u.jsxs)("div",{style:ct.fullWidth,children:[s,(0,u.jsx)(p.TextField,{variant:"standard",style:s?ct.fullWidthIcon:ct.fullWidthOneButton,value:null===this.state.value||void 0===this.state.value?"":this.state.value,error:!!t,disabled:!!e,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:!!this.props.schema.disableEdit}},onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,!1===this.props.schema.trim?e:(e||"").trim())))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}),(0,u.jsx)(p.Button,{disabled:e,variant:"outlined",onClick:()=>this.setState({showFileBrowser:!0}),children:"..."}),this.renderFileBrowser()]})}};const ft=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.props.oContext.socket.getEnums("functions").then((e=>{const s=Object.keys(e).map((t=>({value:this.props.schema.short?t.replace("enum.functions.",""):t,label:this.getText(e[t].common.name),obj:e[t]})));!1!==this.props.schema.allowDeactivate&&s.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.setState({value:t,selectOptions:s})}))}renderItem(t,e){if(!this.state.selectOptions)return null;const s=this.state.selectOptions.find((t=>t.value===this.state.value));return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>s?s.obj?(0,u.jsx)(d.TextWithIcon,{value:s.obj,themeType:this.props.oContext.themeType,lang:d.I18n.getLanguage()}):s.label:"",onChange:t=>{this.setState({value:"_"===t.target.value?"":t.target.value},(()=>this.onChange(this.props.attr,this.state.value)))},children:this.state.selectOptions.map((t=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.DIFFERENT_VALUE?{opacity:.5}:{},children:t.obj?(0,u.jsx)(d.TextWithIcon,{value:t.obj,themeType:this.props.oContext.themeType,lang:d.I18n.getLanguage()}):t.label},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const yt=class extends x{componentDidMount(){super.componentDidMount(),this.props.oContext.socket.getHostByIp(this.props.common.host).then((t=>{this.props.schema.listenOnAllPorts||(t=t.filter((t=>"0.0.0.0"!==t.address&&"::"!==t.address))),this.props.schema.onlyIp4?t=t.filter((t=>"ipv4"===t.family)):this.props.schema.onlyIp6&&(t=t.filter((t=>"ipv6"===t.family))),this.props.schema.noInternal&&(t=t.filter((t=>!t.internal))),t.forEach((t=>{"0.0.0.0"===t.address?t.name="[IPv4] 0.0.0.0 - ".concat(d.I18n.t("ra_Listen on all IPs")):"::"===t.address&&(t.name="[IPv6] :: - ".concat(d.I18n.t("ra_Listen on all IPs")))})),this.setState({ips:t})})).catch((t=>console.error(t)))}renderItem(t,e){var s,i;const o=x.getValue(this.props.data,this.props.attr),a=null===(s=this.state.ips)||void 0===s?void 0:s.find((t=>t.address===o));return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[this.state.ips&&this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,this.state.ips?(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:o,renderValue:t=>(null===a||void 0===a?void 0:a.name)||t,onChange:t=>this.onChange(this.props.attr,t.target.value),children:null===(i=this.state.ips)||void 0===i?void 0:i.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.address,children:t.name},e)))}):(0,u.jsx)(p.TextField,{fullWidth:!0,variant:"standard",error:!!t,disabled:!!e,value:o,onChange:t=>this.onChange(this.props.attr,t.target.value),label:this.getText(this.props.schema.label)}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const bt=class extends x{constructor(){super(...arguments),this.initialized=!1,this.localContext=void 0}componentDidMount(){super.componentDidMount(),this.askInstance()}askInstance(){if(this.props.alive){let e=this.props.schema.data;if(void 0===e&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,null,!0);if(s)try{e=JSON.parse(s)}catch(t){console.error("Cannot parse json data: ".concat(JSON.stringify(e)))}}void 0===e&&(e=null),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",e).then((t=>this.setState({image:t||""})))}}getContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=x.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(){if(this.props.alive){const t=this.getContext();t===this.localContext&&this.initialized||(this.localContext=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}return void 0===this.state.image?null:(0,u.jsx)("img",{alt:"dynamic content",src:this.state.image,style:{width:this.props.schema.width||"100%",height:this.props.schema.height}})}};const Ct=class extends x{constructor(t){super(t),this.index=void 0,this.index=Date.now()}componentDidMount(){if(super.componentDidMount(),this.props.schema.base64){const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t})}else this.props.oContext.socket.fileExists("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.attr).then((t=>t&&this.loadImage()))}_getUrl(t){t&&(this.index=Date.now());let e="files/".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance,"/").concat(this.props.attr,"?t=").concat(this.index);return"3000"===window.location.port&&(e="".concat(window.location.protocol,"//").concat(window.location.hostname,":8081/").concat(e)),e}loadImage(){fetch(this._getUrl()).then((t=>t.blob())).then((t=>{const e=new FileReader;e.onload=()=>{this.setState({value:e.result})},e.readAsDataURL(t)})).catch((t=>console.error(t)))}renderItem(t,e){return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(d.UploadImage,{error:!!t,disabled:e,accept:this.props.schema.accept,crop:this.props.schema.crop,maxSize:this.props.schema.maxSize||262144,icon:this.state.value||void 0,removeIconFunc:()=>this.setState({value:null},(()=>{if(this.props.schema.base64){const t=this.onChange(this.props.attr,this.state.value);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}else this.props.oContext.socket.deleteFile("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.attr).catch((t=>console.error(t)))})),onChange:t=>this.setState({value:t},(()=>{if(this.props.schema.base64){const t=this.onChange(this.props.attr,this.state.value);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))}else t.startsWith("data")&&(t=t.split(",")[1]);this.props.oContext.socket.writeFile64("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.attr,t).catch((t=>console.error(t)))}))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},jt={icon:{width:20,height:20,marginRight:4}};const wt=class extends x{constructor(){super(...arguments),this.onInstancesUpdate=(t,e)=>{if(!t.match(/^system\.adapter\.[-_a-z\d]+\.\d+$/))return;const s=this.props.schema.long?t:this.props.schema.short?t.split(".").pop():t.replace(/^system\.adapter\./,""),i=this.state.selectOptions.findIndex((t=>t.value===s));if(e){if("_dataSources"===this.props.schema.adapter&&(!e.common||!e.common.getHistory))return;if(-1===i){const t=JSON.parse(JSON.stringify(this.state.selectOptions)),s="object"===typeof e.common.name?e.common.name[d.I18n.getLanguage()]||e.common.name.en:e.common.name;t.push({value:this.props.schema.long?e._id:this.props.schema.short?e._id.split(".").pop():e._id.replace(/^system\.adapter\./,""),label:"".concat(s," [").concat(e._id.replace(/^system\.adapter\./,""),"]"),icon:"adapter/".concat(s,"/").concat(e.common.icon)}),t.sort(((t,e)=>t.label>e.label?1:t.label<e.label?-1:0)),this.setState({selectOptions:t})}}else if(-1!==i){const t=JSON.parse(JSON.stringify(this.state.selectOptions)),e={};this.state.value===t[i].value&&(e.value=x.NONE_VALUE),t.splice(i,1),e.selectOptions=t,this.setState(e)}}}componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);let e=this.props.schema.adapter;"_dataSources"===e&&(e=void 0),this.props.oContext.socket.getAdapterInstances(e,!0).then((async s=>{"_dataSources"===this.props.schema.adapter?s=s.filter((t=>{var e;return null===t||void 0===t||null===(e=t.common)||void 0===e?void 0:e.getHistory})):this.props.schema.adapter?s=s.filter((t=>null===t||void 0===t?void 0:t._id.startsWith("system.adapter.".concat(this.props.schema.adapter,".")))):this.props.schema.adapters&&Array.isArray(this.props.schema.adapters)&&(s=s.filter((t=>{var e;return this.props.schema.adapters.includes(null===t||void 0===t||null===(e=t.common)||void 0===e?void 0:e.name)}))),this.props.schema.onlyEnabled&&(s=s.filter((t=>{var e;return null===t||void 0===t||null===(e=t.common)||void 0===e?void 0:e.enabled})));const i=s.map((t=>({value:this.props.schema.long?t._id:this.props.schema.short?t._id.split(".").pop():t._id.replace(/^system\.adapter\./,""),label:"".concat(t.common.name," [").concat(t._id.replace(/^system\.adapter\./,""),"]"),icon:"adapter/".concat(t.common.name,"/").concat(t.common.icon)})));i.sort(((t,e)=>t.value>e.value?1:t.value<e.value?-1:0)),!1!==this.props.schema.allowDeactivate&&i.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.props.schema.all&&i.unshift({label:d.I18n.t("sch_all"),value:"*"}),this.setState({value:t||"",selectOptions:i}),await this.props.oContext.socket.subscribeObject("system.adapter.".concat(e?"".concat(e,"."):"","*"),this.onInstancesUpdate)})).catch((t=>console.error("Cannot get instances: ".concat(t))))}componentWillUnmount(){this.props.oContext.socket.unsubscribeObject("system.adapter.*",this.onInstancesUpdate).then((()=>{})),super.componentWillUnmount()}renderItem(t,e){var s;if(!this.state.selectOptions)return null;const i=null===(s=this.state.selectOptions)||void 0===s?void 0:s.find((t=>t.value===this.state.value));return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:this.state.value,renderValue:()=>(0,u.jsxs)("span",{style:{display:"flex"},children:[null!==i&&void 0!==i&&i.icon?(0,u.jsx)("img",{src:"./".concat(i.icon),alt:i.value,style:jt.icon}):null,this.getText(null===i||void 0===i?void 0:i.label,!0)]}),onChange:t=>this.setState({value:t.target.value},(()=>this.onChange(this.props.attr,this.state.value))),children:this.state.selectOptions.map((t=>(0,u.jsxs)(p.MenuItem,{value:t.value,style:t.value===x.NONE_VALUE?{opacity:.5}:{},children:[t.icon?(0,u.jsx)("img",{src:"./".concat(t.icon),alt:t.value,style:jt.icon}):null,this.getText(t.label,!0)]},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]},this.props.attr)}},Tt={address:{fontSize:"smaller",opacity:.5,marginLeft:8}};const It=class extends x{componentDidMount(){super.componentDidMount(),this.props.oContext.socket.getObject("system.host.".concat(this.props.common.host)).then((t=>{var e,s;const i=[];if(null!==t&&void 0!==t&&null!==(e=t.native)&&void 0!==e&&null!==(s=e.hardware)&&void 0!==s&&s.networkInterfaces){const e=t.native.hardware.networkInterfaces;Object.keys(e).forEach((t=>{if(this.props.schema.ignoreInternal&&!e[t].find((t=>!t.internal)))return;if(this.props.schema.ignoreLoopback&&e[t].find((t=>"127.0.0.1"===t.address||"::1"===t.address)))return;let s=e[t].find((t=>"IPv4"===t.family));s=s||e[t].find((t=>"IPv6"===t.family)),i.push({value:t,address:s.address})}))}this.setState({interfaces:i})})).catch((t=>window.alert("Cannot read interfaces: ".concat(t))))}renderItem(t,e){var s,i,o;const a=x.getValue(this.props.data,this.props.attr),n=null===(s=this.state.interfaces)||void 0===s?void 0:s.find((t=>t.value===a));return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[null!==(i=this.state.interfaces)&&void 0!==i&&i.length&&this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,null!==(o=this.state.interfaces)&&void 0!==o&&o.length?(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:a,renderValue:t=>n?(0,u.jsxs)("span",{children:[n.value,(0,u.jsx)("span",{style:Tt.address,children:n.address})]}):t,onChange:t=>this.onChange(this.props.attr,t.target.value),children:this.state.interfaces.map(((t,e)=>(0,u.jsx)(p.MenuItem,{value:t.value,children:(0,u.jsxs)("span",{children:[t.value,(0,u.jsx)("span",{style:Tt.address,children:t.address})]})},e)))}):(0,u.jsx)(p.TextField,{fullWidth:!0,variant:"standard",error:!!t,disabled:!!e,value:a,onChange:t=>this.onChange(this.props.attr,t.target.value),label:this.getText(this.props.schema.label)}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},St={modalDialog:{minWidth:400,maxWidth:800},overflowHidden:{display:"flex",overflow:"hidden"},titleIcon:{marginRight:5},content:{fontSize:16},languageButton:{position:"absolute",right:8,top:8},languageButtonActive:{color:"primary.main"}},Dt=t=>{let{toggleTranslation:e,noTranslation:s,title:a,fullWidth:n,help:r,maxWidth:l,progress:h,icon:m,applyDisabled:g,applyButton:x,onClose:v,children:f,titleButtonApply:y,titleButtonClose:b,onApply:C,textInput:j,defaultValue:w,overflowHidden:T}=t;const[I,S]=(0,o.useState)(w);(0,o.useEffect)((()=>{S(w)}),[w]);let D=null;return m&&(D=m),(0,u.jsxs)(p.Dialog,{open:!0,maxWidth:l||"md",fullWidth:!!n,disableEscapeKeyDown:!1,onClose:v,sx:{"& .MuiPaper-root":St.modalDialog},children:[a&&(0,u.jsxs)(p.DialogTitle,{children:[m?(0,u.jsx)(D,{style:St.titleIcon}):null,a,"en"!==d.I18n.getLanguage()&&e?(0,u.jsx)(p.IconButton,{size:"large",style:(0,i.A)((0,i.A)({},St.languageButton),s?St.languageButtonActive:{}),onClick:()=>e(),title:d.I18n.t("Disable/Enable translation"),children:(0,u.jsx)(c.Language,{})}):null]}),(0,u.jsxs)(p.DialogContent,{sx:(0,i.A)((0,i.A)({},T?St.overflowHidden:{}),St.content),style:{paddingTop:8},children:[j&&(0,u.jsx)(p.TextField,{autoComplete:"off",fullWidth:!0,autoFocus:!0,variant:"outlined",size:"medium",multiline:!0,value:I,onChange:t=>S(t.target.value)}),f,r?(0,u.jsx)("div",{children:r}):null]}),(0,u.jsxs)(p.DialogActions,{children:[!1!==x&&(0,u.jsx)(p.Button,{startIcon:(0,u.jsx)(c.Check,{}),disabled:h||g&&w===I,onClick:()=>C&&C(j?I:""),variant:"contained",color:"primary",children:d.I18n.t(y||"Ok")}),(0,u.jsx)(p.Button,{color:"grey",onClick:()=>v&&v(),disabled:h,variant:"contained",startIcon:(0,u.jsx)(c.Close,{}),children:d.I18n.t(b||"Cancel")})]})]})};var kt=s(2091),Ot=s.n(kt);s(77563),s(78172),s(67244),s(85781),s(21571);const At={jsonError:{border:"1px solid red",minHeight:200},jsonNoError:{border:"1px solid #00000000",minHeight:200}};const _t=function(t){return(0,u.jsx)(Ot(),{style:!0===t.error?At.jsonError:!1===t.error?At.jsonNoError:void 0,mode:t.mode||"json",width:"100%",height:"100%",showPrintMargin:t.editValueMode,showGutter:t.editValueMode,highlightActiveLine:t.editValueMode,defaultValue:t.defaultValue,theme:"dark"===t.themeType?"clouds_midnight":"chrome",value:t.value,readOnly:!t.onChange,onChange:e=>t.onChange(e),name:t.name||"UNIQUE_ID_OF_DIV1",fontSize:t.fontSize||14,setOptions:{enableBasicAutocompletion:!0,enableLiveAutocompletion:!0,enableSnippets:!0,showLineNumbers:t.editValueMode,tabSize:t.editValueMode?2:void 0},editorProps:{$blockScrolling:!0}})},Ft={fullWidth:{width:"100%"},flex:{display:"flex"},button:{height:48,minWidth:48},wrapper:{width:"calc(100vw - 40px)",height:"calc(100vh - 188px)"}};const Nt=class extends x{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=x.getValue(t,e)||{};this.setState({value:s,initialized:!0,jsonError:this.validateJson(s)})}validateJson(t){let e=!1;if(!1!==this.props.schema.validateJson&&(t||!this.props.schema.allowEmpty))try{JSON.parse(t)}catch(s){console.log("Error in JSON",s),e=!0}return e}renderItem(t,e){if(!this.state.initialized)return null;const{schema:s,data:o,attr:a}=this.props,{value:n,showSelectId:r}=this.state;return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[(0,u.jsx)("div",{style:Ft.flex,children:(0,u.jsx)(p.Button,{color:"grey",disabled:e,style:Ft.button,size:"small",variant:"outlined",onClick:()=>this.setState({showSelectId:!0}),children:d.I18n.t("ra_JSON editor")})}),r?(0,u.jsx)(Dt,{title:this.getText(s.label),overflowHidden:!0,onClose:()=>this.setState({showSelectId:!1,value:x.getValue(o,a)||{}}),onApply:()=>this.setState({showSelectId:!1},(()=>this.onChange(a,n))),children:(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},Ft.wrapper),this.state.jsonError?{}:void 0),children:(0,u.jsx)(_t,{value:"object"===typeof n?JSON.stringify(n):n,onChange:t=>this.setState({value:t,jsonError:this.validateJson(t)}),name:"ConfigJsonEditor",themeType:this.props.oContext.themeType})})}):null,s.help||this.state.jsonError?(0,u.jsx)(p.FormHelperText,{children:this.state.jsonError?d.I18n.t("ra_Invalid JSON"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},Et=[{value:"en",label:"English"},{value:"de",label:"Deutsch"},{value:"ru",label:"\u0440\u0443\u0441\u0441\u043a\u0438\u0439"},{value:"pt",label:"Portugues"},{value:"nl",label:"Nederlands"},{value:"fr",label:"fran\xe7ais"},{value:"it",label:"Italiano"},{value:"es",label:"Espanol"},{value:"pl",label:"Polski"},{value:"uk",label:"\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0438\u0439"},{value:"zh-cn",label:"\u7b80\u4f53\u4e2d\u6587"}];const Lt=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr),e=[...Et];this.props.schema.system?e.unshift({value:"",label:d.I18n.t("ra_System language")}):e.unshift({value:"",label:d.I18n.t("ra_none")}),this.setState({value:this.props.schema.system?t||"":t||d.I18n.getLanguage(),selectOptions:e})}renderItem(t,e){var s,i;if(!this.state.selectOptions)return null;const o=null===(s=this.state.selectOptions)||void 0===s?void 0:s.find((t=>t.value===this.state.value||!t.value&&!this.state.value));return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:e,value:this.state.value||"_",renderValue:()=>this.getText(null===o||void 0===o?void 0:o.label,this.props.schema.noTranslation),onChange:t=>{let{value:e}=t.target;"_"===e&&(e=""),this.setState({value:e},(()=>{const t=this.onChange(this.props.attr,e);if(t instanceof Promise&&t.catch((t=>console.error(t))),this.props.schema.changeGuiLanguage)if(e){if(e===d.I18n.getLanguage())return;d.I18n.setLanguage(e),this.props.oContext.changeLanguage&&this.props.oContext.changeLanguage()}else this.props.oContext.socket.getSystemConfig().then((t=>{t.common.language!==d.I18n.getLanguage()&&t.common.language&&(d.I18n.setLanguage(t.common.language),this.props.oContext.changeLanguage&&this.props.oContext.changeLanguage())})).catch((t=>console.error("Cannot read system config: ".concat(t))))}))},children:null===(i=this.state.selectOptions)||void 0===i?void 0:i.map((t=>(0,u.jsx)(p.MenuItem,{value:t.value,children:t.label},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const Vt=class extends x{constructor(t){super(t),this.scrollRef=void 0,this.scrollRef=a().createRef()}scrolledDown(){return!!this.scrollRef.current&&this.scrollRef.current.offsetHeight+this.scrollRef.current.scrollTop>=this.scrollRef.current.scrollHeight}componentDidMount(){super.componentDidMount(),x.getValue(this.props.data,this.props.attr)||(this.props.schema.licenseUrl?(this.setState({showLicenseDialog:!0,loading:!0,scrolledDown:!1}),fetch(this.props.schema.licenseUrl).then((t=>t.text())).then((t=>this.setState({license:t,loading:!1}))).catch((t=>this.setState({license:t.toString(),loading:!1,error:!0,scrolledDown:!1})))):this.setState({showLicenseDialog:!0,scrolledDown:!1}),setTimeout((()=>{if(this.scrollRef.current){this.scrolledDown()?this.setState({scrolledDown:!0}):this.scrollRef.current.addEventListener("scroll",(()=>{!this.state.scrolledDown&&this.scrolledDown()&&this.setState({scrolledDown:!0})}))}}),1e3))}renderItem(t,e){return this.state.showLicenseDialog?(0,u.jsxs)(p.Dialog,{maxWidth:"lg",open:!0,onClose:(t,e)=>{"escapeKeyDown"!==e&&"backdropClick"!==e&&this.setState({showLicenseDialog:!1})},children:[(0,u.jsx)(p.DialogTitle,{children:this.props.schema.title?d.I18n.t(this.props.schema.title):d.I18n.t("ra_License agreement")}),(0,u.jsxs)(p.DialogContent,{children:[this.props.schema.licenseUrl?(0,u.jsxs)(u.Fragment,{children:[this.state.loading?(0,u.jsx)(p.LinearProgress,{}):null,(0,u.jsx)("pre",{ref:this.scrollRef,style:{width:"100%",height:"100%",overflowY:"auto",fontSize:14},children:this.state.license})]}):null,!this.props.schema.licenseUrl&&this.props.schema.texts?(0,u.jsx)("div",{ref:this.scrollRef,style:{width:"100%",height:"100%",overflowY:"auto",fontSize:14},children:this.props.schema.texts.map(((t,e)=>this.props.schema.noTranslation?(0,u.jsx)("p",{children:t},e):(0,u.jsx)("p",{children:d.I18n.t(t)},e)))}):null]}),(0,u.jsxs)(p.DialogActions,{children:[this.props.schema.checkBox?(0,u.jsx)(p.FormControlLabel,{control:(0,u.jsx)(p.Checkbox,{disabled:e,checked:!!this.state.licenseChecked,onClick:()=>this.setState({licenseChecked:!this.state.licenseChecked})}),label:d.I18n.t(this.props.schema.checkBox)}):null,(0,u.jsx)(p.Button,{disabled:e||this.state.loading||this.state.error||this.props.schema.checkBox&&!this.state.licenseChecked||!this.state.scrolledDown,onClick:()=>{this.setState({showLicenseDialog:!1});const t=this.onChange(this.props.attr,!0);t instanceof Promise&&t.catch((t=>console.error("Cannot set value: ".concat(t))))},color:"primary",variant:"contained",startIcon:(0,u.jsx)(c.Check,{}),children:this.props.schema.agreeText?d.I18n.t(this.props.schema.agreeText):d.I18n.t("ra_Accept license")}),(0,u.jsx)(p.Button,{onClick:()=>{this.setState({showLicenseDialog:!1}),setTimeout((()=>this.setState({showLicenseDialog:!0})),2e3)},color:"grey",variant:"contained",startIcon:(0,u.jsx)(c.Close,{}),children:d.I18n.t("ra_Close")})]})]}):null}},Pt={indeterminate:{opacity:.5},control:{flexDirection:"row",width:"100%"}};const Bt=class extends x{constructor(){super(...arguments),this.updateTimeout=void 0}componentDidMount(){super.componentDidMount();let t=x.getValue(this.props.data,this.props.attr);if(null!==t&&void 0!==t||(t=""),Array.isArray(t)&&this.props.oContext.multiEdit)return t=x.DIFFERENT_VALUE,void this.setState({_value:t,oldValue:t});this.setState({_value:t.toString(),oldValue:t.toString()})}static getDerivedStateFromProps(t,e){if(void 0!==t.schema.min&&t.schema.min<0||void 0!==t.schema.max&&t.schema.max<0)return null;const s=x.getValue(t.data,t.attr);return t.oContext.multiEdit&&e._value===x.DIFFERENT_VALUE?{_value:x.DIFFERENT_VALUE}:null===s||void 0===s||null===e.oldValue||void 0===e.oldValue||s.toString()!==parseFloat(e._value).toString()&&s.toString()!==e.oldValue.toString()?{_value:s}:null}checkValue(t){if(null===t||void 0===t)return null;const e=""===(t=t.toString().trim())?0:parseFloat(t);return""!==t&&Number.isNaN(e)?"ra_Not a number":""!==t&&window.isFinite(e)?void 0!==this.props.schema.min&&e<this.props.schema.min?"ra_Too small":void 0!==this.props.schema.max&&e>this.props.schema.max?"ra_Too big":""===t||"-"===t||Number.isNaN(e)?"ra_Not a number":null:"ra_Not a number"}renderItem(t,e){const s=Array.isArray(this.state._value)||this.state._value===x.DIFFERENT_VALUE;if(null!==this.state.oldValue&&void 0!==this.state.oldValue?(this.updateTimeout&&clearTimeout(this.updateTimeout),this.updateTimeout=setTimeout((()=>{this.updateTimeout=void 0,this.setState({oldValue:null})}),30)):this.updateTimeout&&(clearTimeout(this.updateTimeout),this.updateTimeout=void 0),s){const s=x.getValue(this.props.data,this.props.attr),o=(null===s||void 0===s?void 0:s.filter((t=>t||0===t)).map((t=>({label:t.toString(),value:t}))))||[];return o.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),(0,u.jsx)(p.Autocomplete,{style:Pt.indeterminate,fullWidth:!0,freeSolo:!0,value:o[0],getOptionSelected:(t,e)=>t.label===e.label,onChange:(t,e)=>{const s=this.onChange(this.props.attr,null===e||void 0===e?void 0:e.value,(()=>{this.setState({_value:null===e||void 0===e?void 0:e.value,oldValue:this.state._value})}));s instanceof Promise&&s.catch((t=>console.error(t)))},options:o,getOptionLabel:t=>t.label,renderInput:s=>(0,u.jsx)(p.TextField,(0,i.A)((0,i.A)({},s),{},{label:this.getText(this.props.schema.label),variant:"standard",slotProps:{htmlInput:(0,i.A)((0,i.A)({},s.inputProps),{},{readOnly:this.props.schema.readOnly||!1}),input:{endAdornment:this.props.schema.unit?this.getText(this.props.schema.unit,this.props.schema.noTranslation):void 0}},error:!!t,placeholder:this.getText(this.props.schema.placeholder),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),disabled:!!e}))})}return!t&&null!==this.state._value&&void 0!==this.state._value&&this.state._value&&(t=this.checkValue(this.state._value))&&(t=d.I18n.t(t)),(0,u.jsx)(p.FormControl,{variant:"standard",style:Pt.control,children:(0,u.jsx)(p.TextField,{variant:"standard",type:"number",fullWidth:!0,slotProps:{htmlInput:{min:this.props.schema.min,max:this.props.schema.max,step:this.props.schema.step,readOnly:this.props.schema.readOnly||!1},input:{endAdornment:this.props.schema.unit?this.getText(this.props.schema.unit,this.props.schema.noTranslation):void 0}},value:null===this.state._value||void 0===this.state._value?"":this.state._value,error:!!t,disabled:!!e,onChange:t=>{const e=t.target.value,s=this.checkValue(e);s?this.onError(this.props.attr,d.I18n.t(s)):this.onError(this.props.attr),this.setState({_value:e,oldValue:this.state._value},(()=>this.onChange(this.props.attr,parseFloat(e))))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:t&&"string"===typeof t?t:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})})}},Wt={flex:{display:"flex"},button:{height:48,marginLeft:4,minWidth:48}};const Ut=class extends x{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=x.getValue(t,e)||"";this.setState({value:s,initialized:!0})}renderItem(t,e){if(!this.state.initialized)return null;const s=this.props.oContext.socket,{schema:i,attr:o}=this.props,{value:a,showSelectId:n}=this.state;return(0,u.jsxs)(p.FormControl,{fullWidth:!0,variant:"standard",children:[i.label?(0,u.jsx)(p.InputLabel,{shrink:!0,children:this.getText(i.label)}):null,(0,u.jsxs)("div",{style:Wt.flex,children:[(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:a,error:!!t,disabled:e,placeholder:this.getText(i.placeholder),label:this.getText(i.label),helperText:this.renderHelp(i.help,i.helpLink,i.noTranslation),onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(o,e)))}}),(0,u.jsx)(p.Button,{color:"grey",disabled:e,style:Wt.button,size:"small",variant:"outlined",onClick:()=>this.setState({showSelectId:!0}),children:"..."})]}),n?(0,u.jsx)(d.DialogSelectID,{imagePrefix:void 0===this.props.oContext.imagePrefix?"../..":this.props.oContext.imagePrefix,dialogName:"admin.".concat(this.props.oContext.adapterName),filterFunc:i.filterFunc,themeType:this.props.oContext.themeType,theme:this.props.oContext.theme,types:i.types?Array.isArray(i.types)?i.types:[i.types]:void 0,customFilter:i.customFilter,filters:i.filters,socket:s,selected:a,root:i.root,onClose:()=>this.setState({showSelectId:!1}),onOk:t=>this.setState({showSelectId:!1,value:t},(()=>this.onChange(o,t)))}):null]})}},Mt={fullWidth:{width:"100%",display:"inline-block"},halfWidth1:{width:"calc(50% - 5px)",display:"inline-block",marginRight:8},halfWidth2:{width:"calc(50% - 5px)",display:"inline-block"}},Rt="____ppp____";const Jt=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({_repeat:t?Rt:"",_visible:!1,value:t?Rt:"",_notEqual:!1})}onChangePassword(t,e){void 0===t&&(t=this.state.value),void 0===e&&(e=this.state._repeat);const s=!!this.props.schema.repeat&&e!==t;this.setState({value:t,_repeat:e,_notEqual:s},(()=>{if(s)this.onError(this.props.attr,d.I18n.t("ra_Passwords are not equal!"));else{this.onError(this.props.attr);const e=this.onChange(this.props.attr,t);e instanceof Promise&&e.catch((t=>this.onError(this.props.attr,t)))}}))}renderItem(t,e){if(void 0===this.state._notEqual)return null;const s=(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,type:this.state._visible&&this.state.value!==Rt?"text":"password",value:this.state.value,error:!!t||this.state._notEqual,disabled:!!e,onChange:t=>this.onChangePassword(t.target.value),label:this.getText(this.props.schema.label),slotProps:{input:{autoComplete:"new-password",endAdornment:this.state.value&&this.state.value!==Rt&&this.props.schema.visible&&!e&&!this.props.schema.readOnly?(0,u.jsx)(p.InputAdornment,{position:"end",children:(0,u.jsx)(p.IconButton,{size:"large",tabIndex:-1,onClick:t=>{t.preventDefault(),t.stopPropagation(),this.setState({_visible:!this.state._visible})},edge:"end",children:this.state._visible?(0,u.jsx)(c.VisibilityOff,{}):(0,u.jsx)(c.Visibility,{})})}):void 0},htmlInput:{autoComplete:"new-password",form:{autoComplete:"off"},maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:this.props.schema.readOnly||!1}},helperText:this.state._notEqual?d.I18n.t("ra_Passwords are not equal!"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)});if(this.props.schema.repeat&&!this.props.schema.readOnly){const i=this.state._visible?null:(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,type:"password",value:this.state._repeat,error:!!t||this.state._notEqual,disabled:!!e,onChange:t=>this.onChangePassword(void 0,t.target.value),label:"".concat(this.getText(this.props.schema.label)," (").concat(d.I18n.t("ra_repeat"),")"),slotProps:{input:{autoComplete:"new-password"},htmlInput:{autoComplete:"new-password",form:{autoComplete:"off"},maxLength:this.props.schema.maxLength||this.props.schema.max||void 0}},helperText:this.state._notEqual?d.I18n.t("ra_Passwords are not equal!"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)});return(0,u.jsxs)("div",{style:Mt.fullWidth,children:[(0,u.jsx)("div",{style:Mt.halfWidth1,children:s}),(0,u.jsx)("div",{style:Mt.halfWidth2,children:i})]})}return s}};const zt=class extends x{renderItem(t,e){return(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,disabled:!!e,slotProps:{input:{endAdornment:this.props.schema.copyToClipboard?(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>{d.Utils.copyToClipboard(this.getPattern(this.props.schema.pattern,null,this.props.schema.noTranslation)),window.alert(d.I18n.t("ra_Copied"))},children:(0,u.jsx)(d.IconCopy,{})}):void 0}},value:this.getPattern(this.props.schema.pattern,null,!0),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},Ht={warning:{"& .Mui-error":{color:"orange"}}};const qt=class extends x{constructor(){super(...arguments),this.updateTimeout=void 0}async componentDidMount(){super.componentDidMount();let t=x.getValue(this.props.data,this.props.attr);null!==t&&void 0!==t||(t=""),this.setState({_value:t.toString(),oldValue:t.toString()});const e=await this.props.oContext.socket.getAdapterInstances(),s="system.adapter.".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),i=await this.props.oContext.socket.getObject(s),o=null===i||void 0===i?void 0:i.common.host,a=[];e.forEach((t=>{var e,i;if(!t||t._id===s||t.common.host!==o)return;if(null===(e=t.native)||void 0===e||!e.bind)return;if(null!==t&&void 0!==t&&t.native&&t.native.secure&&t.native.leEnabled&&t.native.leUpdate){const e=parseInt(t.native.leCheckPort||t.native.lePort,10);var n;if(e)a.push({name:"".concat(t._id.replace("system.adapter.","")," (LE)"),port:e,v6bind:t.native.bind.includes(":")?t.native.bind:t.native.v6bind,bind:t.native.bind,enabled:!(null===(n=t.common)||void 0===n||!n.enabled)})}const r=parseInt(null===t||void 0===t||null===(i=t.native)||void 0===i?void 0:i.port,10);var l;r&&a.push({name:t._id.replace("system.adapter.",""),bind:t.native.bind,v6bind:t.native.bind.includes(":")?t.native.bind:t.native.v6bind,port:r,enabled:!(null===(l=t.common)||void 0===l||!l.enabled)})})),this.setState({ports:a})}static getDerivedStateFromProps(t,e){const s=x.getValue(t.data,t.attr);return null===s||void 0===s||null===e.oldValue||void 0===e.oldValue||s.toString()!==parseInt(e._value,10).toString()&&s.toString()!==e.oldValue.toString()?{_value:s}:null}checkValue(t){if(null===t||void 0===t)return null;const e=void 0===this.props.schema.min?20:this.props.schema.min,s=this.props.schema.max||65535,i=""===(t=t.toString().trim())?0:parseInt(t,10);return""!==t&&Number.isNaN(i)?"ra_Not a number":""!==t&&window.isFinite(Number(t))?i<e?"ra_Too small":i>s?"ra_Too big":""===t||"-"===t||Number.isNaN(i)?"ra_Not a number":null:"ra_Not a number"}renderItem(t,e){null!==this.state.oldValue&&void 0!==this.state.oldValue?(this.updateTimeout&&clearTimeout(this.updateTimeout),this.updateTimeout=setTimeout((()=>{this.updateTimeout=void 0,this.setState({oldValue:null})}),30)):this.updateTimeout&&(clearTimeout(this.updateTimeout),this.updateTimeout=void 0);const s=void 0===this.props.schema.min?20:this.props.schema.min,i=this.props.schema.max||65535;let o;if(this.state.ports){const e=parseInt(this.state._value,10);if(e){const s=this.state.ports.filter((t=>!this.props.data.bind||this.props.data.bind===t.bind||"0.0.0.0"===this.props.data.bind||"0.0.0.0"===t.bind));let i=s.findIndex((t=>t.port===e&&t.enabled));-1!==i?t=d.I18n.t("ra_Port is already used by %s",this.state.ports[i].name):(i=s.findIndex((t=>t.port===e&&!t.enabled)),-1!==i&&(o=!0,t=d.I18n.t("ra_Port could be used by %s",this.state.ports[i].name)))}}return t||null===this.state._value||void 0===this.state._value||"string"===typeof(t=this.checkValue(this.state._value))&&(t=d.I18n.t(t)),(0,u.jsx)(p.TextField,{variant:"standard",type:"number",fullWidth:!0,slotProps:{htmlInput:{min:s,max:i,readOnly:this.props.schema.readOnly||!1}},value:null===this.state._value||void 0===this.state._value?"":this.state._value,error:!!t,disabled:!!e,sx:o?Ht.warning:void 0,onChange:t=>{const e=Number(t.target.value.toString().replace(/[^0-9]/g,"")).toString(),s=this.checkValue(e);s?this.onError(this.props.attr,d.I18n.t(s)):this.onError(this.props.attr),this.setState({_value:e,oldValue:this.state._value},(()=>{if(e.trim()===parseInt(e,10).toString()){const t=this.onChange(this.props.attr,parseInt(e,10)||0);t instanceof Promise&&t.catch((t=>{console.error("Cannot set value for ".concat(this.props.attr,": ").concat(t))}))}}))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:t&&"string"===typeof t?t:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}};const Kt=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.props.oContext.socket.getEnums("rooms").then((e=>{const s=Object.keys(e).map((t=>({value:this.props.schema.short?t.replace("enum.rooms.",""):t,label:this.getText(e[t].common.name),obj:e[t]})));!1!==this.props.schema.allowDeactivate&&s.unshift({label:d.I18n.t(x.NONE_LABEL),value:x.NONE_VALUE}),this.setState({value:t,selectOptions:s})})).catch((t=>console.error("Cannot get enums: ".concat(t))))}renderItem(t,e){if(!this.state.selectOptions)return null;const s=this.state.selectOptions.find((t=>t.value===this.state.value));return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>s?s.obj?(0,u.jsx)(d.TextWithIcon,{value:s.obj,themeType:this.props.oContext.themeType,lang:d.I18n.getLanguage()}):s.label:"",onChange:t=>{this.setState({value:"_"===t.target.value?"":t.target.value},(()=>this.onChange(this.props.attr,this.state.value)))},children:this.state.selectOptions.map((t=>(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.DIFFERENT_VALUE?{opacity:.5}:{},children:t.obj?(0,u.jsx)(d.TextWithIcon,{value:t.obj,themeType:this.props.oContext.themeType,lang:d.I18n.getLanguage()}):t.label},t.value)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},$t={fullWidth:{width:"100%"},noMargin:{"&>div":{marginTop:0}}};const Gt=class extends x{constructor(){super(...arguments),this.initialValue=""}componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr),e=[];(this.props.schema.options||[]).forEach((t=>{const s=t;Array.isArray(s.items)?(e.push({label:this.getText(t.label),value:t.value,group:!0}),s.items.forEach((t=>e.push({label:this.getText(t.label),value:t.value,hidden:t.hidden})))):e.push({label:this.getText(t.label),value:t.value,hidden:t.hidden})})),Array.isArray(t)?(this.initialValue=[...t],e.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),this.setState({value:x.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}renderItem(t,e){if(!this.state.selectOptions)return null;const s=(this.state.selectOptions||[]).filter((t=>!t.hidden||(this.props.custom?!this.executeCustom(t.hidden,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):!this.execute(t.hidden,this.props.schema.default,this.props.data,this.props.arrayIndex,this.props.globalData)))),i=s.find((t=>t.value==this.state.value));return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,sx:void 0!==this.props.table&&$t.noMargin,id:"jsonSelect_".concat(this.props.attr,"_").concat(this.props.index||0===this.props.index?this.props.index:""),children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>this.getText(null===i||void 0===i?void 0:i.label,this.props.schema.noTranslation),onChange:t=>{this.setState({value:"_"===t.target.value?"":t.target.value},(()=>{let t;t=this.state.value===x.DIFFERENT_VALUE?this.onChange(this.props.attr,this.initialValue):this.onChange(this.props.attr,this.state.value),t instanceof Promise&&t.catch((t=>console.error(t)))}))},children:s.map(((t,e)=>t.group?(0,u.jsx)(p.ListSubheader,{children:this.getText(t.label,this.props.schema.noTranslation)},e):(0,u.jsx)(p.MenuItem,{value:t.value,style:t.value===x.DIFFERENT_VALUE?{opacity:.5}:{},children:this.getText(t.label,this.props.schema.noTranslation)},e)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},Yt={menuPaper:{maxHeight:800}};const Zt=class extends x{constructor(){super(...arguments),this.initialized=!1,this.localContext=void 0}askInstance(){if(this.props.alive){let e=this.props.schema.data;if(void 0===e&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,null,!0);try{e=JSON.parse(s)}catch(t){console.error("Cannot parse json data: ".concat(s))}}void 0===e&&(e=null),this.setState({running:!0},(()=>{this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",e).then((t=>this.setState({list:t,running:!1}))).catch((t=>{console.error("Cannot send command: ".concat(t))}))}))}else{const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t,running:!1})}}getContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=x.getValue(this.props.data,e))),JSON.stringify(t)}_getValue(){let t=null===this.state.value||void 0===this.state.value?x.getValue(this.props.data,this.props.attr):this.state.value;return this.props.schema.multiple&&("string"===typeof t?t=[t]:null!==t&&void 0!==t||(t=[])),t}renderItem(t,e){var s;if(this.props.alive){const t=this.getContext();t===this.localContext&&this.initialized||(this.localContext=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}const i=this._getValue();if(!this.props.alive||!this.state.running&&(null===(s=this.state.list)||void 0===s||!s.length))return this.props.schema.multiple||!1===this.props.schema.manual?d.I18n.t("ra_Cannot retrieve options, as instance is offline"):(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:i,error:!!t,disabled:!!e,onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,(e||"").trim())))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),slotProps:{input:{endAdornment:this.state.value&&!this.props.schema.noClearButton?(0,u.jsx)(p.InputAdornment,{position:"end",children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.setState({value:""},(()=>this.onChange(this.props.attr,""))),children:(0,u.jsx)(c.Close,{})})}):null}}});if(this.state.running)return(0,u.jsx)(p.CircularProgress,{size:"24"});const o=this.state.list.filter((t=>!t.hidden||(this.props.custom?!this.executeCustom(t.hidden,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.arrayIndex,this.props.globalData):!this.execute(t.hidden,this.props.schema.default,this.props.data,this.props.arrayIndex,this.props.globalData)))),a=o.find((t=>t.value===i));return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Select,{variant:"standard",error:!!t,multiple:this.props.schema.multiple,disabled:!!e,sx:{"&.MuiSelect-paper":this.props.schema.multiple?Yt.menuPaper:void 0},value:i,renderValue:t=>this.props.schema.multiple?(0,u.jsx)(p.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:t.map((t=>{const e=o.find((e=>e.value===t));if(e||!1!==this.props.schema.showAllValues){const s=(null===e||void 0===e?void 0:e.label)||t;return(0,u.jsx)(p.Chip,{label:s},t)}return null}))}):(null===a||void 0===a?void 0:a.label)||t,onChange:t=>{const e=this.onChange(this.props.attr,t.target.value);e instanceof Promise&&e.catch((t=>console.error("Cannot set value: ".concat(t))))},children:o.map(((t,e)=>(0,u.jsxs)(p.MenuItem,{value:t.value,children:[this.props.schema.multiple?(0,u.jsx)(p.Checkbox,{checked:i.includes(t.value),onClick:()=>{const e=JSON.parse(JSON.stringify(this._getValue())),s=i.indexOf(t.value);-1!==s?e.splice(s,1):(e.push(t.value),e.sort()),this.setState({value:e},(()=>this.onChange(this.props.attr,e)))}}):null,(0,u.jsx)(p.ListItemText,{primary:t.label})]},e)))}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},Qt={fullWidth:{width:"100%"}};function Xt(t){return t.split(".").reduce(((t,e)=>(t<<8)+parseInt(e,10)),0)>>>0}const te=class extends x{async componentDidMount(){super.componentDidMount();let t=window.location.hostname;if(this.props.schema.openUrl){const s=await this.props.oContext.socket.getCurrentInstance(),i=await this.props.oContext.socket.getObject("system.adapter.".concat(s));if(i){var e;const s=await this.props.oContext.socket.getObject("system.host.".concat(null===i||void 0===i||null===(e=i.common)||void 0===e?void 0:e.host));if(s){const e=function(t,e){var s,i;const o=null===t||void 0===t||null===(s=t.native)||void 0===s||null===(i=s.hardware)||void 0===i?void 0:i.networkInterfaces;if(!o)return null;let a;return Object.keys(o).forEach((t=>o[t].forEach((t=>{t.internal||e.includes(":")&&"IPv6"!==t.family||e.includes(".")&&!e.match(/[^.\d]/)&&"IPv4"!==t.family||("IPv4"!==t.family||t.address.startsWith("172")||"127.0.0.0"!==e&&"localhost"!==e&&!e.match(/[^.\d]/)?a||("IPv4"===t.family&&e.includes(".")&&(Xt(e),Xt(t.netmask),Xt(t.address),Xt(t.netmask)),a=t.address):a=t.address)})))),a||Object.keys(o).forEach((t=>o[t].forEach((t=>{t.internal||e.includes(":")&&"IPv6"!==t.family||e.includes(".")&&!e.match(/[^.\d]/)&&"IPv4"!==t.family||("IPv6"!==t.family||"127.0.0.0"!==e&&"localhost"!==e&&!e.match(/[^.\d]/)?a||("IPv4"===t.family&&e.includes(".")&&(Xt(e),Xt(t.netmask),Xt(t.address),Xt(t.netmask)),a=t.address):a=t.address)})))),a||Object.keys(o).forEach((t=>{o[t].forEach((t=>{t.internal||e.includes(":")&&"IPv6"!==t.family||e.includes(".")&&!e.match(/[^.\d]/)&&"IPv4"!==t.family||("127.0.0.0"===e||"localhost"===e||e.match(/[^.\d]/),a=t.address)}))})),a||Object.keys(o).forEach((t=>{o[t].forEach((t=>{t.internal||(a=t.address)}))})),a}(s,window.location.hostname);if(!e)return void console.warn("Cannot find suitable IP in host ".concat(i.common.host," for ").concat(i._id));t="".concat(e,":").concat(window.location.port)}}}await new Promise((e=>{this.setState({_error:"",_message:"",hostname:t},e)})),this.props.schema.onLoaded&&this._onClick()}renderErrorDialog(){return this.state._error?(0,u.jsx)(d.DialogError,{text:this.state._error,onClose:()=>this.setState({_error:""})}):null}renderMessageDialog(){return this.state._message?(0,u.jsx)(d.DialogMessage,{text:this.state._message,onClose:()=>this.setState({_message:""})}):null}_onClick(){this.props.oContext.onCommandRunning(!0),this.setState({running:!0});const t="".concat(window.location.protocol,"//").concat(window.location.host).concat(window.location.pathname.replace(/\/index\.html$/,"")),e="".concat(window.location.protocol,"//").concat(this.state.hostname.split(":").length>3?"[".concat(this.state.hostname,"]"):this.state.hostname).concat(window.location.pathname.replace(/\/index\.html$/,""));let s,o=this.props.schema.data;if(void 0===o&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,(0,i.A)({_origin:t,_originIp:e},this.props.data),!0);try{o=JSON.parse(s)}catch(a){console.error("Cannot parse json data: ".concat(s))}}void 0===o&&(o=null),this.props.schema.openUrl&&!o&&(o={_origin:t,_originIp:e}),this.props.schema.timeout&&(s=setTimeout((()=>{this.props.oContext.onCommandRunning(!1),this.setState({_error:d.I18n.t("ra_Request timed out"),running:!1})}),parseInt(this.props.schema.timeout,10)||1e4)),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",o).then((async t=>{if(s&&(clearTimeout(s),s=void 0),null!==t&&void 0!==t&&t.error)if(this.props.schema.error&&this.props.schema.error[t.error]){let e=this.getText(this.props.schema.error[t.error]);t.args&&t.args.forEach((t=>e=e.replace("%s",t))),this.setState({_error:e})}else this.setState({_error:t.error?d.I18n.t(t.error):d.I18n.t("ra_Error")});else{if(null!==t&&void 0!==t&&t.command)return void(this.props.oContext.onBackEndCommand&&this.props.oContext.onBackEndCommand(t.command));if(null!==t&&void 0!==t&&t.reloadBrowser&&this.props.schema.reloadBrowser)window.location.reload();else if(null!==t&&void 0!==t&&t.openUrl&&this.props.schema.openUrl)window.open(t.openUrl,t.window||this.props.schema.window||"_blank");else if(null!==t&&void 0!==t&&t.result&&this.props.schema.result&&this.props.schema.result[t.result]){let e=this.getText(this.props.schema.result[t.result]);t.args&&t.args.forEach((t=>e=e.replace("%s",t))),window.alert(e)}if(null!==t&&void 0!==t&&t.native&&this.props.schema.useNative){for(const[e,s]of Object.entries(t.native))await this.onChangeAsync(e,s);setTimeout((()=>this.props.oContext.forceUpdate(Object.keys(t.native),this.props.data)),300)}else null!==t&&void 0!==t&&t.result?window.alert("object"===typeof t.result?JSON.stringify(t.result):t.result):window.alert(d.I18n.t("ra_Ok"));null!==t&&void 0!==t&&t.saveConfig&&this.props.onChange(null,null,null,!0)}})).catch((t=>{this.props.schema.error&&this.props.schema.error[t.toString()]?this.setState({_error:this.getText(this.props.schema.error[t.toString()])}):this.setState({_error:d.I18n.t(t.toString())||d.I18n.t("ra_Error")})})).then((()=>{this.props.oContext.onCommandRunning(!1),this.setState({running:!1})}))}renderDialogConfirm(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,u.jsx)(c.Warning,{}):"error"===t.type?e=(0,u.jsx)(c.Error,{}):"info"===t.type&&(e=(0,u.jsx)(c.Info,{})),(0,u.jsx)(d.DialogConfirm,{title:this.getText(t.title)||d.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||d.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||d.I18n.t("ra_Cancel"),icon:e||void 0,onClose:t=>this.setState({confirmDialog:!1},(()=>t&&this._onClick()))})}renderItem(t,e){const s=this.getIcon();return(0,u.jsxs)("div",{style:Qt.fullWidth,children:[(0,u.jsxs)(p.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:(0,i.A)((0,i.A)({},Qt.fullWidth),this.props.schema.controlStyle||void 0),disabled:e||!this.props.alive,startIcon:s,title:this.props.alive?this.getText(this.props.schema.title)||"":d.I18n.t("ra_Instance is not alive"),onClick:()=>{this.props.schema.confirm?this.setState({confirmDialog:!0}):this._onClick()},children:[this.props.schema.showProcess&&this.state.running?(0,u.jsx)(p.CircularProgress,{size:20,style:{marginRight:8}}):null,this.getText(this.props.schema.label,this.props.schema.noTranslation)]}),this.renderErrorDialog(),this.renderMessageDialog()]})}},ee={fullWidth:{width:"100%"},icon:{width:24,height:24,marginRight:4}};const se=class extends x{async _onClick(){let t=this.props.schema.val;if("string"===typeof t&&t.includes("${")){var e,s;t=this.getPattern(t,null,!0);const i=await this.props.oContext.socket.getObject(this.props.schema.id);"number"===(null===i||void 0===i||null===(e=i.common)||void 0===e?void 0:e.type)?t=parseFloat(t):"boolean"===(null===i||void 0===i||null===(s=i.common)||void 0===s?void 0:s.type)&&(t="true"===t||!0===t||"1"===t||1===t)}const i=(this.props.schema.id||"").replace(/%INSTANCE%/g,(this.props.oContext.instance||0).toString());try{await this.props.oContext.socket.setState(i,{val:t,ack:!!this.props.schema.ack}),this.props.schema.okText&&window.alert(this.getText(this.props.schema.okText))}catch(o){this.props.schema.error&&this.props.schema.error[o.toString()]?window.alert(this.getText(this.props.schema.error[o.toString()])):window.alert(d.I18n.t(o.toString())||d.I18n.t("ra_Error"))}}renderDialogConfirm(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,u.jsx)(c.Warning,{}):"error"===t.type?e=(0,u.jsx)(c.Error,{}):"info"===t.type&&(e=(0,u.jsx)(c.Info,{})),(0,u.jsx)(d.DialogConfirm,{title:this.getText(t.title)||d.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||d.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||d.I18n.t("ra_Cancel"),icon:e,onClose:t=>this.setState({confirmDialog:!1},(()=>t&&this._onClick()))})}renderItem(t,e){return(0,u.jsxs)(p.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:ee.fullWidth,disabled:e,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0}):await this._onClick()},children:[this.props.schema.icon?(0,u.jsx)(d.Icon,{src:this.props.schema.icon,style:ee.icon}):null,this.getText(this.props.schema.label,this.props.schema.noTranslation)]})}},ie={fullWidth:{width:"100%"},slider:{marginLeft:10,marginRight:10,width:"calc(100% - 20px)"}};const oe=class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({_value:t})}static getDerivedStateFromProps(t,e){if(void 0!==t.schema.min&&t.schema.min<0||void 0!==t.schema.max&&t.schema.max<0)return null;const s=x.getValue(t.data,t.attr);return null===s||void 0===s||s.toString()!==parseFloat(e._value).toString()?{_value:s}:null}renderItem(t,e){const s=this.props.schema.min||0,i=this.props.schema.max||100,o=this.props.schema.unit?this.getText(this.props.schema.unit,this.props.schema.noTranslation):"",a=[{value:s,label:s+o},{value:i,label:i+o}];return(0,u.jsxs)(p.Box,{style:ie.fullWidth,children:[this.props.schema.label?(0,u.jsx)(p.Typography,{gutterBottom:!0,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.Slider,{style:ie.slider,value:this.state._value,getAriaValueText:t=>t+o,step:this.props.schema.step||(i-s)/100,valueLabelDisplay:"auto",marks:a,min:s,max:i,disabled:!!e,onChange:t=>{const e=t.target.value;this.setState({_value:e},(()=>this.onChange(this.props.attr,e)))}}),this.props.schema.help?(0,u.jsx)(p.Typography,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};function ae(t,e){return"edit"===t||"rename"===t?(0,u.jsx)(c.Edit,{style:e}):"delete"===t?(0,u.jsx)(c.Delete,{style:e}):"refresh"===t?(0,u.jsx)(c.Refresh,{style:e}):"newDevice"===t||"new"===t||"add"===t?(0,u.jsx)(c.Add,{style:e}):"discover"===t||"search"===t?(0,u.jsx)(c.Search,{style:e}):"unpairDevice"===t||"unpair"===t?(0,u.jsx)(c.LinkOff,{style:e}):"pairDevice"===t||"pair"===t?(0,u.jsx)(c.Link,{style:e}):"identify"===t?(0,u.jsx)(c.NotListedLocation,{style:e}):"play"===t?(0,u.jsx)(c.PlayArrow,{style:e}):"stop"===t?(0,u.jsx)(c.Stop,{style:e}):"pause"===t?(0,u.jsx)(c.Pause,{style:e}):"forward"===t||"next"===t?(0,u.jsx)(c.FastForward,{style:e}):"rewind"===t||"previous"===t?(0,u.jsx)(c.FastRewind,{style:e}):"lamp"===t||"light"===t?(0,u.jsx)(c.Lightbulb,{style:e}):"backlight"===t?(0,u.jsx)(c.Fluorescent,{style:e}):"dimmer"===t?(0,u.jsx)(c.WbIncandescent,{style:e}):"socket"===t?(0,u.jsx)(c.Power,{style:e}):"settings"===t?(0,u.jsx)(c.Settings,{style:e}):"users"===t||"group"===t?(0,u.jsx)(c.Group,{style:e}):"user"===t?(0,u.jsx)(c.Person,{style:e}):"qrcode"===t?(0,u.jsx)(c.QrCode,{style:e}):"connection"===t?(0,u.jsx)(c.Wifi,{style:e}):"no-connection"===t?(0,u.jsx)(c.WifiOff,{style:e}):"visible"===t?(0,u.jsx)(c.Visibility,{style:e}):null}const ne=class extends x{constructor(){super(...arguments),this.controlTimeout=null,this.delayedUpdate={timer:null,value:null},this.onStateChanged=(t,e)=>{let s=e?e.val:null;"button"===this.state.controlType||"switch"===this.state.controlType?(s=!!s,this.state.stateValue!==s&&this.setState({stateValue:s})):null===s||"slider"!==this.state.controlType&&"number"!==this.state.controlType?this.state.stateValue.toString()!==s.toString()&&this.setState({stateValue:s}):(s=parseFloat(s),console.log("".concat(Date.now()," Received new value: ").concat(s)),s!==this.state.stateValue?(this.delayedUpdate.timer&&(clearTimeout(this.delayedUpdate.timer),this.delayedUpdate.timer=null),this.delayedUpdate.value=s,this.delayedUpdate.timer=setTimeout((()=>{this.setState({stateValue:this.delayedUpdate.value})}),500)):this.delayedUpdate.timer&&(clearTimeout(this.delayedUpdate.timer),this.delayedUpdate.timer=null))}}getObjectID(){return this.props.schema.foreign?this.props.schema.oid:"".concat(this.props.schema.system?"system.adapter.":"").concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance,".").concat(this.props.schema.oid)}async componentDidMount(){super.componentDidMount();const t=await this.props.oContext.socket.getObject(this.getObjectID()),e=this.props.schema.control||this.detectType(t),s=await this.props.oContext.socket.getState(this.getObjectID());this.setState({stateValue:s?s.val:null,controlType:e,obj:t},(async()=>{await this.props.oContext.socket.subscribeState(this.getObjectID(),this.onStateChanged)}))}componentWillUnmount(){super.componentWillUnmount(),this.props.oContext.socket.unsubscribeState(this.getObjectID(),this.onStateChanged),this.delayedUpdate.timer&&(clearTimeout(this.delayedUpdate.timer),this.delayedUpdate.timer=null),this.controlTimeout&&(clearTimeout(this.controlTimeout),this.controlTimeout=null,this.props.oContext.socket.setState(this.getObjectID(),this.state.stateValue,!1).catch((t=>console.error("Cannot control value: ".concat(t)))))}detectType(t){if((t=t||{}).common=t.common||{},"boolean"===t.common.type){if(!1!==this.props.schema.controlled){if(!1===t.common.read||!0===this.props.schema.controlled)return"button";if(t.common.write||!0===this.props.schema.controlled)return"switch"}return"text"}return"number"===t.common.type&&!1!==this.props.schema.controlled?t.common.write||!0===this.props.schema.controlled?void 0!==t.common.max?"slider":"input":"text":t.common.write&&!1!==this.props.schema.controlled?"input":"text"}renderItem(t,e){if(!this.state.obj)return null;let s;if("button"===this.state.controlType){let t=null;this.props.schema.falseImage&&(t=ae(this.props.schema.falseImage));const i=this.getText(this.props.schema.falseText||this.props.schema.label,this.props.schema.noTranslation);s=!i&&t?(0,u.jsx)(p.IconButton,{style:this.props.schema.falseTextStyle,disabled:!!this.props.schema.readOnly,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.oContext.socket.setState(this.getObjectID(),!0,!1)}}):await this.props.oContext.socket.setState(this.getObjectID(),!0,!1)},children:t}):(0,u.jsx)(p.Button,{variant:this.props.schema.variant||"contained",startIcon:t,style:this.props.schema.falseTextStyle,disabled:e||!!this.props.schema.readOnly,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.oContext.socket.setState(this.getObjectID(),!0,!1)}}):await this.props.oContext.socket.setState(this.getObjectID(),!0,!1)},children:i||this.getObjectID().split(".").pop()})}else if("input"===this.state.controlType)s=(0,u.jsx)(p.TextField,{style:{width:"100%"},value:this.state.stateValue,variant:"standard",slotProps:{input:{endAdornment:this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit||void 0},htmlInput:{readOnly:!!this.props.schema.readOnly}},onChange:t=>{this.setState({stateValue:t.target.value},(()=>{this.controlTimeout&&clearTimeout(this.controlTimeout),this.controlTimeout=setTimeout((async()=>{this.controlTimeout=null,await this.props.oContext.socket.setState(this.getObjectID(),this.state.stateValue,!1)}),this.props.schema.controlDelay||0)}))},label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)});else if("number"===this.state.obj.common.type){const t=void 0===this.props.schema.min?this.state.obj.common.min||0:this.props.schema.min,e=void 0===this.props.schema.max?void 0===this.state.obj.common.max?100:this.state.obj.common.max:this.props.schema.max,i=void 0===this.props.schema.step?this.state.obj.common.step||1:this.props.schema.step;s=(0,u.jsx)(p.TextField,{variant:"standard",style:{width:"100%"},value:this.state.stateValue,type:"number",slotProps:{htmlInput:{min:t,max:e,step:i,readOnly:!!this.props.schema.readOnly},input:{endAdornment:this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit||void 0}},onChange:t=>{this.setState({stateValue:t.target.value},(()=>{this.controlTimeout&&clearTimeout(this.controlTimeout),this.controlTimeout=setTimeout((async()=>{this.controlTimeout=null;const t=parseFloat(this.state.stateValue);await this.props.oContext.socket.setState(this.getObjectID(),t,!1)}),this.props.schema.controlDelay||0)}))},label:this.getText(this.props.schema.label,this.props.schema.noTranslation),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}else{let t;"normal"===this.props.schema.size?t=16:"large"===this.props.schema.size?t=20:"number"===typeof this.props.schema.size&&(t=this.props.schema.size);let e=this.getText(this.props.schema.label,this.props.schema.noTranslation);const n={display:"flex",alignItems:"center",fontSize:t||"1rem",gap:8};let r,l,h;if(this.props.schema.narrow||(n.width="100%",n.justifyContent="space-between"),e.trim()&&!e.trim().endsWith(":")&&this.props.schema.addColon&&(e="".concat(e.trim(),":")),this.props.schema.blinkOnUpdate&&(o=this.props.oContext.theme,r="string"===typeof(a=this.props.schema.blinkOnUpdate)?{"@keyframes newStateAnimationOnceColor":{"0%":{color:a},"100%":{color:"dark"===o.palette.mode?"#fff":"#000"}},animation:"newStateAnimationOnceColor 2s ease-in-out"}:{"@keyframes newStateAnimationOnce":{"0%":{color:"#00f900"},"80%":{color:"dark"===o.palette.mode?"#518851":"#008000"},"100%":{color:"dark"===o.palette.mode?"#fff":"#000"}},animation:"newStateAnimationOnce 2s ease-in-out"}),this.props.schema.labelIcon&&(l=(0,u.jsx)(d.Icon,{src:this.props.schema.labelIcon,style:{marginRight:4}})),e&&l?h=(0,u.jsxs)("div",{style:{whiteSpace:"nowrap"},children:[l,e]}):e?h=(0,u.jsx)("div",{style:{whiteSpace:"nowrap"},children:e}):l&&(h=l),"switch"===this.state.controlType){let t=null;const e=this.getText(this.props.schema.falseText,this.props.schema.noTranslation);this.props.schema.falseImage&&(t=ae(this.props.schema.falseImage,e?{marginLeft:8}:void 0));let i=null;const o=this.getText(this.props.schema.trueText,this.props.schema.noTranslation);this.props.schema.trueImage&&(i=ae(this.props.schema.trueImage,o?{marginRight:8}:void 0)),s=(0,u.jsx)(p.Switch,{checked:!!this.state.stateValue,disabled:!!this.props.schema.readOnly,onChange:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.oContext.socket.setState(this.getObjectID(),!this.state.stateValue,!1)}}):await this.props.oContext.socket.setState(this.getObjectID(),!this.state.stateValue,!1)}}),(e||t||o||i)&&(s=(0,u.jsxs)("div",{style:{display:"flex",alignItems:"center",fontSize:14},children:[(0,u.jsxs)("span",{style:this.props.schema.falseTextStyle,children:[e,t]}),s,(0,u.jsxs)("span",{style:this.props.schema.trueTextStyle,children:[i,o]})]})),h&&(s=(0,u.jsxs)("div",{style:n,children:[h,s]}))}else if("slider"===this.state.controlType){let t=null;const e=this.getText(this.props.schema.falseText,this.props.schema.noTranslation);this.props.schema.falseImage&&(t=ae(this.props.schema.falseImage,e?{marginLeft:8}:void 0));let o=null;const a=this.getText(this.props.schema.trueText,this.props.schema.noTranslation);this.props.schema.trueImage&&(o=ae(this.props.schema.trueImage,a?{marginRight:8}:void 0));const r=void 0===this.props.schema.min?this.state.obj.common.min||0:this.props.schema.min,l=void 0===this.props.schema.max?void 0===this.state.obj.common.max?100:this.state.obj.common.max:this.props.schema.max,c=void 0===this.props.schema.step?this.state.obj.common.step||1:this.props.schema.step;s=(0,u.jsx)(p.Slider,{style:{width:"100%",flexGrow:1},min:r,max:l,disabled:!!this.props.schema.readOnly,step:c,value:this.state.stateValue,valueLabelDisplay:"auto",valueLabelFormat:t=>"".concat(t).concat(this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit||""),onChange:(t,e)=>{this.setState({stateValue:e},(()=>{this.controlTimeout&&clearTimeout(this.controlTimeout),this.controlTimeout=setTimeout((async()=>{console.log("".concat(Date.now()," Send new value: ").concat(this.state.stateValue)),this.controlTimeout=null,await this.props.oContext.socket.setState(this.getObjectID(),this.state.stateValue,!1)}),this.props.schema.controlDelay||0)}))}}),(e||t||a||o)&&(s=(0,u.jsxs)("div",{style:{display:"flex",width:"100%",flexGrow:1,alignItems:"center"},children:[(0,u.jsxs)("span",{style:(0,i.A)({marginRight:16},this.props.schema.falseTextStyle),children:[e,t]}),s,(0,u.jsxs)("span",{style:(0,i.A)({marginLeft:16},this.props.schema.trueTextStyle),children:[o,a]})]})),h&&(s=(0,u.jsxs)("div",{style:n,children:[h,s]}))}else if("boolean"===this.state.obj.common.type){let t,e,i=null;this.state.stateValue?(t=this.getText(this.props.schema.trueText,this.props.schema.noTranslation),this.props.schema.trueImage&&(i=ae(this.props.schema.falseImage,t?{marginRight:8}:void 0)),e=this.props.schema.trueTextStyle):(t=this.getText(this.props.schema.falseText,this.props.schema.noTranslation),this.props.schema.falseImage&&(i=ae(this.props.schema.falseImage,t?{marginLeft:8}:void 0)),e=this.props.schema.falseTextStyle),e=Object.assign(n,e),s=(0,u.jsxs)("div",{style:e,children:[h,(0,u.jsxs)(p.Box,{style:{display:"flex",alignItems:"center",gap:8},sx:r,children:[i,t||(this.state.stateValue?d.I18n.t("ra_true"):d.I18n.t("ra_false"))]},this.props.schema.blinkOnUpdate?t:void 0)]})}else{const t=this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit;let e,i;"html"===this.state.controlType?(i=(this.state.stateValue||"").toString(),e=(0,u.jsx)("span",{dangerouslySetInnerHTML:{__html:this.state.stateValue}})):null===this.state.stateValue?(e="null",i=e):void 0===this.state.stateValue?(e="undefined",i=e):(e=this.state.stateValue.toString(),i=e),s=(0,u.jsxs)("div",{style:n,children:[h,(0,u.jsxs)("div",{style:{display:"flex",alignItems:"baseline",gap:4},children:[(0,u.jsx)(p.Box,{sx:r,children:e},this.props.schema.blinkOnUpdate?i:void 0),t?(0,u.jsx)("span",{style:{opacity:.7,fontSize:"smaller"},children:t}):null]})]})}}var o,a;return s}},re={fullWidth:t=>({width:"100%",backgroundColor:"dark"===t.palette.mode?"#FFF":"#000",borderStyle:"hidden"}),primary:t=>({backgroundColor:t.palette.primary.main}),secondary:t=>({backgroundColor:t.palette.secondary.main})};const le=class extends x{renderItem(){return(0,u.jsx)(p.Box,{component:"hr",sx:d.Utils.getStyle(this.props.oContext.theme,re.fullWidth,"primary"===this.props.schema.color?re.primary:"secondary"===this.props.schema.color?re.secondary:{backgroundColor:this.props.schema.color||("dark"===this.props.oContext.themeType?"#333":"#ddd")},{height:this.props.schema.color?this.props.schema.height||2:this.props.schema.height||1})})}},he={header:t=>({width:"100%",background:t.palette.primary.main,color:t.palette.primary.contrastText,padding:"4px !important",borderRadius:"3px",marginBlockEnd:0,marginBlockStart:0})};const pe=class extends x{renderItem(){let t="h5";switch((this.props.schema.size||5).toString()){case"1":t="h1";break;case"2":t="h2";break;case"3":t="h3";break;case"4":t="h4";break;default:t="h5"}return(0,u.jsx)(p.Box,{component:t,sx:he.header,children:this.getText(this.props.schema.label||this.props.schema.text,this.props.schema.noTranslation)})}};const ce=class extends x{renderItem(){let t=this.props.schema.src;return!t||t.startsWith(".")||t.startsWith("http")||t.startsWith("adapter/".concat(this.props.oContext.adapterName,"/"))||t.startsWith("./adapter/".concat(this.props.oContext.adapterName,"/"))||(t="adapter/".concat(this.props.oContext.adapterName,"/").concat(t)),(0,u.jsx)("img",{src:t,style:{cursor:this.props.schema.href?"pointer":void 0,width:"100%",height:"100%"},onClick:this.props.schema.href?()=>this.props.schema.href&&window.open(this.props.schema.href,"_blank"):null,alt:""})}};function de(t,e,s){return"string"===typeof s?{"@keyframes newValueAnimationOnceColor":{"0%":{color:e?"".concat(s," !important"):s},"100%":{color:"dark"===t.palette.mode?e?"#fff !important":"#fff":e?"#000 !important":"#000"}},animation:"newValueAnimationOnceColor 2s ease-in-out"}:{"@keyframes newValueAnimationOnce":{"0%":{color:e?"#00f900 !important":"#00f900"},"80%":{color:"dark"===t.palette.mode?e?"#518851 !important":"#518851":e?"#008000 !important":"#008000"},"100%":{color:"dark"===t.palette.mode?e?"#fff !important":"#fff":e?"#000 !important":"#000"}},animation:"newValueAnimationOnce 2s ease-in-out"}}function ue(t,e){return"string"===typeof e?{"@keyframes blinkAnimationColor":{"0%":{color:e},"100%":{color:"dark"===t.palette.mode?"#fff":"#000"}},animation:"blinkAnimationColor 2s ease-in-out infinite"}:{"@keyframes blinkAnimation":{"0%":{color:"#00f900"},"80%":{color:"dark"===t.palette.mode?"#518851":"#008000"},"100%":{color:"dark"===t.palette.mode?"#fff":"#000"}},animation:"blinkAnimation 2s ease-in-out infinite"}}const me={label:{fontWeight:"bold",whiteSpace:"nowrap"},valueImage:{maxHeight:"100%"},valueAndUnit:{display:"flex",gap:4,alignItems:"baseline"},value:{},unit:{fontSize:"smaller",opacity:.7}};const ge=class extends x{renderItem(t){let e,s=this.getText(this.props.schema.text||this.props.schema.label,this.props.schema.noTranslation);this.props.schema.addColon&&"string"===typeof s&&!s.trim().endsWith(":")&&(s="".concat(s.trim(),":")),s&&(s.includes("<a ")||s.includes("<br")||s.includes("<b>")||s.includes("<i>"))&&(s=d.Utils.renderTextWithA(s)),"normal"===this.props.schema.size?e=16:"large"===this.props.schema.size?e=20:"number"===typeof this.props.schema.size&&(e=this.props.schema.size);const o={width:"100%",height:"100%",display:"flex",alignItems:"center",position:"relative",fontSize:e};let a,n;this.props.schema.narrow?o.gap=8:o.justifyContent="space-between",this.props.schema.data&&"object"===typeof this.props.schema.data&&this.props.schema.data.en?n=this.getText(this.props.schema.data):"object"===typeof this.props.schema.data||void 0===this.props.schema.data||null===this.props.schema.data?n=JSON.stringify(this.props.schema.data):"number"===typeof this.props.schema.data?(n=this.props.schema.data.toString(),this.props.oContext.isFloatComma&&(n=n.replace(".",","))):this.props.schema.booleanAsCheckbox&&"boolean"===typeof this.props.schema.data||(n=this.props.schema.data.toString());let r,l,h=!1;if(this.props.schema.booleanAsCheckbox&&"boolean"===typeof this.props.schema.data)a=(0,u.jsx)(p.Checkbox,{checked:!!a,disabled:!0,size:"small"===this.props.schema.size?"small":"large"===this.props.schema.size?"large":void 0});else if(n.startsWith("data:image/"))a=(0,u.jsx)("div",{style:(0,i.A)((0,i.A)((0,i.A)({},me.value),me.valueImage),this.props.schema.styleValue||void 0),children:(0,u.jsx)(d.Icon,{src:n})});else{const t=(0,i.A)((0,i.A)({},me.value),this.props.schema.styleValue||void 0);this.props.schema.html?a=(0,u.jsx)("div",{style:t,dangerouslySetInnerHTML:{__html:n}}):Array.isArray(this.props.schema.data)?(h=!0,a=(0,u.jsx)("div",{style:t,children:this.props.schema.data.map(((t,e)=>(0,u.jsx)("div",{children:"object"===typeof t||null===t||void 0===t?JSON.stringify(t):t},e)))})):n.includes("\n")?(h=!0,a=(0,u.jsx)("div",{style:t,children:d.Utils.renderTextWithA(n)})):a=(0,u.jsx)("div",{style:t,children:n})}if(this.props.schema.blinkOnUpdate&&this.props.schema.blink){const t=de(this.props.oContext.theme,!0,this.props.schema.blinkOnUpdate),e=ue(this.props.oContext.theme,this.props.schema.blink);a=(0,u.jsx)(p.Box,{sx:(0,i.A)((0,i.A)({},t),e),children:a},n)}else if(this.props.schema.blinkOnUpdate){const t=de(this.props.oContext.theme,!1,this.props.schema.blinkOnUpdate);a=(0,u.jsx)(p.Box,{sx:t,children:a},n)}else if(this.props.schema.blink){const t=ue(this.props.oContext.theme,this.props.schema.blink);a=(0,u.jsx)(p.Box,{sx:t,children:a})}this.props.schema.unit&&(a=(0,u.jsxs)("div",{style:me.valueAndUnit,children:[a,(0,u.jsx)("div",{style:(0,i.A)((0,i.A)({},me.unit),this.props.schema.styleUnit||void 0),children:this.getText(this.props.schema.unit,this.props.schema.noTranslation)})]})),this.props.schema.labelIcon&&(r=(0,u.jsx)(d.Icon,{src:this.props.schema.labelIcon,style:{marginRight:4}})),this.props.schema.copyToClipboard&&(l=(0,u.jsx)(c.ContentCopy,{className:"staticCopyButton",style:{position:"absolute",top:"calc(50% - 12px)",right:0,cursor:"pointer"},onClick:()=>{d.Utils.copyToClipboard(n),window.alert(d.I18n.t("ra_Copied"))}}));const m={"& .staticCopyButton":{display:"none"},"& .staticCopyButton:action":{transform:"scale(0.9)"},"&:hover .staticCopyButton":{display:"block"}};return this.props.schema.highlight&&(m["&:hover"]={backgroundColor:"dark"===this.props.oContext.themeType?"#51515180":"#b8b8b880"}),h&&(o.alignItems="top"),(0,u.jsxs)(p.Box,{component:"div",style:o,sx:m,children:[(0,u.jsxs)("div",{style:(0,i.A)((0,i.A)({},me.label),this.props.schema.styleLabel||void 0),children:[r,s]}),a,l]})}},xe={fullWidth:{height:"100%",width:"100%"},link:t=>({textDecoration:"underline",color:"dark"===t.palette.mode?"#4dabf5":"#254e72",cursor:"pointer"})};function ve(t,e,s){let i,o="";t?t.toString().startsWith("#")||t.toString().startsWith("/")?(i=e||"_self",o=t):t.startsWith("http://")||t.startsWith("https://")?(i=e||"_blank",o=t):(o="#tab-instances/config/".concat(s,"/").concat(t),i=e||"_self"):(o="#tab-instances/config/".concat(s),i=e||"_self"),"_self"===i?setTimeout((t=>{t.startsWith("#")?window.location.hash=t:t.startsWith("/")?o="".concat(window.location.protocol,":").concat(window.location.host).concat(o):(t.startsWith("http://")||t.startsWith("https://"))&&(window.location.href=t)}),100,o):(o.startsWith("#")?o="".concat(window.location.protocol,":").concat(window.location.host).concat(window.location.pathname).concat(o):o.startsWith("/")&&(o="".concat(window.location.protocol,":").concat(window.location.host).concat(o)),window.open(o,i))}const fe=class extends x{renderItem(t,e){if(this.props.schema.button){const t=this.getIcon();return(0,u.jsx)(p.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:(0,i.A)((0,i.A)({},xe.fullWidth),this.props.schema.controlStyle||void 0),disabled:e,startIcon:t,onClick:this.props.schema.href?()=>{const t=this.props.schema.href?this.getText(this.props.schema.href,!0):null;t&&(this.props.oContext.onBackEndCommand?this.props.oContext.onBackEndCommand({command:"link",url:t,target:this.props.schema.target,close:this.props.schema.close}):ve(t,this.props.schema.target,"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance)))}:null,children:this.getText(this.props.schema.text||this.props.schema.label,this.props.schema.noTranslation)})}let s=this.getText(this.props.schema.text||this.props.schema.label,this.props.schema.noTranslation);return s&&(s.includes("<a ")||s.includes("<br")||s.includes("<b>")||s.includes("<i>"))&&(s=d.Utils.renderTextWithA(s)),(0,u.jsx)(p.Box,{component:"span",style:(0,i.A)({},this.props.schema.controlStyle||void 0),sx:this.props.schema.href?xe.link:void 0,onClick:this.props.schema.href?()=>{const t=this.props.schema.href?this.getText(this.props.schema.href,!0):null;t&&(this.props.oContext.onBackEndCommand?this.props.oContext.onBackEndCommand({command:"link",url:t,target:this.props.schema.target||"_blank",close:this.props.schema.close}):ve(t,this.props.schema.target||"_blank","".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance)))}:null,children:s})}},ye=1048576,be={fullWidth:{width:"100%"},root:{width:"100%"},paper:{width:"100%",marginBottom:16,backgroundColor:"rgba(255, 255, 255, 0.1)"},headerText:{width:"100%"},table:{minWidth:750},visuallyHidden:{border:0,clip:"rect(0 0 0 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",top:20,width:1},label:{display:"flex",justifyContent:"space-between"},title:{flex:"1 1 100%"},rootTool:{paddingLeft:16,paddingRight:8},silver:{opacity:.2},flex:{display:"flex",alignItems:"baseline"},filteredOut:{padding:10,display:"flex",textAlign:"center"},buttonEmpty:{width:34,display:"inline-block"},buttonCell:{whiteSpace:"nowrap"},dropZone:{width:"100%",height:100,position:"relative"},dropZoneEmpty:{},uploadDiv:{position:"relative",width:"100%",minHeight:300,opacity:.9,marginTop:30,cursor:"pointer",outline:"none"},uploadDivDragging:{opacity:1,background:"rgba(128,255,128,0.1)"},image:{objectFit:"contain",margin:"auto",display:"flex",width:"100%",height:"100%"},uploadCenterDiv:{margin:5,border:"3px dashed grey",borderRadius:5,width:"calc(100% - 10px)",height:"calc(100% - 10px)",minHeight:300,position:"relative",display:"flex"},uploadCenterIcon:{paddingTop:10,width:48,height:48},uploadCenterText:{fontSize:16},uploadCenterTextAndIcon:{textAlign:"center",position:"absolute",top:0,bottom:0,left:0,right:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center"},buttonRemoveWrapper:{position:"absolute",zIndex:222,right:0},error:{border:"2px solid red",boxSizing:"border-box"},tooltip:{pointerEvents:"none"}};function Ce(t,e,s){e=e||"key";const i={};return t.forEach((t=>{let o=t[e];null!==o&&void 0!==o||(o=""),delete t[e],i[o]=s?t[s]:t})),i}class je extends x{constructor(t){var e;super(t),e=this,this.filterRefs=void 0,this.typingTimer=null,this.resizeTimeout=null,this.secret="Zgfr56gFe87jJOM",this.refDiv=void 0,this.handleRequestSort=function(t){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{order:i,orderBy:o}=e.state,a=s?i:o===t&&"asc"===i?"desc":"asc",n=e.stableSort(a,t);e.setState({value:n,order:a,orderBy:t,iteration:e.state.iteration+1e4},(()=>e.applyFilter(!1,n)))},this.stableSort=(t,e)=>{const{value:s}=this.state,i=je.getComparator(t,e),o=s.map(((t,e)=>({el:t,index:e})));return o.sort(((t,e)=>{const s=i(t.el,e.el);return 0!==s?s:t.index-e.index})),o.map((t=>t.el))},this.onDelete=t=>()=>{const e=JSON.parse(JSON.stringify(this.state.value));e.splice(t,1),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(e)))))},this.onClone=t=>()=>{const e=JSON.parse(JSON.stringify(this.state.value)),s=JSON.parse(JSON.stringify(e[t]));if("string"===typeof this.props.schema.clone&&"string"===typeof s[this.props.schema.clone]){let t=1,i=s[this.props.schema.clone];const o=i.match(/(\d+)$/);for(o?(i=i.replace(o[0],""),t=parseInt(o[0],10)+1):i+="_";e.find((e=>e[this.props.schema.clone]===i+t.toString()));)t++;s[this.props.schema.clone]="".concat(s[this.props.schema.clone],"_").concat(t)}e.splice(t,0,s),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(e)))))},this.onChangeWrapper=(t,e)=>{this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(((t,e)=>{let s;if(this.typingTimer=null,this.props.schema.encryptedAttributes){const e=JSON.parse(JSON.stringify(t));if(e.forEach((t=>{this.props.schema.encryptedAttributes.forEach((e=>{t[e]&&(t[e]=function(t,e){let s="";for(let i=0;i<e.length;i++)s+=String.fromCharCode(t[i%t.length].charCodeAt(0)^e.charCodeAt(i));return s}(this.secret,t[e]))}))})),this.props.schema.objKeyName){const t=Ce(e,this.props.schema.objKeyName,this.props.schema.objValueName);s=this.onChange(this.props.attr,t)}else s=this.onChange(this.props.attr,e)}else if(this.props.schema.objKeyName){const e=Ce(JSON.parse(JSON.stringify(t)),this.props.schema.objKeyName,this.props.schema.objValueName);s=this.onChange(this.props.attr,e)}else s=this.onChange(this.props.attr,t);s instanceof Promise&&s.catch((t=>console.error("Cannot save: ".concat(t)))),e&&(this.applyFilter(!1,t),this.handleRequestSort(this.state.orderBy,!0))}),300,t,e)},this.onAdd=()=>{var t;const{schema:e}=this.props,s=JSON.parse(JSON.stringify(this.state.value)),i=null===(t=e.items)||void 0===t?void 0:t.reduce(((t,e)=>{let i;return i=e.defaultFunc?this.props.custom?e.defaultFunc?this.executeCustom(e.defaultFunc,this.props.data,this.props.customObj,this.props.oContext.instanceObj,s.length,this.props.data):this.props.schema.default:e.defaultFunc?this.execute(e.defaultFunc,this.props.schema.default,this.props.data,s.length,this.props.data):this.props.schema.default:void 0===e.default?null:e.default,t[e.attr]=i,t}),{});s.push(i),this.setState({value:s},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(s)))))},this.applyFilter=(t,e,s)=>{let i=(e=e||this.state.value).map(((t,e)=>e));Object.keys(this.filterRefs).forEach((s=>{let o=je.getFilterValue(this.filterRefs[s]);!t&&o?(o=o.toLowerCase(),i=i.filter((t=>e[t]&&e[t][s]&&e[t][s].toLowerCase().includes(o)))):this.filterRefs[s].current&&je.setFilterValue(this.filterRefs[s],"")})),i.length===e.length&&(i=null),(null!==i||null!==this.state.visibleValue)&&JSON.stringify(i)!==JSON.stringify(this.state.visibleValue)?this.setState({visibleValue:i},(()=>s&&s())):s&&s()},this.filterRefs={},this.props.schema.items=this.props.schema.items||[],this.props.schema.items.forEach((t=>{t.filter&&(this.filterRefs[t.attr]=(0,o.createRef)())})),this.refDiv=a().createRef()}async componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr)||[];let e;if(e=this.props.schema.objKeyName?function(t,e,s){e=e||"key";const i=[];return Object.keys(t).forEach((o=>{const a={};a[e]=o,s?(a[s]=t[o],i.push(a)):i.push(Object.assign(a,t[o]))})),i}(t,this.props.schema.objKeyName,this.props.schema.objValueName):t,Array.isArray(e)||(e=[]),this.props.schema.encryptedAttributes){const e=await this.props.oContext.socket.getCompactSystemConfig();this.secret=(null===e||void 0===e?void 0:e.native.secret)||this.secret,t.forEach((t=>{this.props.schema.encryptedAttributes.forEach((e=>{t[e]&&(t[e]=function(t,e){let s="";for(let i=0;i<e.length;i++)s+=String.fromCharCode(t[i%t.length].charCodeAt(0)^e.charCodeAt(i));return s}(this.secret,t[e]))}))}))}this.setState({value:e,visibleValue:null,orderBy:"",order:"asc",iteration:0,filterOn:[],width:0},(()=>this.validateUniqueProps()))}componentWillUnmount(){this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),this.resizeTimeout&&(clearTimeout(this.resizeTimeout),this.resizeTimeout=null),super.componentWillUnmount()}itemTable(t,e,s){const{schema:i}=this.props,o=i.items&&i.items.find((e=>e.attr===t));if(!o)return null;const a={items:{[t]:o}};return(0,u.jsx)(Ve,{oContext:this.props.oContext,alive:this.props.alive,arrayIndex:s,changed:this.props.changed,common:this.props.common,custom:!0,data:e,globalData:this.props.data,index:s+this.state.iteration,onChange:(t,e)=>{const i=JSON.parse(JSON.stringify(this.state.value));i[s][t]=e,this.setState({value:i},(()=>{this.validateUniqueProps(),this.onChangeWrapper(i,!0)}))},onError:(t,e)=>this.onError(t,e),originalData:this.props.originalData,schema:a,table:!0,themeName:this.props.themeName})}validateUniqueProps(){if(this.props.schema.uniqueColumns)for(const t of this.props.schema.uniqueColumns){const e=[];this.state.value.find((s=>{const i=s[t];return e.includes(i)?(this.onError(t,"is not unique"),this.setState({errorMessage:d.I18n.t('Non-allowed duplicate entry "%s" in column "%s"',i,t)}),!0):(e.push(i),!1)}))||(this.onError(t,null),this.setState({errorMessage:""}))}}static descendingComparator(t,e,s){return e[s]<t[s]?-1:e[s]>t[s]?1:0}static getComparator(t,e){return"desc"===t?(t,s)=>je.descendingComparator(t,s,e):(t,s)=>-je.descendingComparator(t,s,e)}static getFilterValue(t){var e,s,i;return null===t||void 0===t||null===(e=t.current)||void 0===e||null===(s=e.children[0])||void 0===s||null===(i=s.children[0])||void 0===i?void 0:i.value}static setFilterValue(t,e){return t.current.children[0].children[0].value=e}renderShowHideFilter(t){return t.filter?(0,u.jsx)(p.IconButton,{title:d.I18n.t("ra_Show/hide filter input"),size:"small",onClick:()=>{const e=[...this.state.filterOn],s=this.state.filterOn.indexOf(t.attr);-1===s?e.push(t.attr):e.splice(s,1),this.setState({filterOn:e},(()=>{s&&je.getFilterValue(this.filterRefs[t.attr])&&(je.setFilterValue(this.filterRefs[t.attr],""),this.applyFilter())}))},children:this.state.filterOn.includes(t.attr)?(0,u.jsx)(c.FilterAltOff,{}):(0,u.jsx)(c.FilterAlt,{})}):null}renderImportExportButtons(t){return(0,u.jsxs)(u.Fragment,{children:[!t.noDelete&&t.import?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Import data from %s file","CSV"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.setState({showImportDialog:!0}),children:(0,u.jsx)(c.UploadFile,{})})}):null,t.export?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Export data to %s file","CSV"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onExport(),children:(0,u.jsx)(c.Download,{})})}):null,(0,u.jsx)(p.IconButton,{disabled:!0,size:"small",children:(0,u.jsx)(c.Delete,{})})]})}renderAddButton(t){return(0,u.jsx)(p.Tooltip,{title:t?d.I18n.t("ra_Cannot add items with set filter"):d.I18n.t("ra_Add row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)("span",{children:(0,u.jsx)(p.IconButton,{size:"small",color:"primary",disabled:!!t&&!this.props.schema.allowAddByFilter,onClick:this.onAdd,children:(0,u.jsx)(c.Add,{})})})})}enhancedTableHead(t,e){var s;const{schema:i}=this.props,{order:o,orderBy:a}=this.state;return(0,u.jsx)(p.TableHead,{children:(0,u.jsxs)(p.TableRow,{children:[null===(s=i.items)||void 0===s?void 0:s.map(((t,s)=>this.renderOneFilter({schema:i,style:{width:t.width},showAddButton:!s&&!i.noDelete,headCell:t,order:o,orderBy:a,index:s,doAnyFilterSet:e}))),!i.noDelete&&(0,u.jsx)(p.TableCell,{style:{paddingLeft:20,paddingRight:20,width:t,textAlign:"right"},padding:"checkbox",children:this.renderImportExportButtons(i)})]})})}onExport(){const{schema:t}=this.props,{value:e}=this.state,s=[t.items.map((t=>t.attr)).join(";")];e.forEach((e=>{const i=[];t.items.forEach((t=>{var s;null!==(s=e[t.attr])&&void 0!==s&&s.includes(";")?i.push('"'.concat(e[t.attr],'"')):i.push(void 0===e[t.attr]||null===e[t.attr]?"":e[t.attr])})),s.push(i.join(";"))}));const i=document.createElement("a");i.setAttribute("href","data:text/csv;charset=utf-8,".concat(encodeURIComponent(s.join("\n"))));const o=new Date;i.setAttribute("download","".concat(o.getFullYear(),"_").concat((o.getMonth()+1).toString().padStart(2,"0"),"_").concat(o.getDate().toString().padStart(2,"0"),"_").concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance,"_").concat(this.props.attr,".csv")),i.style.display="none",document.body.appendChild(i),i.click(),document.body.removeChild(i)}onImport(t){const e=t.split("\n").map((t=>t.replace("\r","").trim())),{schema:s}=this.props,i=e.shift().split(";").filter((t=>t&&s.items.find((e=>e.attr===t)))),o=[];var a;(e.forEach((t=>{const e=t.split(";"),s={};for(let o=0;o<e.length;o++){let t=e[o];if(t.startsWith('"')){for(t=t.substring(1);o<e.length&&!t.endsWith('"');)t+=";".concat(e[++o]);t=t.substring(0,t.length-1)}let a=t;if("true"===t)a=!0;else if("false"===t)a=!1;else if(window.isFinite(t)){const e=this.props.schema.items.find((t=>t.attr===i[o]));a=e&&"number"===e.type?parseFloat(t):t}else a=t;s[i[o]]=a}o.push(s)})),o.length)?null!==(a=this.state.value)&&void 0!==a&&a.length?this.setState({showTypeOfImportDialog:o,showImportDialog:!1}):this.setState({value:o,showImportDialog:!1}):window.alert("ra_No data found in file")}isAnyFilterSet(){return!!Object.keys(this.filterRefs).find((t=>je.getFilterValue(this.filterRefs[t])))}onMoveUp(t){const e=JSON.parse(JSON.stringify(this.state.value)),s=e[t];e.splice(t,1),e.splice(t-1,0,s),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(e)))))}onMoveDown(t){const e=JSON.parse(JSON.stringify(this.state.value)),s=e[t];e.splice(t,1),e.splice(t+1,0,s),this.setState({value:e,iteration:this.state.iteration+1e4},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(e)))))}onDrop(t){const e=t[0],s=new FileReader;s.onabort=()=>console.log("file reading was aborted"),s.onerror=()=>console.log("file reading has failed"),s.onload=()=>{if(e.size>ye)return void window.alert(d.I18n.t("ra_File is too big. Max %sk allowed. Try use SVG.",Math.round(1024)));const t=new Uint8Array(s.result).reduce(((t,e)=>t+String.fromCharCode(e)),"");this.onImport(t)},s.readAsArrayBuffer(e)}showTypeOfImportDialog(){return this.state.showTypeOfImportDialog?(0,u.jsxs)(p.Dialog,{open:!0,onClose:()=>this.setState({showTypeOfImportDialog:!1}),maxWidth:"md",children:[(0,u.jsx)(p.DialogTitle,{children:d.I18n.t("ra_Append or replace?")}),(0,u.jsx)(p.DialogContent,{children:d.I18n.t("ra_Append %s entries or replace existing?",this.state.showTypeOfImportDialog.length)}),(0,u.jsxs)(p.DialogActions,{children:[(0,u.jsx)(p.Button,{variant:"contained",color:"primary",autoFocus:!0,onClick:()=>{const t=JSON.parse(JSON.stringify(this.state.value));this.state.showTypeOfImportDialog.forEach((e=>t.push(e))),this.setState({value:t,iteration:this.state.iteration+1e4,showTypeOfImportDialog:!1},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(t)))))},children:d.I18n.t("ra_Append")}),(0,u.jsx)(p.Button,{variant:"contained",color:"secondary",autoFocus:!0,onClick:()=>{const t=this.state.showTypeOfImportDialog;this.setState({value:t,iteration:this.state.iteration+1e4,showTypeOfImportDialog:!1},(()=>this.applyFilter(!1,null,(()=>this.onChangeWrapper(t)))))},children:d.I18n.t("ra_Replace")})]})]}):null}showImportDialog(){return this.state.showImportDialog?(0,u.jsxs)(p.Dialog,{open:!0,onClose:()=>this.setState({showImportDialog:!1}),sx:{"& .MuiDialog-paper":{minHeight:500}},maxWidth:"md",fullWidth:!0,children:[(0,u.jsx)(p.DialogTitle,{children:d.I18n.t("ra_Import from %s","CSV")}),(0,u.jsx)(p.DialogContent,{children:(0,u.jsx)(st(),{multiple:!1,accept:{"text/csv":[".csv"]},maxSize:ye,onDragEnter:()=>this.setState({uploadFile:"dragging"}),onDragLeave:()=>this.setState({uploadFile:!0}),onDrop:(t,e)=>{this.setState({uploadFile:!1}),t.length?this.onDrop(t):window.alert(e&&e[0]&&e[0].errors&&e[0].errors[0]&&e[0].errors[0].message||d.I18n.t("ra_Cannot upload"))},children:t=>{let{getRootProps:e,getInputProps:s}=t;return(0,u.jsxs)("div",(0,i.A)((0,i.A)({style:(0,i.A)((0,i.A)((0,i.A)((0,i.A)({},be.uploadDiv),"dragging"===this.state.uploadFile?be.uploadDivDragging:void 0),be.dropZone),this.state.icon?void 0:be.dropZoneEmpty)},e()),{},{children:[(0,u.jsx)("input",(0,i.A)({},s())),(0,u.jsx)("div",{style:be.uploadCenterDiv,children:(0,u.jsxs)("div",{style:be.uploadCenterTextAndIcon,children:[(0,u.jsx)(c.UploadFile,{style:be.uploadCenterIcon}),(0,u.jsx)("div",{style:be.uploadCenterText,children:"dragging"===this.state.uploadFile?d.I18n.t("ra_Drop file here"):d.I18n.t("ra_Place your files here or click here to open the browse dialog")})]})})]}))}})}),(0,u.jsx)(p.DialogActions,{children:(0,u.jsx)(p.Button,{variant:"contained",onClick:()=>this.setState({showImportDialog:!1}),color:"primary",startIcon:(0,u.jsx)(c.Close,{}),children:d.I18n.t("Cancel")})})]}):null}renderOneFilter(t){return(0,u.jsx)(p.TableCell,{style:t.style,align:"left",sortDirection:t.orderBy===t.headCell.attr&&t.order,children:(0,u.jsxs)("div",{style:(0,i.A)((0,i.A)({},be.flex),t.schema.showFirstAddOnTop?{flexDirection:"column"}:void 0),children:[t.showAddButton?this.renderAddButton(t.doAnyFilterSet):null,t.headCell.sort&&(0,u.jsx)(p.TableSortLabel,{active:!0,style:t.orderBy!==t.headCell.attr?be.silver:void 0,direction:t.orderBy===t.headCell.attr?t.order:"asc",onClick:()=>this.handleRequestSort(t.headCell.attr)}),t.headCell.filter&&this.state.filterOn.includes(t.headCell.attr)?(0,u.jsx)(p.TextField,{variant:"standard",ref:this.filterRefs[t.headCell.attr],onChange:()=>this.applyFilter(),title:d.I18n.t("ra_You can filter entries by entering here some text"),slotProps:{input:{endAdornment:je.getFilterValue(this.filterRefs[t.headCell.attr])&&(0,u.jsx)(p.InputAdornment,{position:"end",children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>{je.setFilterValue(this.filterRefs[t.headCell.attr],""),this.applyFilter()},children:(0,u.jsx)(c.Close,{})})})}},fullWidth:!0,placeholder:this.getText(t.headCell.title)}):(0,u.jsx)("span",{style:be.headerText,children:this.getText(t.headCell.title)}),this.renderShowHideFilter(t.headCell)]})},"".concat(t.headCell.attr,"_").concat(t.index))}enhancedFilterCard(){var t;const{schema:e}=this.props,{order:s,orderBy:i}=this.state;let o;return this.props.schema.compact&&(o={paddingTop:1,paddingBottom:1}),(0,u.jsx)(p.Grid2,{size:{xs:e.xs||12,sm:e.sm||void 0,md:e.md||void 0,lg:e.lg||void 0,xl:e.xl||void 0},children:(0,u.jsx)(p.Card,{children:(0,u.jsx)(p.Paper,{style:be.paper,children:(0,u.jsxs)(p.Accordion,{style:be.paper,children:[(0,u.jsx)(p.AccordionSummary,{expandIcon:(0,u.jsx)(c.ExpandMore,{}),children:(0,u.jsx)(p.Typography,{children:d.I18n.t("ra_Filter and Data Actions")})}),(0,u.jsx)(p.AccordionDetails,{children:(0,u.jsx)(p.Table,{children:(0,u.jsxs)(p.TableBody,{children:[null===(t=e.items)||void 0===t?void 0:t.map(((t,a)=>(0,u.jsx)(p.TableRow,{children:this.renderOneFilter({schema:e,style:o,showAddButton:!1,headCell:t,order:s,orderBy:i,index:a,doAnyFilterSet:!1})},"".concat(t.attr,"_").concat(a)))),(0,u.jsxs)(p.TableRow,{children:[(0,u.jsx)(p.TableCell,{align:"left",style:o,children:(0,u.jsx)("span",{style:be.headerText,children:d.I18n.t("ra_Actions")})}),(0,u.jsx)(p.TableCell,{style:o,children:this.renderImportExportButtons(e)})]})]})})})]})})})})}enhancedBottomCard(){const{schema:t}=this.props;let e;this.props.schema.compact&&(e={paddingTop:1,paddingBottom:1});const s=this.isAnyFilterSet();return(0,u.jsx)(p.Grid2,{size:{xs:t.xs||12,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},children:(0,u.jsx)(p.Card,{children:(0,u.jsx)(p.Paper,{style:be.paper,children:(0,u.jsx)(p.Table,{children:(0,u.jsx)(p.TableBody,{children:(0,u.jsx)(p.TableRow,{children:(0,u.jsx)(p.TableCell,{colSpan:t.items.length+1,style:e,children:this.renderAddButton(s)})})})})})})})}renderCards(){const{schema:t}=this.props;let e,{visibleValue:s}=this.state;this.props.schema.compact&&(e={paddingTop:1,paddingBottom:1}),s=s||this.state.value.map(((t,e)=>e));const i=this.isAnyFilterSet();return(0,u.jsxs)(p.Grid2,{container:!0,children:[this.showImportDialog(),this.showTypeOfImportDialog(),this.enhancedFilterCard(),s.map(((o,a)=>{var n;return(0,u.jsx)(p.Grid2,{size:{xs:t.xs||12,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},children:(0,u.jsx)(p.Card,{children:(0,u.jsx)(p.Paper,{style:be.paper,children:(0,u.jsx)(p.Table,{children:(0,u.jsxs)(p.TableBody,{children:[null===(n=t.items)||void 0===n?void 0:n.map((t=>(0,u.jsxs)(p.TableRow,{children:[(0,u.jsx)(p.TableCell,{align:"left",style:e,children:(0,u.jsx)("span",{style:be.headerText,children:this.getText(t.title)})}),(0,u.jsx)(p.TableCell,{align:"left",style:e,children:this.itemTable(t.attr,this.state.value[o],o)})]},"".concat(t.attr,"_").concat(o)))),(0,u.jsxs)(p.TableRow,{children:[(0,u.jsx)(p.TableCell,{align:"left",style:e,children:(0,u.jsx)("span",{style:be.headerText,children:this.getText("Actions")})}),(0,u.jsxs)(p.TableCell,{align:"left",style:e,children:[i||this.state.orderBy?null:(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move up"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)("span",{children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveUp(o),disabled:0===a,children:(0,u.jsx)(c.ArrowUpward,{})})})}),i||this.state.orderBy?null:(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move down"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)("span",{children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveDown(o),disabled:a===s.length-1,children:(0,u.jsx)(c.ArrowDownward,{})})})}),(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Delete current row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onDelete(o),children:(0,u.jsx)(c.Delete,{})})}),this.props.schema.clone?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Clone current row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onClone(o),children:(0,u.jsx)(c.ContentCopy,{})})}):null]})]})]})})})})},"".concat(o,"_").concat(a))})),this.enhancedBottomCard()]})}renderTable(){const{schema:t}=this.props;let{visibleValue:e}=this.state;e=e||this.state.value.map(((t,e)=>e));const s=this.isAnyFilterSet();let o;return this.props.schema.compact&&(o={paddingTop:1,paddingBottom:1}),(0,u.jsxs)(p.Paper,{style:be.paper,children:[this.showImportDialog(),this.showTypeOfImportDialog(),t.label?(0,u.jsx)("div",{style:be.label,children:(0,u.jsx)(p.Toolbar,{variant:"dense",style:be.rootTool,children:(0,u.jsx)(p.Typography,{style:be.title,variant:"h6",id:"tableTitle",component:"div",children:this.getText(t.label)})})}):null,(0,u.jsxs)(p.TableContainer,{children:[(0,u.jsxs)(p.Table,{style:be.table,size:"small",children:[this.enhancedTableHead(s||this.state.orderBy?64:120,s),(0,u.jsxs)(p.TableBody,{children:[e.map(((a,n)=>{var r;return(0,u.jsxs)(p.TableRow,{hover:!0,children:[null===(r=t.items)||void 0===r?void 0:r.map((t=>(0,u.jsx)(p.TableCell,{align:"left",style:o,children:this.itemTable(t.attr,this.state.value[a],a)},"".concat(t.attr,"_").concat(a)))),!t.noDelete&&(0,u.jsxs)(p.TableCell,{align:"left",style:(0,i.A)((0,i.A)({},o),be.buttonCell),children:[s||this.state.orderBy?null:n?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move up"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveUp(a),children:(0,u.jsx)(c.ArrowUpward,{})})}):(0,u.jsx)("div",{style:be.buttonEmpty}),s||this.state.orderBy?null:n<e.length-1?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Move down"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.onMoveDown(a),children:(0,u.jsx)(c.ArrowDownward,{})})}):(0,u.jsx)("div",{style:be.buttonEmpty}),(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Delete current row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onDelete(a),children:(0,u.jsx)(c.Delete,{})})}),this.props.schema.clone?(0,u.jsx)(p.Tooltip,{title:d.I18n.t("ra_Clone current row"),slotProps:{popper:{sx:be.tooltip}},children:(0,u.jsx)(p.IconButton,{size:"small",onClick:this.onClone(a),children:(0,u.jsx)(c.ContentCopy,{})})}):null]})]},"".concat(a,"_").concat(n))})),!t.noDelete&&e.length>=(t.showSecondAddAt||5)?(0,u.jsx)(p.TableRow,{children:(0,u.jsx)(p.TableCell,{colSpan:t.items.length+1,style:(0,i.A)({},o),children:this.renderAddButton(s)})}):null]})]}),!e.length&&this.state.value.length?(0,u.jsx)("div",{style:be.filteredOut,children:(0,u.jsxs)(p.Typography,{style:be.title,variant:"h6",id:"tableTitle",component:"div",children:[d.I18n.t("ra_All items are filtered out"),(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>this.applyFilter(!0),children:(0,u.jsx)(c.Close,{})})]})}):null]}),t.help?(0,u.jsx)(p.FormHelperText,{style:{paddingLeft:16},children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null,this.state.errorMessage?(0,u.jsxs)("div",{style:{display:"flex",padding:"5px"},children:[(0,u.jsx)(c.Warning,{color:"error"}),(0,u.jsx)("span",{style:{color:"red",alignSelf:"center"},children:this.state.errorMessage})]}):null]})}componentDidUpdate(){var t;null!==(t=this.refDiv.current)&&void 0!==t&&t.clientWidth&&this.refDiv.current.clientWidth!==this.state.width&&(this.resizeTimeout&&clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout((()=>{var t;this.resizeTimeout=null,this.setState({width:null===(t=this.refDiv.current)||void 0===t?void 0:t.clientWidth})}),50))}getCurrentBreakpoint(){return this.state.width?this.state.width<600?"xs":this.state.width<900?"sm":this.state.width<1200?"md":this.state.width<1536?"lg":"xl":"md"}renderItem(){const{schema:t}=this.props;if(!this.state.value||!Array.isArray(this.state.value))return null;const e=this.getCurrentBreakpoint();let s;return s=e&&(t.useCardFor||["xs"]).includes(e)?this.renderCards():this.renderTable(),(0,u.jsx)("div",{ref:this.refDiv,style:{width:"100%"},children:s})}}const we=je,Te={indeterminate:{opacity:.5},label:{width:"100%",fontSize:14,marginBottom:2},helper:{width:"100%",fontSize:12},error:{width:"100%",fontSize:12,color:"#FF0000"}};const Ie=class extends x{constructor(){super(...arguments),this.updateTimeout=null}componentDidMount(){super.componentDidMount();let t=x.getValue(this.props.data,this.props.attr);if(Array.isArray(t)&&this.props.oContext.multiEdit)return t=x.DIFFERENT_VALUE,void this.setState({value:t,oldValue:t,jsonError:!1});this.setState({value:t,oldValue:t,jsonError:this.validateJson(t)})}validateJson(t){let e=!1;if(this.props.schema.validateJson&&(t||!this.props.schema.allowEmpty))try{JSON.parse(t)}catch(s){console.log("Error in JSON",s),e=!0}return e}static getDerivedStateFromProps(t,e){if(t.oContext.multiEdit&&e.value===x.DIFFERENT_VALUE)return{value:x.DIFFERENT_VALUE};let s=x.getValue(t.data,t.attr);return null!==s&&void 0!==s&&(s=s.toString()),null===s||void 0===s||s!==e.value&&s!==e.oldValue?{value:s}:null}renderItem(t,e){const s=Array.isArray(this.state.value)||this.state.value===x.DIFFERENT_VALUE;if(this.props.schema.time){let s="";return"number"===typeof this.state.value?s=this.state.value&&this.state.value<9466596e5?new Date(1e3*this.state.value).toLocaleString():new Date(this.state.value).toLocaleString():"string"===typeof this.state.value&&(s=new Date(this.state.value).toLocaleString()),(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:s,error:!!t||!!this.state.jsonError,disabled:!!e,slotProps:{htmlInput:{readOnly:!0}},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}if(null!==this.state.oldValue&&void 0!==this.state.oldValue?(this.updateTimeout&&clearTimeout(this.updateTimeout),this.updateTimeout=setTimeout((()=>{this.updateTimeout=null,this.setState({oldValue:null})}),30)):this.updateTimeout&&(clearTimeout(this.updateTimeout),this.updateTimeout=null),s){const s=x.getValue(this.props.data,this.props.attr),o=(null===s||void 0===s?void 0:s.filter((t=>t||0===t)).map((t=>({label:t.toString()||"",value:t}))))||[];return o.unshift({label:d.I18n.t(x.DIFFERENT_LABEL),value:x.DIFFERENT_VALUE}),(0,u.jsx)(p.Autocomplete,{style:Te.indeterminate,fullWidth:!0,value:o[0],onChange:(t,e)=>{const s=e?e.value:"",i=this.onChange(this.props.attr,s,(()=>{this.setState({value:s,oldValue:s,jsonError:this.validateJson(e)})}));i instanceof Promise&&i.catch((t=>console.error("Cannot set value: ".concat(t))))},options:o,getOptionLabel:t=>t.label,renderInput:s=>(0,u.jsx)(p.TextField,(0,i.A)((0,i.A)({variant:"standard"},s),{},{error:!!t,placeholder:this.getText(this.props.schema.placeholder),slotProps:{htmlInput:(0,i.A)((0,i.A)({},s.inputProps),{},{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:this.props.schema.readOnly||!1})},label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),disabled:!!e}))})}let o,a;if((this.props.schema.readOnly||e)&&this.props.schema.copyToClipboard?(this.props.schema.minRows>1&&(a={position:"absolute",right:3,top:20,zIndex:1e3}),o=(0,u.jsx)(p.IconButton,{style:a,size:"small",onClick:()=>{d.Utils.copyToClipboard(this.state.value),window.alert(d.I18n.t("ra_Copied"))},children:(0,u.jsx)(d.IconCopy,{})})):this.props.schema.readOnly||e||!this.state.value||this.props.schema.noClearButton||(this.props.schema.minRows>1&&(a={position:"absolute",right:3,top:20,zIndex:1e3}),o=(0,u.jsx)(p.IconButton,{style:a,size:"small",onClick:()=>this.setState({value:"",oldValue:this.state.value},(()=>this.onChange(this.props.attr,""))),children:(0,u.jsx)(c.Close,{})}),this.props.schema.minRows<=1&&(o=(0,u.jsx)(p.InputAdornment,{position:"end",children:o}))),this.props.schema.minRows>1){const s=this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation);return(0,u.jsxs)("div",{style:{width:"100%",position:"relative"},children:[this.props.schema.label?(0,u.jsx)("div",{style:Te.label,children:this.getText(this.props.schema.label)}):null,(0,u.jsx)(p.TextareaAutosize,{style:{width:"100%",resize:"vertical",backgroundColor:"dark"===this.props.oContext.themeType?"#363636":"#cccccc",color:"dark"===this.props.oContext.themeType?"#fff":"#111"},minRows:this.props.schema.minRows,maxRows:this.props.schema.maxRows,value:null===this.state.value||void 0===this.state.value?"":this.state.value,disabled:!!e,readOnly:this.props.schema.readOnly||!1,onChange:t=>{const e=t.target.value;this.setState({value:e,oldValue:this.state.value,jsonError:this.validateJson(e)},(()=>this.onChange(this.props.attr,e||"")))},placeholder:this.getText(this.props.schema.placeholder)}),s||t||this.state.jsonError?(0,u.jsx)("div",{style:t?Te.error:Te.helper,children:t||(this.state.jsonError?d.I18n.t("ra_Invalid JSON"):s)}):null]})}return(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,value:null===this.state.value||void 0===this.state.value?"":this.state.value,error:!!t||!!this.state.jsonError,disabled:!!e,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0,readOnly:this.props.schema.readOnly||!1},input:{endAdornment:o}},onChange:t=>{const e=t.target.value;this.setState({value:e,oldValue:this.state.value,jsonError:this.validateJson(e)},(()=>this.onChange(this.props.attr,e)))},placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.state.jsonError?d.I18n.t("ra_Invalid JSON"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},Se={width:"100%"};const De=class extends x{constructor(){super(...arguments),this.initialized=!1,this.localContext=void 0}askInstance(){if(this.props.alive){let e=this.props.schema.data;if(void 0===e&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,null,!0);try{e=JSON.parse(s)}catch(t){console.error("Cannot parse json data: ".concat(s))}}void 0===e&&(e=null),this.props.oContext.socket.sendTo("".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance),this.props.schema.command||"send",e).then((t=>{if("object"===typeof t){const e=t;this.setState({text:e.text||"",style:e.style,icon:e.icon,iconStyle:e.iconStyle})}else"string"===typeof t&&this.setState({text:t||""})})).catch((t=>console.error("Cannot send command: ".concat(t))))}}getLocalContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=x.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(){if(this.props.alive){const t=this.getLocalContext();t===this.localContext&&this.initialized||(this.localContext=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}if(void 0===this.state.text)return null;let t=null;return this.state.icon&&(t=ae(this.state.icon,(0,i.A)({marginRight:this.state.text?8:void 0},this.state.iconStyle||void 0)),t||(t=(0,u.jsx)(d.Icon,{src:this.state.icon,style:(0,i.A)({marginRight:this.state.text?8:void 0},this.state.iconStyle||void 0)}))),"text"===this.props.schema.container?(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,slotProps:{input:{endAdornment:this.props.schema.copyToClipboard?(0,u.jsx)(p.IconButton,{size:"small",onClick:()=>{d.Utils.copyToClipboard(this.state.text),window.alert(d.I18n.t("ra_Copied"))},children:(0,u.jsx)(d.IconCopy,{})}):void 0}},value:this.state.text,label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):(0,u.jsxs)("div",{style:(0,i.A)((0,i.A)({},Se),this.state.style||void 0),children:[t,"html"===this.props.schema.container?(0,u.jsx)("span",{dangerouslySetInnerHTML:{__html:this.state.text||""}}):this.state.text]})}};const ke=class extends x{componentDidMount(){var t;super.componentDidMount();const e=x.getValue(this.props.data,this.props.attr);if(!e&&null!==(t=this.props.customObj)&&void 0!==t&&t._id){const t=function(t,e){let s;return s=e&&t.substring(0,e.length)===e?t.substring(e.length+1):t,s=s.replace(/\./g,"/").replace(/_/g," "),s}(this.props.customObj._id,"".concat(this.props.oContext.adapterName,".").concat(this.props.oContext.instance));this.setState({value:t})}else this.setState({value:e||""})}renderItem(t,e){return(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,slotProps:{htmlInput:{maxLength:this.props.schema.maxLength||this.props.schema.max||void 0}},value:this.state.value,error:!!t,disabled:e,placeholder:this.getText(this.props.schema.placeholder),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation),onChange:t=>{const e=t.target.value;this.setState({value:e},(()=>this.onChange(this.props.attr,e)))}})}};const Oe=class extends x{async componentDidMount(){var t;super.componentDidMount();const e=await this.props.oContext.socket.getObject("system.meta.uuid");this.setState({uuid:(null===e||void 0===e||null===(t=e.native)||void 0===t?void 0:t.uuid)||"unknown"})}renderItem(t,e){return(0,u.jsx)(p.TextField,{variant:"standard",fullWidth:!0,error:!!t,disabled:!!e,slotProps:{htmlInput:{readOnly:!0},input:{endAdornment:(0,u.jsx)(p.IconButton,{onClick:()=>{d.Utils.copyToClipboard(this.state.uuid),window.alert(d.I18n.t("ra_Copied %s",this.state.uuid))},children:(0,u.jsx)(c.ContentCopy,{})})}},value:this.state.uuid||"",label:this.getText(this.props.schema.label)||d.I18n.t("ra_Serial number (UUID)"),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},Ae={icon:{width:16,height:16,marginRight:8}};const _e=class extends x{componentDidMount(){super.componentDidMount(),this.props.oContext.socket.getUsers().then((t=>{const e={},s=d.I18n.getLanguage();this.props.schema.short?t.forEach((t=>{var i,o;return e[t._id]={color:null===(i=t.common)||void 0===i?void 0:i.color,icon:null===(o=t.common)||void 0===o?void 0:o.icon,name:d.Utils.getObjectNameFromObj(t,s)}})):t.forEach((t=>{var i,o;return e[t._id.replace(/^system\.user\./,"")]={color:null===(i=t.common)||void 0===i?void 0:i.color,icon:null===(o=t.common)||void 0===o?void 0:o.icon,name:d.Utils.getObjectNameFromObj(t,s)}})),this.setState({users:e})})).catch((t=>console.error("Cannot get users: ".concat(t))))}renderItem(t,e){var s,i;const o=x.getValue(this.props.data,this.props.attr);return(0,u.jsxs)(p.FormControl,{variant:"standard",fullWidth:!0,children:[this.state.users&&this.props.schema.label?(0,u.jsx)(p.InputLabel,{children:this.getText(this.props.schema.label)}):null,this.state.users?(0,u.jsx)(p.Select,{variant:"standard",error:!!t,disabled:!!e,value:o,renderValue:t=>{var e,s,i;return(0,u.jsxs)("span",{children:[this.state.users&&null!==(e=this.state.users[t])&&void 0!==e&&e.icon?(0,u.jsx)(d.Icon,{src:this.state.users&&(null===(s=this.state.users[t])||void 0===s?void 0:s.icon),style:Ae.icon}):null,this.state.users&&(null===(i=this.state.users[t])||void 0===i?void 0:i.name)||t||""]})},style:{color:this.state.users&&(null===(s=this.state.users[o])||void 0===s?void 0:s.color)||void 0,backgroundColor:d.Utils.getInvertedColor(this.state.users&&(null===(i=this.state.users[o])||void 0===i?void 0:i.color),this.props.oContext.themeType)},onChange:t=>this.onChange(this.props.attr,t.target.value),children:this.state.users&&Object.keys(this.state.users).map((t=>(0,u.jsxs)(p.MenuItem,{style:{color:this.state.users[t].color||void 0,backgroundColor:d.Utils.getInvertedColor(this.state.users[t].color,this.props.oContext.themeType)},value:t,children:[this.state.users[t].icon?(0,u.jsx)(d.Icon,{src:this.state.users[t].icon,style:Ae.icon}):null,this.state.users[t].name]},t)))}):(0,u.jsx)(p.TextField,{variant:"standard",error:!!t,disabled:!!e,value:o,onChange:t=>this.onChange(this.props.attr,t.target.value),label:this.getText(this.props.schema.label)}),this.props.schema.help?(0,u.jsx)(p.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const Fe=class extends x{async componentDidMount(){super.componentDidMount();const t=await s.e(7249).then(s.bind(s,47249));this.setState({QRCode:t.default})}renderItem(){const t=this.state.QRCode;return t?(0,u.jsx)(t,{value:this.props.schema.data,size:this.props.schema.size,fgColor:this.props.schema.fgColor,bgColor:this.props.schema.bgColor,level:this.props.schema.level}):null}},Ne={accordion:f,alive:b,autocomplete:C,autocompleteSendTo:j,certCollection:k,certificate:I,certificates:D,checkbox:F,checkLicense:_,chip:q,chips:q,color:$,coordinates:Y,cron:T,custom:Q,datePicker:class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t})}renderItem(t,e){return(0,u.jsx)(X.DatePicker,{sx:t=>({width:"100%",borderBottom:"1px solid ".concat(t.palette.text.primary),"& fieldset":{display:"none"},"& input":{padding:"".concat(t.spacing(1.5)," 0 4px 0")},"& .MuiInputAdornment-root":{marginLeft:0,marginTop:1},"& label":{transform:"translate(0px, -9px) scale(0.75)"}}),format:this.props.oContext.systemConfig.dateFormat.toLowerCase().replace("mm","MM"),disabled:!!e,value:this.state.value,onChange:t=>{this.setState({value:t},(()=>this.onChange(this.props.attr,this.state.value)))},label:this.getText(this.props.schema.label)})}},deviceManager:tt,divider:le,file:vt,fileSelector:pt,func:ft,header:pe,image:Ct,imageSendTo:bt,instance:wt,interface:It,ip:yt,jsonEditor:Nt,language:Lt,license:Vt,number:Bt,objectId:Ut,password:Jt,pattern:zt,port:qt,qrCode:Fe,room:Kt,select:Gt,selectSendTo:Zt,sendto:te,sendTo:te,setState:se,slider:oe,state:ne,staticImage:ce,staticInfo:ge,staticLink:fe,staticText:fe,table:we,text:Ie,textSendTo:De,timePicker:class extends x{componentDidMount(){super.componentDidMount();const t=x.getValue(this.props.data,this.props.attr);this.setState({value:t})}renderItem(t,e){const s="HH:mm:ss"!==this.props.schema.returnFormat,i=new Date(Date.parse("Thu, 01 Jan 1970 ".concat(this.state.value||"00:00:00")));return(0,u.jsx)(X.TimePicker,{sx:t=>({width:"100%",borderBottom:"1px solid ".concat(t.palette.text.primary),"& fieldset":{display:"none"},"& input":{padding:"".concat(t.spacing(1.5)," 0 4px 0")},"& .MuiInputAdornment-root":{marginLeft:0,marginTop:1},"& label":{transform:"translate(0px, -9px) scale(0.75)"}}),ampm:this.props.oContext.systemConfig.dateFormat.includes("/"),timeSteps:this.props.schema.timeSteps||this.props.schema.timesteps||{hours:1,minutes:5,seconds:5},format:this.props.schema.format||"HH:mm:ss",disabled:!!e,value:i,onChange:t=>{let e;e=t instanceof Date?t.toTimeString().split(" ")[0]:t.toTimeString(),s&&(e=e.split(":").slice(0,2).join(":")),this.setState({value:e},(()=>this.onChange(this.props.attr,this.state.value)))},views:this.props.schema.views||["hours","minutes","seconds"],label:this.getText(this.props.schema.label)})}},topic:ke,uuid:Oe,user:_e},Ee={fullWidth:{width:"100%"},paper:{margin:1,width:"auto !important",overflowY:"auto",paddingBottom:1},paperWithIcons:{height:"calc(100vh - 259px) !important"},paperWithoutIcons:{height:"calc(100vh - 235px) !important"},padding:{padding:"10px"},heading:{},primary:t=>({backgroundColor:t.palette.primary.main,color:"dark"===t.palette.mode?"inherit":"#FFF"}),secondary:t=>({backgroundColor:t.palette.secondary.main})};class Le extends x{componentDidMount(){super.componentDidMount(),this.props.schema&&this.props.schema.collapsable&&this.setState({expanded:"true"===(window._localStorage||window.localStorage).getItem("".concat(this.props.oContext.adapterName,".").concat(this.props.attr))})}renderItems(t,e){return t?Object.keys(t).map((s=>{if(this.props.oContext.multiEdit&&t[s].noMultiEdit)return null;const i=t[s].type||"panel";let o,a="Use this.props.oContext.socket!";return"custom"===i?(t[s].url?o=Q:this.props.oContext.customs&&this.props.oContext.customs[t[s].component]?o=this.props.oContext.customs[t[s].component]:(console.error("Cannot find custom component: ".concat(t[s].component)),o=x),a=this.props.oContext.socket):o="panel"===i?Le:Ne[i]||x,(0,u.jsx)(o,{socket:a,globalData:this.props.globalData,oContext:this.props.oContext,index:this.props.index,changed:this.props.changed,arrayIndex:this.props.arrayIndex,commandRunning:this.props.commandRunning,style:Ee.panel,common:this.props.common,alive:this.props.alive,themeName:this.props.themeName,data:this.props.data,originalData:this.props.originalData,onError:this.props.onError,onChange:this.props.onChange,disabled:e,customObj:this.props.customObj,custom:this.props.custom,schema:t[s],attr:s,table:this.props.table},"".concat(s,"_").concat(void 0===this.props.index?"":this.props.index))})):null}render(){const t=this.props.schema;if(!t)return null;const{disabled:e,hidden:s}=this.calculate(t),o=this.props.schema.items,a=this.props.schema.style||{};if(s){if(t.hideOnlyControl){const e=(0,u.jsx)(p.Grid2,{size:{xs:t.xs||void 0,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},sx:d.Utils.getStyle(this.props.oContext.theme,{marginBottom:0,textAlign:"left"},a,"dark"===this.props.oContext.themeType&&t.darkStyle)});return t.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return null}if(this.props.table)return this.renderItems(o,e);if(this.props.custom)return(0,u.jsx)(p.Grid2,{container:!0,style:Ee.fullWidth,columnSpacing:2,rowSpacing:1,sx:a,children:this.renderItems(o,e)},"".concat(this.props.attr,"_").concat(this.props.index));let n;if(n=t.collapsable?(0,u.jsxs)(p.Accordion,{style:Ee.fullWidth,expanded:!!this.state.expanded,onChange:()=>{(window._localStorage||window.localStorage).setItem("".concat(this.props.oContext.adapterName,".").concat(this.props.attr),this.state.expanded?"false":"true"),this.setState({expanded:!this.state.expanded})},children:[(0,u.jsx)(p.AccordionSummary,{expandIcon:(0,u.jsx)(c.ExpandMore,{}),sx:d.Utils.getStyle(this.props.oContext.theme,a,this.props.oContext.themeType&&t.darkStyle,"primary"===t.color?Ee.primary:"secondary"===t.color&&Ee.secondary,{width:"100%"}),children:(0,u.jsx)(p.Typography,{style:Ee.heading,children:this.getText(t.label)})}),(0,u.jsx)(p.AccordionDetails,{children:(0,u.jsx)(p.Grid2,{container:!0,columnSpacing:2,rowSpacing:1,sx:(0,i.A)((0,i.A)({},a),{},{width:"100%",padding:"10px"}),children:this.renderItems(o,e)})})]},"".concat(this.props.attr,"_").concat(this.props.index)):(0,u.jsx)(p.Box,{component:"div",className:this.props.className,sx:d.Utils.getStyle(this.props.oContext.theme,this.props.style,a,{width:"100%"},this.props.isParentTab&&Ee.paper,this.props.isParentTab&&(this.props.withIcons?Ee.paperWithIcons:Ee.paperWithoutIcons)),children:(0,u.jsx)(p.Grid2,{container:!0,columnSpacing:2,rowSpacing:1,sx:d.Utils.getStyle(this.props.oContext.theme,{width:"100%"},this.props.isParentTab&&Ee.padding,this.props.schema.innerStyle),children:this.renderItems(o,e)})},"".concat(this.props.attr,"_").concat(this.props.index)),!this.props.isParentTab){const e=(0,u.jsx)(p.Grid2,{title:this.getText(t.tooltip),size:{xs:t.xs||void 0,sm:t.sm||void 0,md:t.md||void 0,lg:t.lg||void 0,xl:t.xl||void 0},sx:(0,i.A)({marginBottom:0,textAlign:"left"},a),children:n});return t.newLine?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return n}}const Ve=Le,Pe={tabs:{height:"100%",width:"100%"},panel:{width:"100%",display:"block"},panelWithIcons:{height:"calc(100% - 72px)"},panelWithoutIcons:{height:"calc(100% - 48px)"}};const Be=class extends x{constructor(t){let e;if(super(t),this.resizeTimeout=null,this.refDiv=void 0,this.onHashTabsChanged=()=>{const t=(window.location.hash||"").replace(/^#/,"").split("/");if(t.length>3&&"config"===t[1]){const e=t[3],s=parseInt(e,10);let i;s.toString()===e?s>=0&&s<Object.keys(this.props.schema.items).length&&(i=Object.keys(this.props.schema.items)[s]):Object.keys(this.props.schema.items).includes(e)&&(i=e),void 0!==i&&i!==this.state.tab&&((window._localStorage||window.localStorage).setItem("".concat(this.props.dialogName||"App",".").concat(this.props.oContext.adapterName),i),this.setState({tab:i}))}},this.props.root){const t=(window.location.hash||"").replace(/^#/,"").split("/");if(t.length>=3&&"config"===t[1]){const s=t[3],i=parseInt(s,10);s&&i.toString()===s?i>=0&&i<Object.keys(this.props.schema.items).length&&(e=Object.keys(this.props.schema.items)[i]):s&&Object.keys(this.props.schema.items).includes(s)&&(e=s),window.addEventListener("hashchange",this.onHashTabsChanged,!1)}}void 0===e&&(e=(window._localStorage||window.localStorage).getItem("".concat(this.props.dialogName||"App",".").concat(this.props.oContext.adapterName))||Object.keys(this.props.schema.items)[0],Object.keys(this.props.schema.items).includes(e)||(e=Object.keys(this.props.schema.items)[0])),this.refDiv=a().createRef(),Object.assign(this.state,{tab:e,width:0,openMenu:null})}componentWillUnmount(){this.resizeTimeout&&(clearTimeout(this.resizeTimeout),this.resizeTimeout=null),window.removeEventListener("hashchange",this.onHashTabsChanged,!1),super.componentWillUnmount()}getCurrentBreakpoint(){return this.state.width?this.state.width<600?"xs":this.state.width<900?"sm":this.state.width<1200?"md":this.state.width<1536?"lg":"xl":"md"}componentDidUpdate(){var t;null!==(t=this.refDiv.current)&&void 0!==t&&t.clientWidth&&this.refDiv.current.clientWidth!==this.state.width&&(this.resizeTimeout&&clearTimeout(this.resizeTimeout),this.resizeTimeout=setTimeout((()=>{var t;this.resizeTimeout=null,this.setState({width:null===(t=this.refDiv.current)||void 0===t?void 0:t.clientWidth})}),50))}onMenuChange(t){(window._localStorage||window.localStorage).setItem("".concat(this.props.dialogName||"App",".").concat(this.props.oContext.adapterName),t),this.setState({tab:t},(()=>{if(this.props.root){const t=(window.location.hash||"").split("/");t.length>=3&&"config"===t[1]&&(t[3]=this.state.tab,window.location.hash=t.join("/"))}}))}render(){const t=this.props.schema.items;let e=!1;const s=[];Object.keys(t).map((i=>{let o;if(this.props.custom){if(this.executeCustom(t[i].hidden,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.index,this.props.globalData))return;o=this.executeCustom(t[i].disabled,this.props.data,this.props.customObj,this.props.oContext.instanceObj,this.props.index,this.props.globalData)}else{if(this.execute(t[i].hidden,!1,this.props.data,this.props.index,this.props.globalData))return;o=this.execute(t[i].disabled,!1,this.props.data,this.props.index,this.props.globalData)}const a=this.getIcon(t[i].icon);e=e||!!a,s.push({icon:a,disabled:o,label:this.getText(t[i].label),name:i})}));const o=this.getCurrentBreakpoint();let a;return a="xs"===o||"sm"===o?(0,u.jsxs)(p.Toolbar,{style:{width:"100%",backgroundColor:"dark"===this.props.oContext.themeType?"#222":"#DDD"},variant:"dense",children:[(0,u.jsx)(p.IconButton,{onClick:t=>this.setState({openMenu:t.currentTarget}),children:(0,u.jsx)(c.Menu,{})}),this.state.openMenu?(0,u.jsx)(p.Menu,{open:!0,anchorEl:this.state.openMenu,onClose:()=>this.setState({openMenu:null}),children:s.map((t=>(0,u.jsxs)(p.MenuItem,{disabled:t.disabled,onClick:()=>{this.setState({openMenu:null},(()=>this.onMenuChange(t.name)))},selected:t.name===this.state.tab,children:[e?(0,u.jsx)(p.ListItemIcon,{children:t.icon}):null,t.label]},t.name)))}):null]}):(0,u.jsx)(p.Tabs,{variant:"scrollable",scrollButtons:"auto",style:this.props.schema.tabsStyle,value:this.state.tab,onChange:(t,e)=>this.onMenuChange(e),children:s.map((t=>(0,u.jsx)(p.Tab,{id:t.name,wrapped:!0,disabled:t.disabled,value:t.name,iconPosition:this.props.schema.iconPosition||"start",icon:t.icon,label:t.label},t.name)))}),(0,u.jsxs)("div",{style:Pe.tabs,ref:this.refDiv,children:[a,(0,u.jsx)(Ve,{oContext:this.props.oContext,isParentTab:!0,changed:this.props.changed,index:1001,arrayIndex:this.props.arrayIndex,globalData:this.props.globalData,commandRunning:this.props.commandRunning,style:(0,i.A)((0,i.A)({},Pe.panel),e?Pe.panelWithIcons:Pe.panelWithoutIcons),common:this.props.common,alive:this.props.alive,themeName:this.props.themeName,data:this.props.data,originalData:this.props.originalData,onChange:this.props.onChange,onError:this.props.onError,customObj:this.props.customObj,custom:this.props.custom,schema:t[this.state.tab],table:this.props.table,withIcons:e},this.state.tab)]})}},We={root:{width:"100%",height:"100%"}};class Ue extends o.Component{constructor(t){super(t),this.forceUpdateHandlers=void 0,this.errorTimeout=null,this.errorCached=null,this.oContext=void 0,this.onCommandRunning=t=>this.setState({commandRunning:t}),this.onAlive=(t,e)=>{!(null===e||void 0===e||!e.val)!==this.state.alive&&this.setState({alive:!(null===e||void 0===e||!e.val)})},this.onChange=(t,e,s,i)=>{if(this.props.onValueChange)this.props.onValueChange(t,e,i),s&&s();else if(t&&this.props.onChange){const e={changed:JSON.stringify(t)!==this.state.originalData};this.setState(e,(()=>{this.props.onChange(t,e.changed,i),s&&s()}))}else i&&this.props.onChange(null,null,i)},this.onError=(t,e)=>{this.errorCached=this.errorCached||JSON.parse(JSON.stringify(this.state.errors));const s=this.errorCached;e?s[t]=e:delete s[t],this.errorTimeout&&clearTimeout(this.errorTimeout),JSON.stringify(s)!==JSON.stringify(this.state.errors)?this.errorTimeout=setTimeout((()=>this.setState({errors:this.errorCached},(()=>{this.errorTimeout=null,this.errorCached=null,this.props.onError(!!Object.keys(this.state.errors).length)}))),50):this.errorCached=null},this.changeLanguage=()=>{this.forceUpdate()},this.forceAttrUpdate=(t,e)=>{Array.isArray(t)?t.forEach((t=>this.forceUpdateHandlers[t]&&this.forceUpdateHandlers[t](e))):this.forceUpdateHandlers[t]&&this.forceUpdateHandlers[t](e)},this.registerOnForceUpdate=(t,e)=>{e?this.forceUpdateHandlers[t]=e:this.forceUpdateHandlers[t]&&delete this.forceUpdateHandlers[t]},this.state={originalData:JSON.stringify(this.props.data),changed:!1,errors:{},updateData:this.props.updateData||0,systemConfig:null,alive:!1,commandRunning:!1,schema:JSON.parse(JSON.stringify(this.props.schema))},this.forceUpdateHandlers={},this.buildDependencies(this.state.schema),this.readData()}static getDerivedStateFromProps(t,e){return t.updateData!==e.updateData?{updateData:t.updateData,originalData:JSON.stringify(t.data),schema:JSON.parse(JSON.stringify(t.schema))}:null}static async loadI18n(t,e,s){if(!0===e||e&&"string"===typeof e){const o=d.I18n.getLanguage(),a="string"===typeof e?e:"i18n";let n,r=await t.fileExists("".concat(s,".admin"),"".concat(a,"/").concat(o,".json"));if(r?n="".concat(a,"/").concat(o,".json"):(r=await t.fileExists("".concat(s,".admin"),"".concat(a,"/").concat(o,"/translations.json")),r?n="".concat(a,"/").concat(o,"/translations.json"):"en"!==o&&(r=await t.fileExists("".concat(s,".admin"),"".concat(a,"/en.json")),r?n="".concat(a,"/en.json"):(r=await t.fileExists("".concat(s,".admin"),"".concat(a,"/en/translations.json")),r&&(n="".concat(a,"/en/translations.json"))))),n){const e=await t.readFile("".concat(s,".admin"),n);let a;a=void 0!==e.file?e.file:e;try{const t=JSON.parse(a);d.I18n.extendTranslations(t,o)}catch(i){return console.error('Cannot parse language file "'.concat(s,".admin/").concat(n,": ").concat(i)),""}return n}return console.warn("Cannot find i18n for ".concat(s," / ").concat(n)),""}return e&&"object"===typeof e?(d.I18n.extendTranslations(e),""):""}readData(){this.props.socket.getCompactSystemConfig().then((t=>this.props.socket.getState("system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance,".alive")).then((e=>this.setState({systemConfig:t.common,alive:!(!e||!e.val)},(()=>{this.updateContext(!0),this.props.custom||this.props.socket.subscribeState("system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance,".alive"),this.onAlive)})))))).catch((t=>console.error("Cannot read system config: ".concat(t))))}flatten(t,e){return e=e||{},t.items&&Object.keys(t.items).forEach((s=>{e[s]=t.items[s],this.flatten(t.items[s],e)})),e}buildDependencies(t){const e=this.flatten(t);Object.keys(e).forEach((t=>{var s,o,a,n,r,l,h,p,c,d;null!==(s=e[t].confirm)&&void 0!==s&&s.alsoDependsOn&&(null===(l=e[t].confirm)||void 0===l||l.alsoDependsOn.forEach((s=>{if(e[s]){e[s].confirmDependsOn=e[s].confirmDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});o.confirm&&(o.confirm.cancel="Undo"),e[s].confirmDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));null!==(o=e[t].onChange)&&void 0!==o&&o.alsoDependsOn&&(null===(h=e[t].onChange)||void 0===h||h.alsoDependsOn.forEach((s=>{if(e[s]){e[s].onChangeDependsOn=e[s].onChangeDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});e[s].onChangeDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));null!==(a=e[t].hidden)&&void 0!==a&&a.alsoDependsOn&&(null===(p=e[t].hidden)||void 0===p||p.alsoDependsOn.forEach((s=>{if(e[s]){e[s].hiddenDependsOn=e[s].hiddenDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});e[s].hiddenDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));null!==(n=e[t].label)&&void 0!==n&&n.alsoDependsOn&&(null===(c=e[t].label)||void 0===c||c.alsoDependsOn.forEach((s=>{if(e[s]){e[s].labelDependsOn=e[s].labelDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});e[s].labelDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})));null!==(r=e[t].help)&&void 0!==r&&r.alsoDependsOn&&(null===(d=e[t].help)||void 0===d||d.alsoDependsOn.forEach((s=>{if(e[s]){e[s].helpDependsOn=e[s].helpDependsOn||[];const o=(0,i.A)((0,i.A)({},e[t]),{},{attr:t});e[s].helpDependsOn.push(o)}else console.error("[JsonConfigComponent] Attribute ".concat(s," does not exist!")),s.startsWith("data.")&&console.warn('[JsonConfigComponent] please use "'.concat(s.replace(/^data\./,""),'" instead of "').concat(s,'"'))})))}))}updateContext(t){this.oContext={DeviceManager:this.props.DeviceManager,adapterName:this.props.adapterName,changeLanguage:this.changeLanguage,common:this.props.common,customs:this.props.customs,dateFormat:this.props.dateFormat,embedded:this.props.embedded,expertMode:this.props.expertMode,forceUpdate:this.forceAttrUpdate,imagePrefix:this.props.imagePrefix,instance:this.props.instance,instanceObj:this.props.instanceObj,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,onBackEndCommand:this.props.onBackEndCommand,onCommandRunning:this.onCommandRunning,onValueChange:this.props.onValueChange,registerOnForceUpdate:this.registerOnForceUpdate,socket:this.props.socket,systemConfig:this.state.systemConfig,theme:this.props.theme,themeType:this.props.themeType,_themeName:this.props.themeName,updateData:this.state.updateData},t&&this.forceUpdate()}renderItem(t){return"tabs"===t.type?(0,u.jsx)(Be,{oContext:this.oContext,alive:this.state.alive,changed:this.state.changed,commandRunning:this.state.commandRunning,common:this.props.common,custom:this.props.custom,customObj:this.props.customObj,data:this.props.data,onChange:this.onChange,onError:(t,e)=>this.onError(t,e),originalData:JSON.parse(this.state.originalData),root:!0,schema:t,themeName:this.props.themeName}):"panel"!==t.type&&t.type?(console.error("Unknown item type in root: ".concat(JSON.stringify(t))),null):(0,u.jsx)(Ve,{oContext:this.oContext,alive:this.state.alive,changed:this.state.changed,commandRunning:this.state.commandRunning,common:this.props.common,custom:this.props.custom,customObj:this.props.customObj,data:this.props.data,index:1e3,isParentTab:!this.props.embedded,onChange:this.onChange,onError:(t,e)=>this.onError(t,e),originalData:JSON.parse(this.state.originalData),root:!0,schema:t,themeName:this.props.themeName})}render(){return this.state.systemConfig&&this.oContext?(this.oContext._themeName!==this.props.themeName&&(this.oContext._themeName=this.props.themeName,setTimeout((()=>this.updateContext(!0)),0)),(0,u.jsx)("div",{style:(0,i.A)((0,i.A)((0,i.A)({},this.props.embedded?void 0:We.root),this.props.style),this.state.schema.style),children:this.renderItem(this.state.schema)})):(0,u.jsx)(p.LinearProgress,{})}}const Me=Ue,Re={root:{width:"100%",height:"100%",overflow:"hidden",position:"relative"},scroll:{height:"calc(100% - 48px)",overflowY:"auto"},exportImportButtons:{position:"absolute",top:5,right:0,zIndex:3},button:{marginRight:"5px"},tooltip:{pointerEvents:"none"}};function Je(t,e){if("string"!==typeof e)return e;if(!e.startsWith("$/aes-192-cbc:")||!/^[0-9a-f]{48}$/.test(t))return function(t,e){let s="";for(let i=0;i<e.length;i++)s+=String.fromCharCode(t[i%t.length].charCodeAt(0)^e.charCodeAt(i));return s}(t,e);const s=e.split(":",3),i=window.CryptoJS.enc.Hex.parse(t),o=window.CryptoJS.enc.Hex.parse(s[1]),a=window.CryptoJS.lib.CipherParams.create({ciphertext:window.CryptoJS.enc.Hex.parse(s[2])}),n=window.CryptoJS.AES.decrypt(a,i,{iv:o});return window.CryptoJS.enc.Utf8.stringify(n)}function ze(t,e,s){if("string"!==typeof e)return e;if(!/^[0-9a-f]{48}$/.test(t))return function(t,e){let s="";for(let i=0;i<e.length;i++)s+=String.fromCharCode(t[i%t.length].charCodeAt(0)^e.charCodeAt(i));return s}(t,e);let i;i=s?window.CryptoJS.enc.Hex.parse(s):window.CryptoJS.lib.WordArray.random(16);const o=window.CryptoJS.enc.Hex.parse(t),a=window.CryptoJS.AES.encrypt(e,o,{iv:i}).ciphertext;return"$/aes-192-cbc:".concat(window.CryptoJS.enc.Hex.stringify(i),":").concat(a)}function He(t,e){var s;return e&&document.getElementById(e)?null===(s=document.getElementById(e))||void 0===s?void 0:s.onload:new Promise((s=>{const i=document.createElement("script");i.setAttribute("id",e),i.onload=s,i.src=t,document.getElementsByTagName("head")[0].appendChild(i)}))}class qe extends d.Router{constructor(t){super(t),this.fileSubscribed=[],this.fileLangSubscribed="",this.secret=void 0,this.handleFileSelect=t=>{const e=t.target.files[0];if(e){const t=new FileReader;t.onload=t=>{if(!t.target)return;const e=t.target.result;try{const t=JSON.parse(e);this.setState({data:t,changed:JSON.stringify(t)!==JSON.stringify(this.state.originalData)})}catch(s){window.alert(d.I18n.t("[JsonConfig] Failed to parse JSON file"))}},t.readAsText(e)}else window.alert(d.I18n.t("[JsonConfig] Failed to open JSON File"))},this.onFileChange=async(t,e,s)=>{if(t==="".concat(this.props.adapterName,".admin")&&s)if(e===this.fileLangSubscribed)try{var i;await Me.loadI18n(this.props.socket,null===(i=this.state.schema)||void 0===i?void 0:i.i18n,this.props.adapterName),this.setState({hash:"".concat(this.state.hash,"1")})}catch(o){}else if(this.fileSubscribed.includes(e))try{const t=await this.getConfigFile(this.fileSubscribed[0]);this.setState({schema:t,hash:h()(JSON.stringify(t)).toString()})}catch(a){}},this.state={updateData:0,changed:!1,confirmDialog:!1,theme:(0,d.Theme)(t.themeName),saveConfigDialog:!1,hash:"_"},this.secret=t.secret||"",this.getInstanceObject().then((t=>this.getConfigFile().then((e=>Me.loadI18n(this.props.socket,null===e||void 0===e?void 0:e.i18n,this.props.adapterName).then((s=>{s&&(this.fileLangSubscribed||(this.fileLangSubscribed=s,this.props.socket.subscribeFiles("".concat(this.props.adapterName,".admin"),this.fileLangSubscribed,this.onFileChange))),t?this.setState({schema:e,data:t.native,common:t.common,hash:h()(JSON.stringify(e)).toString()}):window.alert("Instance system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance," not found!"))}))))))}componentWillUnmount(){super.componentWillUnmount(),this.fileSubscribed.length&&(this.props.socket.unsubscribeFiles("".concat(this.props.adapterName,".admin"),this.fileSubscribed,this.onFileChange),this.fileSubscribed=[]),this.fileLangSubscribed&&(this.props.socket.unsubscribeFiles("".concat(this.props.adapterName,".admin"),this.fileLangSubscribed,this.onFileChange),this.fileLangSubscribed="")}getExportImportButtons(){return(0,u.jsxs)("div",{style:Re.exportImportButtons,children:[(0,u.jsx)(p.Tooltip,{title:this.props.t("Import settings from JSON file"),slotProps:{popper:{sx:Re.tooltip}},children:(0,u.jsx)(p.Fab,{size:"small",sx:{"&.MuiFab-root":Re.button},onClick:()=>{const t=document.createElement("input");t.setAttribute("type","file"),t.setAttribute("id","files"),t.setAttribute("opacity",0),t.addEventListener("change",(t=>this.handleFileSelect(t)),!1),t.click()},children:(0,u.jsx)(c.Publish,{})})}),(0,u.jsx)(p.Tooltip,{title:this.props.t("Export setting to JSON file"),slotProps:{popper:{sx:Re.tooltip}},children:(0,u.jsx)(p.Fab,{size:"small",sx:{"&.MuiFab-root":Re.button},onClick:()=>{this.state.data&&d.Utils.generateFile("".concat(this.props.adapterName,".").concat(this.props.instance,".json"),this.state.data)},children:(0,u.jsx)(c.Publish,{style:{transform:"rotate(180deg)"}})})})]})}async getInstanceObject(){try{const e=await this.props.socket.getObject("system.adapter.".concat(this.props.adapterName,".").concat(this.props.instance));if(Array.isArray(e.encryptedNative)){var t;if(!this.secret){const t=await this.props.socket.getSystemConfig();await He("../../lib/js/crypto-js/crypto-js.js","crypto-js"),this.secret=t.native.secret}return null===(t=e.encryptedNative)||void 0===t||t.forEach((t=>{e.native[t]&&(e.native[t]=Je(this.secret,e.native[t]))})),e}return e}catch(e){window.alert("[JsonConfig] Cannot read instance object: ".concat(e))}return null}renderDialogConfirm(){return this.state.confirmDialog?(0,u.jsx)(d.DialogConfirm,{title:d.I18n.t("ra_Please confirm"),text:d.I18n.t("ra_Some data are not stored. Discard?"),ok:d.I18n.t("ra_Discard"),cancel:d.I18n.t("ra_Cancel"),onClose:t=>this.setState({confirmDialog:!1},(()=>t&&d.Router.doNavigate(null)))}):null}async scanForInclude(t,e){if("string"===typeof t["#include"]){const s=await this._getConfigFile(t["#include"],[...e]);return delete t["#include"],s&&(t=(0,i.A)((0,i.A)({},t),s)),t}const s=Object.keys(t);for(let i=0;i<s.length;i++)t[s[i]]&&"object"===typeof t[s[i]]&&(t[s[i]]=await this.scanForInclude(t[s[i]],e));return t}async getConfigFile(t){return this._getConfigFile(t)}async _getConfigFile(t,e){if(t=t||"jsonConfig.json5",(e=e||[]).includes(t))return window.alert("[JsonConfig] Circular reference in file: ".concat(t," => ").concat(e.join(" => "))),null;e.push(t);try{await this.props.socket.fileExists("".concat(this.props.adapterName,".admin"),t)||(t="jsonConfig.json");const i=await this.props.socket.readFile("".concat(this.props.adapterName,".admin"),t);let o="",a="";if(void 0!==i.file&&(a=i.file),"string"===typeof a)o=a;else if("Buffer"===a.type){let t="";const e=new Uint8Array(a.data),s=e.byteLength;for(let i=0;i<s;i++)t+=String.fromCharCode(e[i]);o=t}this.fileSubscribed.includes(t)||(this.fileSubscribed.push(t),await this.props.socket.subscribeFiles("".concat(this.props.adapterName,".admin"),t,this.onFileChange));try{return await this.scanForInclude(r().parse(o),e)}catch(s){window.alert("[JsonConfig] Cannot parse json5 config!"),console.log(s)}}catch(i){this.state.schema||window.alert('[JsonConfig] Cannot read file "'.concat(t,": ").concat(i))}return null}renderSaveConfigDialog(){return this.state.saveConfigDialog?(0,u.jsx)(d.DialogConfirm,{title:d.I18n.t("ra_Please confirm"),text:d.I18n.t("Save configuration?"),ok:d.I18n.t("ra_Save"),cancel:d.I18n.t("ra_Cancel"),onClose:t=>this.setState({saveConfigDialog:!1},(()=>t&&this.onSave(!0)))}):null}findAttr(t,e){var s;if(null!==(s=e=e||this.state.schema)&&void 0!==s&&s.items){if(t in e.items)return e.items[t];for(const s of Object.values(e.items)){const e=this.findAttr(t,s);if(e)return e}}return null}postProcessing(t,e,s){if(s=s||this.state.schema,!t)return void console.error("Data is empty in postProcessing: ".concat(e,", ").concat(JSON.stringify(s)));const i=t[e];if(s.items)if("table"===s.type){const t=i;if(!Array.isArray(t))return;for(const e of t)for(const t of s.items)this.postProcessing(e,t.attr,t)}else for(const[o,a]of Object.entries(s.items)){if("panel"===a.type||"tabs"===a.type||"accordion"===a.type)return;this.postProcessing(t,o,a)}else if(e&&"string"===typeof i)if("text"===s.type)!1!==s.trim&&(t[e]=i.trim());else if("ip"===s.type)t[e]=i.trim();else if("number"===s.type){const o=parseFloat(i.toString().replace(",","."));void 0!==s.min&&o<s.min?t[e]=s.min:void 0!==s.max&&o>s.max?t[e]=s.max:t[e]=o}else if("port"===s.type){const o=parseInt(i.toString(),10);void 0!==s.min&&o<s.min?t[e]=s.min:void 0!==s.max&&o>s.max&&(t[e]=s.max),0!==t[e]&&o<20?t[e]=20:t[e]=o>65535?65535:o}else"checkbox"===s.type&&(t[e]=!0===t[e]||"true"===t[e]||"on"===t[e]||1===t[e]||"1"===t[e])}async onSave(t,e){if(t){const t=await this.getInstanceObject();if(!t)return console.error("Something went wrong: may be no connection?"),void window.alert("Something went wrong: may be no connection?");if(!this.state.data||!this.state.schema)return;const o={};for(const e of Object.keys(this.state.data)){const s=this.findAttr(e);s&&s.doNotSave&&"state"!==s.type||e.startsWith("_")?(x.setValue(t.native,e,null),o[e]=this.state.data[e]):x.setValue(t.native,e,this.state.data[e])}try{const e=JSON.parse(JSON.stringify(t));if(Array.isArray(e.encryptedNative)){await He("../../lib/js/crypto-js/crypto-js.js","crypto-js");for(const t of e.encryptedNative)e.native[t]&&(e.native[t]=ze(this.secret,e.native[t]))}await this.props.socket.setObject(e._id,e)}catch(s){window.alert("[JsonConfig] Cannot set object: ".concat(s))}const a=(0,i.A)((0,i.A)({},t.native),o);console.log(a),this.setState({changed:!1,data:a,updateData:this.state.updateData+1,originalData:a},(()=>e&&d.Router.doNavigate(null)))}else this.state.changed?this.setState({confirmDialog:!0}):d.Router.doNavigate(null)}componentDidUpdate(t,e){e.changed!==this.state.changed&&this.props.configStored(!this.state.changed)}async componentDidMount(){const t="".concat(window.location.protocol,"//").concat(window.location.host).concat(window.location.pathname,"validate_config/").concat(this.props.adapterName);console.log("fetch ".concat(t)),await fetch(t)}render(){return this.state.data&&this.state.schema?(0,u.jsxs)("div",{style:Re.root,children:[this.renderDialogConfirm(),this.getExportImportButtons(),this.renderSaveConfigDialog(),(0,u.jsx)(Me,{style:Re.scroll,socket:this.props.socket,themeName:this.props.themeName,themeType:this.props.themeType,adapterName:this.props.adapterName,instance:this.props.instance,isFloatComma:this.props.isFloatComma,dateFormat:this.props.dateFormat,schema:this.state.schema,common:this.state.common,expertMode:this.props.expertMode,data:this.state.data,updateData:this.state.updateData,onError:t=>this.setState({error:t}),onChange:(t,e,s)=>{s&&this.state.error&&(window.alert(d.I18n.t("Cannot save configuration because of error in configuration")),s=!1),!s||this.state.changed||e||(s=!1),t?this.setState({data:t,changed:e,saveConfigDialog:s}):void 0!==s&&this.setState({saveConfigDialog:s})},DeviceManager:this.props.DeviceManager,theme:this.state.theme},this.state.hash),(0,u.jsx)(d.SaveCloseButtons,{isIFrame:!1,dense:!0,paddingLeft:0,newReact:!0,theme:this.state.theme,noTextOnButtons:"xs"===this.props.width||"sm"===this.props.width||"md"===this.props.width,changed:!(!this.state.error&&!this.state.changed),error:!!this.state.error,onSave:t=>this.onSave(!0,t),onClose:()=>this.onSave(!1)})]}):(0,u.jsx)(p.LinearProgress,{})}}const Ke=qe},75443:()=>{}}]);
|
|
2
|
+
//# sourceMappingURL=6853.c817c98e.chunk.js.map
|