import{useInteraction as e}from"@gem-sdk/core";import t from"./useTimeLeft.js";import{useRef as r}from"react";import{convertTime as o}from"../common/helpers.js";import{useTransition as n}from"../../product/components/product-variants/common/common.js";let useCountDownTimer=(i,m)=>{let a=r(null),{trigger:u}=e(),{timerDaily:s,timerEverygreen:c,dateStandard:l,behaviour:p,redirectUrl:d,timeZone:b,standardType:f,enableDay:g,enableHour:h,enableMinute:j,enableSecond:v,enableWeek:y,autoHideWhenTimeout:w}=i??{},A="evergreen"===p&&!w&&i?.loopAfterFinish,D=t({timerDaily:s,timerEverygreen:c,dateStandard:l,behaviour:p,loopAfterFinish:A,redirectUrl:d,timeZone:b,standardType:f}),{week:N,day:O,hour:S,minute:T,second:E}=o(D,{enableWeek:y,enableDay:g,enableHour:h,enableMinute:j,enableSecond:v});n(e=>{e!==D&&k(D)},[D]);let k=e=>{let t=a.current,r=new Map(Object.entries(JSON.parse(t?.getAttribute("gp-interaction-counter")??"{}")));r.size<=0||r.forEach((o,n)=>{e!==Number(n)||(u({event:"gp:countdown-timer",selector:`[data-id="${m?.uid}"]`,element:t,data:Number(n)}),A||(r.delete(n),t.setAttribute("gp-interaction-counter",JSON.stringify(Object.fromEntries(r)))))})};return{week:N,day:O,hour:S,minute:T,second:E,timeLeft:D,ref:a}};export{useCountDownTimer as default};
