"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@gem-sdk/core"),t=require("../common/helpers.js");const n=(e,r)=>e&&"evergreen"===r,a=e=>t.refreshAfterFinish(e.endTime,{days:e.days,hours:e.hours,mins:e.mins});exports.default=s=>{let u=r.useEditorMode(),{timerDaily:l,behaviour:c,timerEverygreen:i,loopAfterFinish:d,redirectUrl:o,timeZone:m,dateStandard:v,standardType:f}=s,h=e.useMemo(()=>{switch(c){case"daily":return t.daily(l.hours,l.mins,l.format);case"evergreen":return t.evergreen(i);case"standard":return t.standard(v,m,f);default:return 0}},[c,v,m,f,l.format,l.hours,l.mins,i.endTime]),[I,g]=e.useState(h),k=e.useRef(),p=e.useCallback(()=>g(e=>e<=0?(o.link&&"#"!==o.link&&"edit"!==u&&window.open(o.link,o.target),n(d,c))?a(i):(clearInterval(k.current),0):e-1),[c,d,u,o.link,o.target,i]);return e.useEffect(()=>{let e=n(d,c);return e&&(clearInterval(k.current),g(a(i)),k.current=setInterval(p,1e3)),h<=0&&!e&&(clearInterval(k.current),g(0)),h>0&&(clearInterval(k.current),g(h),k.current=setInterval(p,1e3)),()=>{clearInterval(k.current)}},[c,p,h,d,i]),I};
