"use strict";(self.webpackChunkdami=self.webpackChunkdami||[]).push([[6599],{26599:(o,e,t)=>{t.r(e),t.d(e,{default:()=>s});var a=t(31528),l=t.n(a),r=t(31263);const s=async function({data:o,id:e},{refData:t}){try{if(this.loopList[o.loopId]){const e=this.loopList[o.loopId].index+1;let a;this.loopList[o.loopId].index=e,a="numbers"===o.loopThrough?t.loopData[o.loopId].data+1:this.loopList[o.loopId].data[e],t.loopData[o.loopId]={data:a,$index:e}}else{const a=+o.maxLoop||0,s={numbers:()=>o.fromNumber,table:()=>t.table,"custom-data":()=>JSON.parse(o.loopData),"data-columns":()=>t.table,"google-sheets":()=>t.googleSheets[o.referenceKey],variable:()=>{const e=l().get(t.variables,o.variableName);return Array.isArray(e)?e:(0,r.Rx)(e,e)},elements:async()=>{const t=(0,r.mq)(o.elementSelector)?"xpath":"cssSelector",{elements:l,url:s,loopId:i}=await this._sendMessageToTab({id:e,label:"loop-data",data:{findBy:t,max:a,multiple:!0,reverseLoop:o.reverseLoop,selector:o.elementSelector,waitForSelector:o.waitForSelector??!1,waitSelectorTimeout:o.waitSelectorTimeout??5e3}});return this.loopEls.push({url:s,loopId:i,findBy:t,max:a,blockId:e,selector:o.elementSelector}),l}},i=await s[o.loopThrough]();let d=0;if("numbers"!==o.loopThrough){if(!Array.isArray(i))throw new Error("invalid-loop-data");o.resumeLastWorkflow?d=JSON.parse(localStorage.getItem(`index:${e}`))||0:o.startIndex>0&&(d=o.startIndex),o.reverseLoop&&"elements"!==o.loopThrough&&i.reverse()}this.loopList[o.loopId]={index:d,blockId:e,id:o.loopId,data:i,type:o.loopThrough,maxLoop:"numbers"===o.loopThrough?o.toNumber+1-o.fromNumber:a},t.loopData[o.loopId]={data:"numbers"===o.loopThrough?o.fromNumber:i[d],$index:d}}return localStorage.setItem(`index:${e}`,this.loopList[o.loopId].index),{data:t.loopData[o.loopId],nextBlockId:this.getBlockConnections(e)}}catch(e){throw"elements"===o.loopThrough&&(e.data={selector:o.elementSelector}),e}}}}]);