"use strict";(self.webpackChunkdami=self.webpackChunkdami||[]).push([[2081],{22081:(e,t,a)=>{a.r(t),a.d(t,{default:()=>f});var n=a(59022),o=a(93150),i=a.n(o);const r={"==":(e,t)=>e===t,"!=":(e,t)=>e!==t,">":(e,t)=>e>t,">=":(e,t)=>e>=t,"<":(e,t)=>e<t,"<=":(e,t)=>e<=t,"()":(e,t)=>e?.includes(t)??!1};function s(e,t,a){const n=r[e];return!!n&&n(t,a)}var c=a(93325),d=a(43210),l=a(31791);const u=(0,n.k)("1234567890abcdef",5);const f=async function({data:e,id:t},{prevBlockData:a,refData:n}){if(0===e.conditions.length)throw new Error("conditions-empty");let o="",r=!1,f="fallback";const p={},w=e.conditions[0],m=Array.isArray(a)?a[0]:a;if(w&&w.conditions){const a={refData:n,isMV2:this.engine.isMV2,checkCodeCondition:e=>async function(e,t){const a=u();if(!t.data.context||"website"===t.data.context){if(!e.id)throw new Error("no-tab");const[{result:n}]=await i().scripting.executeScript({world:"MAIN",args:[t,a,(0,l.XB)(a)],target:{tabId:e.id,frameIds:[e.frameId||0]},func:({data:e,refData:t},a,n)=>new Promise(((o,i)=>{const r=`automa${a}`,s=document.createElement("script");s.textContent=`\n            (async () => {\n              const ${r} = ${JSON.stringify(t)};\n              ${n}\n              try {\n                ${e.code}\n              } catch (error) {\n                return {\n                  $isError: true,\n                  message: error.message,\n                }\n              }\n            })()\n              .then((detail) => {\n                window.dispatchEvent(new CustomEvent('__automa-condition-code__', { detail }));\n              });\n          `,document.documentElement.appendChild(s);const c=({detail:e})=>{s.remove(),window.removeEventListener("__automa-condition-code__",c),e.$isError?i(new Error(e.message)):o(e)};window.addEventListener("__automa-condition-code__",c)}))});return n}const n=await(0,l.k$)("conditionCode",t);if(n&&n.$isError)throw new Error(n.message);return n}(this.activeTab,e),sendMessage:e=>this._sendMessageToTab({...e.data,label:"conditions",id:t})},o=await function(e,t){return new Promise(((a,n)=>{let o=1;const i={},r=async()=>{try{for(let n=0;n<e.conditions.length;n+=1){const o=await(0,c.Z)(e.conditions[n].conditions,t);if(Object.assign(i,o?.replacedValue||{}),o.isMatch)return void a({match:!0,index:n,replacedValue:i})}e.retryConditions&&o<=e.retryCount?(o+=1,setTimeout((()=>{r()}),e.retryTimeout)):a({match:!1,replacedValue:i})}catch(e){n(e)}};r()}))}(e,a);o.replacedValue&&Object.assign(p,o.replacedValue),o.match&&(r=!0,f=e.conditions[o.index].id)}else for(const{type:t,value:a,compareValue:i,id:c}of e.conditions){if(r)break;const e=await(0,d.Z)(i??m,n).value,l=await(0,d.Z)(a,n).value;Object.assign(p,e.list,l.list);s(t,e.value,l.value)&&(f=c,o=a,r=!0)}return{replacedValue:p,data:o,nextBlockId:this.getBlockConnections(t,f)}}},93325:(e,t,a)=>{a.d(t,{Z:()=>f});var n=a(83465),o=a.n(n),i=a(31528),r=a.n(i),s=a(43210),c=a(64989);const d=e=>"true"===e||"false"!==e&&e,l=e=>Number.isNaN(+e)?e:+e,u={eq:(e,t)=>e===t,eqi:(e,t)=>e?.toLocaleLowerCase()===t?.toLocaleLowerCase(),nq:(e,t)=>e!==t,gt:(e,t)=>l(e)>l(t),gte:(e,t)=>l(e)>=l(t),lt:(e,t)=>l(e)<l(t),lte:(e,t)=>l(e)<=l(t),cnt:(e,t)=>e?.includes(t)??!1,cni:(e,t)=>e?.toLocaleLowerCase().includes(t?.toLocaleLowerCase())??!1,nct:(e,t)=>!u.cnt(e,t),nci:(e,t)=>!u.cni(e,t),stw:(e,t)=>e?.startsWith(t)??!1,enw:(e,t)=>e?.endsWith(t)??!1,rgx:(e,t)=>{const a=t.match(/^\/(.*?)\/([gimy]*)$/);return(a?new RegExp(a[1],a[2]):new RegExp(t)).test(e)},itr:e=>Boolean(d(e)),ifl:e=>!d(e)};async function f(e,t){const a={isMatch:!1,replacedValue:{}};async function n({type:e,data:n}){if(e.startsWith("data")){let e=n.dataPath.trim().replace("@",".");return e.startsWith("{{")&&e.endsWith("}}")&&(e=e.slice(2,-2).trim()),r().has(t.refData,e)}const i=o()(n);for(const e of Object.keys(n)){const{value:n,list:o}=await(0,s.Z)(i[e],t.refData);i[e]=n??"",Object.assign(a.replacedValue,o)}if("value"===e)return i.value;if(e.startsWith("code")){let a;return a=t.isMV2?await t.sendMessage({type:"condition-builder",data:{type:e,data:i,refData:t.refData}}):await t.checkCodeCondition({data:i,refData:t.refData}),a}if(e.startsWith("element")){return await t.sendMessage({type:"condition-builder",data:{type:e,data:i}})}return""}async function i(e){let t=!0;const a={value:"",operator:""};for(const{category:o,data:i,type:r}of e){if(!t)return t;if("compare"===o){const{needValue:e}=c.YK.compareTypes.find((({id:e})=>e===r));if(!e)return t=u[r](a.value),t;a.operator=r}else if("value"===o){const e=await n({data:i,type:r}),{compareable:o}=c.YK.valueTypes.find((({id:e})=>e===r));o?a.operator&&(t=u[a.operator](a.value,e),a.operator=""):t=e,a.value=e}}return t}for(const{conditions:t}of e){if(a.isMatch)return a;let e=!1;for(const{items:a}of t)if(e=await i(a),!e)break;a.isMatch=e}return a}}}]);