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