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