UNPKG

iobroker.javascript

Version:
2 lines (1 loc) 22.4 kB
import{j as n}from"./createSvgIcon-DPvF8xqu.js";import{c as E,h as yt,j as M,m as nt,k as lt,l as Dt,b as ut,o as xt}from"./iobroker_javascript__loadShare__react__loadShare__.mjs-CTZOFJS2.js";import{_ as u}from"./iobroker_javascript__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__.mjs-DkBjPSMw.js";import{u as kt,a as St,M as Y,C as et,G as Nt,b as $t,c as bt,I as qt,S as J,d as Bt,e as ft,j as Mt,D as Ht,f as Wt}from"./index-XSrHkgLE.js";import{_ as wt,b as Ct,h as vt,i as jt,p as Tt,f as Et,g as mt,o as Pt,Y as Ut,Z as Ft,C as Jt,D as st}from"./iobroker_javascript__loadShare___mf_0_mui_mf_1_material__loadShare__.mjs-QWG5Arqe.js";import{I as Lt}from"./index-C49cpVll.js";import"./iobroker_javascript__loadShare__react__loadShare__.mjs_commonjs-proxy-CE9lvhW8.js";import"./iobroker_javascript__loadShare__prop_mf_2_types__loadShare__.mjs-BCtSFofY.js";import"./virtual_mf-REMOTE_ENTRY_ID_iobroker_javascript__remoteEntry_js-D-eF6r8M.js";import"./preload-helper-BDBacUwf.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs_commonjs-proxy-RQRRZMX5.js";import"./iobroker_javascript__loadShare__react_mf_2_dom__loadShare__.mjs-DeVAS-oa.js";import"./inheritsLoose-B0Ba5G9z.js";function zt(e){const s=kt().getMonitor(),[i,a]=St(s,e);return E(()=>s.subscribeToOffsetChange(a)),E(()=>s.subscribeToStateChange(a)),i}let V;function Gt(){return V||(V=new Image,V.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="),V}const Kt="_wrapperRules_nnott_1",Qt="_rootWrapper_nnott_9",Yt="_addClass_nnott_14",ot={wrapperRules:Kt,rootWrapper:Qt,addClass:Yt},Zt="_switchesItem_10ls3_1",Xt="_switchesItemActive_10ls3_28",Vt="_iconTheme_10ls3_36",it={switchesItem:Zt,switchesItemActive:Xt,iconTheme:Vt},It=({name:e,id:t,active:s,icon:i,adapter:a,socket:o,onDoubleClick:c,title:l,onTouchMove:d,style:j})=>n.jsxs("div",{onDoubleClick:c,onTouchMove:d,title:l?u.I18n.t(l):void 0,className:u.Utils.clsx(it.switchesItem,s&&it.switchesItemActive,`block-${t}`),children:[n.jsx(Y,{iconName:i,className:it.iconTheme,adapter:a,socket:o,style:j}),n.jsx("span",{children:e?u.I18n.t(e):""})]},t),Rt="_cardStyle_8rq8v_1",tn="_cardStyleActive_8rq8v_17",nn="_controlMenu_8rq8v_22",en="_closeBtn_8rq8v_31",sn="_isDelete_8rq8v_73",on="_drag_mobile_8rq8v_90",G={cardStyle:Rt,cardStyleActive:tn,controlMenu:nn,closeBtn:en,isDelete:sn,drag_mobile:on};function K(e,t,s){let i;switch(e){case"actions":if(s==="else")return i={...t,actions:{...t[e],else:[...t[e].else]}},i;if(s==="then")return i={...t,actions:{...t[e],then:[...t[e].then]}},i;throw console.error(`Unknown additionalParameter: ${s}`),new Error(`Unknown additionalParameter: ${s}`);case"triggers":return i={...t,triggers:[...t.triggers]},i;case"conditions":return i={...t,conditions:[...t.conditions]},i;default:throw new Error(`Unknown name: ${e}`)}}function z(e,t,s,i){var a;switch(e){case"actions":return t.actions[s]=t.actions[s].filter(o=>o._id!==i),t;case"conditions":return t.conditions[s]=(a=t.conditions[s])==null?void 0:a.filter(o=>o._id!==i),t;default:return t.triggers=t.triggers.filter(o=>o._id!==i),t}}function cn(e,t,s){const{_id:i,acceptedBy:a}=e;let o;if(!a||!t[a])return console.warn(`Cannot find ${a}`),t;switch(a){case"actions":if(o=t.actions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.actions[s].indexOf(o);t.actions[s][c]=e}return t;case"conditions":if(o=t.conditions[s].find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.conditions[s].indexOf(o);t.conditions[s][c]=e}return t;default:if(o=t.triggers.find(c=>c._id===i),!o)console.warn(`Cannot find ${i}`);else{const c=t.triggers.indexOf(o);t.triggers[c]=e}return t}}const Ot=yt(e=>{var N;const{setUserRules:t,userRules:s,_id:i,id:a,blockValue:o,active:c,acceptedBy:l,isTourOpen:d,setTourStep:j,tourStep:O}=e,[I,_]=M(null),{blocks:r,socket:k,onUpdate:H,setOnUpdate:w,onDebugMessage:f,enableSimulation:x}=nt(et),p=lt(h=>r==null?void 0:r.find(b=>b.getStaticData().id===h),[r]),g=lt(h=>{const b=cn(h,s,o);b&&t(b)},[s]),C=h=>{h.currentTarget!==I&&_(h.currentTarget)},q=()=>_(null),T=Dt(()=>{const h=p(a)||Nt;return n.jsx(h,{...e,notFound:!p(a),isTourOpen:d,setTourStep:j,tourStep:O,onUpdate:H,setOnUpdate:w,enableSimulation:x,onDebugMessage:f,onChange:g,className:void 0,socket:k})},[s,H,f,x]),[S,B]=M(!1);return n.jsxs("div",{onMouseMove:C,onMouseEnter:C,onMouseLeave:q,onMouseDown:h=>{if(h.ctrlKey){let b;const v=K(l,s,o);l==="conditions"?(b=v.conditions[o].find(m=>m._id===i),b&&v.conditions[o].splice(v.conditions[o].indexOf(b),0,{...b,_id:Date.now()})):l==="actions"?(b=v.actions[o].find(m=>m._id===i),b&&v.actions[o].splice(v.actions[o].indexOf(b),0,{...b,_id:Date.now()})):(b=v.triggers.find(m=>m._id===i),b&&v.triggers.splice(v[l].indexOf(b),0,{...b,_id:Date.now()})),t(v)}},id:"height",style:c?{width:(((N=document.getElementById("width"))==null?void 0:N.clientWidth)||0)-70}:void 0,className:`${G.cardStyle} ${c?G.cardStyleActive:null} ${S?G.isDelete:null}`,children:[n.jsx("div",{className:G.drag_mobile}),T,t&&n.jsx("div",{className:G.controlMenu,style:I?{opacity:1}:{opacity:0},children:n.jsx("div",{onClick:()=>{let h=K(l,s,o);h=z(l,h,o,i),B(!0),setTimeout(()=>{l==="triggers"&&w(!0),t(h)},300)},className:G.closeBtn})})]})}),rn={position:"fixed",pointerEvents:"none",zIndex:100,left:0,top:0,width:"100%",height:"100%"},an=(e,t,s)=>{if(!e||!t)return{display:"none"};let{x:i,y:a}=t;const o=`translate(${i}px, ${a}px)`;return{transform:o,WebkitTransform:o}},ln=e=>{const{itemType:t,isDragging:s,item:i,initialOffset:a,currentOffset:o,targetIds:c}=zt(d=>({item:d.getItem(),itemType:d.getItemType(),initialOffset:d.getInitialSourceClientOffset(),currentOffset:d.getSourceClientOffset(),isDragging:d.isDragging(),targetIds:d.getTargetIds()})),l=()=>t==="box"?c.length?n.jsx(Ot,{active:!0,...i,allBlocks:e.allBlocks}):n.jsx(It,{active:!0,...i,socket:e.socket}):null;return s?n.jsx("div",{style:rn,children:n.jsx("div",{style:an(a,o),children:l()})}):null},dn="_border_wrpm3_1",fn="_emptyBlockStyle_wrpm3_6",mn="_emptyBlock_wrpm3_6",gn="_selectOnChange_wrpm3_22",hn="_selectOnChangeHelp_wrpm3_28",_n="_selectOnChangeHelpIcon_wrpm3_34",pn="_emptyBlockNone_wrpm3_49",un="_mainBlockItemRules_wrpm3_55",xn="_nameBlockItems_wrpm3_63",bn="_contentBlockItem_wrpm3_73",wn="_wrapperMargin_wrpm3_81",Cn="_contentHeightOn_wrpm3_87",vn="_contentHeightOff_wrpm3_99",jn="_cardAdd_wrpm3_105",In="_blockCardAdd_wrpm3_125",On="_addClassOverflow_wrpm3_136",An="_addClassHeight_wrpm3_140",D={border:dn,emptyBlockStyle:fn,emptyBlock:mn,selectOnChange:gn,selectOnChangeHelp:hn,selectOnChangeHelpIcon:_n,emptyBlockNone:pn,mainBlockItemRules:un,nameBlockItems:xn,contentBlockItem:bn,wrapperMargin:wn,contentHeightOn:Cn,contentHeightOff:vn,cardAdd:jn,blockCardAdd:In,addClassOverflow:On,addClassHeight:An};function dt(e,t){const[s,i]=M(window.localStorage.getItem(t)?JSON.parse(window.localStorage.getItem(t)||""):e);return[s,o=>{window.localStorage.setItem(t,JSON.stringify(o)),i(o)},!!window.localStorage.getItem(t)]}function yn(e,t){let s=0,i=null,a;return function(...o){const c=Date.now();a=o,c-s>=t?(s=c,e.apply(this,o)):i||(i=setTimeout(()=>{s=Date.now(),i=null,e.apply(this,a)},t-(c-s)))}}function tt(e){if(Array.isArray(e))return e.map(t=>tt(t));if(typeof e=="function")return e.bind(null);if(e&&typeof e=="object"){const t={};return Object.keys(e).forEach(s=>{t[s]=tt(e[s])}),t}return e}const ct=yn((e,t)=>e(t),0);function R(e,t){const s=t.find(i=>i._id===e);return{card:s,index:s?t.indexOf(s):-1}}function rt(e,t,s,i,a,o,c,l,d){const{card:j,index:O}=R(e,s);if(!(O<t&&l<d)&&!(O>t&&l>d)&&j&&O!==t){const I=tt(s);I.splice(O,1),I.splice(t,0,j);const _=tt(a);switch(o){case"actions":_.actions[c]=I,ct(i,_);return;case"conditions":_.conditions[c]=I,ct(i,_);return;default:_.triggers=I,ct(i,_);return}}}const Dn="_drag_7xfhc_1",kn="_root_7xfhc_11",gt={drag:Dn,root:kn},At=({typeBlock:e,allProperties:t,id:s,isActive:i,setUserRules:a,userRules:o,children:c,_id:l,blockValue:d})=>{const{setOnUpdate:j}=nt(et),[{opacity:O},I,_]=$t({type:"box",item:()=>({...t,id:s,isActive:i,_id:l}),end:(w,f)=>{const{acceptedBy:x}=w,p=f.getDropResult();let g;if(!p)return typeof l=="number"&&!f.getTargetIds().length&&(g=K(x,o,d),g=z(x,g,d,l),a(g)),null;if(p.blockValue!==d){const C=typeof l=="number"?l:Date.now();g=K(x,o,p.blockValue);const q={id:w.id,acceptedBy:w.acceptedBy};switch(x){case"actions":return d&&(g=z("actions",g,d,C)),g=z("actions",g,p.blockValue,C),g.actions[p.blockValue].push({...q,_id:C}),a(g);case"conditions":return typeof d=="number"&&(g=z("conditions",g,d,C)),g=z("conditions",g,p.blockValue,C),g.conditions[p.blockValue].push({...q,_id:C}),a(g);default:return j(!0),g=z("triggers",g,p.blockValue,C),g.triggers.push({...q,_id:C}),a(g)}}},collect:w=>({opacity:w.isDragging()?.4:1,isDragging:w.isDragging()})}),r=ut(null),[,k]=bt({accept:"box",canDrop:()=>!1,hover({_id:w,acceptedBy:f},x){var T;if(!r.current||e!==f)return;const p=(T=r.current)==null?void 0:T.getBoundingClientRect(),g=(p.bottom-p.top)/2,C=x.getClientOffset(),q=((C==null?void 0:C.y)||0)-p.top;if(l&&w!==l)switch(f){case"actions":if(d==="then"||d==="else"){const{index:S}=R(l,o.actions[d]);S!==w&&rt(w,S,o[f][d],a,o,f,d,q,g)}return;case"conditions":if(typeof d=="number"){const{index:S}=R(l,o[f][d]);S!==w&&rt(w,S,o[f][d],a,o,f,d,q,g)}return;default:{const{index:S}=R(l,o[f]);S!==w&&rt(w,S,o[f],a,o,f,void 0,q,g);return}}}});E(()=>{_(Gt(),{captureDraggingState:!0})},[]),I(k(r));const H=window.innerWidth<600;return n.jsxs("div",{ref:H&&l?null:r,className:gt.root,style:{opacity:O},children:[n.jsx("div",{className:l?gt.drag:null,ref:l&&H?r:null}),c]})},Sn=({onClose:e,open:t})=>n.jsxs(wt,{open:t,onClose:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[n.jsx(Ct,{children:n.jsxs("div",{style:{fontSize:"1rem",fontFamily:'"Roboto", "Helvetica", "Arial", sans-serif',fontWeight:400,lineHeight:1.5,letterSpacing:"0.00938em"},children:[n.jsx("h3",{children:u.I18n.t("On condition change")}),n.jsx("div",{children:u.I18n.t("help_on_change")}),n.jsx("h3",{children:u.I18n.t("Just check")}),n.jsx("div",{children:u.I18n.t("help_just_check")})]})}),n.jsx(vt,{children:n.jsx(jt,{onClick:e,color:"primary",autoFocus:!0,startIcon:n.jsx(Lt,{}),children:u.I18n.t("OK")})})]}),Nn=({onClose:e,open:t})=>n.jsxs(wt,{open:t,onClose:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",children:[n.jsx(Ct,{children:n.jsxs(Tt,{id:"alert-dialog-description",children:[n.jsx("h3",{children:u.I18n.t("On condition change")}),n.jsx("div",{children:u.I18n.t("help_on_change")}),n.jsx("h3",{children:u.I18n.t("Just check")}),n.jsx("div",{children:u.I18n.t("help_just_check")})]})}),n.jsx(vt,{children:n.jsx(jt,{onClick:e,color:"primary",autoFocus:!0,children:u.I18n.t("OK")})})]}),ht=({size:e,blockValue:t,boolean:s,typeBlock:i,userRules:a,setUserRules:o,animation:c,setTourStep:l,tourStep:d,isTourOpen:j,theme:O,themeType:I,themeName:_})=>{var W;const[r,k]=M(!1),[H,w]=M(!1),[f,x]=M(!1),[p,g]=M("");s===void 0&&(s=!0);const C=bt({accept:"box",drop:()=>({blockValue:t}),hover:({acceptedBy:A,_id:L},Z)=>{k(A===i),x(!!L),g(Z.getHandlerId()||"")},canDrop:({acceptedBy:A})=>(w(A===i),A===i),collect:A=>{var L;return{isOver:A.isOver(),canDrop:((L=A.getItem())==null?void 0:L.acceptedBy)===i,offset:A.getClientOffset(),targetId:A.getHandlerId()}}}),q=C[0],{canDrop:T,isOver:S,offset:B,targetId:N}=q,h=C[1];E(()=>{g("")},[B]);const b=T&&S;let v="";b?v=r?"#00fb003d":"#fb00002e":T?v=H?"#00fb003d":"#fb00002e":B&&(v=N===p?"#fb00002e":"");let m;return i==="actions"?m=a.actions[t]:i==="conditions"?m=a.conditions[t]:m=a.triggers,n.jsx("div",{ref:h,style:{backgroundColor:v},className:`${u.Utils.clsx(D.contentBlockItem,e&&D.addClassHeight)} ${s?c?D.contentHeightOn:null:D.contentHeightOff}`,children:n.jsxs("div",{className:D.wrapperMargin,children:[m.map(A=>n.jsx(At,{typeBlock:i,...A,blockValue:t,allProperties:A,userRules:a,setUserRules:o,children:n.jsx(Ot,{...A,isTourOpen:j,setTourStep:l,tourStep:d,settings:A,blockValue:t,userRules:a,setUserRules:o,theme:O,themeType:I,themeName:_})},A._id)),n.jsx("div",{style:b&&r&&!f?{height:((W=document.getElementById("height"))==null?void 0:W.clientHeight)||200}:void 0,className:`${D.emptyBlockStyle} ${b&&r&&!f?D.emptyBlock:D.emptyBlockNone}`})]})})},at=({size:e,typeBlock:t,name:s,nameAdditionally:i,additionally:a,border:o,userRules:c,setUserRules:l,iconName:d,adapter:j,socket:O,setTourStep:I,tourStep:_,isTourOpen:r,theme:k,themeType:H,themeName:w})=>{const[f,x,p]=dt(t==="actions"?!1:[],`additionallyClickItems_${t}`),[g,C]=M(!1),[q,T]=M(!1);E(()=>{if(t==="conditions"&&(f==null?void 0:f.length)!==c.conditions.length-1){const N=[];c.conditions.forEach((h,b)=>{b>0&&N.push({_id:Date.now(),open:!0})}),x([...f,...N])}t==="actions"&&!p&&c.actions.else.length&&x(!0)},[]);const[S,B]=M(!1);return n.jsxs("div",{className:`${u.Utils.clsx(D.mainBlockItemRules,e&&D.addClassOverflow)} ${o&&!e?D.border:null}`,children:[n.jsxs("span",{id:"width",className:D.nameBlockItems,children:[n.jsx(Y,{iconName:d,className:D.iconThemCard,adapter:j,socket:O}),s]}),t==="conditions"?n.jsxs("div",{style:{width:"100%"},children:[n.jsxs(Et,{variant:"standard",className:D.selectOnChange,value:c.justCheck||!1,onChange:N=>{const h=K("conditions",c);h.justCheck=N.target.value==="true",l(h)},children:[n.jsx(mt,{value:"false",children:u.I18n.t("on condition change")}),n.jsx(mt,{value:"true",children:u.I18n.t("just check")})]}),n.jsx(Pt,{size:"small",title:u.I18n.t("Explanation"),className:D.selectOnChangeHelp,onClick:()=>C(!0),children:n.jsx(qt,{className:D.selectOnChangeHelpIcon})})]}):null,n.jsx(ht,{setTourStep:I,tourStep:_,isTourOpen:r,blockValue:t==="actions"?"then":t==="conditions"?0:t,typeBlock:t,setUserRules:l,userRules:c,theme:k,themeName:w,themeType:H,size:e}),a&&[...Array(t==="actions"?1:c.conditions.length-1)].map((N,h)=>{const b=(v=h)=>t==="actions"?!!f:!!f.find((m,W)=>W===v&&m.open);return n.jsxs(xt,{children:[n.jsxs("div",{onClick:()=>{if(t==="actions")return x(!f),null;let v=JSON.parse(JSON.stringify(f));if(c.conditions[h+1].length)return v[h].open=!v[h].open,x(v),null;v=v.filter((m,W)=>W!==h),x(v),B(h),setTimeout(()=>{B(!1),l({...c,conditions:[...c.conditions.filter((m,W)=>W!==h+1)]})},250)},className:D.blockCardAdd,children:[b()?"-":"+",n.jsx("div",{className:D.cardAdd,children:i})]},h),n.jsx(ht,{blockValue:t==="actions"?"else":t==="conditions"?h+1:t,typeBlock:t,setUserRules:l,userRules:c,boolean:b(),animation:S===h,size:e,theme:k,themeName:w,themeType:H})]},`${h}_block_${t}`)}),a&&t==="conditions"&&n.jsxs("div",{onClick:()=>{x([...f,{_id:Date.now(),open:!0}]),l({...c,conditions:[...c.conditions,[]]}),B(c.conditions.length-1),setTimeout(()=>B(!1),1e3)},className:D.blockCardAdd,children:["+",n.jsx("div",{className:D.cardAdd,children:i})]}),n.jsx(Sn,{open:g,onClose:()=>C(!1)}),n.jsx(Nn,{open:q,onClose:()=>T(!1)})]})},$n="_menuRules_1qqcb_1",qn="_switchesRenderWrapper_1qqcb_13",Bn="_menuOff_1qqcb_22",Mn="_menuTitle_1qqcb_28",Hn="_marginAuto_1qqcb_42",Wn="_inputWidth_1qqcb_47",Tn="_menuWrapper_1qqcb_52",En="_hamburgerWrapper_1qqcb_57",Pn="_hamburgerOff_1qqcb_74",Un="_nothingFound_1qqcb_82",Fn="_resetSearch_1qqcb_89",Jn="_controlPanel_1qqcb_101",Ln="_controlPanelAppBar_1qqcb_112",zn="_addClassMenu_1qqcb_126",Gn="_addClassBackground_1qqcb_132",Kn="_addClassPosition_1qqcb_136",$={menuRules:$n,switchesRenderWrapper:qn,menuOff:Bn,menuTitle:Mn,marginAuto:Hn,inputWidth:Wn,menuWrapper:Tn,hamburgerWrapper:En,hamburgerOff:Pn,nothingFound:Un,resetSearch:Fn,controlPanel:Jn,controlPanelAppBar:Ln,addClassMenu:zn,addClassBackground:Gn,addClassPosition:Kn},Qn=e=>{const{allProperties:t,allProperties:{acceptedBy:s,id:i},setUserRules:a,userRules:o,setTourStep:c,tourStep:l,isTourOpen:d,onTouchMove:j,isActive:O}=e;return n.jsx(At,{allProperties:t,id:t.id,isActive:O,setUserRules:a,userRules:o,children:n.jsx(It,{onDoubleClick:()=>{d&&l===J.addScheduleByDoubleClick&&i==="TriggerScheduleBlock"&&c(J.openTagsMenu),d&&l===J.addActionPrintText&&i==="ActionPrintText"&&c(J.showJavascript);const I=Date.now();let _;switch(s){case"actions":_="then";break;case"conditions":_=o[s].length-1;break}const r=K(s,o,_),k={id:i,_id:I,acceptedBy:s};_!==void 0?s==="actions"?r.actions[_].push({...k}):s==="conditions"&&r.conditions[_].push({...k}):r.triggers.push({...k}),a(r)},...e,...t,onTouchMove:j})})},Yn="_hamburgerMenu_hqnsm_8",Zn="_animate_hqnsm_21",_t={hamburgerMenu:Yn,animate:Zn};function Xn({bool:e}){return n.jsx("div",{className:`${_t.hamburgerMenu} ${e?_t.animate:""}`})}const Vn=({addClass:e,setAllBlocks:t,allBlocks:s,userRules:i,onChangeBlocks:a,setTourStep:o,tourStep:c,isTourOpen:l})=>{const{blocks:d,socket:j}=nt(et),[O,I]=dt(!1,"hamburgerOnOff"),[_,r]=dt({text:"",type:"triggers",index:0},"filterControlPanel"),k=(f=_.text,x=_.type)=>{if(!d)return;let p=[...d];p=p.filter(g=>{if(!f)return!0;const{name:C}=g.getStaticData();return C&&u.I18n.t(C).toLowerCase().includes(f.toLowerCase())}),p=p.filter(g=>x===g.getStaticData().acceptedBy),t(p)},H=(f,x)=>{l&&x===0&&c===J.selectTriggers&&o(J.addScheduleByDoubleClick),l&&x===2&&c===J.selectActions&&o(J.addActionPrintText),r({..._,index:x,type:["triggers","conditions","actions"][x]}),k(_.text,["triggers","conditions","actions"][x])},w=f=>({id:`scrollable-force-tab-${f}`,"aria-controls":`scrollable-force-tabpanel-${f}`});return E(()=>{k()},[d]),n.jsx(Ut,{mouseEvent:!1,touchEvent:"onTouchStart",onClickAway:()=>I(!0),children:n.jsxs("div",{className:u.Utils.clsx($.menuWrapper,e[1035]&&$.addClassMenu),children:[n.jsx("div",{className:`${$.hamburgerWrapper} ${O?$.hamburgerOff:null}`,onClick:()=>I(!O),children:n.jsx(Xn,{bool:!O})}),n.jsxs("div",{className:`${u.Utils.clsx($.menuRules,e[1035]&&$.addClassBackground,e[835]&&$.addClassPosition)} ${O?$.menuOff:null}`,children:[n.jsx("div",{className:$.controlPanel,children:n.jsx(Ft,{className:$.controlPanelAppBar,position:"static",children:n.jsxs(Jt,{value:_.index,onChange:H,children:[n.jsx(st,{className:"blocks-triggers",title:u.I18n.t("Triggers"),icon:n.jsx(Y,{iconName:"FlashOn"}),...w(0)}),n.jsx(st,{title:u.I18n.t("Conditions"),className:"blocks-conditions",icon:n.jsx(Y,{iconName:"Help"}),...w(1)}),n.jsx(st,{title:u.I18n.t("Actions"),className:"blocks-actions",icon:n.jsx(Y,{iconName:"PlayForWork"}),...w(2)})]})})}),n.jsx("div",{className:$.switchesRenderWrapper,children:n.jsxs("span",{children:[s.map(f=>{const{name:x,id:p,icon:g,adapter:C}=f.getStaticData();return n.jsx(xt,{children:n.jsx(Qn,{adapter:C,allProperties:f.getStaticData(),icon:g,id:p,isActive:!1,isTourOpen:l,name:x,onTouchMove:()=>I(!0),setTourStep:o,setUserRules:a,socket:j,tourStep:c,userRules:i})},p)}),!s.length&&n.jsxs("div",{className:$.nothingFound,children:[u.I18n.t("Nothing found"),"...",n.jsx("div",{className:$.resetSearch,onClick:()=>{r({..._,text:""}),k("")},children:u.I18n.t("reset search")})]})]})}),n.jsx("div",{className:u.Utils.clsx($.menuTitle,$.marginAuto)}),n.jsx(Bt,{className:$.inputWidth,fullWidth:!0,customValue:!0,value:_.text,size:"small",autoComplete:"off",label:u.I18n.t("search"),variant:"outlined",onChange:f=>{r({..._,text:f}),k(f)}})]})]})})};let pt=[];const me=({code:e,onChange:t,themeName:s,themeType:i,theme:a,setTourStep:o,tourStep:c,isTourOpen:l,command:d,scriptId:j,changed:O,running:I})=>{var v;const{blocks:_,socket:r,setOnUpdate:k,setOnDebugMessage:H,setEnableSimulation:w}=nt(et),[f,x]=M([]),[p,g]=M(ft(e)),[C,q]=M(""),[T,S]=M(!1);E(()=>{let m,W;const A=(P,y)=>{P===`${m}.alive`&&W!==(y==null?void 0:y.val)&&(W=!!(y!=null&&y.val),W&&m&&(r==null||r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOn",j)))},L=(P,y)=>{var U,Q;r&&m!==((U=y==null?void 0:y.common)==null?void 0:U.engine)&&(m&&(r.unsubscribeState(`${m}.alive`,A),W&&r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOn",j)),m=(Q=y==null?void 0:y.common)==null?void 0:Q.engine,m&&m&&r.subscribeState(`${m}.alive`,A))},Z=(P,y)=>{if(y)try{const U=JSON.parse(y.val),Q=Date.now();if(U.ruleId===j&&Q-U.ts<1e3){const F=[...pt,{blockId:U.blockId,data:U.data,ts:U.ts}];F.length>200&&F.splice(0,200-F.length);for(let X=F.length-1;X>=0;X--)if(F[X].ts<Q-5e3){F.splice(0,X);break}pt=F,H(F)}}catch{console.error(`Cannot parse: ${y.val}`)}};return r==null||r.getObject(j).then(P=>{var y;m=(y=P==null?void 0:P.common)==null?void 0:y.engine,r.subscribeObject(j,L),m&&(r.subscribeState(`${m}.alive`,A),r.subscribeState(`${m.replace(/^system\.adapter\./,"")}.debug.rules`,Z))}),function(){r==null||r.unsubscribeObject(j,L),m&&(r==null||r.unsubscribeState(`${m}.alive`,A),W&&(r==null||r.sendTo(m.replace(/^system\.adapter\./,""),"rulesOff",j)),r==null||r.unsubscribeState(`${m.replace(/^system\.adapter\./,"")}.debug.rules`,Z))}},[]),E(()=>{w(!O&&I)},[O,I,w]),E(()=>{d&&(q(d),T||S(!0))},[d]),E(()=>{const m=ft(e);JSON.stringify(m)!==JSON.stringify(p)&&(g(m),k(!0))},[e]),E(()=>{document.getElementsByTagName("HTML")[0].className=s||"blue"},[s]);const B=lt(m=>{g(m),_&&t(Mt(m,_))},[_,t]),N=ut(null),[h,b]=M({835:!1,1035:!1});return E(()=>{N.current&&(N.current.clientWidth<=1035&&b({835:!1,1035:!0}),N.current.clientWidth<=835&&b({1035:!0,835:!0}),N.current.clientWidth>1035&&b({835:!1,1035:!1}))},[((v=N.current)==null?void 0:v.clientWidth)||0]),!_||!r?null:n.jsxs("div",{className:ot.wrapperRules,ref:N,children:[n.jsx(ln,{allBlocks:f,socket:r}),T?C==="export"?n.jsx(Ht,{scriptId:j,themeType:i,onClose:()=>S(!1),text:JSON.stringify(p,null,2)}):n.jsx(Wt,{themeType:i,onClose:m=>{S(!1),m&&B(JSON.parse(m))}}):null,n.jsxs("div",{className:u.Utils.clsx(ot.rootWrapper,h[835]&&ot.addClass),children:[n.jsx(Vn,{setAllBlocks:x,allBlocks:f,userRules:p,onChangeBlocks:B,setTourStep:o,tourStep:c,addClass:h,isTourOpen:l}),n.jsx(at,{socket:r,setUserRules:B,userRules:p,isTourOpen:l,setTourStep:o,tourStep:c,name:`${u.I18n.t("when")}...`,typeBlock:"triggers",iconName:"FlashOn",size:h[835],themeType:i,themeName:s,theme:a}),n.jsx(at,{socket:r,setUserRules:B,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${u.I18n.t("and")}...`,typeBlock:"conditions",iconName:"Help",nameAdditionally:u.I18n.t("or"),additionally:!0,border:!0,size:h[835],themeType:i,themeName:s,theme:a}),n.jsx(at,{socket:r,setUserRules:B,isTourOpen:l,setTourStep:o,tourStep:c,userRules:p,name:`...${u.I18n.t("then")}`,typeBlock:"actions",iconName:"PlayForWork",nameAdditionally:u.I18n.t("else"),additionally:!0,size:h[835],themeType:i,themeName:s,theme:a})]})]},"rulesEditor")};export{me as default};