iobroker.admin 7.1.1 → 7.1.2
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 +5 -8
- package/adminWww/asset-manifest.json +33 -33
- package/adminWww/index.html +1 -1
- package/adminWww/static/css/3210.f6c8a5fc.chunk.css.map +1 -1
- package/adminWww/static/js/2534.d8fd195b.chunk.js +2 -0
- package/adminWww/static/js/2534.d8fd195b.chunk.js.map +1 -0
- package/adminWww/static/js/2544.047df092.chunk.js +2 -0
- package/adminWww/static/js/2544.047df092.chunk.js.map +1 -0
- package/adminWww/static/js/2816.f7bf6ba0.chunk.js +2 -0
- package/adminWww/static/js/2816.f7bf6ba0.chunk.js.map +1 -0
- package/adminWww/static/js/3210.1be726e7.chunk.js +2 -0
- package/adminWww/static/js/3210.1be726e7.chunk.js.map +1 -0
- package/adminWww/static/js/4112.9b241792.chunk.js +2 -0
- package/adminWww/static/js/4112.9b241792.chunk.js.map +1 -0
- package/adminWww/static/js/4579.014de1f1.chunk.js +2 -0
- package/adminWww/static/js/4579.014de1f1.chunk.js.map +1 -0
- package/adminWww/static/js/{5174.60f22386.chunk.js → 5174.f5aa1074.chunk.js} +2 -2
- package/adminWww/static/js/5174.f5aa1074.chunk.js.map +1 -0
- package/adminWww/static/js/530.cb8dbcf9.chunk.js +2 -0
- package/adminWww/static/js/530.cb8dbcf9.chunk.js.map +1 -0
- package/adminWww/static/js/6552.0a447e18.chunk.js +2 -0
- package/adminWww/static/js/6552.0a447e18.chunk.js.map +1 -0
- package/adminWww/static/js/6938.af058182.chunk.js +2 -0
- package/adminWww/static/js/6938.af058182.chunk.js.map +1 -0
- package/adminWww/static/js/{8038.cacab580.chunk.js → 8038.ae8b7862.chunk.js} +2 -2
- package/adminWww/static/js/8038.ae8b7862.chunk.js.map +1 -0
- package/adminWww/static/js/858.f34ea2c6.chunk.js +2 -0
- package/adminWww/static/js/858.f34ea2c6.chunk.js.map +1 -0
- package/adminWww/static/js/9399.5852b7e7.chunk.js +2 -0
- package/adminWww/static/js/9399.5852b7e7.chunk.js.map +1 -0
- package/adminWww/static/js/9534.2af54084.chunk.js +2 -0
- package/adminWww/static/js/9534.2af54084.chunk.js.map +1 -0
- package/adminWww/static/js/9917.3662a807.chunk.js +2 -0
- package/adminWww/static/js/9917.3662a807.chunk.js.map +1 -0
- package/adminWww/static/js/{main.c1384a82.js → main.423e60b6.js} +2 -2
- package/adminWww/static/js/main.423e60b6.js.map +1 -0
- package/build-backend/lib/passportSocket.js +8 -10
- package/build-backend/lib/translations.js +0 -1
- package/build-backend/lib/web.js +101 -81
- package/build-backend/main.js +173 -184
- package/io-package.json +14 -14
- package/package.json +97 -96
- package/adminWww/static/js/2534.0bc9912f.chunk.js +0 -2
- package/adminWww/static/js/2534.0bc9912f.chunk.js.map +0 -1
- package/adminWww/static/js/2544.4fa1eef5.chunk.js +0 -2
- package/adminWww/static/js/2544.4fa1eef5.chunk.js.map +0 -1
- package/adminWww/static/js/2816.cfab0128.chunk.js +0 -2
- package/adminWww/static/js/2816.cfab0128.chunk.js.map +0 -1
- package/adminWww/static/js/3210.4c1ccdc2.chunk.js +0 -2
- package/adminWww/static/js/3210.4c1ccdc2.chunk.js.map +0 -1
- package/adminWww/static/js/4112.8c6e6dae.chunk.js +0 -2
- package/adminWww/static/js/4112.8c6e6dae.chunk.js.map +0 -1
- package/adminWww/static/js/4579.cd86a1cb.chunk.js +0 -2
- package/adminWww/static/js/4579.cd86a1cb.chunk.js.map +0 -1
- package/adminWww/static/js/5174.60f22386.chunk.js.map +0 -1
- package/adminWww/static/js/530.8eed62a7.chunk.js +0 -2
- package/adminWww/static/js/530.8eed62a7.chunk.js.map +0 -1
- package/adminWww/static/js/6552.29112fa0.chunk.js +0 -2
- package/adminWww/static/js/6552.29112fa0.chunk.js.map +0 -1
- package/adminWww/static/js/6938.f4331126.chunk.js +0 -2
- package/adminWww/static/js/6938.f4331126.chunk.js.map +0 -1
- package/adminWww/static/js/8038.cacab580.chunk.js.map +0 -1
- package/adminWww/static/js/858.3a130f69.chunk.js +0 -2
- package/adminWww/static/js/858.3a130f69.chunk.js.map +0 -1
- package/adminWww/static/js/9399.c959c5de.chunk.js +0 -2
- package/adminWww/static/js/9399.c959c5de.chunk.js.map +0 -1
- package/adminWww/static/js/9534.68ac37f7.chunk.js +0 -2
- package/adminWww/static/js/9534.68ac37f7.chunk.js.map +0 -1
- package/adminWww/static/js/9917.28c0dbc2.chunk.js +0 -2
- package/adminWww/static/js/9917.28c0dbc2.chunk.js.map +0 -1
- package/adminWww/static/js/main.c1384a82.js.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(self.webpackChunksrc_rx=self.webpackChunksrc_rx||[]).push([[9399],{81661:(t,e,s)=>{"use strict";s.r(e),s.d(e,{ConfigGeneric:()=>C,ConfigPanel:()=>We,JsonConfig:()=>Ye,JsonConfigComponent:()=>Je});var i=s(29183),a=s.n(i),o=s(58680),n=s.n(o),r=s(33005),l=s.n(r),h=s(89303),p=s(32075),c=s(26699),d=s(99277);const u="material",m=["Su","Mo","Tu","We","Th","Fr","Sa"],g=["Jan","Feb","Mar","Apr","Mai","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],f={0:"0x00 - good",1:"0x01 - general problem",2:"0x02 - no connection problem",16:"0x10 - substitute value from controller",32:"0x20 - substitute initial value",64:"0x40 - substitute value from device or instance",128:"0x80 - substitute value from sensor",17:"0x11 - general problem by instance",65:"0x41 - general problem by device",129:"0x81 - general problem by sensor",18:"0x12 - instance not connected",66:"0x42 - device not connected",130:"0x82 - sensor not connected",68:"0x44 - device reports error",132:"0x84 - sensor reports error"},v={JVBERi0:"pdf",R0lGODdh:"gif",R0lGODlh:"gif",iVBORw0KGgo:"png","/9j/":"jpg",PHN2Zw:"svg",Qk1:"bmp",AAABAA:"ico"};class x{static CapitalWords(t){return(t||"").split(/[\s_]/).filter((t=>t)).map((t=>t?t[0].toUpperCase()+t.substring(1).toLowerCase():"")).join(" ")}static formatSeconds(t){const e=Math.floor(t/86400);t%=86400;let s=Math.floor(t/3600);s<10&&(s=`0${s}`),t%=3600;let i=Math.floor(t/60);i<10&&(i=`0${i}`),t%=60,(t=Math.floor(t))<10&&(t=`0${t}`);let a="";return e&&(a+=`${e} ${c.I18n.t("ra_daysShortText")} `),a+=`${s}:${i}:${t}`,a}static getObjectName(t,e,s,i,a){const o=t[e];let n;const r=a?"desc":"name";if("string"!==typeof s||i||(i={language:s},s=null),(i=i||{}).language||(i.language=t["system.config"]&&t["system.config"].common&&t["system.config"].common.language||window.sysLang||"en"),s&&s.name)n=s.name,"object"===typeof n&&(n=n[i.language]||n.en);else if(o&&o.common&&o.common[r])n=o.common[r],"desc"!==r&&!n&&o.common.desc&&(n=o.common.desc),"object"===typeof n&&(n=n[i.language]||n.en||n.de||n.ru||""),n=(n||"").toString().replace(/[_.]/g," "),n===n.toUpperCase()&&(n=n[0]+n.substring(1).toLowerCase());else{const t=e.lastIndexOf(".");n=e.substring(t+1).replace(/[_.]/g," "),n=x.CapitalWords(n)}return n.trim()}static getObjectNameFromObj(t,e,s,i,a){const o=t;let n=t&&t._id||"";const r=i?"desc":"name";return"string"!==typeof e||s||(s={language:e},e=null),s=s||{},e&&e.name?(n=e.name,"object"===typeof n&&(n=n[s.language]||n.en)):o&&o.common&&o.common[r]&&(n=o.common[r],"desc"!==r&&!n&&o.common.desc&&(n=o.common.desc),"object"===typeof n&&(n=n[s.language]||n.en),n=(n||"").toString().replace(/[_.]/g," "),n===n.toUpperCase()&&(n=n[0]+n.substring(1).toLowerCase())),a?n:n.trim()}static getSettingsOrder(t,e,s){let i;if(t&&Object.prototype.hasOwnProperty.call(t,"common")&&(t=t.common),t&&t.custom){i=(t.custom||{})[u];const a=s.user||"admin";if(i&&i[a])if(e){if(i[a].subOrder&&i[a].subOrder[e])return JSON.parse(JSON.stringify(i[a].subOrder[e]))}else if(i[a].order)return JSON.parse(JSON.stringify(i[a].order))}return null}static getSettingsCustomURLs(t,e,s){let i;if(t&&Object.prototype.hasOwnProperty.call(t,"common")&&(t=t.common),t&&t.custom){i=(t.custom||{})[u];const a=s.user||"admin";if(i&&i[a])if(e){if(i[a].subURLs&&i[a].subURLs[e])return JSON.parse(JSON.stringify(i[a].subURLs[e]))}else if(i[a].URLs)return JSON.parse(JSON.stringify(i[a].URLs))}return null}static reorder(t,e,s){const i=Array.from(t),[a]=i.splice(e,1);return i.splice(s,0,a),i}static getSettings(t,e,s){var i;let a;const o=t&&t._id||e&&e.id;if(t&&Object.prototype.hasOwnProperty.call(t,"common")&&(t=t.common),null!==(i=t)&&void 0!==i&&i.custom?(a=t.custom,a=a[u]&&a[u][e.user||"admin"]?JSON.parse(JSON.stringify(a[u][e.user||"admin"])):{enabled:!0}):a={enabled:void 0===s||s,useCustom:!1},Object.prototype.hasOwnProperty.call(a,"enabled")||(a.enabled=void 0===s||s),e&&(!a.name&&e.name&&(a.name=e.name),!a.icon&&e.icon&&(a.icon=e.icon),!a.color&&e.color&&(a.color=e.color)),t&&(!a.color&&t.color&&(a.color=t.color),!a.icon&&t.icon&&(a.icon=t.icon),!a.name&&t.name&&(a.name=t.name)),"object"===typeof a.name&&(a.name=a.name[e.language]||a.name.en,a.name=(a.name||"").toString().replace(/_/g," "),a.name===a.name.toUpperCase()&&(a.name=a.name[0]+a.name.substring(1).toLowerCase())),!a.name&&o){const t=o.lastIndexOf(".");a.name=o.substring(t+1).replace(/[_.]/g," "),a.name=(a.name||"").toString().replace(/_/g," "),a.name=x.CapitalWords(a.name)}return a}static setSettings(t,e,s){if(t){t.common=t.common||{},t.common.custom=t.common.custom||{},t.common.custom[u]=t.common.custom[u]||{},t.common.custom[u][s.user||"admin"]=e;const i=t.common.custom[u][s.user||"admin"];return i.useCommon&&(void 0!==i.color&&(t.common.color=i.color,delete i.color),void 0!==i.icon&&(t.common.icon=i.icon,delete i.icon),void 0!==i.name&&("object"!==typeof t.common.name?(t.common.name={},t.common.name[s.language]=i.name):t.common.name[s.language]=i.name,delete i.name)),!0}return!1}static getIcon(t,e){return t&&t.icon?t.icon.length<=2?(0,d.jsx)("span",{style:e||{},children:t.icon}):t.icon.startsWith("data:image")?(0,d.jsx)("img",{alt:t.name,src:t.icon,style:e||{}}):(0,d.jsx)("img",{alt:t.name,src:(t.prefix||"")+t.icon,style:e||{}}):null}static getObjectIcon(t,e){if("object"===typeof t&&(t=(e=t)._id),e&&e.common&&e.common.icon){let s=e.common.icon;if("string"===typeof s&&s.length<=2)return s;if(s.startsWith("data:image"))return s;const i=t.split(".");return s="system"===i[0]?`adapter/${i[2]}${s.startsWith("/")?"":"/"}${s}`:`adapter/${i[0]}${s.startsWith("/")?"":"/"}${s}`,window.location.pathname.match(/adapter\/[^/]+\/[^/]+\.html/)||window.location.pathname.match(/material\/[.\d]+/)?s=`../../${s}`:window.location.pathname.match(/material\//)&&(s=`../${s}`),s}return null}static splitCamelCase(t){return x.CapitalWords(t)}static isUseBright(t,e){if(null===t||void 0===t||""===t)return void 0===e||e;let s,i,a;(t=t.toString()).startsWith("#")&&(t=t.slice(1));const o=t.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);if(o&&4===o.length)s=parseInt(o[1],10),i=parseInt(o[2],10),a=parseInt(o[3],10);else{if(3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),8===t.length)t=t.substring(0,6);else if(6!==t.length)return!1;s=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),a=parseInt(t.slice(4,6),16)}return.299*s+.587*i+.114*a<=186}static getTimeString(t){if(t=parseFloat(t),Number.isNaN(t))return"--:--";const e=Math.floor(t/3600);let s=Math.floor(t%3600/60),i=t%60;return e?(s<10&&(s=`0${s}`),i<10&&(i=`0${i}`),`${e}:${s}:${i}`):(i<10&&(i=`0${i}`),`${s}:${i}`)}static getWindDirection(t){return t>=0&&t<11.25?"N":t>=11.25&&t<33.75?"NNE":t>=33.75&&t<56.25?"NE":t>=56.25&&t<78.75?"ENE":t>=78.75&&t<101.25?"E":t>=101.25&&t<123.75?"ESE":t>=123.75&&t<146.25?"SE":t>=146.25&&t<168.75?"SSE":t>=168.75&&t<191.25?"S":t>=191.25&&t<213.75?"SSW":t>=213.75&&t<236.25?"SW":t>=236.25&&t<258.75?"WSW":t>=258.75&&t<281.25?"W":t>=281.25&&t<303.75?"WNW":t>=303.75&&t<326.25?"NW":t>=326.25&&t<348.75?"NNW":"N"}static padding(t){return"string"===typeof t?t.length<2?`0${t}`:t:t<10?`0${t}`:t}static setDataFormat(t){t&&(x.dateFormat=t.toUpperCase().split(/[.-/]/),x.dateFormat.splice(x.dateFormat.indexOf("YYYY"),1))}static date2string(t){if("string"===typeof t){if(!(t=t.trim()))return"";if(t.match(/^[\w\s]+$/))return t;const e=t.match(/(\d{1,4})[-./](\d{1,2})[-./](\d{1,4})/);if(e){const s=[parseInt(e[1],10),parseInt(e[2],10),parseInt(e[3],10)],i=s.find((t=>t>31));s.splice(s.indexOf(i),1);const a=s.find((t=>t>12));a?(s.splice(s.indexOf(a),1),t=new Date(i,s[0]-1,a)):"M"===x.dateFormat[0][0]&&"D"===x.dateFormat[1][0]?(t=new Date(i,s[0]-1,s[1]),Math.abs(t.getTime-Date.now())>864e6&&(t=new Date(i,s[1]-1,s[0]))):"D"===x.dateFormat[0][0]&&"M"===x.dateFormat[1][0]?(t=new Date(i,s[1]-1,s[0]),Math.abs(t.getTime-Date.now())>864e6&&(t=new Date(i,s[0]-1,s[1]))):t=new Date(t)}else t=new Date(t)}else t=new Date(t);let e=c.I18n.t(`ra_dow_${m[t.getDay()]}`).replace("ra_dow_","");return e+=`. ${t.getDate()} ${c.I18n.t(`ra_month_${g[t.getMonth()]}`).replace("ra_month_","")}`,e}static renderTextWithA(t){let e=t.match(/<a [^<]+<\/a>|<br\/?>|<b>[^<]+<\/b>|<i>[^<]+<\/i>/);if(e){const s=[];let i=1;do{const a=t.substring(0,e.index);if(t=t.substring(e.index+e[0].length),a&&s.push((0,d.jsx)("span",{children:a},"a"+i++)),e[0].startsWith("<b>"))s.push((0,d.jsx)("b",{children:e[0].substring(3,e[0].length-4)},"a"+i++));else if(e[0].startsWith("<i>"))s.push((0,d.jsx)("i",{children:e[0].substring(3,e[0].length-4)},"a"+i++));else if(e[0].startsWith("<br"))s.push((0,d.jsx)("br",{},"a"+i++));else{const t=e[0].match(/href="([^"]+)"/)||e[0].match(/href='([^']+)'/),a=e[0].match(/target="([^"]+)"/)||e[0].match(/target='([^']+)'/),o=e[0].match(/rel="([^"]+)"/)||e[0].match(/rel='([^']+)'/),n=e[0].match(/>([^<]*)</);s.push((0,d.jsx)("a",{href:t?t[1]:"",target:a?a[1]:"_blank",rel:o?o[1]:"",style:{color:"inherit"},children:n?n[1]:""},"a"+i++))}e=t&&t.match(/<a [^<]+<\/a>|<br\/?>|<b>[^<]+<\/b>|<i>[^<]+<\/i>/),!e&&t&&s.push((0,d.jsx)("span",{children:t},"a"+i++))}while(e);return s}return t}static getSmartName(t,e,s,i){var a,o;return e?i?t[e]&&null!==(a=t[e].common)&&void 0!==a&&a.custom&&t[e].common.custom[s]&&t[e].common.custom[s].smartName||null:t[e].common.smartName:i?t&&!t.common?t.smartName:null!==t&&void 0!==t&&null!==(o=t.common)&&void 0!==o&&o.custom&&t.common.custom[s]?t.common.custom[s].smartName:void 0:t.common?t&&!t.common?t.smartName:t.common.smartName:t.smartName}static getSmartNameFromObj(t,e,s){var i;return s?t&&!t.common?t.smartName:null!==t&&void 0!==t&&null!==(i=t.common)&&void 0!==i&&i.custom&&t.common.custom[e]?t.common.custom[e].smartName:void 0:t.common?t&&!t.common?t.smartName:t.common.smartName:t.smartName}static enableSmartName(t,e,s){s?(t.common.custom=t.common.custom||{},t.common.custom[e]=t.common.custom[e]||{},t.common.custom[e].smartName={}):t.common.smartName={}}static removeSmartName(t,e,s){s?t.common&&t.common.custom&&t.common.custom[e]&&(t.common.custom[e]=null):t.common.smartName=null}static updateSmartName(t,e,s,i,a,o){const n=c.I18n.getLanguage();if("string"===typeof t.common.smartName){const e=t.common.smartName;t.common.smartName={},t.common.smartName[n]=e}if(t.native&&t.native.byON){delete t.native.byON;let e=t.common.smartName;e&&"object"===typeof e||(e={en:e},e[n]=e.en),t.common.smartName=e}if(void 0!==i&&(o?(t.common.custom=t.common.custom||{},t.common.custom[a]=t.common.custom[a]||{},t.common.custom[a].smartName=t.common.custom[a].smartName||{},i?t.common.custom[a].smartName.smartType=i:delete t.common.custom[a].smartName.smartType):(t.common.smartName=t.common.smartName||{},i?t.common.smartName.smartType=i:delete t.common.smartName.smartType)),void 0!==s&&(o?(t.common.custom=t.common.custom||{},t.common.custom[a]=t.common.custom[a]||{},t.common.custom[a].smartName=t.common.custom[a].smartName||{},t.common.custom[a].smartName.byON=s):(t.common.smartName=t.common.smartName||{},t.common.smartName.byON=s)),void 0!==e){let s;if(o?(t.common.custom=t.common.custom||{},t.common.custom[a]=t.common.custom[a]||{},t.common.custom[a].smartName=t.common.custom[a].smartName||{},s=t.common.custom[a].smartName):(t.common.smartName=t.common.smartName||{},s=t.common.smartName),s[n]=e,s&&(!s[n]||s[n]===t.common.name&&(!t.common.role||t.common.role.includes("button")))){delete s[n];let e=!0;for(const t in s)if(Object.prototype.hasOwnProperty.call(s,t)){e=!1;break}e&&(o?void 0===t.common.custom[a].smartName.byON?delete t.common.custom[a]:(delete t.common.custom[a].en,delete t.common.custom[a].de,delete t.common.custom[a].ru,delete t.common.custom[a].nl,delete t.common.custom[a].pl,delete t.common.custom[a].it,delete t.common.custom[a].fr,delete t.common.custom[a].pt,delete t.common.custom[a].es,delete t.common.custom[a].uk,delete t.common.custom[a]["zh-cn"]):void 0!==t.common.smartName.byON?(delete t.common.smartName.en,delete t.common.smartName.de,delete t.common.smartName.ru,delete t.common.smartName.nl,delete t.common.smartName.pl,delete t.common.smartName.it,delete t.common.smartName.fr,delete t.common.smartName.pt,delete t.common.smartName.es,delete t.common.smartName.uk,delete t.common.smartName["zh-cn"]):t.common.smartName=null)}}}static disableSmartName(t,e,s){s?(t.common.custom=t.common.custom||{},t.common.custom[e]=t.common.custom[e]||{},t.common.custom[e].smartName=!1):t.common.smartName=!1}static copyToClipboard(t,e){return e&&(e.stopPropagation(),e.preventDefault()),c.Utils.copyToClipboard(t)}static getFileExtension(t){const e=(t||"").lastIndexOf(".");return-1!==e?t.substring(e+1).toLowerCase():null}static formatBytes(t){if(Math.abs(t)<1024)return`${t} B`;const e=["KB","MB","GB"];let s=-1;do{t/=1024,++s}while(Math.abs(t)>=1024&&s<e.length-1);return`${t.toFixed(1)} ${e[s]}`}static getInvertedColor(t,e,s){if(!t)return;const i=x.invertColor(t,!0);return"#FFFFFF"===i&&("dark"===e||s&&"light"===e)?"#DDD":"#000000"===i&&("light"===e||s&&"dark"===e)?"#222":void 0}static invertColor(t,e){if(void 0===t||null===t||""===t||"string"!==typeof t)return"";if(t.startsWith("rgba")){const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)/);e&&(t=parseInt(e[1],10).toString(16).padStart(2,"0")+parseInt(e[2],10).toString(16).padStart(2,"0")+parseInt(e[2],10).toString(16).padStart(2,"0"))}else if(t.startsWith("rgb")){const e=t.match(/rgb?\((\d+),\s*(\d+),\s*(\d+)\)/);e&&(t=parseInt(e[1],10).toString(16).padStart(2,"0")+parseInt(e[2],10).toString(16).padStart(2,"0")+parseInt(e[2],10).toString(16).padStart(2,"0"))}else t.startsWith("#")&&(t=t.slice(1));3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]);let s=null;if(8===t.length)s=t.substring(6,8),t=t.substring(0,6);else if(6!==t.length)return console.warn(`Cannot invert color: ${t}`),t;let i=parseInt(t.slice(0,2),16),a=parseInt(t.slice(2,4),16),o=parseInt(t.slice(4,6),16);return e?.299*i+.587*a+.114*o>186?`#000000${s||""}`:`#FFFFFF${s||""}`:(i=(255-i).toString(16),a=(255-a).toString(16),o=(255-o).toString(16),`#${i.padStart(2,"0")}${a.padStart(2,"0")}${o.padStart(2,"0")}${s||""}`)}static color2rgb(t){if(void 0===t||null===t||""===t||"string"!==typeof t)return"";if(t.startsWith("rgba")){const e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+),\s*([.\d]+)\)/);e&&(t=parseInt(e[1],10).toString(16).padStart(2,"0")+parseInt(e[2],10).toString(16).padStart(2,"0")+parseInt(e[2],10).toString(16).padStart(2,"0"))}else if(t.startsWith("rgb")){const e=t.match(/rgb?\((\d+),\s*(\d+),\s*(\d+)\)/);e&&(t=parseInt(e[1],10).toString(16).padStart(2,"0")+parseInt(e[2],10).toString(16).padStart(2,"0")+parseInt(e[2],10).toString(16).padStart(2,"0"))}else t.startsWith("#")&&(t=t.slice(1));return 3===t.length&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),6!==t.length&&8!==t.length?(console.warn(`Cannot invert color: ${t}`),!1):[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}static rgb2lab(t){let e=t[0]/255,s=t[1]/255,i=t[2]/255;e=e>.04045?((e+.055)/1.055)**2.4:e/12.92,s=s>.04045?((s+.055)/1.055)**2.4:s/12.92,i=i>.04045?((i+.055)/1.055)**2.4:i/12.92;let a=(.4124*e+.3576*s+.1805*i)/.95047,o=.2126*e+.7152*s+.0722*i,n=(.0193*e+.1192*s+.9505*i)/1.08883;return a=a>.008856?a**.33333333:7.787*a+.137931,o=o>.008856?o**.33333333:7.787*o+.137931,n=n>.008856?n**.33333333:7.787*n+.137931,[116*o-16,500*(a-o),200*(o-n)]}static colorDistance(t,e){const s=x.rgb2lab(x.color2rgb(t)),i=x.rgb2lab(x.color2rgb(e)),a=s[0]-i[0],o=s[1]-i[1],n=s[2]-i[2],r=Math.sqrt(s[1]*s[1]+s[2]*s[2]),l=r-Math.sqrt(i[1]*i[1]+i[2]*i[2]);let h=o*o+n*n-l*l;h=h<0?0:Math.sqrt(h);const p=l/(1+.045*r),c=h/(1+.015*r),d=a*a+p*p+c*c;return d<0?0:d}static _toVal(t){let e,s="";if("string"===typeof t||"number"===typeof t)s+=t;else if("object"===typeof t)if(Array.isArray(t))for(let i=0;i<t.length;i++)t[i]&&(e=x._toVal(t[i]),e&&(s+=(s?" ":"")+e));else for(const i in t)t[i]&&(s+=(s?" ":"")+i);return s}static clsx(){let t,e,s=0,i="";for(;s<arguments.length;)t=arguments[s++],t&&(e=x._toVal(t),e&&(i+=(i?" ":"")+e));return i}static getThemeName(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return window.vendorPrefix&&"@@vendorPrefix@@"!==window.vendorPrefix?window.vendorPrefix:t||((window._localStorage||window.localStorage).getItem("App.themeName")?(window._localStorage||window.localStorage).getItem("App.themeName"):window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"colored")}static getThemeType(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return window.vendorPrefix&&"@@vendorPrefix@@"!==window.vendorPrefix?"light":(t=t||(window._localStorage||window.localStorage).getItem("App.themeName"),"dark"===t||"blue"===t?"dark":"light")}static setThemeName(t){window.vendorPrefix&&"@@vendorPrefix@@"!==window.vendorPrefix||((window._localStorage||window.localStorage).setItem("App.themeName",t),(window._localStorage||window.localStorage).setItem("App.theme","dark"===t||"blue"===t?"dark":"light"))}static toggleTheme(t){if(window.vendorPrefix&&"@@vendorPrefix@@"!==window.vendorPrefix)return window.vendorPrefix;t=t||(window._localStorage||window.localStorage).getItem("App.themeName");const e=x.getThemeNames(),s=e.indexOf(t);let i;return i=-1!==s?e[(s+1)%e.length]:e[0],x.setThemeName(i),i}static getThemeNames(){return window.vendorPrefix&&"@@vendorPrefix@@"!==window.vendorPrefix?[window.vendorPrefix]:["light","dark","blue","colored"]}static parseQuery(t){t=(t||"").toString().replace(/^\?/,"");const e={};return t.split("&").forEach((t=>{if(t=t.trim()){const s=t.split("="),i=decodeURIComponent(s[0]).trim();if(s.length>1)if(e[i]=decodeURIComponent(s[1]),"true"===e[i])e[i]=!0;else if("false"===e[i])e[i]=!1;else{const t=parseFloat(e[i]);t.toString()===e[i]&&(e[i]=t)}else e[i]=!0}})),e}static getParentId(t){const e=(t||"").toString().split(".");return e.length>1?(e.pop(),e.join(".")):null}static formatDate(t,e){if(!t)return"";let s,i=t.getMonth()+1;i<10&&(i=`0${i}`);let a=t.getDate();a<10&&(a=`0${a}`),s="MM/DD/YYYY"===e?`${i}/${a}/${t.getFullYear()}`:`${t.getFullYear()}-${i}-${a}`;let o=t.getHours();return s+=o<10?` 0${o}`:` ${o}`,o=t.getMinutes(),s+=o<10?`:0${o}`:`:${o}`,o=t.getSeconds(),s+=o<10?`:0${o}`:`:${o}`,o=t.getMilliseconds(),s+=o<10?`.00${o}`:o<100?`.0${o}`:`.${o}`,s}static formatTime(t){if(t){t=Math.round(t);const e=Math.floor(t/86400),s=Math.floor(t%86400/3600),i=Math.floor(t%3600/60),a=t%60;return e?`${e}.${s.toString().padStart(2,"0")}:${i.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`:s?`${s}:${i.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`:`0:${i.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`}return"0:00:00"}static MDtext2link(t){const e=t.match(/\d+\.\)\s/);return e&&(t=t.replace(e[0],e[0].replace(/\s/," "))),t.replace(/[^a-zA-Z\u0430-\u044f\u0410-\u042f0-9]/g,"").trim().replace(/\s/g,"").toLowerCase()}static openLink(t,e){t=t.replace(/\/\/([0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*:[0-9a-f]*)(:\d+)?\//i,"//[$1]$2/"),"this"===e?window.location=t:window.open(t,e||"_blank")}static MDgetTitle(t){const e=x.extractHeader(t),s=e.header;let i=e.body;if(!s.title){i=i.replace(/{[^}]*}/g,""),i=i.trim();const t=i.replace(/\r/g,"").split("\n");for(let e=0;e<t.length;e++)if(t[e].startsWith("# "))return t[e].substring(2).trim();return""}return s.title}static MDextractHeader(t){const e={};if("---"===t.substring(0,3)){const s=t.substring(3).indexOf("\n---");if(-1!==s){t.substring(3,s+3).replace(/\r/g,"").split("\n").forEach((t=>{if(!t.trim())return;const s=t.indexOf(":");if(-1!==s){const i=t.substring(0,s).trim();e[i]=t.substring(s+1).trim(),e[i]=e[i].replace(/^['"]|['"]$/g,""),"true"===e[i]?e[i]=!0:"false"===e[i]?e[i]=!1:parseFloat(e[i]).toString()===e[i]&&(e[i]=parseFloat(e[i]))}else e[t.trim()]=!0})),t=t.substring(s+7)}}return{header:e,body:t}}static MDremoveDocsify(t){const e=t.match(/{docsify-[^}]*}/g);return e&&e.forEach((e=>t=t.replace(e,""))),t}static generateFile(t,e){const s=document.createElement("a");s.setAttribute("href",`data:application/json;charset=utf-8,${encodeURIComponent(JSON.stringify(e,null,2))}`),s.setAttribute("download",t),s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s)}static quality2text(t){const e=4294901760&t,s=f[t];let i;return i=s?[s]:1&t?[f[1],`0x${(65534&t).toString(16)}`]:2&t?[f[2],`0x${(65533&t).toString(16)}`]:[`0x${t.toString(16)}`],e&&i.push(`0x${(e>>16).toString(16).toUpperCase()}`),i}static clone(t){return JSON.parse(JSON.stringify(t))}static getStates(t){var e;let s=null===t||void 0===t||null===(e=t.common)||void 0===e?void 0:e.states;if(s)if("string"===typeof s&&"{"===s[0])try{s=JSON.parse(s)}catch{console.error(`Cannot parse states: ${s}`),s=null}else if("string"===typeof s){const t=s.split(";");s={};for(let e=0;e<t.length;e++){const i=t[e].split(":");s[i[0]]=i[1]}}else if(Array.isArray(s)){const e={};return"number"===t.common.type?s.forEach(((t,s)=>e[s]=t)):"string"===t.common.type?s.forEach((t=>e[t]=t)):"boolean"===t.common.type&&(e.false=s[0],e.true=s[1]),e}return s}static getSvg(t){return fetch(t).then((t=>t.blob())).then((t=>new Promise((e=>{const s=new FileReader;s.onload=function(){e(this.result)},s.readAsDataURL(t)}))))}static detectMimeType(t){const e=Object.keys(v).find((e=>t.startsWith(e)));return e?v[e]:null}static isStableRepository(t){return!!("string"===typeof t&&t.toLowerCase().startsWith("stable")||t&&"string"!==typeof t&&t.find((t=>t.toLowerCase().startsWith("stable"))))}static isStringInteger(t){return parseInt(t).toString()===t}static isValidDate(t){return t instanceof Date&&!isNaN(t)}static getStyle(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const a={};for(let o=0;o<s.length;o++)"function"===typeof s[o]?Object.assign(a,s[o](t)):s[o]&&"object"===typeof s[o]&&Object.keys(s[o]).forEach((e=>{if("function"===typeof s[o][e])a[e]=s[o][e](t);else if("object"===typeof s[o][e]){const i=s[o][e];a[e]=a[e]||{},Object.keys(i).forEach((s=>{"function"===typeof i[s]?a[e][s]=i(t):(i[s]||0===i[s])&&(a[e][s]=i[s])}))}else(s[o][e]||0===s[o][e])&&(a[e]=s[o][e])}));return a}}x.namespace=u,x.INSTANCES="instances",x.dateFormat=["DD","MM"],x.FORBIDDEN_CHARS=/[^._\-/ :!#$%&()+=@^{}|~\p{Ll}\p{Lu}\p{Nd}]+/gu;const y=x;function b(t){return"[object Object]"===Object.prototype.toString.call(t)}class C extends i.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=C.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.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=c.I18n.getLanguage()}componentDidMount(){this.props.registerOnForceUpdate&&this.props.registerOnForceUpdate(this.props.attr,this.onUpdate);const t=["select","autocomplete","autocompleteSendTo"];if(void 0!==this.defaultValue){const e=C.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.forceUpdate([this.props.attr],this.props.data)),100))):(C.setValue(this.props.data,this.props.attr,this.defaultValue),this.props.onChange(this.props.data,void 0,(()=>this.props.forceUpdate([this.props.attr],this.props.data))))}),100)}else this.props.schema.defaultSendTo&&this.sendTo()}sendTo(){if(this.props.alive){this.defaultSendToDone=!0;let t=this.props.schema.data;if(void 0===t&&this.props.schema.jsonData){const e=this.getPattern(this.props.schema.jsonData);try{t=JSON.parse(e)}catch{console.error(`Cannot parse json data: ${e}`)}}else t={attr:this.props.attr,value:C.getValue(this.props.data,this.props.attr)};void 0===t&&(t=null),this.props.socket.sendTo(`${this.props.adapterName}.${this.props.instance}`,this.props.schema.defaultSendTo,t).then((t=>{null!==t&&void 0!==t&&(this.props.custom?this.props.onChange(this.props.attr,t,(()=>this.props.forceUpdate([this.props.attr],this.props.data))):(C.setValue(this.props.data,this.props.attr,t),this.props.onChange(this.props.data,void 0,(()=>this.props.forceUpdate([this.props.attr],this.props.data)))))}))}else this.defaultSendToDone=!1,this.props.schema.allowSaveWithError||this.onError(this.props.attr,c.I18n.t("ra_Instance %s is not alive",this.props.instance.toString()))}componentWillUnmount(){this.props.registerOnForceUpdate&&this.props.registerOnForceUpdate(this.props.attr),this.sendToTimeout&&(clearTimeout(this.sendToTimeout),this.sendToTimeout=null)}static getValue(t,e){if("string"===typeof e)return C.getValue(t,e.split("."));if(1===e.length)return t[e[0]];const s=e.shift();return"string"===typeof s&&"object"===typeof t[s]?C.getValue(t[s],e):null}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]||{}),C.setValue(t[i],e,s)}else C.setValue(t,e.split("."),s)}getText(t,e){if(!t)return"";if("string"===typeof t){const s=e?t:c.I18n.t(t);return s.includes("${")?this.getPattern(s):s}return b(t)?t.func?"object"===typeof t.func?this.getPattern(t.func[this.lang]||t.func.en||""):this.getPattern(t.func):t[this.lang]||t.en||"":t.toString()}renderConfirmDialog(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,d.jsx)(p.Warning,{}):"error"===t.type?e=(0,d.jsx)(p.Error,{}):"info"===t.type&&(e=(0,d.jsx)(p.Info,{})),(0,d.jsx)(c.Confirm,{title:this.getText(t.title)||c.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||c.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||c.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&&C.setValue(t,this.state.confirmDepAttr,this.state.confirmDepNewValue),C.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,d.jsx)(p.Key,{}):"send"===t?e=(0,d.jsx)(p.Send,{}):"web"===t?e=(0,d.jsx)(p.Public,{}):"warning"===t?e=(0,d.jsx)(p.Warning,{}):"error"===t?e=(0,d.jsx)(p.Error,{}):"info"===t?e=(0,d.jsx)(p.Info,{}):"search"===t?e=(0,d.jsx)(p.Search,{}):"book"===t?e=(0,d.jsx)(p.MenuBook,{}):"help"===t?e=(0,d.jsx)(p.Help,{}):"upload"===t?e=(0,d.jsx)(p.UploadFile,{}):"edit"===t?e=(0,d.jsx)(p.Edit,{}):"user"===t?e=(0,d.jsx)(p.Person,{}):"group"===t?e=(0,d.jsx)(p.Group,{}):"delete"===t?e=(0,d.jsx)(p.Delete,{}):"refresh"===t?e=(0,d.jsx)(p.Refresh,{}):"add"===t?e=(0,d.jsx)(p.Add,{}):"unpair"===t?e=(0,d.jsx)(p.LinkOff,{}):"pair"===t?e=(0,d.jsx)(p.Link,{}):"save"===t?e=(0,d.jsx)(p.Save,{}):"open"===t?e=(0,d.jsx)(p.OpenInNew,{}):t&&((t.endsWith(".png")||t.endsWith(".svg")||t.endsWith(".jpg"))&&(t.startsWith("http://")||t.startsWith("https://")||(t=`./adapter/${this.props.adapterName}/${t}`)),e=(0,d.jsx)(c.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: ${t}`)))}))}onChange(t,e,s){const i=JSON.parse(JSON.stringify(this.props.data));if(C.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 o=0;o<this.props.schema.confirmDependsOn.length;o++){const a=this.props.schema.confirmDependsOn[o];if(a.confirm){const o=C.getValue(i,a.attr);if(this.execute(a.confirm.condition,!1,i,this.props.arrayIndex,this.props.globalData))return new Promise((i=>{this.setState({confirmDialog:!0,confirmNewValue:e,confirmAttr:t,confirmDepNewValue:o,confirmDepAttr:a.attr,confirmData:a.confirm},(()=>{"function"===typeof s?s():i()}))}))}}const a=[];if(this.props.schema.onChangeDependsOn)for(let o=0;o<this.props.schema.onChangeDependsOn.length;o++){const t=this.props.schema.onChangeDependsOn[o];if(t.onChange){const e=C.getValue(i,t.attr);let s;s=this.props.custom?this.executeCustom(t.onChange.calculateFunc,i,this.props.customObj,this.props.instanceObj,this.props.arrayIndex,this.props.globalData):this.execute(t.onChange.calculateFunc,e,i,this.props.arrayIndex,this.props.globalData),s!==e&&(C.setValue(i,t.attr,s),a.push(t.attr))}}if(this.props.schema.hiddenDependsOn)for(let o=0;o<this.props.schema.hiddenDependsOn.length;o++){const t=this.props.schema.hiddenDependsOn[o];t.hidden&&a.push(t.attr)}if(this.props.schema.labelDependsOn)for(let o=0;o<this.props.schema.labelDependsOn.length;o++){const t=this.props.schema.labelDependsOn[o];t.hidden&&a.push(t.attr)}if(this.props.schema.helpDependsOn)for(let o=0;o<this.props.schema.helpDependsOn.length;o++){const t=this.props.schema.helpDependsOn[o];t.hidden&&a.push(t.attr)}if(this.props.schema.onChange&&!this.props.schema.onChange.ignoreOwnChanges){const t=C.getValue(i,this.props.attr),e=this.props.custom?this.executeCustom(this.props.schema.onChange.calculateFunc,i,this.props.customObj,this.props.instanceObj,this.props.arrayIndex,this.props.globalData):this.execute(this.props.schema.onChange.calculateFunc,t,i,this.props.arrayIndex,this.props.globalData);e!==t&&C.setValue(i,this.props.attr,e)}return this.props.custom?(this.props.onChange(t,e,(()=>s&&s())),null!==a&&void 0!==a&&a.length&&a.forEach(((t,e)=>setTimeout((()=>this.props.onChange(t,C.getValue(i,t))),50*e)))):this.props.onChange(i,void 0,(()=>{a.length&&this.props.forceUpdate(a,i),s&&s()})),Promise.resolve()}execute(t,e,s,i,a){let o;if(b(t))o=t.func;else{if("string"!==typeof t)return t;o=t}if(!o)return e;try{return new Function("data","originalData","_system","_alive","_common","_socket","_instance","arrayIndex","globalData","_changed",o.includes("return")?o:`return ${o}`)(s||this.props.data,this.props.originalData,this.props.systemConfig,this.props.alive,this.props.common,this.props.socket,this.props.instance,i,a,this.props.changed)}catch(n){return console.error(`Cannot execute ${JSON.stringify(t)}: ${n}`),e}}executeCustom(t,e,s,i,a,o){let n;if(b(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 ${n}`)(e||this.props.data,this.props.originalData,this.props.systemConfig,i,s,this.props.socket,a,o,this.props.changed)}catch(r){return console.error(`Cannot execute ${n}: ${r}`),null}}calculate(t){let e,s,i,a;return this.props.custom?(e=!!t.validator&&!this.executeCustom(t.validator,this.props.data,this.props.customObj,this.props.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.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.instanceObj,this.props.arrayIndex,this.props.globalData),a=t.defaultFunc?this.executeCustom(t.defaultFunc,this.props.data,this.props.customObj,this.props.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),a=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:a}}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,d.jsx)("a",{href:e,target:"_blank",rel:"noreferrer",style:{color:"dark"===this.props.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>"))?c.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=C.getValue(e,s.replace(/^data\./,""));if("string"===typeof t&&t.includes('"'))return`\${${s}.replace(/"/g, '\\\\"')}`}return t}))}getPattern(t,e){if(e=e||this.props.data,!t)return"";let s;"object"===typeof t?t.func?s=t.func:(console.log(`Object must be stringified: ${JSON.stringify(t)}`),s=JSON.stringify(t)):s=t;try{if(this.props.custom){return new Function("data","originalData","arrayIndex","globalData","_system","instanceObj","customObj","_socket","_changed",`return \`${C.escapeString(s,e)}\``)(e,this.props.originalData,this.props.arrayIndex,this.props.globalData,this.props.systemConfig,this.props.instanceObj,this.props.customObj,this.props.socket,this.props.changed)}return new Function("data","originalData","arrayIndex","globalData","_system","_alive","_common","_socket","_changed",`return \`${C.escapeString(s,e)}\``)(e,this.props.originalData,this.props.arrayIndex,this.props.globalData,this.props.systemConfig,this.props.alive,this.props.common,this.props.socket,this.props.changed)}catch(i){return console.error(`Cannot execute ${s}: ${i}`),s}}render(){const t=this.props.schema;if(!t)return null;this.props.alive&&!1===this.defaultSendToDone&&(this.sendToTimeout=setTimeout((()=>{this.sendToTimeout=null,this.sendTo()}),200));const{error:e,disabled:s,hidden:i,defaultValue:a}=this.calculate(t);if(i){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,d.jsx)(h.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},style:{marginBottom:0,textAlign:"left",...t.style,..."dark"===this.props.themeType?t.darkStyle:{}}});return t.newLine?(0,d.jsxs)(d.Fragment,{children:[(0,d.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||c.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 o=this.renderItem(e,s||this.props.commandRunning||this.props.disabled,a);if(this.noPlaceRequired)return o;const n=(0,d.jsx)(h.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},style:{marginBottom:0,textAlign:"left",width:"divider"===t.type||"header"===t.type?t.width||"100%":void 0,...t.style,..."dark"===this.props.themeType?t.darkStyle:{}},children:this.props.schema.defaultSendTo&&this.props.schema.button?(0,d.jsxs)(h.Grid2,{container:!0,style:{width:"100%"},children:[(0,d.jsx)(h.Grid2,{flex:1,children:o}),(0,d.jsx)(h.Grid2,{children:(0,d.jsx)(h.Button,{variant:"outlined",onClick:()=>this.sendTo(),title:this.props.schema.buttonTooltip?this.getText(this.props.schema.buttonTooltip,this.props.schema.buttonTooltipNoTranslation):c.I18n.t("ra_Request data by instance"),children:this.getText(this.props.schema.button)})})]}):o});return t.newLine?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{flexBasis:"100%",height:0}}),this.renderConfirmDialog(),n]}):this.state.confirmDialog?(0,d.jsxs)(d.Fragment,{children:[this.renderConfirmDialog(),n]}):n}}C.DIFFERENT_VALUE="__different__",C.DIFFERENT_LABEL="ra___different__",C.NONE_VALUE="",C.NONE_LABEL="ra_none";const j={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 w=class extends C{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 a=i.match(/(\d+)$/);for(a?(i=i.replace(a[0],""),t=parseInt(a[0],10)+1):i+="_";e.find((e=>e[this.props.schema.clone]===i+t.toString()));)t++;s[this.props.schema.clone]=`${s[this.props.schema.clone]}_${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.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=C.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,a={type:"panel",items:i.items.reduce(((t,e)=>(t[e.attr]=e,t)),{}),style:{marginLeft:"-8px",marginTop:"10px",marginBottom:"10px"}};return(0,d.jsx)(We,{index:e+this.state.iteration,arrayIndex:e,changed:this.props.changed,globalData:this.props.data,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,alive:this.props.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:t,custom:!0,schema:a,systemConfig:this.props.systemConfig,originalData:this.props.originalData,customs:this.props.customs,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,forceUpdate:this.props.forceUpdate,imagePrefix:this.props.imagePrefix,onCommandRunning:this.props.onCommandRunning,onChange:(t,i)=>{const a=JSON.parse(JSON.stringify(s));a[e][t]=i,this.setState({value:a},(()=>this.onChangeWrapper(a)))},onError:(t,e)=>this.onError(t,e),onBackEndCommand:this.props.onBackEndCommand,table:this.props.table,DeviceManager:this.props.DeviceManager,theme:this.props.theme})}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,d.jsxs)(h.Paper,{children:[t.label||!t.noDelete?(0,d.jsxs)(h.Toolbar,{variant:"dense",children:[t.label?(0,d.jsx)(h.Typography,{variant:"h6",id:"tableTitle",component:"div",children:this.getText(t.label)}):null,t.noDelete?null:(0,d.jsx)(h.IconButton,{size:"small",color:"primary",onClick:this.onAdd,children:(0,d.jsx)(p.Add,{})})]}):null,e.map(((s,i)=>(0,d.jsxs)(h.Accordion,{expanded:this.state.activeIndex===i,onChange:(t,e)=>this.setState({activeIndex:e?i:-1}),children:[(0,d.jsx)(h.AccordionSummary,{expandIcon:(0,d.jsx)(p.ExpandMore,{}),sx:y.getStyle(this.props.theme,j.fullWidth,j.accordionSummary),children:(0,d.jsx)(h.Typography,{style:j.accordionTitle,children:s[t.titleAttr]})}),(0,d.jsxs)(h.AccordionDetails,{style:{...t.style,...this.props.themeType?t.darkStyle:void 0},children:[this.itemAccordion(e[i],i),(0,d.jsxs)(h.Toolbar,{sx:j.toolbar,children:[i?(0,d.jsx)(h.Tooltip,{title:c.I18n.t("ra_Move up"),slotProps:{popper:{sx:j.tooltip}},children:(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>this.onMoveUp(i),children:(0,d.jsx)(p.ArrowUpward,{})})}):(0,d.jsx)("div",{style:j.buttonEmpty}),i<e.length-1?(0,d.jsx)(h.Tooltip,{title:c.I18n.t("ra_Move down"),slotProps:{popper:{sx:j.tooltip}},children:(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>this.onMoveDown(i),children:(0,d.jsx)(p.ArrowDownward,{})})}):(0,d.jsx)("div",{style:j.buttonEmpty}),t.noDelete?null:(0,d.jsx)(h.Tooltip,{title:c.I18n.t("ra_Delete current row"),slotProps:{popper:{sx:j.tooltip}},children:(0,d.jsx)(h.IconButton,{size:"small",onClick:this.onDelete(i),children:(0,d.jsx)(p.Delete,{})})}),t.clone?(0,d.jsx)(h.Tooltip,{title:c.I18n.t("ra_Clone current row"),slotProps:{popper:{sx:j.tooltip}},children:(0,d.jsx)(h.IconButton,{size:"small",onClick:this.onClone(i),children:(0,d.jsx)(p.ContentCopy,{})})}):null]})]})]},`${s}_${i}`))),!t.noDelete&&e.length>0?(0,d.jsx)(h.Toolbar,{variant:"dense",sx:j.rootTool,children:(0,d.jsx)(h.IconButton,{size:"small",color:"primary",onClick:this.onAdd,children:(0,d.jsx)(p.Add,{})})}):null,t.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]}):null}},S={width:"100%"},I={color:"#a30000"};const T=class extends C{componentDidMount(){super.componentDidMount();const t=this.getInstance();this.props.socket.getState(`${t}.alive`).then((e=>this.setState({alive:!(!e||!e.val),instance:t})))}getInstance(){let t=this.props.schema.instance||`${this.props.adapterName}.${this.props.instance}`;return t.includes("${")&&(t=this.getPattern(t)),t&&!t.startsWith("system.adapter.")&&(t=`system.adapter.${t}`),t}renderItem(){if(this.getInstance()!==this.state.instance&&setTimeout((()=>{const t=this.getInstance();t?this.props.socket.getState(`${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,d.jsx)("div",{style:{...S,...this.state.alive?void 0:I},children:this.state.alive?void 0!==this.props.schema.textAlive?this.props.schema.textAlive?c.I18n.t(this.props.schema.textAlive,t):"":c.I18n.t("ra_Instance %s is alive",t):void 0!==this.props.schema.textNotAlive?this.props.schema.textNotAlive?c.I18n.t(this.props.schema.textNotAlive,t):"":c.I18n.t("ra_Instance %s is not alive",t)})}};const D=class extends C{componentDidMount(){super.componentDidMount();const t=C.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:c.I18n.t(C.DIFFERENT_LABEL),value:C.DIFFERENT_VALUE}),this.setState({value:C.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}renderItem(t,e){if(!this.state.selectOptions)return null;let s;const i=JSON.parse(JSON.stringify(this.state.selectOptions));return Array.isArray(this.state.value)||this.state.value===C.DIFFERENT_VALUE?([...this.state.value].filter((t=>!i.find((e=>"object"===typeof e?e.value===t:e===t)))).forEach((t=>i.push({label:t.toString(),value:t}))),s={label:c.I18n.t(C.DIFFERENT_LABEL),value:C.DIFFERENT_VALUE},i.unshift(s)):(s=null!==this.state.value&&void 0!==this.state.value&&i.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},i.push(s))),(0,d.jsx)(h.Autocomplete,{fullWidth:!0,freeSolo:!!this.props.schema.freeSolo,value:s,options:i,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,d.jsx)(h.TextField,{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 O=class extends C{constructor(){super(...arguments),this.initialized=!1,this._context=void 0}askInstance(){const t=C.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 s=this.props.schema.data;if(void 0===s&&this.props.schema.jsonData){const t=this.getPattern(this.props.schema.jsonData);try{"string"===typeof t&&(s=JSON.parse(t))}catch{console.error(`Cannot parse json data: ${JSON.stringify(s)}`)}}void 0===s&&(s=null),this.props.socket.sendTo(`${this.props.adapterName}.${this.props.instance}`,this.props.schema.command||"send",s).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:c.I18n.t(C.DIFFERENT_LABEL),value:C.DIFFERENT_VALUE}),this.setState({value:C.DIFFERENT_VALUE,selectOptions:e})):this.setState({value:t,selectOptions:e})}))}else Array.isArray(t)?(e.unshift({label:c.I18n.t(C.DIFFERENT_LABEL),value:C.DIFFERENT_VALUE}),this.setState({value:C.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]=C.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(t,e){if(this.props.alive){const t=this.getContext();t===this._context&&this.initialized||(this._context=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}let s;const i=this.state.selectOptions?JSON.parse(JSON.stringify(this.state.selectOptions)):[];return Array.isArray(this.state.value)||this.state.value===C.DIFFERENT_LABEL?([...this.state.value].filter((t=>!i.find((e=>e.value===t)))).forEach((t=>i.push({label:t.toString(),value:t}))),s={label:c.I18n.t(C.DIFFERENT_LABEL),value:C.DIFFERENT_VALUE},i.unshift(s)):(s=null!==this.state.value&&void 0!==this.state.value&&i.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},i.push(s)),s=s||null),i.length?(0,d.jsx)(h.Autocomplete,{value:s,fullWidth:!0,freeSolo:!!this.props.schema.freeSolo,options:i,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,d.jsx)(h.TextField,{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,d.jsx)(h.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)})}},k={fullWidth:{width:"100%"},flex:{display:"flex"},button:{height:48,marginLeft:4,minWidth:48}};const N=class extends C{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=C.getValue(t,e)||"";this.setState({value:s,showDialog:!1})}renderItem(t,e){const{schema:s,attr:i}=this.props,{value:a,showDialog:o}=this.state;return(0,d.jsxs)(h.FormControl,{style:k.fullWidth,variant:"standard",children:[s.label?(0,d.jsx)(h.InputLabel,{shrink:!0,children:this.getText(s.label)}):null,(0,d.jsxs)("div",{style:k.flex,children:[(0,d.jsx)(h.TextField,{variant:"standard",fullWidth:!0,value:null!==a&&void 0!==a?a:"",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,d.jsx)(h.Button,{color:"grey",style:k.button,size:"small",variant:"outlined",onClick:()=>this.setState({showDialog:!0}),children:"..."})]}),o?(0,d.jsx)(c.Cron,{title:c.I18n.t("ra_Define schedule"),simple:s.simple,complex:s.complex,cron:a,onClose:()=>this.setState({showDialog:!1}),cancel:c.I18n.t("ra_Cancel"),ok:c.I18n.t("ra_Ok"),theme:this.props.theme,onOk:t=>this.setState({showDialog:!1,value:t},(()=>this.onChange(i,t)))}):null]})}};const _=class extends C{async componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr),e=(await this.props.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:c.I18n.t(C.NONE_LABEL),value:C.NONE_VALUE}),this.setState({value:t,selectOptions:e})}renderItem(t,e){var s,i;if(!this.state.selectOptions)return null;const a=null===(s=this.state.selectOptions)||void 0===s?void 0:s.find((t=>t.value===this.state.value));return(0,d.jsxs)(h.FormControl,{style:{width:"100%"},variant:"standard",children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:this.state.value,renderValue:()=>this.getText(null===a||void 0===a?void 0:a.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,d.jsx)(h.MenuItem,{value:t.value,style:t.value===C.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label,!1!==this.props.schema.noTranslation)},t.value)))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},F={fullWidth:{width:"100%"},leWidth:{width:620,marginBottom:10},certWidth:{width:200,marginRight:10}};const $=class extends C{async componentDidMount(){var t;super.componentDidMount();const e=await this.props.socket.getCertificates(),s=[],i=[],a=[];let o=[];const n=await this.props.socket.getObject("system.certificates");o=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})),a.push({label:t.name,value:t.name}))})),s.unshift({label:c.I18n.t(C.NONE_LABEL),value:C.NONE_VALUE}),i.unshift({label:c.I18n.t(C.NONE_LABEL),value:C.NONE_VALUE}),a.unshift({label:c.I18n.t(C.NONE_LABEL),value:C.NONE_VALUE}),this.setState({certsPublicOptions:s,certsChainOptions:a,certsPrivateOptions:i,collectionsOptions:o})}renderItem(t,e){var s,i,a,o,n,r,l;if(!this.state.certsPublicOptions||!this.state.certsPrivateOptions||!this.state.certsChainOptions)return null;const p=(C.getValue(this.props.data,this.props.schema.leCollectionName||"leCollection")||"false").toString(),u=C.getValue(this.props.data,this.props.schema.certPublicName||"certPublic"),m=C.getValue(this.props.data,this.props.schema.certPrivateName||"certPrivate"),g=C.getValue(this.props.data,this.props.schema.certChainedName||"certChained"),f=null===(s=this.state.certsPublicOptions)||void 0===s?void 0:s.find((t=>t.value===u)),v=null===(i=this.state.certsPrivateOptions)||void 0===i?void 0:i.find((t=>t.value===m)),x=null===(a=this.state.certsChainOptions)||void 0===a?void 0:a.find((t=>t.value===g));return(0,d.jsxs)("div",{style:F.fullWidth,children:[this.state.collectionsOptions?(0,d.jsxs)(h.FormControl,{style:F.leWidth,variant:"standard",children:[(0,d.jsx)(h.InputLabel,{shrink:!0,children:"Let's encrypt"}),(0,d.jsxs)(h.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:p,onChange:t=>this.onChange(this.props.schema.leCollectionName||"leCollection","false"!==t.target.value&&("true"===t.target.value||t.target.value)),children:[(0,d.jsx)(h.MenuItem,{value:"false",style:{fontWeight:"bold"},children:c.I18n.t("ra_Do not use let's encrypt")},"_false"),(0,d.jsx)(h.MenuItem,{value:"true",style:{fontWeight:"bold"},children:c.I18n.t("ra_Use all available let's encrypt certificates")},"_true"),null===(o=this.state.collectionsOptions)||void 0===o?void 0:o.map((t=>(0,d.jsx)(h.MenuItem,{value:t,children:t},t)))]})]}):null,this.state.collectionsOptions?(0,d.jsx)("br",{}):null,this.state.collectionsOptions&&"false"!==p?(0,d.jsx)("div",{children:c.I18n.t("ra_Fallback custom certificates")}):null,(0,d.jsxs)(h.FormControl,{style:F.certWidth,variant:"standard",children:[(0,d.jsx)(h.InputLabel,{shrink:!0,children:c.I18n.t("ra_Public certificate")}),(0,d.jsx)(h.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:u||"",renderValue:()=>this.getText(null===f||void 0===f?void 0:f.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,d.jsx)(h.MenuItem,{value:t.value,style:t.value===C.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},`${t.value}_${e}`)))})]}),(0,d.jsxs)(h.FormControl,{style:F.certWidth,variant:"standard",children:[(0,d.jsx)(h.InputLabel,{shrink:!0,children:c.I18n.t("ra_Private certificate")}),(0,d.jsx)(h.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:m||"",renderValue:()=>this.getText(null===v||void 0===v?void 0:v.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,d.jsx)(h.MenuItem,{value:t.value,style:t.value===C.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},`${t.value}_${e}`)))})]}),(0,d.jsxs)(h.FormControl,{style:F.certWidth,variant:"standard",children:[(0,d.jsx)(h.InputLabel,{shrink:!0,children:c.I18n.t("ra_Chained certificate")}),(0,d.jsx)(h.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:g||"",renderValue:()=>this.getText(null===x||void 0===x?void 0:x.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,d.jsx)(h.MenuItem,{value:t.value,style:t.value===C.NONE_VALUE?{opacity:.5}:{},children:this.getText(t.label)},`${t.value}_${e}`)))})]})]})}};const E=class extends C{async componentDidMount(){var t;let e;super.componentDidMount();const s=await this.props.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=(C.getValue(this.props.data,this.props.schema.leCollectionName||"leCollection")||"false").toString();return(0,d.jsxs)(h.FormControl,{style:{width:"100%"},variant:"standard",children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,d.jsxs)(h.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,d.jsx)(h.MenuItem,{value:"false",style:{fontWeight:"bold"},children:c.I18n.t("ra_Do not use let's encrypt")},"_false"),(0,d.jsx)(h.MenuItem,{value:"true",style:{fontWeight:"bold"},children:c.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,d.jsx)(h.MenuItem,{value:t,children:t},t)))]}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},L={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 C{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,d.jsx)("div",{children:t},"error")],t.push((0,d.jsx)(h.Button,{variant:"contained",onClick:()=>window.open("https://iobroker.net/www/account/licenses","_blank"),children:c.I18n.t("iobroker.net")},"button")),this.state.allLicenses.length?t.push((0,d.jsx)(h.TableContainer,{children:(0,d.jsxs)(h.Table,{size:"small",children:[(0,d.jsx)(h.TableHead,{children:(0,d.jsxs)(h.TableRow,{children:[(0,d.jsx)(h.TableCell,{children:c.I18n.t("ra_Product")}),(0,d.jsx)(h.TableCell,{children:c.I18n.t("ra_Version")}),(0,d.jsx)(h.TableCell,{children:"UUID"}),(0,d.jsx)(h.TableCell,{children:c.I18n.t("ra_ValidTill")}),(0,d.jsx)(h.TableCell,{children:c.I18n.t("ra_Commercial")}),(0,d.jsx)(h.TableCell,{children:"ID"})]})}),(0,d.jsx)(h.TableBody,{children:this.state.allLicenses.map((t=>(0,d.jsxs)(h.TableRow,{children:[(0,d.jsx)(h.TableCell,{sx:t.validName?null:L.errorText,children:t.license.product}),(0,d.jsx)(h.TableCell,{sx:t.validVersion?null:L.errorText,children:t.license.version}),(0,d.jsx)(h.TableCell,{sx:t.validUuid?null:L.errorText,children:t.license.uuid||"--"}),(0,d.jsx)(h.TableCell,{sx:t.validTill?null:L.errorText,children:t.license.validTill&&"0000-00-00 00:00:00"!==t.license.validTill?new Date(t.license.validTill).toLocaleDateString():"--"}),(0,d.jsx)(h.TableCell,{children:"free"!==t.license.invoice?"MANUALLY_CREATED"===t.license.invoice?"\u2713":t.license.invoice:"-"}),(0,d.jsx)(h.TableCell,{children:t.id})]},t.id)))})]})},"table")):(t.push((0,d.jsx)("div",{children:c.I18n.t("ra_No one license found in license manager")},"text1")),t.push((0,d.jsx)("div",{children:c.I18n.t("ra_Please create license")},"text2")))),(0,d.jsxs)(h.Dialog,{open:!0,maxWidth:"xl",fullWidth:void 0===this.props.fullWidth||this.props.fullWidth,onClick:()=>this.setState({_error:"",allLicenses:null}),children:[(0,d.jsx)(h.DialogTitle,{children:c.I18n.t("ra_Error")}),(0,d.jsx)(h.DialogContent,{children:(0,d.jsx)(h.DialogContentText,{children:t})}),(0,d.jsx)(h.DialogActions,{children:(0,d.jsx)(h.Button,{variant:"contained",onClick:()=>this.setState({_error:"",allLicenses:null}),color:"primary",autoFocus:!0,startIcon:(0,d.jsx)(p.Check,{}),children:c.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,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:L.licLabel,children:[e,":"]}),JSON.stringify(i[e],null,2)]},e)):t.push((0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:L.licLabel,children:[s," -",e,":"]}),i[e].toString()]},e)))}))}else t.push((0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:L.licLabel,children:[s.replace(/_/g," "),":"]}),e[s].toString()]},s))})),t.push((0,d.jsxs)("div",{children:[(0,d.jsxs)("div",{style:L.licLabel,children:[c.I18n.t("ra_Checked"),":"]}),this.state.licenseOfflineCheck?c.I18n.t("ra_locally"):c.I18n.t("ra_via internet")]},"checked")),(0,d.jsxs)(h.Dialog,{open:!0,onClose:()=>this.setState({showLicenseData:null}),children:[(0,d.jsx)(h.DialogTitle,{children:(0,d.jsx)(h.Box,{component:"span",sx:this.state.result?L.okTitle:L.errorTitle,children:c.I18n.t("ra_License %s",this.state.result?"OK":"INVALID")})}),(0,d.jsxs)(h.DialogContent,{children:[this.state.showLinkToProfile?(0,d.jsx)(h.Button,{variant:"contained",onClick:()=>window.open("https://iobroker.net/www/account/licenses","_blank"),children:"https://iobroker.net"}):null,this.state._error?(0,d.jsx)(h.Box,{component:"div",sx:L.errorText,children:this.state._error}):null,t]}),(0,d.jsx)(h.DialogActions,{children:(0,d.jsx)(h.Button,{onClick:()=>this.setState({showLicenseData:null,_error:""}),color:"primary",variant:"contained",children:c.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=>`%${`00${t.charCodeAt(0).toString(16)}`.slice(-2)}`)).join(""));try{return JSON.parse(s)}catch{return null}}static isVersionValid(t,e,s,i){if(!e||!t)return!0;let a=!0;const[o]=t.split(".");return e.startsWith(">=")?a=parseInt(o,10)>=parseInt(e.substring(2,10)):e.startsWith("<=")?a=parseInt(o,10)<=parseInt(e.substring(2,10)):e.startsWith(">")?a=parseInt(o,10)>parseInt(e.substring(1,10)):e.startsWith("<")?a=parseInt(o,10)<parseInt(e.substring(1,10)):e.startsWith("=")?a=parseInt(o,10)===parseInt(e.substring(1,10)):e.startsWith("==")?a=parseInt(o,10)===parseInt(e.substring(2,10)):e.startsWith("===")&&(a=parseInt(o,10)===parseInt(e.substring(3,10))),!0}async findInLicenseManager(t){var e,s;const i=await this.props.socket.getObject("system.licenses"),a=[];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 o;const t=await this.props.socket.getObject("system.meta.uuid");r=null===t||void 0===t||null===(o=t.native)||void 0===o?void 0:o.uuid}if(this.props.schema.version){var n;const e=await this.props.socket.getObject(`system.adapter.${t}`);l=null===e||void 0===e||null===(n=e.common)||void 0===n?void 0:n.version}i.native.licenses.forEach((i=>{const o=!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)&&o&&h&&p&&c&&(e=i),a.push({id:i.id,validName:h,validUuid:p,validVersion:c,validTill:o,license:i})})),e&&(a.find((t=>t.id===e.id)).used=!0)}return a}async checkLicense(t,e){let s,i;if(this.props.schema.uuid){var a;const t=await this.props.socket.getObject("system.meta.uuid");s=null===t||void 0===t||null===(a=t.native)||void 0===a?void 0:a.uuid}if(this.props.schema.version){var o;const t=await this.props.socket.getObject(`system.adapter.${e}`);i=null===t||void 0===t||null===(o=t.common)||void 0===o?void 0:o.version}const n=new AbortController;let r=setTimeout((()=>{r=null,n.abort()}),5e3);try{var l;const a=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 o=await a.text();let h;try{h=JSON.parse(o)}catch{}if(null===(l=h)||void 0===l||!l.error){let a=null;try{a=A.parseJwt(t)}catch{}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:c.I18n.t("ra_License expired on %s",new Date(t).toLocaleString()),licenseOfflineCheck:!1,showLicenseData:a,result:!1,running:!1});const o=(h.name||"").split(".");return o[1]===e||"vis"===o[1]&&"vis-2"===e?s&&!h.uuid&&"vis-2"===e?this.setState({_error:c.I18n.t("ra_License must be converted",h.uuid),showLinkToProfile:!0,licenseOfflineCheck:!1,showLicenseData:a,result:!1,running:!1}):s&&h.uuid&&h.uuid!==s?this.setState({_error:c.I18n.t('ra_Serial number (UUID) "%s" in license is for other device.',h.uuid),licenseOfflineCheck:!1,showLicenseData:a,result:!1,running:!1}):A.isVersionValid(i,h.version,h.invoice,e)?this.setState({licenseOfflineCheck:!1,showLicenseData:a,result:!0,running:!1}):this.setState({_error:c.I18n.t("ra_License is for version %s, but required version is %s",h.version,this.props.schema.version),licenseOfflineCheck:!1,showLicenseData:a,result:!1,running:!1}):this.setState({_error:c.I18n.t('ra_License for other product "%s"',h.name),licenseOfflineCheck:!1,showLicenseData:a,result:!1,running:!1})}throw new Error("ra_Invalid answer from server")}try{const e=A.parseJwt(t),s=c.I18n.t(`ra_${e.error||h.error||"Unknown error"}`).replace(/^ra_/,"");return this.setState({_error:s,licenseOfflineCheck:!1,showLicenseData:e,result:!1,running:!1})}catch{return console.log("Cannot parse license"),this.setState({_error:h.error,result:!1,running:!1})}}catch(p){var h;if(404===(null===p||void 0===p||null===(h=p.response)||void 0===h?void 0:h.status))return this.setState({_error:c.I18n.t("ra_License does not exist"),result:!1,running:!1});try{const a=A.parseJwt(t),o=(a.name||"").split(".");return a.valid_till&&"0000-00-00 00:00:00"!==a.valid_till&&new Date(a.valid_till).getTime()<Date.now()?this.setState({_error:c.I18n.t("ra_License expired on %s",new Date(a.valid_till).toLocaleString()),showLicenseData:a,licenseOfflineCheck:!0,running:!1,result:!1}):o[1]===e?s&&a.uuid&&a.uuid!==s?this.setState({_error:c.I18n.t('ra_Serial number (UUID) "%s" in license is for other device.',a.uuid),showLicenseData:a,licenseOfflineCheck:!0,result:!1,running:!1}):A.isVersionValid(i,a.version,a.invoice,e)?this.setState({running:!1,result:!0,licenseOfflineCheck:!0,showLicenseData:a}):this.setState({_error:c.I18n.t("ra_License is for version %s, but required version is %s",a.version,this.props.schema.version),licenseOfflineCheck:!0,showLicenseData:a,result:!1,running:!1}):this.setState({_error:c.I18n.t('ra_License for other product "%s"',a.name),licenseOfflineCheck:!0,showLicenseData:a,result:!1,running:!1})}catch{return this.setState({_error:c.I18n.t("ra_Cannot decode license"),result:!1,licenseOfflineCheck:!0,running:!1})}}}renderAskForUpdate(){return this.state.askForUpdate?(0,d.jsx)(c.Confirm,{text:c.I18n.t("ra_License not found in license manager. Do you want to read licenses from iobroker.net?"),ok:c.I18n.t("ra_Yes"),onClose:async t=>{if(t){this.setState({askForUpdate:!1});try{await this.props.socket.updateLicenses(null,null)}catch(e){return void window.alert(c.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.adapterName?"vis":this.props.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:c.I18n.t("ra_Suitable license not found in license manager"),result:!1,running:!1,allLicenses:i}):this.setState({_error:c.I18n.t("ra_Please enter the license"),result:!1,running:!1})}renderItem(){return(0,d.jsxs)("div",{style:L.fullWidth,children:[(0,d.jsxs)(h.Button,{variant:this.props.schema.variant||"outlined",color:this.props.schema.color||"primary",style:L.fullWidth,disabled:!this.props.data.license&&!this.props.data.useLicenseManager||this.state.running,startIcon:(0,d.jsx)(p.Send,{}),onClick:()=>this._onClick(),children:[this.state.running?(0,d.jsx)(h.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 V=A;const P=class extends C{renderItem(t,e){const s=C.getValue(this.props.data,this.props.attr),i=Array.isArray(s);return(0,d.jsxs)(h.FormControl,{style:{width:"100%"},variant:"standard",children:[(0,d.jsx)(h.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: ${t}`)))}},control:(0,d.jsx)(h.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: ${t}`)))},disabled:e}),label:this.getText(this.props.schema.label)}),(0,d.jsx)(h.FormHelperText,{style:{color:"red"},children:t?this.props.schema.validatorErrorText?c.I18n.t(this.props.schema.validatorErrorText):c.I18n.t("ra_Error"):null}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};var W=s(32619),U=s.n(W),B=s(48762),M=s(61204);const R={standard:h.Input,filled:B.A,outlined:h.OutlinedInput},J=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 ${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 ${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 ${t.palette.text.primary}`,"@media (hover: none)":{borderBottom:`1px solid ${s}`}},"&$disabled:before":{borderBottomStyle:"dotted"}},error:{"&:after":{backgroundColor:t.palette.error.main,transform:"scaleX(1)"}},chip:{margin:"0 8px 8px 0",float:"left"},marginDense:{}}},z=8,H=46,q=37,K=39,G=(t,e)=>{let{value:s,isFocused:i,isDisabled:a,isReadOnly:o,handleClick:n,handleDelete:r,style:l}=t;return(0,d.jsx)(h.Chip,{style:{...l,pointerEvents:a||o?"none":void 0,backgroundColor:i?M.A[300]:void 0},onClick:n,onDelete:r,label:s},e)};class Y 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 z:""===t.target.value&&(e?(this.handleDeleteChip(s[e],e),e&&this.setState({focusedChip:e-1})):this.setState({focusedChip:s.length-1}));break;case H:""===t.target.value&&e&&(this.handleDeleteChip(s[e],e),e<=s.length-1&&this.setState({focusedChip:e}));break;case q:null===e&&""===t.target.value&&s.length?this.setState({focusedChip:s.length-1}):null!==e&&e>0&&this.setState({focusedChip:e-1});break;case K: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=U().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={...s,focusedChip:null}),!e.chipsUpdated&&t.defaultValue&&(s={...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({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=G,className:s,disabled:i,disableUnderline:a,error:o,FormHelperTextProps:n,fullWidth:r,fullWidthInput:l,helperText:p,id:c,InputProps:u={},InputLabelProps:m={},inputValue:g,label:f,placeholder:v,readOnly:x,required:b,rootRef:C,value:j,margin:w}=this.props,S=this.state.variant;this.styleTheme!==this.props.theme.palette.mode&&(this.styleTheme=this.props.theme.palette.mode,this.styles=y.getStyle(this.props.theme,J));let I=j||this.state.chips||[];Array.isArray(I)||(I=(I||"").toString().split(/[,\s]+/).map((t=>t.trim())));const T=null!==g&&void 0!==g?g:this.state.inputValue,D=(this.props.value||T).length||T.length,O="boolean"===typeof m.shrink?m.shrink:null!==f&&(D||this.state.isFocused||I.length),k=I.map(((t,s)=>e({value:t,isDisabled:!!i,isReadOnly:x,isFocused:this.state.focusedChip===s,handleClick:()=>this.setState({focusedChip:s}),handleDelete:()=>this.handleDeleteChip(t,s),style:this.styles.chip},s.toString()))),N={};"outlined"===S&&(N.notched=!!O,N.labelWidth=O&&this.labelNode&&this.labelNode.offsetWidth||0),"standard"!==S?N.startAdornment=k:u.disableUnderline=!0;const _=R[S];return(0,d.jsxs)(h.FormControl,{ref:C,fullWidth:r,className:s,sx:{...this.styles.root,..."dense"===w?this.styles.marginDense:{}},error:o,required:I.length>0?void 0:b,onClick:this.focus,disabled:i,variant:S,component:"div",margin:w,children:[f&&(0,d.jsx)(h.InputLabel,{htmlFor:c,sx:{"&.MuiInputLabel-root":this.styles.label,"&.MuiInputLabel-shrink":this.styles.labelShrink},shrink:!!O,focused:this.state.isFocused,variant:S,ref:this.labelRef,required:b,component:"label",...m,children:f}),(0,d.jsxs)(h.Box,{component:"div",id:"input-chip-container",sx:{...this.styles[S],...this.styles.chipContainer,...this.state.isFocused?this.styles.focused:void 0,...a||"standard"!==S?void 0:this.styles.underline,...i?this.styles.disabled:void 0,...f?this.styles.labeled:void 0,...o?this.styles.error:void 0},children:["standard"===S&&k,(0,d.jsx)(_,{ref:this.input,className:`mui-variant-${this.styles[S]} ${f?"mui-chip-with-label":"mui-chip-no-label"}`,sx:{"&.MuiInputBase-input":{...this.styles.input,...this.styles[S]},"&.MuiInputBase-root":{...this.styles.inputRoot}},id:c,value:T,onChange:this.handleUpdateInput,onKeyDown:this.handleKeyDown,onKeyUp:this.handleKeyUp,onFocus:this.handleInputFocus,onBlur:this.handleInputBlur,inputRef:this.setActualInputRef,disabled:i,fullWidth:l,placeholder:!D&&(O||null===f||void 0===f)||t?v:null,readOnly:x,...u,...N})]}),p&&(0,d.jsx)(h.FormHelperText,{...n,className:null===n||void 0===n?void 0:n.className,style:this.styles.helperText,children:p})]})}}const Z=Y;const Q=class extends C{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=C.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:a}=this.state;return(0,d.jsxs)(h.FormControl,{fullWidth:!0,variant:"standard",children:[(0,d.jsx)(Z,{value:a,disabled:!!e,label:this.getText(i.label),error:!!t,onAdd:t=>{const e=JSON.parse(JSON.stringify(a));e.push(t),this.setState({value:e},(()=>{let t;t=this.props.schema.delimiter?this.onChange(s,e.join(`${this.props.schema.delimiter} `)):this.onChange(s,e),t instanceof Promise&&t.catch((t=>console.error(t)))}))},theme:this.props.theme,onDelete:(t,e)=>{const i=JSON.parse(JSON.stringify(a));i.splice(e,1),this.setState({value:i},(()=>{let t;t=this.props.schema.delimiter?this.onChange(s,i.join(`${this.props.schema.delimiter} `)):this.onChange(s,i),t instanceof Promise&&t.catch((t=>console.error(t)))}))}}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};var X=s(31428);const tt=class extends C{renderColorDialog(){return!!this.state.showColorDialog&&(0,d.jsx)(h.Dialog,{onClose:()=>this.setState({showColorDialog:!1}),open:this.state.showColorDialog,children:(0,d.jsx)(X.ChromePicker,{color:this.state.colorDialogValue,onChange:t=>this.setState({colorDialogValue:t.hex},(()=>this.onChange(this.props.attr,this.state.colorDialogValue)))})})}renderItem(t,e){const s=C.getValue(this.props.data,this.props.attr);let i=c.Utils.isUseBright(s,null);return null===i&&(i=void 0),(0,d.jsxs)(d.Fragment,{children:[this.renderColorDialog(),(0,d.jsx)(h.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: ${t}`)))},slotProps:{htmlInput:{style:{backgroundColor:s,color:i?"#FFF":"#000"},readOnly:this.props.schema.readOnly||!1},input:{endAdornment:s&&!this.props.schema.noClearButton?(0,d.jsx)(h.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: ${t}`)))},children:(0,d.jsx)(p.Close,{})}):void 0},inputLabel:{shrink:!0}}})]})}},et={width:{width:"calc(100% - 85px)"},width50:{width:120,marginRight:5}};const st=class extends C{componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr);this.setState({value:t});const e={};if(this.props.schema.useSystemName&&(e.useSystem=!!C.getValue(this.props.data,this.props.schema.useSystemName)),this.props.schema.longitudeName&&this.props.schema.latitudeName)e.longitude=C.getValue(this.props.data,this.props.schema.longitudeName),e.latitude=C.getValue(this.props.data,this.props.schema.latitudeName),e.longitude||e.latitude||!this.props.schema.autoInit||setTimeout((()=>this.getCoordinates()),300);else{!C.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.socket.getCompactSystemConfig();if(null!==t&&void 0!==t&&t.common&&(t.common.longitude||t.common.latitude))if(window.alert(c.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: ${t}`)))}))}else window.alert(c.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: ${t}`)))}))}else await this.getSystemCoordinates()}),(async t=>{console.error(`Cannot determine coordinates from browser: ${t.message}`),await this.getSystemCoordinates()})):this.getSystemCoordinates().catch((t=>{console.error(`Cannot determine coordinates: ${t}`)}))}renderItem(t,e){var s,i;return(0,d.jsxs)(d.Fragment,{children:[this.props.schema.useSystemName?(0,d.jsx)(h.FormControlLabel,{control:(0,d.jsx)(h.Checkbox,{checked:!!this.state.useSystem,onChange:t=>{const e=t.target.checked;e&&this.getSystemCoordinates().catch((t=>console.error(`Cannot determine coordinates: ${t}`))),this.setState({useSystem:e},(()=>this.onChange(this.props.schema.useSystemName,e)))}}),label:c.I18n.t("ra_Use system settings for position")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?(0,d.jsx)(h.TextField,{variant:"standard",style:et.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: ${t}`)))}))},label:c.I18n.t("ra_Longitude")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?(0,d.jsx)(h.TextField,{variant:"standard",style:et.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:c.I18n.t("ra_Latitude")}):null,this.props.schema.longitudeName&&this.props.schema.latitudeName?null:(0,d.jsx)(h.TextField,{variant:"standard",style:et.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,d.jsx)(h.Fab,{size:"small",onClick:()=>this.getCoordinates(),title:c.I18n.t("ra_Take browser position"),style:{marginRight:4},children:(0,d.jsx)(p.LocationOn,{})}),this.state.useSystem?null:(0,d.jsx)(h.Fab,{size:"small",onClick:()=>this.getSystemCoordinates(),title:c.I18n.t("ra_Take position from system settings"),children:(0,d.jsx)(p.GpsFixed,{})})]})}};function it(t,e,i,a){return async()=>{const o=await((t,e,i)=>new Promise(((a,o)=>{if(window[t])a(window[t]);else{const n=document.querySelector(`script[data-webpack="${t}"]`),r=async()=>{if(!window[t])return console.error(`Cannot load ${t}`),void o(new Error(`Cannot load ${t}`));window[t].__initialized||(await window[t].init(s.S[e]),window[t].__initialized=!0),a(window[t])};if(n)n.onload=r,n.onerror=o;else if(i){const e=document,s=e.createElement("script");s.type="text/javascript",s.setAttribute("data-webpack",`${t}`),s.async=!0,s.onerror=o,s.onload=r,s.src=i,e.getElementsByTagName("head")[0].appendChild(s)}else o(new Error(`Cannot Find Remote ${t} to inject`))}})))(t,e,a);return(await o.get(i))()}}class at extends C{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("./")?`${window.location.protocol}//${window.location.host}${this.props.schema.url.replace(/^\./,"")}`:`${window.location.protocol}//${window.location.host}/adapter/${this.props.adapterName}/${this.props.schema.url}`;const[e,s,...i]=this.props.schema.name.split("/"),a=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||!a)return void console.error('Invalid format of "name"! Please define "name" as "ConfigCustomBackItUpSet/Components/AdapterExist" in the schema');let o=at.runningLoads[`${t}!${s}`];if(!(o 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 a=c.I18n.getLanguage(),o=`${s}/i18n/${a}.json`;i=fetch(o).then((t=>t.json())).then((t=>c.I18n.extendTranslations(t,a))).catch((t=>{"en"===a?console.log(`Cannot load i18n "${o}": ${t}`):fetch(`${s}/i18n/en.json`).then((t=>t.json())).then((t=>c.I18n.extendTranslations(t,a))).catch((t=>console.log(`Cannot load i18n "${o}": ${t}`)))}))}else if(this.props.schema.i18n&&"object"===typeof this.props.schema.i18n)try{c.I18n.extendTranslations(this.props.schema.i18n)}catch(n){console.error(`Cannot import i18n: ${n}`)}try{console.log(e,s,a),o=it(e,"default",`./${s}`,t)(),i instanceof Promise&&(o=Promise.all([o,i]).then((t=>t[0]))),at.runningLoads[`${t}!${s}`]=o}catch(n){this.setState({error:`Cannot import from ${this.props.schema.url}: ${n}`})}}try{const t=(await o).default;if(null!==t&&void 0!==t&&t[a])this.setState({Component:t[a]});else{const e=Object.keys(t||{});console.error("URL is empty. Cannot load custom component!"),this.setState({error:`Component ${this.props.schema.name} not found in ${this.props.schema.url}. Found: ${e.join(", ")}`})}}catch(n){this.setState({error:`Cannot import from ${this.props.schema.url}: ${n}`})}}render(){const t=this.state.Component;if(!t){const t=this.props.schema||{},e=(0,d.jsx)(h.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},style:{marginBottom:0,textAlign:"left",...t.style,..."dark"===this.props.themeType?t.darkStyle:{}},children:this.state.error?(0,d.jsx)("div",{children:this.state.error}):(0,d.jsx)(h.LinearProgress,{})});return t.newLine?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return(0,d.jsx)(t,{...this.props})}}at.runningLoads={};var ot=s(46567);const nt=class extends C{renderItem(){if(!this.props.schema)return null;if(this.props.DeviceManager){const t=this.props.DeviceManager;return(0,d.jsx)(t,{uploadImagesToInstance:`${this.props.adapterName}.${this.props.instance}`,title:this.getText(this.props.schema.label),socket:this.props.socket,selectedInstance:`${this.props.adapterName}.${this.props.instance}`,themeName:this.props.themeName,themeType:this.props.themeType,isFloatComma:this.props.isFloatComma,dateFormat:this.props.dateFormat})}return(0,d.jsx)("div",{children:"DeviceManager not found"})}};var rt=s(51189),lt=s.n(rt),ht=s(25512);const pt={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}},ct=["jpg","jpeg","svg","png","webp","gif","apng","avif","webp"],dt=["mp3","ogg","wav","aac"],ut=["avi","mp4","mov"],mt=["txt","log","html","htm"],gt=["json","js","ts"];class ft extends C{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.imagePrefix?"./files":this.props.imagePrefix}componentDidMount(){super.componentDidMount(),this.objectID=(this.props.schema.objectID||"0_userdata.0").replace("%INSTANCE%",(this.props.instance||0).toString()),this.path=this.props.schema.upload,this.path&&("/"===this.path?this.path="":this.path.endsWith("/")||(this.path=`${this.path}/`)),this.updateFiles().then((()=>{const t=C.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.socket.readDir(this.objectID,t.replace(/^\//,"")||null);for(let a=0;a<i.length;a++){const o=i[a];if(o.isDir)await this.readFolder(`${t+o.file}/`,e,s);else{let i=!1;if("*.*"===s&&o.file.includes("."))i=!0;else if(s&&"*"!==s)if(".*"===s&&o.file.startsWith("."))i=!0;else{i=new RegExp(`^${s.replace(/\./g,"\\.").replace(/\*/g,".*")}$`).test(o.file)}else i=!0;i&&e.push({name:t+o.file,size:o.stats?c.Utils.formatBytes(o.stats.size):"--"})}}}catch(i){console.error(`Cannot read "${t}": ${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 a=t.substring(0,i+1);await this.readFolder(a,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/${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(c.I18n.t("File is too big. Max %sk allowed. Try use SVG.",Math.round(i/1024)));const a=`data:${t};base64,${btoa(new Uint8Array(s.result).reduce(((t,e)=>t+String.fromCharCode(e)),""))}`;this.props.socket.writeFile64(this.objectID,this.path+e.name,a).then((()=>this.updateFiles())).catch((t=>window.alert(`Cannot upload file: ${t}`)))},s.readAsArrayBuffer(e)}renderDeleteDialog(){return this.state.deleteFile?(0,d.jsx)(c.Confirm,{title:c.I18n.t("ra_Are you sure?"),text:c.I18n.t("ra_File will be deleted"),ok:c.I18n.t("ra_Delete"),cancel:c.I18n.t("ra_Cancel"),onClose:t=>{const e=this.state.deleteFile;this.setState({deleteFile:""},(()=>{t&&this.props.socket.deleteFile(this.objectID,e).then((()=>this.updateFiles())).catch((t=>window.alert(`Cannot delete file: ${t}`)))}))}}):null}static base64ToArrayBuffer(t){const e=window.atob(t),s=e.length,i=new Uint8Array(s);for(let a=0;a<s;a++)i[a]=e.charCodeAt(a);return i.buffer}loadFile(){return this.props.socket.readFile(this.objectID,this.state.value,!0)}play(){this.loadFile().then((t=>{if("undefined"!==typeof AudioContext){const e=new AudioContext,s=ft.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: ${t.message}`)))}}))}getFileIcon(t){return null!==t&&void 0!==t&&t.extension?ct.includes(t.extension)?(0,d.jsx)("div",{style:{...pt.selectedImage,backgroundImage:`url(${this.imagePrefix}/${this.objectID}/${t.value})`,backgroundSize:"contain",backgroundRepeat:"no-repeat"}}):dt.includes(t.extension)?(0,d.jsx)(p.MusicNote,{}):mt.includes(t.extension)?(0,d.jsx)(p.Article,{}):ut.includes(t.extension)?(0,d.jsx)(p.Videocam,{}):gt.includes(t.extension)?(0,d.jsx)(p.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 i=this.state.files.map((t=>({value:t.name,label:this.props.schema.withFolder||1!==s.length?`${t.name}${this.props.schema.noSize?"":`(${t.size})`}`:`${t.name.substring(s[0].length)}`,extension:t.name.toLowerCase().split(".").pop()})));this.props.schema.noNone||i.unshift({label:c.I18n.t("ra_none"),value:""});const a=i.find((t=>t.value===this.state.value));let o=0;this.props.schema.upload&&o++,this.props.schema.refresh&&o++;const n=this.state.value&&(this.state.value.endsWith(".mp3")||this.state.value.endsWith(".ogg")||this.state.value.endsWith(".wav"));n&&o++;const r=(0,d.jsxs)("div",{style:pt.fullWidth,children:[(0,d.jsxs)(h.FormControl,{variant:"standard",style:{width:`calc(100% - ${42*o}px)`},children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>(0,d.jsxs)(d.Fragment,{children:[this.getFileIcon(a),(0,d.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:i.map((t=>(0,d.jsxs)(h.MenuItem,{value:t.value,children:[(0,d.jsx)(h.ListItemIcon,{children:this.getFileIcon(t)}),(0,d.jsx)(h.ListItemText,{children:t.label}),this.props.schema.delete&&a.value?(0,d.jsx)(h.IconButton,{style:pt.deleteButton,size:"small",onClick:()=>this.setState({deleteFile:a.value}),children:(0,d.jsx)(p.Delete,{})}):null]},t.value)))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]}),this.props.schema.refresh&&(0,d.jsx)(h.IconButton,{onClick:()=>this.updateFiles(),children:(0,d.jsx)(p.Refresh,{})}),this.props.schema.upload&&(0,d.jsx)(h.IconButton,{onClick:()=>{var t;return null===(t=this.dropzoneRef.current)||void 0===t?void 0:t.open()},children:(0,d.jsx)(p.UploadFile,{})}),n&&(0,d.jsx)(h.IconButton,{style:{color:"#00FF00"},onClick:()=>this.play(),children:(0,d.jsx)(p.PlayArrow,{})})]});if(!this.props.schema.upload)return(0,d.jsxs)(d.Fragment,{children:[r,this.renderDeleteDialog()]});let l={"*/*":[]};if("image"===this.props.schema.fileTypes?l={"image/*":[".png",".jpg",".svg",".gif",".apng",".avif",".webp"]}:"audio"===this.props.schema.fileTypes?l={"audio/*":[".mp3",".ogg",".wav",".mp4"]}:"text"===this.props.schema.fileTypes&&(l={"text/plain":[".txt"]}),this.props.schema.pattern){const t=this.props.schema.pattern.split("/").pop().toLowerCase().replace(/.*\./,"");l="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"]}:{"*/*":[`.${t}`]}}return(0,d.jsx)(lt(),{ref:this.dropzoneRef,multiple:!1,accept:l,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||c.I18n.t("Cannot upload"))},children:t=>{let{getRootProps:s,getInputProps:i}=t;return(0,d.jsxs)("div",{style:{...pt.uploadDiv,..."dragging"===this.state.uploadFile?pt.uploadDivDragging:void 0,...e?pt.disabledOpacity:void 0},...s(),children:[(0,d.jsx)("input",{...i()}),"dragging"===this.state.uploadFile?(0,d.jsx)("div",{style:{...pt.uploadCenterDiv,...this.state.uploadError?pt.error:void 0},children:(0,d.jsxs)("div",{style:pt.uploadCenterTextAndIcon,children:[(0,d.jsx)(ht.l1U,{style:pt.uploadCenterIcon}),(0,d.jsx)("div",{style:pt.uploadCenterText,children:"dragging"===this.state.uploadFile?c.I18n.t("ra_Drop file here"):c.I18n.t("ra_Place your files here or click here to open the browse dialog")})]})}):null,r,this.renderDeleteDialog()]})}})}}const vt=ft,xt={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}},yt=["jpg","jpeg","svg","png","webp","gif","apng","avif","webp"],bt=["mp3","ogg","wav","aac"],Ct=["avi","mp4","mov"],jt=["txt","log","html","htm"],wt=["json","js","ts"];const St=class extends C{constructor(){super(...arguments),this.imagePrefix="../.."}componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr);this.imagePrefix=void 0===this.props.imagePrefix?"./files":this.props.imagePrefix,this.setState({value:null!==t&&void 0!==t?t:""})}static getDerivedStateFromProps(t,e){const s=C.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.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=vt.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: ${t.message}`)))}}))}getIcon(){const t=this.state.value.split(".").pop().toLowerCase();return yt.includes(t)?(0,d.jsx)("div",{style:{...xt.selectedImage,backgroundImage:`url(${this.imagePrefix}/${this.state.value})`,backgroundSize:"contain",backgroundRepeat:"no-repeat"}}):bt.includes(t)?(0,d.jsx)(h.IconButton,{style:{color:"#00FF00"},onClick:()=>this.play(),children:(0,d.jsx)(p.PlayArrow,{})}):jt.includes(t)?(0,d.jsx)(p.Article,{}):Ct.includes(t)?(0,d.jsx)(p.Videocam,{}):wt.includes(t)?(0,d.jsx)(p.Code,{}):null}renderFileBrowser(){return this.state.showFileBrowser?(0,d.jsx)(c.SelectFile,{imagePrefix:this.props.imagePrefix,socket:this.props.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.theme}):null}renderItem(t,e){const s=this.getIcon();return(0,d.jsxs)("div",{style:xt.fullWidth,children:[s,(0,d.jsx)(h.TextField,{variant:"standard",style:s?xt.fullWidthIcon:xt.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,d.jsx)(h.Button,{variant:"outlined",onClick:()=>this.setState({showFileBrowser:!0}),children:"..."}),this.renderFileBrowser()]})}};const It=class extends C{componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr);this.props.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:c.I18n.t(C.NONE_LABEL),value:C.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,d.jsxs)(h.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>s?s.obj?(0,d.jsx)(c.TextWithIcon,{value:s.obj,themeType:this.props.themeType,lang:c.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,d.jsx)(h.MenuItem,{value:t.value,style:t.value===C.DIFFERENT_VALUE?{opacity:.5}:{},children:t.obj?(0,d.jsx)(c.TextWithIcon,{value:t.obj,themeType:this.props.themeType,lang:c.I18n.getLanguage()}):t.label},t.value)))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const Tt=class extends C{componentDidMount(){super.componentDidMount(),this.props.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 - ${c.I18n.t("ra_Listen on all IPs")}`:"::"===t.address&&(t.name=`[IPv6] :: - ${c.I18n.t("ra_Listen on all IPs")}`)})),this.setState({ips:t})})).catch((t=>console.error(t)))}renderItem(t,e){var s,i;const a=C.getValue(this.props.data,this.props.attr),o=null===(s=this.state.ips)||void 0===s?void 0:s.find((t=>t.address===a));return(0,d.jsxs)(h.FormControl,{fullWidth:!0,variant:"standard",children:[this.state.ips&&this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,this.state.ips?(0,d.jsx)(h.Select,{variant:"standard",error:!!t,disabled:!!e,value:a,renderValue:t=>(null===o||void 0===o?void 0:o.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,d.jsx)(h.MenuItem,{value:t.address,children:t.name},e)))}):(0,d.jsx)(h.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,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const Dt=class extends C{constructor(){super(...arguments),this.initialized=!1,this._context=void 0}componentDidMount(){super.componentDidMount(),this.askInstance()}askInstance(){if(this.props.alive){let t=this.props.schema.data;if(void 0===t&&this.props.schema.jsonData){const e=this.getPattern(this.props.schema.jsonData);if(e)try{t=JSON.parse(e)}catch{console.error(`Cannot parse json data: ${JSON.stringify(t)}`)}}void 0===t&&(t=null),this.props.socket.sendTo(`${this.props.adapterName}.${this.props.instance}`,this.props.schema.command||"send",t).then((t=>this.setState({image:t||""})))}}getContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=C.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(){if(this.props.alive){const t=this.getContext();t===this._context&&this.initialized||(this._context=t,setTimeout((()=>this.askInstance()),this.initialized?300:50),this.initialized=!0)}return void 0===this.state.image?null:(0,d.jsx)("img",{alt:"dynamic content",src:this.state.image,style:{width:this.props.schema.width||"100%",height:this.props.schema.height}})}};const Ot=class extends C{constructor(t){super(t),this.index=void 0,this.index=Date.now()}componentDidMount(){if(super.componentDidMount(),this.props.schema.base64){const t=C.getValue(this.props.data,this.props.attr);this.setState({value:t})}else this.props.socket.fileExists(`${this.props.adapterName}.${this.props.instance}`,this.props.attr).then((t=>t&&this.loadImage()))}_getUrl(t){t&&(this.index=Date.now());let e=`files/${this.props.adapterName}.${this.props.instance}/${this.props.attr}?t=${this.index}`;return"3000"===window.location.port&&(e=`${window.location.protocol}//${window.location.hostname}:8081/${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,d.jsxs)(h.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(c.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: ${t}`)))}else this.props.socket.deleteFile(`${this.props.adapterName}.${this.props.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: ${t}`)))}else t.startsWith("data")&&(t=t.split(",")[1]);this.props.socket.writeFile64(`${this.props.adapterName}.${this.props.instance}`,this.props.attr,t).catch((t=>console.error(t)))}))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},kt={icon:{width:20,height:20,marginRight:4}};const Nt=class extends C{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[c.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:`${s} [${e._id.replace(/^system\.adapter\./,"")}]`,icon:`adapter/${s}/${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=C.NONE_VALUE),t.splice(i,1),e.selectOptions=t,this.setState(e)}}}componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr);let e=this.props.schema.adapter;"_dataSources"===e&&(e=void 0),this.props.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.${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:`${t.common.name} [${t._id.replace(/^system\.adapter\./,"")}]`,icon:`adapter/${t.common.name}/${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:c.I18n.t(C.NONE_LABEL),value:C.NONE_VALUE}),this.props.schema.all&&i.unshift({label:c.I18n.t("sch_all"),value:"*"}),this.setState({value:t||"",selectOptions:i}),await this.props.socket.subscribeObject(`system.adapter.${e?`${e}.`:""}*`,this.onInstancesUpdate)})).catch((t=>console.error(`Cannot get instances: ${t}`)))}componentWillUnmount(){this.props.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,d.jsxs)(h.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{shrink:!0,children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.Select,{variant:"standard",error:!!t,displayEmpty:!0,disabled:!!e,value:this.state.value,renderValue:()=>(0,d.jsxs)("span",{style:{display:"flex"},children:[null!==i&&void 0!==i&&i.icon?(0,d.jsx)("img",{src:`./${i.icon}`,alt:i.value,style:kt.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,d.jsxs)(h.MenuItem,{value:t.value,style:t.value===C.NONE_VALUE?{opacity:.5}:{},children:[t.icon?(0,d.jsx)("img",{src:`./${t.icon}`,alt:t.value,style:kt.icon}):null,this.getText(t.label,!0)]},t.value)))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]},this.props.attr)}},_t={address:{fontSize:"smaller",opacity:.5,marginLeft:8}};const Ft=class extends C{componentDidMount(){super.componentDidMount(),this.props.socket.getObject(`system.host.${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: ${t}`)))}renderItem(t,e){var s,i,a;const o=C.getValue(this.props.data,this.props.attr),n=null===(s=this.state.interfaces)||void 0===s?void 0:s.find((t=>t.value===o));return(0,d.jsxs)(h.FormControl,{fullWidth:!0,variant:"standard",children:[null!==(i=this.state.interfaces)&&void 0!==i&&i.length&&this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,null!==(a=this.state.interfaces)&&void 0!==a&&a.length?(0,d.jsx)(h.Select,{variant:"standard",error:!!t,disabled:!!e,value:o,renderValue:t=>n?(0,d.jsxs)("span",{children:[n.value,(0,d.jsx)("span",{style:_t.address,children:n.address})]}):t,onChange:t=>this.onChange(this.props.attr,t.target.value),children:this.state.interfaces.map(((t,e)=>(0,d.jsx)(h.MenuItem,{value:t.value,children:(0,d.jsxs)("span",{children:[t.value,(0,d.jsx)("span",{style:_t.address,children:t.address})]})},e)))}):(0,d.jsx)(h.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,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},$t={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"}},Et=t=>{let{toggleTranslation:e,noTranslation:s,title:a,fullWidth:o,help:n,maxWidth:r,progress:l,icon:u,applyDisabled:m,applyButton:g,onClose:f,children:v,titleButtonApply:x,titleButtonClose:y,onApply:b,textInput:C,defaultValue:j,overflowHidden:w}=t;const[S,I]=(0,i.useState)(j);(0,i.useEffect)((()=>{I(j)}),[j]);let T=null;return u&&(T=u),(0,d.jsxs)(h.Dialog,{open:!0,maxWidth:r||"md",fullWidth:!!o,disableEscapeKeyDown:!1,onClose:f,sx:{"& .MuiPaper-root":$t.modalDialog},children:[a&&(0,d.jsxs)(h.DialogTitle,{children:[u?(0,d.jsx)(T,{style:$t.titleIcon}):null,a,"en"!==c.I18n.getLanguage()&&e?(0,d.jsx)(h.IconButton,{size:"large",style:{...$t.languageButton,...s?$t.languageButtonActive:{}},onClick:()=>e(),title:c.I18n.t("Disable/Enable translation"),children:(0,d.jsx)(p.Language,{})}):null]}),(0,d.jsxs)(h.DialogContent,{sx:{...w?$t.overflowHidden:{},...$t.content},style:{paddingTop:8},children:[C&&(0,d.jsx)(h.TextField,{autoComplete:"off",fullWidth:!0,autoFocus:!0,variant:"outlined",size:"medium",multiline:!0,value:S,onChange:t=>I(t.target.value)}),v,n?(0,d.jsx)("div",{children:n}):null]}),(0,d.jsxs)(h.DialogActions,{children:[!1!==g&&(0,d.jsx)(h.Button,{startIcon:(0,d.jsx)(p.Check,{}),disabled:l||m&&j===S,onClick:()=>b&&b(C?S:""),variant:"contained",color:"primary",children:c.I18n.t(x||"Ok")}),(0,d.jsx)(h.Button,{color:"grey",onClick:()=>f&&f(),disabled:l,variant:"contained",startIcon:(0,d.jsx)(p.Close,{}),children:c.I18n.t(y||"Cancel")})]})]})};var Lt=s(2091),At=s.n(Lt);s(29953),s(62954),s(35534),s(9607),s(11197);const Vt={jsonError:{border:"1px solid red",minHeight:200},jsonNoError:{border:"1px solid #00000000",minHeight:200}};const Pt=function(t){return(0,d.jsx)(At(),{style:!0===t.error?Vt.jsonError:!1===t.error?Vt.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}})},Wt={fullWidth:{width:"100%"},flex:{display:"flex"},button:{height:48,minWidth:48},wrapper:{width:"calc(100vw - 40px)",height:"calc(100vh - 188px)"}};const Ut=class extends C{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=C.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(){if(!this.state.initialized)return null;const{schema:t,data:e,attr:s}=this.props,{value:i,showSelectId:a}=this.state;return(0,d.jsxs)(h.FormControl,{fullWidth:!0,variant:"standard",children:[(0,d.jsx)("div",{style:Wt.flex,children:(0,d.jsx)(h.Button,{color:"grey",style:Wt.button,size:"small",variant:"outlined",onClick:()=>this.setState({showSelectId:!0}),children:c.I18n.t("ra_JSON editor")})}),a?(0,d.jsx)(Et,{title:this.getText(t.label),overflowHidden:!0,onClose:()=>this.setState({showSelectId:!1,value:C.getValue(e,s)||{}}),onApply:()=>this.setState({showSelectId:!1},(()=>this.onChange(s,i))),children:(0,d.jsx)("div",{style:{...Wt.wrapper,...this.state.jsonError?{}:void 0},children:(0,d.jsx)(Pt,{value:"object"===typeof i?JSON.stringify(i):i,onChange:t=>this.setState({value:t,jsonError:this.validateJson(t)}),name:"ConfigJsonEditor",themeType:this.props.themeType})})}):null,t.help||this.state.jsonError?(0,d.jsx)(h.FormHelperText,{children:this.state.jsonError?c.I18n.t("ra_Invalid JSON"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},Bt=[{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-ch",label:"\u7b80\u4f53\u4e2d\u6587"}];const Mt=class extends C{componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr),e=[...Bt];this.props.schema.system?e.unshift({value:"",label:c.I18n.t("ra_System language")}):e.unshift({value:"",label:c.I18n.t("ra_none")}),this.setState({value:this.props.schema.system?t||"":t||c.I18n.getLanguage(),selectOptions:e})}renderItem(t,e){var s,i;if(!this.state.selectOptions)return null;const a=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,d.jsxs)(h.FormControl,{fullWidth:!0,variant:"standard",children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.Select,{variant:"standard",error:!!t,disabled:e,value:this.state.value||"_",renderValue:()=>this.getText(null===a||void 0===a?void 0:a.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===c.I18n.getLanguage())return;c.I18n.setLanguage(e),this.props.changeLanguage&&this.props.changeLanguage()}else this.props.socket.getSystemConfig().then((t=>{t.common.language!==c.I18n.getLanguage()&&t.common.language&&(c.I18n.setLanguage(t.common.language),this.props.changeLanguage&&this.props.changeLanguage())})).catch((t=>console.error(`Cannot read system config: ${t}`)))}))},children:null===(i=this.state.selectOptions)||void 0===i?void 0:i.map((t=>(0,d.jsx)(h.MenuItem,{value:t.value,children:t.label},t.value)))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const Rt=class extends C{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(),C.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(){return this.state.showLicenseDialog?(0,d.jsxs)(h.Dialog,{maxWidth:"lg",open:!0,onClose:(t,e)=>{"escapeKeyDown"!==e&&"backdropClick"!==e&&this.setState({showLicenseDialog:!1})},children:[(0,d.jsx)(h.DialogTitle,{children:this.props.schema.title?c.I18n.t(this.props.schema.title):c.I18n.t("ra_License agreement")}),(0,d.jsxs)(h.DialogContent,{children:[this.props.schema.licenseUrl?(0,d.jsxs)(d.Fragment,{children:[this.state.loading?(0,d.jsx)(h.LinearProgress,{}):null,(0,d.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,d.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,d.jsx)("p",{children:t},e):(0,d.jsx)("p",{children:c.I18n.t(t)},e)))}):null]}),(0,d.jsxs)(h.DialogActions,{children:[this.props.schema.checkBox?(0,d.jsx)(h.FormControlLabel,{control:(0,d.jsx)(h.Checkbox,{checked:!!this.state.licenseChecked,onClick:()=>this.setState({licenseChecked:!this.state.licenseChecked})}),label:c.I18n.t(this.props.schema.checkBox)}):null,(0,d.jsx)(h.Button,{disabled: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: ${t}`)))},color:"primary",variant:"contained",startIcon:(0,d.jsx)(p.Check,{}),children:this.props.schema.agreeText?c.I18n.t(this.props.schema.agreeText):c.I18n.t("ra_Accept license")}),(0,d.jsx)(h.Button,{onClick:()=>{this.setState({showLicenseDialog:!1}),setTimeout((()=>this.setState({showLicenseDialog:!0})),2e3)},color:"grey",variant:"contained",startIcon:(0,d.jsx)(p.Close,{}),children:c.I18n.t("ra_Close")})]})]}):null}},Jt={indeterminate:{opacity:.5},control:{flexDirection:"row",width:"100%"}};const zt=class extends C{constructor(){super(...arguments),this.updateTimeout=void 0}componentDidMount(){super.componentDidMount();let t=C.getValue(this.props.data,this.props.attr);if(null!==t&&void 0!==t||(t=""),Array.isArray(t)&&this.props.multiEdit)return t=C.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=C.getValue(t.data,t.attr);return t.multiEdit&&e._value===C.DIFFERENT_VALUE?{_value:C.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===C.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=C.getValue(this.props.data,this.props.attr),i=(null===s||void 0===s?void 0:s.filter((t=>t||0===t)).map((t=>({label:t.toString(),value:t}))))||[];return i.unshift({label:c.I18n.t(C.DIFFERENT_LABEL),value:C.DIFFERENT_VALUE}),(0,d.jsx)(h.Autocomplete,{style:Jt.indeterminate,fullWidth:!0,freeSolo:!0,value:i[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:i,getOptionLabel:t=>t.label,renderInput:s=>(0,d.jsx)(h.TextField,{...s,label:this.getText(this.props.schema.label),variant:"standard",slotProps:{htmlInput:{...s.inputProps,readOnly:this.props.schema.readOnly||!1}},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=c.I18n.t(t)),(0,d.jsx)(h.FormControl,{variant:"standard",style:Jt.control,children:(0,d.jsx)(h.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}},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,c.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)})})}},Ht={flex:{display:"flex"},button:{height:48,marginLeft:4,minWidth:48}};const qt=class extends C{componentDidMount(){super.componentDidMount();const{data:t,attr:e}=this.props,s=C.getValue(t,e)||"";this.setState({value:s,initialized:!0})}renderItem(t,e){if(!this.state.initialized)return null;const{schema:s,socket:i,attr:a}=this.props,{value:o,showSelectId:n}=this.state;return(0,d.jsxs)(h.FormControl,{fullWidth:!0,variant:"standard",children:[s.label?(0,d.jsx)(h.InputLabel,{shrink:!0,children:this.getText(s.label)}):null,(0,d.jsxs)("div",{style:Ht.flex,children:[(0,d.jsx)(h.TextField,{variant:"standard",fullWidth:!0,value: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(a,e)))}}),(0,d.jsx)(h.Button,{color:"grey",style:Ht.button,size:"small",variant:"outlined",onClick:()=>this.setState({showSelectId:!0}),children:"..."})]}),n?(0,d.jsx)(c.SelectID,{imagePrefix:void 0===this.props.imagePrefix?"../..":this.props.imagePrefix,dialogName:`admin.${this.props.adapterName}`,filterFunc:s.filterFunc,themeType:this.props.themeType,theme:this.props.theme,types:s.types?Array.isArray(s.types)?s.types:[s.types]:void 0,customFilter:s.customFilter,filters:s.filters,socket:i,selected:o,root:s.root,onClose:()=>this.setState({showSelectId:!1}),onOk:t=>this.setState({showSelectId:!1,value:t},(()=>this.onChange(a,t)))}):null]})}},Kt={fullWidth:{width:"100%",display:"inline-block"},halfWidth1:{width:"calc(50% - 4px)",display:"inline-block",marginRight:8},halfWidth2:{width:"calc(50% - 4px)",display:"inline-block"}},Gt="____ppp____";const Yt=class extends C{componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr);this.setState({_repeat:t?Gt:"",_visible:!1,value:t?Gt:"",_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,c.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,d.jsx)(h.TextField,{variant:"standard",fullWidth:!0,type:this.state._visible&&this.state.value!==Gt?"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!==Gt&&(this.props.schema.visible||this.props.schema.readOnly)?(0,d.jsx)(h.InputAdornment,{position:"end",children:(0,d.jsx)(h.IconButton,{size:"large",tabIndex:-1,onClick:t=>{t.preventDefault(),t.stopPropagation(),this.setState({_visible:!this.state._visible})},edge:"end",children:this.state._visible?(0,d.jsx)(p.VisibilityOff,{}):(0,d.jsx)(p.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?c.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=(0,d.jsx)(h.TextField,{variant:"standard",fullWidth:!0,type:this.state._visible&&this.state._repeat!==Gt?"text":"password",value:this.state._repeat,error:!!t||this.state._notEqual,disabled:!!e,onChange:t=>this.onChangePassword(void 0,t.target.value),label:`${this.getText(this.props.schema.label)} (${c.I18n.t("ra_repeat")})`,slotProps:{input:{endAdornment:this.state._repeat&&this.state._repeat!==Gt&&this.props.schema.visible?(0,d.jsx)(h.InputAdornment,{position:"end",children:(0,d.jsx)(h.IconButton,{size:"large",tabIndex:-1,onClick:t=>{t.preventDefault(),t.stopPropagation(),this.setState({_visible:!this.state._visible})},edge:"end",children:this.state._visible?(0,d.jsx)(p.VisibilityOff,{}):(0,d.jsx)(p.Visibility,{})})}):void 0,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?c.I18n.t("ra_Passwords are not equal!"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)});return(0,d.jsxs)("div",{style:Kt.fullWidth,children:[(0,d.jsx)("div",{style:Kt.halfWidth1,children:s}),(0,d.jsx)("div",{style:Kt.halfWidth2,children:i})]})}return s}};const Zt=class extends C{renderItem(t,e){return(0,d.jsx)(h.TextField,{variant:"standard",fullWidth:!0,disabled:!!e,slotProps:{input:{endAdornment:this.props.schema.copyToClipboard?(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>{c.Utils.copyToClipboard(this.getPattern(this.props.schema.pattern)),window.alert("Copied")},children:(0,d.jsx)(c.IconCopy,{})}):void 0}},value:this.getPattern(this.props.schema.pattern),label:this.getText(this.props.schema.label),helperText:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},Qt={warning:{"& .Mui-error":{color:"orange"}}};const Xt=class extends C{constructor(){super(...arguments),this.updateTimeout=void 0}async componentDidMount(){super.componentDidMount();let t=C.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.socket.getAdapterInstances(),s=`system.adapter.${this.props.adapterName}.${this.props.instance}`,i=await this.props.socket.getObject(s),a=null===i||void 0===i?void 0:i.common.host,o=[];e.forEach((t=>{var e,i;if(!t||t._id===s||t.common.host!==a)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)o.push({name:`${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&&o.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:o})}static getDerivedStateFromProps(t,e){const s=C.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 a;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=c.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&&(a=!0,t=c.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=c.I18n.t(t)),(0,d.jsx)(h.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:a?Qt.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,c.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 ${this.props.attr}: ${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 te=class extends C{componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr);this.props.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:c.I18n.t(C.NONE_LABEL),value:C.NONE_VALUE}),this.setState({value:t,selectOptions:s})})).catch((t=>console.error(`Cannot get enums: ${t}`)))}renderItem(t,e){if(!this.state.selectOptions)return null;const s=this.state.selectOptions.find((t=>t.value===this.state.value));return(0,d.jsxs)(h.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.Select,{variant:"standard",error:!!t,disabled:!!e,value:this.state.value||"_",renderValue:()=>s?s.obj?(0,d.jsx)(c.TextWithIcon,{value:s.obj,themeType:this.props.themeType,lang:c.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,d.jsx)(h.MenuItem,{value:t.value,style:t.value===C.DIFFERENT_VALUE?{opacity:.5}:{},children:t.obj?(0,d.jsx)(c.TextWithIcon,{value:t.obj,themeType:this.props.themeType,lang:c.I18n.getLanguage()}):t.label},t.value)))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},ee={fullWidth:{width:"100%"},noMargin:{"&>div":{marginTop:0}}};const se=class extends C{constructor(){super(...arguments),this.initialValue=""}componentDidMount(){super.componentDidMount();const t=C.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:c.I18n.t(C.DIFFERENT_LABEL),value:C.DIFFERENT_VALUE}),this.setState({value:C.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.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,d.jsxs)(h.FormControl,{variant:"standard",fullWidth:!0,sx:void 0!==this.props.table&&ee.noMargin,id:`jsonSelect_${this.props.attr}_${this.props.index||0===this.props.index?this.props.index:""}`,children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.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===C.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,d.jsx)(h.ListSubheader,{children:this.getText(t.label,this.props.schema.noTranslation)},e):(0,d.jsx)(h.MenuItem,{value:t.value,style:t.value===C.DIFFERENT_VALUE?{opacity:.5}:{},children:this.getText(t.label,this.props.schema.noTranslation)},e)))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},ie={menuPaper:{maxHeight:800}};const ae=class extends C{constructor(){super(...arguments),this.initialized=!1,this._context=void 0}askInstance(){if(this.props.alive){let t=this.props.schema.data;if(void 0===t&&this.props.schema.jsonData){const e=this.getPattern(this.props.schema.jsonData);try{t=JSON.parse(e)}catch{console.error(`Cannot parse json data: ${e}`)}}void 0===t&&(t=null),this.setState({running:!0},(()=>{this.props.socket.sendTo(`${this.props.adapterName}.${this.props.instance}`,this.props.schema.command||"send",t).then((t=>this.setState({list:t,running:!1}))).catch((t=>{console.error(`Cannot send command: ${t}`)}))}))}else{const t=C.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]=C.getValue(this.props.data,e))),JSON.stringify(t)}_getValue(){let t=null===this.state.value||void 0===this.state.value?C.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._context&&this.initialized||(this._context=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?c.I18n.t("ra_Cannot retrieve options, as instance is offline"):(0,d.jsx)(h.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,d.jsx)(h.InputAdornment,{position:"end",children:(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>this.setState({value:""},(()=>this.onChange(this.props.attr,""))),children:(0,d.jsx)(p.Close,{})})}):null}}});if(this.state.running)return(0,d.jsx)(h.CircularProgress,{size:"24"});const a=this.state.list.filter((t=>!t.hidden||(this.props.custom?!this.executeCustom(t.hidden,this.props.data,this.props.customObj,this.props.instanceObj,this.props.arrayIndex,this.props.globalData):!this.execute(t.hidden,this.props.schema.default,this.props.data,this.props.arrayIndex,this.props.globalData)))),o=a.find((t=>t.value===i));return(0,d.jsxs)(h.FormControl,{variant:"standard",fullWidth:!0,children:[this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.Select,{variant:"standard",error:!!t,multiple:this.props.schema.multiple,disabled:!!e,sx:{"&.MuiSelect-paper":this.props.schema.multiple?ie.menuPaper:void 0},value:i,renderValue:t=>this.props.schema.multiple?(0,d.jsx)(h.Box,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:t.map((t=>{const e=a.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,d.jsx)(h.Chip,{label:s},t)}return null}))}):(null===o||void 0===o?void 0:o.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: ${t}`)))},children:a.map(((t,e)=>(0,d.jsxs)(h.MenuItem,{value:t.value,children:[this.props.schema.multiple?(0,d.jsx)(h.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,d.jsx)(h.ListItemText,{primary:t.label})]},e)))}),this.props.schema.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}},oe={fullWidth:{width:"100%"}};function ne(t){return t.split(".").reduce(((t,e)=>(t<<8)+parseInt(e,10)),0)>>>0}const re=class extends C{async componentDidMount(){super.componentDidMount();let t=window.location.hostname;if(this.props.schema.openUrl){const s=await this.props.socket.getCurrentInstance(),i=await this.props.socket.getObject(`system.adapter.${s}`);if(i){var e;const s=await this.props.socket.getObject(`system.host.${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 a=null===t||void 0===t||null===(s=t.native)||void 0===s||null===(i=s.hardware)||void 0===i?void 0:i.networkInterfaces;if(!a)return null;let o;return Object.keys(a).forEach((t=>a[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]/)?o||("IPv4"===t.family&&e.includes(".")&&(ne(e),ne(t.netmask),ne(t.address),ne(t.netmask)),o=t.address):o=t.address)})))),o||Object.keys(a).forEach((t=>a[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]/)?o||("IPv4"===t.family&&e.includes(".")&&(ne(e),ne(t.netmask),ne(t.address),ne(t.netmask)),o=t.address):o=t.address)})))),o||Object.keys(a).forEach((t=>{a[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]/),o=t.address)}))})),o||Object.keys(a).forEach((t=>{a[t].forEach((t=>{t.internal||(o=t.address)}))})),o}(s,window.location.hostname);if(!e)return void console.warn(`Cannot find suitable IP in host ${i.common.host} for ${i._id}`);t=`${e}:${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,d.jsx)(c.Error,{text:this.state._error,onClose:()=>this.setState({_error:""})}):null}renderMessageDialog(){return this.state._message?(0,d.jsx)(c.Message,{text:this.state._message,onClose:()=>this.setState({_message:""})}):null}_onClick(){this.props.onCommandRunning(!0),this.setState({running:!0});const t=`${window.location.protocol}//${window.location.host}${window.location.pathname.replace(/\/index\.html$/,"")}`,e=`${window.location.protocol}//${this.state.hostname.split(":").length>3?`[${this.state.hostname}]`:this.state.hostname}${window.location.pathname.replace(/\/index\.html$/,"")}`;let s,i=this.props.schema.data;if(void 0===i&&this.props.schema.jsonData){const s=this.getPattern(this.props.schema.jsonData,{_origin:t,_originIp:e,...this.props.data});try{i=JSON.parse(s)}catch{console.error(`Cannot parse json data: ${s}`)}}void 0===i&&(i=null),this.props.schema.openUrl&&!i&&(i={_origin:t,_originIp:e}),this.props.schema.timeout&&(s=setTimeout((()=>{this.props.onCommandRunning(!1),this.setState({_error:c.I18n.t("ra_Request timed out"),running:!1})}),parseInt(this.props.schema.timeout,10)||1e4)),this.props.socket.sendTo(`${this.props.adapterName}.${this.props.instance}`,this.props.schema.command||"send",i).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?c.I18n.t(t.error):c.I18n.t("ra_Error")});else{if(null!==t&&void 0!==t&&t.command)return void(this.props.onBackEndCommand&&this.props.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.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(c.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:c.I18n.t(t.toString())||c.I18n.t("ra_Error")})})).then((()=>{this.props.onCommandRunning(!1),this.setState({running:!1})}))}renderConfirmDialog(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,d.jsx)(p.Warning,{}):"error"===t.type?e=(0,d.jsx)(p.Error,{}):"info"===t.type&&(e=(0,d.jsx)(p.Info,{})),(0,d.jsx)(c.Confirm,{title:this.getText(t.title)||c.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||c.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||c.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,d.jsxs)("div",{style:oe.fullWidth,children:[(0,d.jsxs)(h.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:{...oe.fullWidth,...this.props.schema.controlStyle||void 0},disabled:e||!this.props.alive,startIcon:s,title:this.props.alive?this.getText(this.props.schema.title)||"":c.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,d.jsx)(h.CircularProgress,{size:20,style:{marginRight:8}}):null,this.getText(this.props.schema.label,this.props.schema.noTranslation)]}),this.renderErrorDialog(),this.renderMessageDialog()]})}},le={fullWidth:{width:"100%"},icon:{width:24,height:24,marginRight:4}};const he=class extends C{async _onClick(){let t=this.props.schema.val;if("string"===typeof t&&t.includes("${")){var e,s;t=this.getPattern(t);const i=await this.props.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.instance||0).toString());try{await this.props.socket.setState(i,{val:t,ack:!!this.props.schema.ack}),this.props.schema.okText&&window.alert(this.getText(this.props.schema.okText))}catch(a){this.props.schema.error&&this.props.schema.error[a.toString()]?window.alert(this.getText(this.props.schema.error[a.toString()])):window.alert(c.I18n.t(a.toString())||c.I18n.t("ra_Error"))}}renderConfirmDialog(){if(!this.state.confirmDialog)return null;const t=this.state.confirmData||this.props.schema.confirm;let e=null;return"warning"===t.type?e=(0,d.jsx)(p.Warning,{}):"error"===t.type?e=(0,d.jsx)(p.Error,{}):"info"===t.type&&(e=(0,d.jsx)(p.Info,{})),(0,d.jsx)(c.Confirm,{title:this.getText(t.title)||c.I18n.t("ra_Please confirm"),text:this.getText(t.text),ok:this.getText(t.ok)||c.I18n.t("ra_Ok"),cancel:this.getText(t.cancel)||c.I18n.t("ra_Cancel"),icon:e,onClose:t=>this.setState({confirmDialog:!1},(()=>t&&this._onClick()))})}renderItem(t,e){return(0,d.jsxs)(h.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:le.fullWidth,disabled:e,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0}):await this._onClick()},children:[this.props.schema.icon?(0,d.jsx)(c.Icon,{src:this.props.schema.icon,style:le.icon}):null,this.getText(this.props.schema.label,this.props.schema.noTranslation)]})}},pe={fullWidth:{width:"100%"},slider:{marginLeft:10,marginRight:10,width:"calc(100% - 20px)"}};const ce=class extends C{componentDidMount(){super.componentDidMount();const t=C.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=C.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,a=this.props.schema.unit||"",o=[{value:s,label:s+a},{value:i,label:i+a}];return(0,d.jsxs)(h.Box,{style:pe.fullWidth,children:[this.props.schema.label?(0,d.jsx)(h.Typography,{gutterBottom:!0,children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.Slider,{style:pe.slider,value:this.state._value,getAriaValueText:t=>t+a,step:this.props.schema.step||(i-s)/100,valueLabelDisplay:"auto",marks:o,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,d.jsx)(h.Typography,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};function de(t,e){return"edit"===t||"rename"===t?(0,d.jsx)(p.Edit,{style:e}):"delete"===t?(0,d.jsx)(p.Delete,{style:e}):"refresh"===t?(0,d.jsx)(p.Refresh,{style:e}):"newDevice"===t||"new"===t||"add"===t?(0,d.jsx)(p.Add,{style:e}):"discover"===t||"search"===t?(0,d.jsx)(p.Search,{style:e}):"unpairDevice"===t||"unpair"===t?(0,d.jsx)(p.LinkOff,{style:e}):"pairDevice"===t||"pair"===t?(0,d.jsx)(p.Link,{style:e}):"identify"===t?(0,d.jsx)(p.NotListedLocation,{style:e}):"play"===t?(0,d.jsx)(p.PlayArrow,{style:e}):"stop"===t?(0,d.jsx)(p.Stop,{style:e}):"pause"===t?(0,d.jsx)(p.Pause,{style:e}):"forward"===t||"next"===t?(0,d.jsx)(p.FastForward,{style:e}):"rewind"===t||"previous"===t?(0,d.jsx)(p.FastRewind,{style:e}):"lamp"===t||"light"===t?(0,d.jsx)(p.Lightbulb,{style:e}):"backlight"===t?(0,d.jsx)(p.Fluorescent,{style:e}):"dimmer"===t?(0,d.jsx)(p.WbIncandescent,{style:e}):"socket"===t?(0,d.jsx)(p.Power,{style:e}):"settings"===t?(0,d.jsx)(p.Settings,{style:e}):"users"===t||"group"===t?(0,d.jsx)(p.Group,{style:e}):"user"===t?(0,d.jsx)(p.Person,{style:e}):"qrcode"===t?(0,d.jsx)(p.QrCode,{style:e}):"connection"===t?(0,d.jsx)(p.Wifi,{style:e}):"no-connection"===t?(0,d.jsx)(p.WifiOff,{style:e}):"visible"===t?(0,d.jsx)(p.Visibility,{style:e}):null}const ue=class extends C{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(`${Date.now()} Received new value: ${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.system?"system.adapter.":""}${this.props.adapterName}.${this.props.instance}.${this.props.schema.oid}`}async componentDidMount(){super.componentDidMount();const t=await this.props.socket.getObject(this.getObjectID()),e=this.props.schema.control||this.detectType(t),s=await this.props.socket.getState(this.getObjectID());this.setState({stateValue:s?s.val:null,controlType:e,obj:t},(async()=>{await this.props.socket.subscribeState(this.getObjectID(),this.onStateChanged)}))}componentWillUnmount(){super.componentWillUnmount(),this.props.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.socket.setState(this.getObjectID(),this.state.stateValue,!1).catch((t=>console.error(`Cannot control value: ${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(){if(!this.state.obj)return null;let t;if("button"===this.state.controlType){let e=null;this.props.schema.falseImage&&(e=de(this.props.schema.falseImage));const s=this.getText(this.props.schema.falseText,this.props.schema.noTranslation)||this.getText(this.props.schema.label,this.props.schema.noTranslation);t=!s&&e?(0,d.jsx)(h.IconButton,{style:this.props.schema.falseTextStyle,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.socket.setState(this.getObjectID(),!0,!1)}}):await this.props.socket.setState(this.getObjectID(),!0,!1)},children:e}):(0,d.jsx)(h.Button,{variant:this.props.schema.variant||"contained",startIcon:e,style:this.props.schema.falseTextStyle,onClick:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.socket.setState(this.getObjectID(),!0,!1)}}):await this.props.socket.setState(this.getObjectID(),!0,!1)},children:s||this.getObjectID().split(".").pop()})}else if("switch"===this.state.controlType){let e=null;const s=this.getText(this.props.schema.falseText,this.props.schema.noTranslation);this.props.schema.falseImage&&(e=de(this.props.schema.falseImage,s?{marginLeft:8}:void 0));let i=null;const a=this.getText(this.props.schema.trueText,this.props.schema.noTranslation);this.props.schema.trueImage&&(i=de(this.props.schema.trueImage,a?{marginRight:8}:void 0)),t=(0,d.jsx)(h.Switch,{checked:!!this.state.stateValue,onChange:async()=>{this.props.schema.confirm?this.setState({confirmDialog:!0,confirmCallback:async t=>{t&&await this.props.socket.setState(this.getObjectID(),!this.state.stateValue,!1)}}):await this.props.socket.setState(this.getObjectID(),!this.state.stateValue,!1)}}),(s||e||a||i)&&(t=(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",fontSize:14},children:[(0,d.jsxs)("span",{style:this.props.schema.falseTextStyle,children:[s,e]}),t,(0,d.jsxs)("span",{style:this.props.schema.trueTextStyle,children:[i,a]})]}));const o=this.getText(this.props.schema.label,this.props.schema.noTranslation);o&&(t=(0,d.jsxs)("div",{style:{display:"flex",alignItems:"center",fontSize:"1rem"},children:[(0,d.jsx)("span",{style:{marginRight:8},children:o}),t]}))}else if("slider"===this.state.controlType){let e=null;const s=this.getText(this.props.schema.falseText,this.props.schema.noTranslation);this.props.schema.falseImage&&(e=de(this.props.schema.falseImage,s?{marginLeft:8}:void 0));let i=null;const a=this.getText(this.props.schema.trueText,this.props.schema.noTranslation);this.props.schema.trueImage&&(i=de(this.props.schema.trueImage,a?{marginRight:8}:void 0));const o=void 0===this.props.schema.min?this.state.obj.common.min||0:this.props.schema.min,n=void 0===this.props.schema.max?void 0===this.state.obj.common.max?100:this.state.obj.common.max:this.props.schema.max,r=void 0===this.props.schema.step?this.state.obj.common.step||1:this.props.schema.step;t=(0,d.jsx)(h.Slider,{style:{width:"100%",flexGrow:1},min:o,max:n,step:r,value:this.state.stateValue,valueLabelDisplay:"auto",valueLabelFormat:t=>`${t}${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(`${Date.now()} Send new value: ${this.state.stateValue}`),this.controlTimeout=null,await this.props.socket.setState(this.getObjectID(),this.state.stateValue,!1)}),this.props.schema.controlDelay||0)}))}}),(s||e||a||i)&&(t=(0,d.jsxs)("div",{style:{display:"flex",width:"100%",flexGrow:1,alignItems:"center"},children:[(0,d.jsxs)("span",{style:{marginRight:16,...this.props.schema.falseTextStyle},children:[s,e]}),t,(0,d.jsxs)("span",{style:{marginLeft:16,...this.props.schema.trueTextStyle},children:[i,a]})]}));const l=this.getText(this.props.schema.label,this.props.schema.noTranslation);l&&(t=(0,d.jsxs)("div",{style:{display:"flex",width:"100%",alignItems:"center"},children:[(0,d.jsx)("span",{style:{whiteSpace:"nowrap",marginRight:8,fontSize:"1rem"},children:l}),t]}))}else if("input"===this.state.controlType)t=(0,d.jsx)(h.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}},onChange:t=>{this.setState({stateValue:t.target.value},(()=>{this.controlTimeout&&clearTimeout(this.controlTimeout),this.controlTimeout=setTimeout((async()=>{this.controlTimeout=null,await this.props.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 e=void 0===this.props.schema.min?this.state.obj.common.min||0:this.props.schema.min,s=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;t=(0,d.jsx)(h.TextField,{variant:"standard",style:{width:"100%"},value:this.state.stateValue,type:"number",slotProps:{htmlInput:{min:e,max:s,step:i},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.socket.setState(this.getObjectID(),t,!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("boolean"===this.state.obj.common.type){let e,s,i=null;this.state.stateValue?(e=this.getText(this.props.schema.trueText,this.props.schema.noTranslation),this.props.schema.trueImage&&(i=de(this.props.schema.falseImage,e?{marginRight:8}:void 0)),s=this.props.schema.trueTextStyle):(e=this.getText(this.props.schema.falseText,this.props.schema.noTranslation),this.props.schema.falseImage&&(i=de(this.props.schema.falseImage,e?{marginLeft:8}:void 0)),s=this.props.schema.falseTextStyle);const a=this.getText(this.props.schema.label,this.props.schema.noTranslation);t=(0,d.jsxs)("div",{style:{fontSize:"1rem",...s},children:[a,a?(0,d.jsx)("span",{style:{marginRight:8},children:":"}):null,i,e||(this.state.stateValue?c.I18n.t("ra_true"):c.I18n.t("ra_false"))]})}else{const e=this.getText(this.props.schema.label,this.props.schema.noTranslation),s=this.getText(this.props.schema.unit,this.props.schema.noTranslation)||this.state.obj.common.unit;let i;i="html"===this.state.controlType?(0,d.jsx)("span",{dangerouslySetInnerHTML:{__html:this.state.stateValue}}):null===this.state.stateValue?"null":void 0===this.state.stateValue?"undefined":this.state.stateValue,t=(0,d.jsxs)("div",{style:{fontSize:"1rem"},children:[e,e?(0,d.jsx)("span",{style:{marginRight:8},children:":"}):null,i,s?(0,d.jsx)("span",{style:{opacity:.7},children:s}):null]})}return t}},me={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 ge=class extends C{renderItem(){return(0,d.jsx)(h.Box,{component:"hr",sx:y.getStyle(this.props.theme,me.fullWidth,"primary"===this.props.schema.color?me.primary:"secondary"===this.props.schema.color?me.secondary:{backgroundColor:this.props.schema.color||("dark"===this.props.themeType?"#333":"#ddd")},{height:this.props.schema.color?this.props.schema.height||2:this.props.schema.height||1})})}},fe={header:t=>({width:"100%",background:t.palette.primary.main,color:t.palette.primary.contrastText,padding:"4px !important",borderRadius:"3px",marginBlockEnd:0,marginBlockStart:0})};const ve=class extends C{renderItem(){switch((this.props.schema.size||5).toString()){case"1":return(0,d.jsx)(h.Box,{component:"h1",sx:fe.header,children:this.getText(this.props.schema.text,this.props.schema.noTranslation)});case"2":return(0,d.jsx)(h.Box,{component:"h2",sx:fe.header,children:this.getText(this.props.schema.text,this.props.schema.noTranslation)});case"3":return(0,d.jsx)(h.Box,{component:"h3",sx:fe.header,children:this.getText(this.props.schema.text,this.props.schema.noTranslation)});case"4":return(0,d.jsx)(h.Box,{component:"h4",sx:fe.header,children:this.getText(this.props.schema.text,this.props.schema.noTranslation)});default:return(0,d.jsx)(h.Box,{component:"h5",sx:fe.header,children:this.getText(this.props.schema.text,this.props.schema.noTranslation)})}}};const xe=class extends C{renderItem(){let t=this.props.schema.src;return!t||t.startsWith(".")||t.startsWith("http")||t.startsWith(`adapter/${this.props.adapterName}/`)||t.startsWith(`./adapter/${this.props.adapterName}/`)||(t=`adapter/${this.props.adapterName}/${t}`),(0,d.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:""})}},ye={fullWidth:{height:"100%",width:"100%"},link:t=>({textDecoration:"underline",color:"dark"===t.palette.mode?"#4dabf5":"#254e72",cursor:"pointer"})};function be(t,e,s){let i,a="";t?t.toString().startsWith("#")||t.toString().startsWith("/")?(i=e||"_self",a=t):t.startsWith("http://")||t.startsWith("https://")?(i=e||"_blank",a=t):(a=`#tab-instances/config/${s}/${t}`,i=e||"_self"):(a=`#tab-instances/config/${s}`,i=e||"_self"),"_self"===i?setTimeout((t=>{t.startsWith("#")?window.location.hash=t:t.startsWith("/")?a=`${window.location.protocol}:${window.location.host}${a}`:(t.startsWith("http://")||t.startsWith("https://"))&&(window.location.href=t)}),100,a):(a.startsWith("#")?a=`${window.location.protocol}:${window.location.host}${window.location.pathname}${a}`:a.startsWith("/")&&(a=`${window.location.protocol}:${window.location.host}${a}`),window.open(a,i))}const Ce=class extends C{renderItem(t,e){if(this.props.schema.button){const t=this.getIcon();return(0,d.jsx)(h.Button,{variant:this.props.schema.variant||void 0,color:this.props.schema.color||"grey",style:{...ye.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.onBackEndCommand?this.props.onBackEndCommand({command:"link",url:t,target:this.props.schema.target,close:this.props.schema.close}):be(t,this.props.schema.target,`${this.props.adapterName}.${this.props.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=c.Utils.renderTextWithA(s)),(0,d.jsx)(h.Box,{component:"span",style:{...this.props.schema.controlStyle||void 0},sx:this.props.schema.href?ye.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.onBackEndCommand?this.props.onBackEndCommand({command:"link",url:t,target:this.props.schema.target||"_blank",close:this.props.schema.close}):be(t,this.props.schema.target||"_blank",`${this.props.adapterName}.${this.props.instance}`))}:null,children:s})}},je=1048576,we={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 Se(t,e,s){e=e||"key";const i={};return t.forEach((t=>{let a=t[e];null!==a&&void 0!==a||(a=""),delete t[e],i[a]=s?t[s]:t})),i}class Ie extends C{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:a}=e.state;if(a){const o=s?i:a===t&&"asc"===i?"desc":"asc",n=e.stableSort(o,t);e.setState({order:o,orderBy:t,iteration:e.state.iteration+1e4},(()=>e.applyFilter(!1,n)))}},this.stableSort=(t,e)=>{const{value:s}=this.state,i=Ie.getComparator(t,e),a=s.map(((t,e)=>({el:t,index:e})));return a.sort(((t,e)=>{const s=i(t.el,e.el);return 0!==s?s:t.index-e.index})),a.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 a=i.match(/(\d+)$/);for(a?(i=i.replace(a[0],""),t=parseInt(a[0],10)+1):i+="_";e.find((e=>e[this.props.schema.clone]===i+t.toString()));)t++;s[this.props.schema.clone]=`${s[this.props.schema.clone]}_${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=Se(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=Se(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: ${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.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 a=Ie.getFilterValue(this.filterRefs[s]);!t&&a?(a=a.toLowerCase(),i=i.filter((t=>e[t]&&e[t][s]&&e[t][s].toLowerCase().includes(a)))):this.filterRefs[s].current&&Ie.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,i.createRef)())}))}async componentDidMount(){super.componentDidMount();const t=C.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((a=>{const o={};o[e]=a,s?(o[s]=t[a],i.push(o)):i.push(Object.assign(o,t[a]))})),i}(t,this.props.schema.objKeyName,this.props.schema.objValueName):t,Array.isArray(e)||(e=[]),this.props.schema.encryptedAttributes){const e=await this.props.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,a=i.items&&i.items.find((e=>e.attr===t));if(!a)return null;const o={items:{[t]:a}};return(0,d.jsx)(We,{index:s+this.state.iteration,arrayIndex:s,changed:this.props.changed,globalData:this.props.data,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,alive:this.props.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:e,table:!0,custom:!0,schema:o,systemConfig:this.props.systemConfig,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,imagePrefix:this.props.imagePrefix,onCommandRunning:this.props.onCommandRunning,forceUpdate:this.props.forceUpdate,originalData:this.props.originalData,customs:this.props.customs,theme:this.props.theme,DeviceManager:this.props.DeviceManager,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),onBackEndCommand:this.props.onBackEndCommand})}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:c.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)=>Ie.descendingComparator(t,s,e):(t,s)=>-Ie.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:i,orderBy:a}=this.state;return(0,d.jsx)(h.TableHead,{children:(0,d.jsxs)(h.TableRow,{children:[s.items&&s.items.map(((t,o)=>(0,d.jsx)(h.TableCell,{style:{width:("string"===typeof t.width&&t.width.endsWith("%"),t.width)},align:"left",sortDirection:a===t.attr&&i,children:(0,d.jsxs)("div",{style:{...we.flex,...s.showFirstAddOnTop?{flexDirection:"column"}:void 0},children:[o||s.noDelete?null:(0,d.jsx)(h.Tooltip,{title:e?c.I18n.t("ra_Cannot add items with set filter"):c.I18n.t("ra_Add row"),slotProps:{popper:{sx:we.tooltip}},children:(0,d.jsx)("span",{children:(0,d.jsx)(h.IconButton,{size:"small",color:"primary",disabled:!!e&&!this.props.schema.allowAddByFilter,onClick:this.onAdd,children:(0,d.jsx)(p.Add,{})})})}),t.sort&&(0,d.jsx)(h.TableSortLabel,{active:!0,style:a!==t.attr?we.silver:void 0,direction:a===t.attr?i:"asc",onClick:()=>this.handleRequestSort(t.attr)}),t.filter&&this.state.filterOn.includes(t.attr)?(0,d.jsx)(h.TextField,{variant:"standard",ref:this.filterRefs[t.attr],onChange:()=>this.applyFilter(),title:c.I18n.t("ra_You can filter entries by entering here some text"),slotProps:{input:{endAdornment:Ie.getFilterValue(this.filterRefs[t.attr])&&(0,d.jsx)(h.InputAdornment,{position:"end",children:(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>{Ie.setFilterValue(this.filterRefs[t.attr],""),this.applyFilter()},children:(0,d.jsx)(p.Close,{})})})}},fullWidth:!0,placeholder:this.getText(t.title)}):(0,d.jsx)("span",{style:we.headerText,children:this.getText(t.title)}),t.filter?(0,d.jsx)(h.IconButton,{title:c.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&&Ie.getFilterValue(this.filterRefs[t.attr])&&(Ie.setFilterValue(this.filterRefs[t.attr],""),this.applyFilter())}))},children:this.state.filterOn.includes(t.attr)?(0,d.jsx)(p.FilterAltOff,{}):(0,d.jsx)(p.FilterAlt,{})}):null]})},`${t.attr}_${o}`))),!s.noDelete&&(0,d.jsxs)(h.TableCell,{style:{paddingLeft:20,paddingRight:20,width:t,textAlign:"right"},padding:"checkbox",children:[s.import?(0,d.jsx)(h.IconButton,{style:{marginRight:10},size:"small",onClick:()=>this.setState({showImportDialog:!0}),title:c.I18n.t("ra_import data from %s file","CSV"),children:(0,d.jsx)(p.UploadFile,{})}):null,s.export?(0,d.jsx)(h.IconButton,{style:{marginRight:10},size:"small",onClick:()=>this.onExport(),title:c.I18n.t("ra_Export data to %s file","CSV"),children:(0,d.jsx)(p.Download,{})}):null,(0,d.jsx)(h.IconButton,{disabled:!0,size:"small",children:(0,d.jsx)(p.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(`"${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,${encodeURIComponent(s.join("\n"))}`);const a=new Date;i.setAttribute("download",`${a.getFullYear()}_${(a.getMonth()+1).toString().padStart(2,"0")}_${a.getDate().toString().padStart(2,"0")}_${this.props.adapterName}.${this.props.instance}_${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)))),a=[];var o;(e.forEach((t=>{const e=t.split(";"),s={};for(let a=0;a<e.length;a++){let t=e[a];if(t.startsWith('"')){for(t=t.substring(1);a<e.length&&!t.endsWith('"');)t+=`;${e[++a]}`;t=t.substring(0,t.length-1)}let o=t;if("true"===t)o=!0;else if("false"===t)o=!1;else if(window.isFinite(t)){const e=this.props.schema.items.find((t=>t.attr===i[a]));o=e&&"number"===e.type?parseFloat(t):t}else o=t;s[i[a]]=o}a.push(s)})),a.length)?null!==(o=this.state.value)&&void 0!==o&&o.length?this.setState({showTypeOfImportDialog:a,showImportDialog:!1}):this.setState({value:a,showImportDialog:!1}):window.alert("ra_No data found in file")}isAnyFilterSet(){return!!Object.keys(this.filterRefs).find((t=>Ie.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>je)return void window.alert(c.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,d.jsxs)(h.Dialog,{open:!0,onClose:()=>this.setState({showTypeOfImportDialog:!1}),maxWidth:"md",children:[(0,d.jsx)(h.DialogTitle,{children:c.I18n.t("ra_Append or replace?")}),(0,d.jsx)(h.DialogContent,{children:c.I18n.t("ra_Append %s entries or replace existing?",this.state.showTypeOfImportDialog.length)}),(0,d.jsxs)(h.DialogActions,{children:[(0,d.jsx)(h.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:c.I18n.t("ra_Append")}),(0,d.jsx)(h.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:c.I18n.t("ra_Replace")})]})]}):null}showImportDialog(){return this.state.showImportDialog?(0,d.jsxs)(h.Dialog,{open:!0,onClose:()=>this.setState({showImportDialog:!1}),sx:{"& .MuiDialog-paper":{minHeight:500}},maxWidth:"md",fullWidth:!0,children:[(0,d.jsx)(h.DialogTitle,{children:c.I18n.t("ra_Import from %s","CSV")}),(0,d.jsx)(h.DialogContent,{children:(0,d.jsx)(lt(),{multiple:!1,accept:{"text/csv":[".csv"]},maxSize:je,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||c.I18n.t("ra_Cannot upload"))},children:t=>{let{getRootProps:e,getInputProps:s}=t;return(0,d.jsxs)("div",{style:{...we.uploadDiv,..."dragging"===this.state.uploadFile?we.uploadDivDragging:void 0,...we.dropZone,...this.state.icon?void 0:we.dropZoneEmpty},...e(),children:[(0,d.jsx)("input",{...s()}),(0,d.jsx)("div",{style:we.uploadCenterDiv,children:(0,d.jsxs)("div",{style:we.uploadCenterTextAndIcon,children:[(0,d.jsx)(p.UploadFile,{style:we.uploadCenterIcon}),(0,d.jsx)("div",{style:we.uploadCenterText,children:"dragging"===this.state.uploadFile?c.I18n.t("ra_Drop file here"):c.I18n.t("ra_Place your files here or click here to open the browse dialog")})]})})]})}})}),(0,d.jsx)(h.DialogActions,{children:(0,d.jsx)(h.Button,{variant:"contained",onClick:()=>this.setState({showImportDialog:!1}),color:"primary",startIcon:(0,d.jsx)(p.Close,{}),children:c.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 i;return this.props.schema.compact&&(i={paddingTop:1,paddingBottom:1}),(0,d.jsxs)(h.Paper,{style:we.paper,children:[this.showImportDialog(),this.showTypeOfImportDialog(),t.label?(0,d.jsx)("div",{style:we.label,children:(0,d.jsx)(h.Toolbar,{variant:"dense",style:we.rootTool,children:(0,d.jsx)(h.Typography,{style:we.title,variant:"h6",id:"tableTitle",component:"div",children:this.getText(t.label)})})}):null,(0,d.jsxs)(h.TableContainer,{children:[(0,d.jsxs)(h.Table,{style:we.table,size:"small",children:[this.enhancedTableHead(s||this.state.orderBy?64:120,s),(0,d.jsxs)(h.TableBody,{children:[e.map(((a,o)=>(0,d.jsxs)(h.TableRow,{hover:!0,children:[t.items&&t.items.map((t=>(0,d.jsx)(h.TableCell,{align:"left",style:i,children:this.itemTable(t.attr,this.state.value[a],a)},`${t.attr}_${a}`))),!t.noDelete&&(0,d.jsxs)(h.TableCell,{align:"left",style:{...i,...we.buttonCell},children:[s||this.state.orderBy?null:o?(0,d.jsx)(h.Tooltip,{title:c.I18n.t("ra_Move up"),slotProps:{popper:{sx:we.tooltip}},children:(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>this.onMoveUp(a),children:(0,d.jsx)(p.ArrowUpward,{})})}):(0,d.jsx)("div",{style:we.buttonEmpty}),s||this.state.orderBy?null:o<e.length-1?(0,d.jsx)(h.Tooltip,{title:c.I18n.t("ra_Move down"),slotProps:{popper:{sx:we.tooltip}},children:(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>this.onMoveDown(a),children:(0,d.jsx)(p.ArrowDownward,{})})}):(0,d.jsx)("div",{style:we.buttonEmpty}),(0,d.jsx)(h.Tooltip,{title:c.I18n.t("ra_Delete current row"),slotProps:{popper:{sx:we.tooltip}},children:(0,d.jsx)(h.IconButton,{size:"small",onClick:this.onDelete(a),children:(0,d.jsx)(p.Delete,{})})}),this.props.schema.clone?(0,d.jsx)(h.Tooltip,{title:c.I18n.t("ra_Clone current row"),slotProps:{popper:{sx:we.tooltip}},children:(0,d.jsx)(h.IconButton,{size:"small",onClick:this.onClone(a),children:(0,d.jsx)(p.ContentCopy,{})})}):null]})]},`${a}_${o}`))),!t.noDelete&&e.length>=(t.showSecondAddAt||5)?(0,d.jsx)(h.TableRow,{children:(0,d.jsx)(h.TableCell,{colSpan:t.items.length+1,style:{...i},children:(0,d.jsx)(h.Tooltip,{title:s?c.I18n.t("ra_Cannot add items with set filter"):c.I18n.t("ra_Add row"),slotProps:{popper:{sx:we.tooltip}},children:(0,d.jsx)("span",{children:(0,d.jsx)(h.IconButton,{size:"small",color:"primary",disabled:!!s&&!this.props.schema.allowAddByFilter,onClick:this.onAdd,children:(0,d.jsx)(p.Add,{})})})})})}):null]})]}),!e.length&&this.state.value.length?(0,d.jsx)("div",{style:we.filteredOut,children:(0,d.jsxs)(h.Typography,{style:we.title,variant:"h6",id:"tableTitle",component:"div",children:[c.I18n.t("ra_All items are filtered out"),(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>this.applyFilter(!0),children:(0,d.jsx)(p.Close,{})})]})}):null]}),t.help?(0,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null,this.state.errorMessage?(0,d.jsxs)("div",{style:{display:"flex",padding:"5px"},children:[(0,d.jsx)(p.Warning,{color:"error"}),(0,d.jsx)("span",{style:{color:"red",alignSelf:"center"},children:this.state.errorMessage})]}):null]})}}const Te=Ie,De={indeterminate:{opacity:.5},label:{width:"100%",fontSize:16},helper:{width:"100%",fontSize:12},error:{width:"100%",fontSize:12,color:"#FF0000"}};const Oe=class extends C{constructor(){super(...arguments),this.updateTimeout=null}componentDidMount(){super.componentDidMount();let t=C.getValue(this.props.data,this.props.attr);if(Array.isArray(t)&&this.props.multiEdit)return t=C.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.multiEdit&&e.value===C.DIFFERENT_VALUE)return{value:C.DIFFERENT_VALUE};let s=C.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===C.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,d.jsx)(h.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=C.getValue(this.props.data,this.props.attr),i=(null===s||void 0===s?void 0:s.filter((t=>t||0===t)).map((t=>({label:t.toString()||"",value:t}))))||[];return i.unshift({label:c.I18n.t(C.DIFFERENT_LABEL),value:C.DIFFERENT_VALUE}),(0,d.jsx)(h.Autocomplete,{style:De.indeterminate,fullWidth:!0,value:i[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: ${t}`)))},options:i,getOptionLabel:t=>t.label,renderInput:s=>(0,d.jsx)(h.TextField,{variant:"standard",...s,error:!!t,placeholder:this.getText(this.props.schema.placeholder),slotProps:{htmlInput:{...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})})}if(this.props.schema.minRows>1){const s=this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation);return(0,d.jsxs)("div",{style:{width:"100%"},children:[this.props.schema.label?(0,d.jsx)("div",{style:De.label,children:this.getText(this.props.schema.label)}):null,(0,d.jsx)(h.TextareaAutosize,{style:{width:"100%",resize:"vertical",backgroundColor:"dark"===this.props.themeType?"#363636":"#cccccc",color:"dark"===this.props.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,d.jsx)("div",{style:t?De.error:De.helper,children:t||(this.state.jsonError?c.I18n.t("ra_Invalid JSON"):s)}):null]})}return(0,d.jsx)(h.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:this.state.value&&!this.props.schema.noClearButton?(0,d.jsx)(h.InputAdornment,{position:"end",children:(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>this.setState({value:"",oldValue:this.state.value},(()=>this.onChange(this.props.attr,""))),children:(0,d.jsx)(p.Close,{})})}):null}},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?c.I18n.t("ra_Invalid JSON"):this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)})}},ke={width:"100%"};const Ne=class extends C{constructor(){super(...arguments),this.initialized=!1,this._context=void 0}askInstance(){if(this.props.alive){let t=this.props.schema.data;if(void 0===t&&this.props.schema.jsonData){const e=this.getPattern(this.props.schema.jsonData);try{t=JSON.parse(e)}catch{console.error(`Cannot parse json data: ${e}`)}}void 0===t&&(t=null),this.props.socket.sendTo(`${this.props.adapterName}.${this.props.instance}`,this.props.schema.command||"send",t).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: ${t}`)))}}getContext(){const t={};return Array.isArray(this.props.schema.alsoDependsOn)&&this.props.schema.alsoDependsOn.forEach((e=>t[e]=C.getValue(this.props.data,e))),JSON.stringify(t)}renderItem(){if(this.props.alive){const t=this.getContext();t===this._context&&this.initialized||(this._context=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=de(this.state.icon,{marginRight:this.state.text?8:void 0,...this.state.iconStyle||void 0}),t||(t=(0,d.jsx)(c.Icon,{src:this.state.icon,style:{marginRight:this.state.text?8:void 0,...this.state.iconStyle||void 0}}))),"text"===this.props.schema.container?(0,d.jsx)(h.TextField,{variant:"standard",fullWidth:!0,InputProps:{endAdornment:this.props.schema.copyToClipboard?(0,d.jsx)(h.IconButton,{size:"small",onClick:()=>{c.Utils.copyToClipboard(this.state.text),window.alert("Copied")},children:(0,d.jsx)(c.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,d.jsxs)("div",{style:{...ke,...this.state.style||void 0},children:[t,"html"===this.props.schema.container?(0,d.jsx)("span",{dangerouslySetInnerHTML:{__html:this.state.text||""}}):this.state.text]})}};const _e=class extends C{componentDidMount(){var t;super.componentDidMount();const e=C.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,`${this.props.adapterName}.${this.props.instance}`);this.setState({value:t})}else this.setState({value:e||""})}renderItem(t,e){return(0,d.jsx)(h.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 Fe=class extends C{async componentDidMount(){var t;super.componentDidMount();const e=await this.props.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,d.jsx)(h.TextField,{variant:"standard",fullWidth:!0,error:!!t,disabled:!!e,slotProps:{htmlInput:{readOnly:!0},input:{endAdornment:(0,d.jsx)(h.IconButton,{onClick:()=>{c.Utils.copyToClipboard(this.state.uuid),window.alert(c.I18n.t("ra_Copied %s",this.state.uuid))},children:(0,d.jsx)(p.ContentCopy,{})})}},value:this.state.uuid||"",label:this.getText(this.props.schema.label)||c.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 Ee=class extends C{componentDidMount(){super.componentDidMount(),this.props.socket.getUsers().then((t=>{const e={},s=c.I18n.getLanguage();this.props.schema.short?t.forEach((t=>{var i,a;return e[t._id]={color:null===(i=t.common)||void 0===i?void 0:i.color,icon:null===(a=t.common)||void 0===a?void 0:a.icon,name:c.Utils.getObjectNameFromObj(t,s)}})):t.forEach((t=>{var i,a;return e[t._id.replace(/^system\.user\./,"")]={color:null===(i=t.common)||void 0===i?void 0:i.color,icon:null===(a=t.common)||void 0===a?void 0:a.icon,name:c.Utils.getObjectNameFromObj(t,s)}})),this.setState({users:e})})).catch((t=>console.error(`Cannot get users: ${t}`)))}renderItem(t,e){var s,i;const a=C.getValue(this.props.data,this.props.attr);return(0,d.jsxs)(h.FormControl,{variant:"standard",fullWidth:!0,children:[this.state.users&&this.props.schema.label?(0,d.jsx)(h.InputLabel,{children:this.getText(this.props.schema.label)}):null,this.state.users?(0,d.jsx)(h.Select,{variant:"standard",error:!!t,disabled:!!e,value:a,renderValue:t=>{var e,s,i;return(0,d.jsxs)("span",{children:[this.state.users&&null!==(e=this.state.users[t])&&void 0!==e&&e.icon?(0,d.jsx)(c.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[a])||void 0===s?void 0:s.color)||void 0,backgroundColor:c.Utils.getInvertedColor(this.state.users&&(null===(i=this.state.users[a])||void 0===i?void 0:i.color),this.props.themeType)},onChange:t=>this.onChange(this.props.attr,t.target.value),children:this.state.users&&Object.keys(this.state.users).map((t=>(0,d.jsxs)(h.MenuItem,{style:{color:this.state.users[t].color||void 0,backgroundColor:c.Utils.getInvertedColor(this.state.users[t].color,this.props.themeType)},value:t,children:[this.state.users[t].icon?(0,d.jsx)(c.Icon,{src:this.state.users[t].icon,style:$e.icon}):null,this.state.users[t].name]},t)))}):(0,d.jsx)(h.TextField,{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,d.jsx)(h.FormHelperText,{children:this.renderHelp(this.props.schema.help,this.props.schema.helpLink,this.props.schema.noTranslation)}):null]})}};const Le=class extends C{async componentDidMount(){super.componentDidMount();const t=await s.e(5831).then(s.bind(s,15831));this.setState({QRCode:t.default})}renderItem(){const t=this.state.QRCode;return t?(0,d.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}},Ae={accordion:w,alive:T,autocomplete:D,autocompleteSendTo:O,certCollection:E,certificate:_,certificates:$,checkbox:P,checkLicense:V,chip:Q,chips:Q,color:tt,coordinates:st,cron:N,custom:at,datePicker:class extends C{componentDidMount(){super.componentDidMount();const t=C.getValue(this.props.data,this.props.attr);this.setState({value:t})}renderItem(t,e){return(0,d.jsx)(ot.DatePicker,{sx:t=>({width:"100%",borderBottom:`1px solid ${t.palette.text.primary}`,"& fieldset":{display:"none"},"& input":{padding:`${t.spacing(1.5)} 0 4px 0`},"& .MuiInputAdornment-root":{marginLeft:0,marginTop:1},"& label":{transform:"translate(0px, -9px) scale(0.75)"}}),format:this.props.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:nt,divider:ge,file:St,fileSelector:vt,func:It,header:ve,image:Ot,imageSendTo:Dt,instance:Nt,interface:Ft,ip:Tt,jsonEditor:Ut,language:Mt,license:Rt,number:zt,objectId:qt,password:Yt,pattern:Zt,port:Xt,qrCode:Le,room:te,select:se,selectSendTo:ae,sendto:re,sendTo:re,setState:he,slider:ce,state:ue,staticImage:xe,staticLink:Ce,staticText:Ce,table:Te,text:Oe,textSendTo:Ne,timePicker:class extends C{componentDidMount(){super.componentDidMount();const t=C.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 ${this.state.value||"00:00:00"}`));return(0,d.jsx)(ot.TimePicker,{sx:t=>({width:"100%",borderBottom:`1px solid ${t.palette.text.primary}`,"& fieldset":{display:"none"},"& input":{padding:`${t.spacing(1.5)} 0 4px 0`},"& .MuiInputAdornment-root":{marginLeft:0,marginTop:1},"& label":{transform:"translate(0px, -9px) scale(0.75)"}}),ampm:this.props.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:_e,uuid:Fe,user:Ee},Ve={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 Pe extends C{componentDidMount(){super.componentDidMount(),this.props.schema&&this.props.schema.collapsable&&this.setState({expanded:"true"===(window._localStorage||window.localStorage).getItem(`${this.props.adapterName}.${this.props.attr}`)})}renderItems(t,e){return t?Object.keys(t).map((s=>{if(this.props.multiEdit&&t[s].noMultiEdit)return null;const i=t[s].type||"panel";let a;return"custom"===i?t[s].url?a=at:this.props.customs&&this.props.customs[t[s].component]?a=this.props.customs[t[s].component]:(console.error(`Cannot find custom component: ${t[s].component}`),a=C):a="panel"===i?Pe:Ae[i]||C,(0,d.jsx)(a,{index:this.props.index,changed:this.props.changed,arrayIndex:this.props.arrayIndex,globalData:this.props.globalData,onCommandRunning:this.props.onCommandRunning,commandRunning:this.props.commandRunning,style:Ve.panel,socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,customs:this.props.customs,alive:this.props.alive,themeType:this.props.themeType,themeName:this.props.themeName,theme:this.props.theme,data:this.props.data,originalData:this.props.originalData,systemConfig:this.props.systemConfig,onError:this.props.onError,onChange:this.props.onChange,onBackEndCommand:this.props.onBackEndCommand,multiEdit:this.props.multiEdit,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,disabled:e,imagePrefix:this.props.imagePrefix,changeLanguage:this.props.changeLanguage,forceUpdate:this.props.forceUpdate,registerOnForceUpdate:this.props.registerOnForceUpdate,customObj:this.props.customObj,instanceObj:this.props.instanceObj,custom:this.props.custom,schema:t[s],DeviceManager:this.props.DeviceManager,attr:s,table:this.props.table},`${s}_${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),i=this.props.schema.items,a=this.props.schema.style||{};if(s){if(t.hideOnlyControl){const e=(0,d.jsx)(h.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:y.getStyle(this.props.theme,{marginBottom:0,textAlign:"left"},a,"dark"===this.props.themeType&&t.darkStyle)});return t.newLine?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return null}if(this.props.table)return this.renderItems(i,e);if(this.props.custom)return(0,d.jsx)(h.Grid2,{container:!0,style:Ve.fullWidth,columnSpacing:2,rowSpacing:1,sx:a,children:this.renderItems(i,e)},`${this.props.attr}_${this.props.index}`);let o;if(o=t.collapsable?(0,d.jsxs)(h.Accordion,{style:Ve.fullWidth,expanded:!!this.state.expanded,onChange:()=>{(window._localStorage||window.localStorage).setItem(`${this.props.adapterName}.${this.props.attr}`,this.state.expanded?"false":"true"),this.setState({expanded:!this.state.expanded})},children:[(0,d.jsx)(h.AccordionSummary,{expandIcon:(0,d.jsx)(p.ExpandMore,{}),sx:y.getStyle(this.props.theme,a,this.props.themeType&&t.darkStyle,"primary"===t.color?Ve.primary:"secondary"===t.color&&Ve.secondary,{width:"100%"}),children:(0,d.jsx)(h.Typography,{style:Ve.heading,children:this.getText(t.label)})}),(0,d.jsx)(h.AccordionDetails,{children:(0,d.jsx)(h.Grid2,{container:!0,columnSpacing:2,rowSpacing:1,sx:{...a,width:"100%",padding:"10px"},children:this.renderItems(i,e)})})]},`${this.props.attr}_${this.props.index}`):(0,d.jsx)(h.Box,{component:"div",className:this.props.className,sx:y.getStyle(this.props.theme,this.props.style,a,{width:"100%"},this.props.isParentTab&&Ve.paper,this.props.isParentTab&&(this.props.withIcons?Ve.paperWithIcons:Ve.paperWithoutIcons)),children:(0,d.jsx)(h.Grid2,{container:!0,columnSpacing:2,rowSpacing:1,sx:y.getStyle(this.props.theme,{width:"100%"},this.props.isParentTab&&Ve.padding,this.props.schema.innerStyle),children:this.renderItems(i,e)})},`${this.props.attr}_${this.props.index}`),!this.props.isParentTab){const e=(0,d.jsx)(h.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:{marginBottom:0,textAlign:"left",...a},children:o});return t.newLine?(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)("div",{style:{flexBasis:"100%",height:0}}),e]}):e}return o}}const We=Pe,Ue={tabs:{height:"100%",width:"100%"},panel:{width:"100%",display:"block"},panelWithIcons:{height:"calc(100% - 72px)"},panelWithoutIcons:{height:"calc(100% - 48px)"}};const Be=class extends C{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(`${this.props.dialogName||"App"}.${this.props.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(`${this.props.dialogName||"App"}.${this.props.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,d.jsxs)("div",{style:Ue.tabs,children:[(0,d.jsx)(h.Tabs,{variant:"scrollable",scrollButtons:"auto",style:this.props.schema.tabsStyle,value:this.state.tab,onChange:(t,e)=>{(window._localStorage||window.localStorage).setItem(`${this.props.dialogName||"App"}.${this.props.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.instanceObj,this.props.index,this.props.globalData))return null;i=this.executeCustom(t[s].disabled,this.props.data,this.props.customObj,this.props.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 a=this.getIcon(t[s].icon);return e=e||!!a,(0,d.jsx)(h.Tab,{id:s,wrapped:!0,disabled:i,value:s,iconPosition:this.props.schema.iconPosition||"start",icon:a,label:this.getText(t[s].label)},s)}))}),(0,d.jsx)(We,{isParentTab:!0,changed:this.props.changed,index:1001,arrayIndex:this.props.arrayIndex,globalData:this.props.globalData,onCommandRunning:this.props.onCommandRunning,commandRunning:this.props.commandRunning,style:{...Ue.panel,...e?Ue.panelWithIcons:Ue.panelWithoutIcons},socket:this.props.socket,adapterName:this.props.adapterName,instance:this.props.instance,common:this.props.common,customs:this.props.customs,alive:this.props.alive,themeType:this.props.themeType,themeName:this.props.themeName,data:this.props.data,originalData:this.props.originalData,systemConfig:this.props.systemConfig,onChange:this.props.onChange,onError:this.props.onError,onBackEndCommand:this.props.onBackEndCommand,multiEdit:this.props.multiEdit,dateFormat:this.props.dateFormat,isFloatComma:this.props.isFloatComma,imagePrefix:this.props.imagePrefix,changeLanguage:this.props.changeLanguage,forceUpdate:this.props.forceUpdate,registerOnForceUpdate:this.props.registerOnForceUpdate,customObj:this.props.customObj,instanceObj:this.props.instanceObj,custom:this.props.custom,schema:t[this.state.tab],table:this.props.table,theme:this.props.theme,DeviceManager:this.props.DeviceManager,withIcons:e},this.state.tab)]})}},Me={width:"100%",height:"100%"};class Re extends i.Component{constructor(t){super(t),this.forceUpdateHandlers=void 0,this.errorTimeout=null,this.errorCached=null,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 a=c.I18n.getLanguage(),o="string"===typeof e?e:"i18n";let n,r=await t.fileExists(`${s}.admin`,`${o}/${a}.json`);if(r?n=`${o}/${a}.json`:(r=await t.fileExists(`${s}.admin`,`${o}/${a}/translations.json`),r?n=`${o}/${a}/translations.json`:"en"!==a&&(r=await t.fileExists(`${s}.admin`,`${o}/en.json`),r?n=`${o}/en.json`:(r=await t.fileExists(`${s}.admin`,`${o}/en/translations.json`),r&&(n=`${o}/en/translations.json`)))),n){const e=await t.readFile(`${s}.admin`,n);let o;o=void 0!==e.file?e.file:e;try{const t=JSON.parse(o);c.I18n.extendTranslations(t,a)}catch(i){return console.error(`Cannot parse language file "${s}.admin/${n}: ${i}`),""}return n}return console.warn(`Cannot find i18n for ${s} / ${n}`),""}return e&&"object"===typeof e?(c.I18n.extendTranslations(e),""):""}readData(){this.props.socket.getCompactSystemConfig().then((t=>this.props.socket.getState(`system.adapter.${this.props.adapterName}.${this.props.instance}.alive`).then((e=>{this.props.custom?this.setState({systemConfig:t.common,alive:!(!e||!e.val)}):this.setState({systemConfig:t.common,alive:!(!e||!e.val)},(()=>this.props.socket.subscribeState(`system.adapter.${this.props.adapterName}.${this.props.instance}.alive`,this.onAlive)))})))).catch((t=>console.error(`Cannot read system config: ${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,i,a,o,n,r,l,h,p,c;null!==(s=e[t].confirm)&&void 0!==s&&s.alsoDependsOn&&(null===(r=e[t].confirm)||void 0===r||r.alsoDependsOn.forEach((s=>{if(e[s]){e[s].confirmDependsOn=e[s].confirmDependsOn||[];const i={...e[t],attr:t};i.confirm&&(i.confirm.cancel="Undo"),e[s].confirmDependsOn.push(i)}else console.error(`[JsonConfigComponent] Attribute ${s} does not exist!`),s.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${s.replace(/^data\./,"")}" instead of "${s}"`)})));null!==(i=e[t].onChange)&&void 0!==i&&i.alsoDependsOn&&(null===(l=e[t].onChange)||void 0===l||l.alsoDependsOn.forEach((s=>{if(e[s]){e[s].onChangeDependsOn=e[s].onChangeDependsOn||[];const i={...e[t],attr:t};e[s].onChangeDependsOn.push(i)}else console.error(`[JsonConfigComponent] Attribute ${s} does not exist!`),s.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${s.replace(/^data\./,"")}" instead of "${s}"`)})));null!==(a=e[t].hidden)&&void 0!==a&&a.alsoDependsOn&&(null===(h=e[t].hidden)||void 0===h||h.alsoDependsOn.forEach((s=>{if(e[s]){e[s].hiddenDependsOn=e[s].hiddenDependsOn||[];const i={...e[t],attr:t};e[s].hiddenDependsOn.push(i)}else console.error(`[JsonConfigComponent] Attribute ${s} does not exist!`),s.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${s.replace(/^data\./,"")}" instead of "${s}"`)})));null!==(o=e[t].label)&&void 0!==o&&o.alsoDependsOn&&(null===(p=e[t].label)||void 0===p||p.alsoDependsOn.forEach((s=>{if(e[s]){e[s].labelDependsOn=e[s].labelDependsOn||[];const i={...e[t],attr:t};e[s].labelDependsOn.push(i)}else console.error(`[JsonConfigComponent] Attribute ${s} does not exist!`),s.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${s.replace(/^data\./,"")}" instead of "${s}"`)})));null!==(n=e[t].help)&&void 0!==n&&n.alsoDependsOn&&(null===(c=e[t].help)||void 0===c||c.alsoDependsOn.forEach((s=>{if(e[s]){e[s].helpDependsOn=e[s].helpDependsOn||[];const i={...e[t],attr:t};e[s].helpDependsOn.push(i)}else console.error(`[JsonConfigComponent] Attribute ${s} does not exist!`),s.startsWith("data.")&&console.warn(`[JsonConfigComponent] please use "${s.replace(/^data\./,"")}" instead of "${s}"`)})))}))}renderItem(t){return"tabs"===t.type?(0,d.jsx)(Be,{DeviceManager:this.props.DeviceManager,adapterName:this.props.adapterName,alive:this.state.alive,changeLanguage:this.changeLanguage,changed:this.state.changed,commandRunning:this.state.commandRunning,common:this.props.common,custom:this.props.custom,customObj:this.props.customObj,customs:this.props.customs,data:this.props.data,dateFormat:this.props.dateFormat,forceUpdate:this.forceAttrUpdate,imagePrefix:this.props.imagePrefix,instance:this.props.instance,instanceObj:this.props.instanceObj,isFloatComma:this.props.isFloatComma,multiEdit:this.props.multiEdit,onChange:this.onChange,onCommandRunning:this.onCommandRunning,onError:(t,e)=>this.onError(t,e),onBackEndCommand:this.props.onBackEndCommand,originalData:JSON.parse(this.state.originalData),registerOnForceUpdate:this.registerOnForceUpdate,root:!0,schema:t,socket:this.props.socket,systemConfig:this.state.systemConfig,theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType}):"panel"!==t.type&&t.type?null:(0,d.jsx)(We,{DeviceManager:this.props.DeviceManager,adapterName:this.props.adapterName,alive:this.state.alive,changeLanguage:this.changeLanguage,changed:this.state.changed,commandRunning:this.state.commandRunning,common:this.props.common,custom:this.props.custom,customObj:this.props.customObj,customs:this.props.customs,data:this.props.data,dateFormat:this.props.dateFormat,forceUpdate:this.forceAttrUpdate,imagePrefix:this.props.imagePrefix,index:1e3,instance:this.props.instance,instanceObj:this.props.instanceObj,isFloatComma:this.props.isFloatComma,isParentTab:!this.props.embedded,multiEdit:this.props.multiEdit,onChange:this.onChange,onCommandRunning:this.onCommandRunning,onError:(t,e)=>this.onError(t,e),onBackEndCommand:this.props.onBackEndCommand,originalData:JSON.parse(this.state.originalData),registerOnForceUpdate:this.registerOnForceUpdate,root:!0,schema:t,socket:this.props.socket,systemConfig:this.state.systemConfig,theme:this.props.theme,themeName:this.props.themeName,themeType:this.props.themeType})}render(){return this.state.systemConfig?(0,d.jsx)("div",{style:{...this.props.embedded?void 0:Me,...this.props.style,...this.state.schema.style},children:this.renderItem(this.state.schema)}):(0,d.jsx)(h.LinearProgress,{})}}const Je=Re,ze={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 He(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),a=window.CryptoJS.enc.Hex.parse(s[1]),o=window.CryptoJS.lib.CipherParams.create({ciphertext:window.CryptoJS.enc.Hex.parse(s[2])}),n=window.CryptoJS.AES.decrypt(o,i,{iv:a});return window.CryptoJS.enc.Utf8.stringify(n)}function qe(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 a=window.CryptoJS.enc.Hex.parse(t),o=window.CryptoJS.AES.encrypt(e,a,{iv:i}).ciphertext;return`$/aes-192-cbc:${window.CryptoJS.enc.Hex.stringify(i)}:${o}`}function Ke(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 Ge extends c.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{window.alert(c.I18n.t("[JsonConfig] Failed to parse JSON file"))}},t.readAsText(e)}else window.alert(c.I18n.t("[JsonConfig] Failed to open JSON File"))},this.onFileChange=async(t,e,s)=>{if(t===`${this.props.adapterName}.admin`&&s)if(e===this.fileLangSubscribed)try{var i;await Je.loadI18n(this.props.socket,null===(i=this.state.schema)||void 0===i?void 0:i.i18n,this.props.adapterName),this.setState({hash:`${this.state.hash}1`})}catch{}else if(this.fileSubscribed.includes(e))try{const t=await this.getConfigFile(this.fileSubscribed[0]);this.setState({schema:t,hash:l()(JSON.stringify(t)).toString()})}catch{}},this.state={updateData:0,changed:!1,confirmDialog:!1,theme:(0,c.Theme)(t.themeName),saveConfigDialog:!1,hash:"_"},this.secret=t.secret||"",this.getInstanceObject().then((t=>this.getConfigFile().then((e=>Je.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(`${this.props.adapterName}.admin`,this.fileLangSubscribed,this.onFileChange))),t?this.setState({schema:e,data:t.native,common:t.common,hash:l()(JSON.stringify(e)).toString()}):window.alert(`Instance system.adapter.${this.props.adapterName}.${this.props.instance} not found!`)}))))))}componentWillUnmount(){super.componentWillUnmount(),this.fileSubscribed.length&&(this.props.socket.unsubscribeFiles(`${this.props.adapterName}.admin`,this.fileSubscribed,this.onFileChange),this.fileSubscribed=[]),this.fileLangSubscribed&&(this.props.socket.unsubscribeFiles(`${this.props.adapterName}.admin`,this.fileLangSubscribed,this.onFileChange),this.fileLangSubscribed="")}getExportImportButtons(){return(0,d.jsxs)("div",{style:ze.exportImportButtons,children:[(0,d.jsx)(h.Tooltip,{title:this.props.t("Import settings from JSON file"),slotProps:{popper:{sx:ze.tooltip}},children:(0,d.jsx)(h.Fab,{size:"small",sx:{"&.MuiFab-root":ze.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,d.jsx)(p.Publish,{})})}),(0,d.jsx)(h.Tooltip,{title:this.props.t("Export setting to JSON file"),slotProps:{popper:{sx:ze.tooltip}},children:(0,d.jsx)(h.Fab,{size:"small",sx:{"&.MuiFab-root":ze.button},onClick:()=>{this.state.data&&y.generateFile(`${this.props.adapterName}.${this.props.instance}.json`,this.state.data)},children:(0,d.jsx)(p.Publish,{style:{transform:"rotate(180deg)"}})})})]})}async getInstanceObject(){try{const e=await this.props.socket.getObject(`system.adapter.${this.props.adapterName}.${this.props.instance}`);if(Array.isArray(e.encryptedNative)){var t;if(!this.secret){const t=await this.props.socket.getSystemConfig();await Ke("../../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]=He(this.secret,e.native[t]))})),e}return e}catch(e){window.alert(`[JsonConfig] Cannot read instance object: ${e}`)}return null}renderConfirmDialog(){return this.state.confirmDialog?(0,d.jsx)(c.Confirm,{title:c.I18n.t("ra_Please confirm"),text:c.I18n.t("ra_Some data are not stored. Discard?"),ok:c.I18n.t("ra_Discard"),cancel:c.I18n.t("ra_Cancel"),onClose:t=>this.setState({confirmDialog:!1},(()=>t&&c.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={...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: ${t} => ${e.join(" => ")}`),null;e.push(t);try{await this.props.socket.fileExists(`${this.props.adapterName}.admin`,t)||(t="jsonConfig.json");const i=await this.props.socket.readFile(`${this.props.adapterName}.admin`,t);let a="",o="";if(void 0!==i.file&&(o=i.file),"string"===typeof o)a=o;else if("Buffer"===o.type){let t="";const e=new Uint8Array(o.data),s=e.byteLength;for(let i=0;i<s;i++)t+=String.fromCharCode(e[i]);a=t}this.fileSubscribed.includes(t)||(this.fileSubscribed.push(t),await this.props.socket.subscribeFiles(`${this.props.adapterName}.admin`,t,this.onFileChange));try{return await this.scanForInclude(n().parse(a),e)}catch(s){window.alert("[JsonConfig] Cannot parse json5 config!"),console.log(s)}}catch(i){this.state.schema||window.alert(`[JsonConfig] Cannot read file "${t}: ${i}`)}return null}renderSaveConfigDialog(){return this.state.saveConfigDialog?(0,d.jsx)(c.Confirm,{title:c.I18n.t("ra_Please confirm"),text:c.I18n.t("Save configuration?"),ok:c.I18n.t("ra_Save"),cancel:c.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: ${e}, ${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[a,o]of Object.entries(s.items)){if("panel"===o.type||"tabs"===o.type||"accordion"===o.type)return;this.postProcessing(t,a,o)}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 a=parseFloat(i.toString().replace(",","."));void 0!==s.min&&a<s.min?t[e]=s.min:void 0!==s.max&&a>s.max?t[e]=s.max:t[e]=a}else if("port"===s.type){const a=parseInt(i.toString(),10);void 0!==s.min&&a<s.min?t[e]=s.min:void 0!==s.max&&a>s.max&&(t[e]=s.max),0!==t[e]&&a<20?t[e]=20:t[e]=a>65535?65535:a}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 i={};for(const e of Object.keys(this.state.data)){const s=this.findAttr(e);s&&s.doNotSave&&"state"!==s.type||e.startsWith("_")?(C.setValue(t.native,e,null),i[e]=this.state.data[e]):C.setValue(t.native,e,this.state.data[e])}try{const e=JSON.parse(JSON.stringify(t));if(Array.isArray(e.encryptedNative)){await Ke("../../lib/js/crypto-js/crypto-js.js","crypto-js");for(const t of e.encryptedNative)e.native[t]&&(e.native[t]=qe(this.secret,e.native[t]))}await this.props.socket.setObject(e._id,e)}catch(s){window.alert(`[JsonConfig] Cannot set object: ${s}`)}const a={...t.native,...i};console.log(a),this.setState({changed:!1,data:a,updateData:this.state.updateData+1,originalData:a},(()=>e&&c.Router.doNavigate(null)))}else this.state.changed?this.setState({confirmDialog:!0}):c.Router.doNavigate(null)}componentDidUpdate(t,e){e.changed!==this.state.changed&&this.props.configStored(!this.state.changed)}async componentDidMount(){const t=`${window.location.protocol}//${window.location.host}${window.location.pathname}validate_config/${this.props.adapterName}`;console.log(`fetch ${t}`),await fetch(t)}render(){return this.state.data&&this.state.schema?(0,d.jsxs)("div",{style:ze.root,children:[this.renderConfirmDialog(),this.getExportImportButtons(),this.renderSaveConfigDialog(),(0,d.jsx)(Je,{style:ze.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,data:this.state.data,updateData:this.state.updateData,onError:t=>this.setState({error:t}),onChange:(t,e,s)=>{s&&this.state.error&&(window.alert(c.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,d.jsx)(c.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,d.jsx)(h.LinearProgress,{})}}const Ye=Ge},75443:()=>{}}]);
|
|
2
|
+
//# sourceMappingURL=9399.5852b7e7.chunk.js.map
|