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