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:c,timerEverygreen:s,dateStandard:l,behaviour:p,redirectUrl:d,timeZone:b,enableDay:f,enableHour:g,enableMinute:h,enableSecond:j,enableWeek:v,autoHideWhenTimeout:w}=i??{},y="evergreen"===p&&!1===w&&i?.loopAfterFinish,A=t({timerDaily:c,timerEverygreen:s,dateStandard:l,behaviour:p,loopAfterFinish:y,redirectUrl:d,timeZone:b}),{week:D,day:N,hour:O,minute:S,second:E}=o(A,{enableWeek:v,enableDay:f,enableHour:g,enableMinute:h,enableSecond:j});n(e=>{e!==A&&T(A)},[A]);let T=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)}),y||(r.delete(n),t.setAttribute("gp-interaction-counter",JSON.stringify(Object.fromEntries(r)))))})};return{week:D,day:N,hour:O,minute:S,second:E,timeLeft:A,ref:a}};export{useCountDownTimer as default};
