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