import{r as G,ad as _}from"./index-Bkt-lHwp.js";var j={exports:{}};(function(I,q){(function(E,v){I.exports=v(G)})(typeof self<"u"?self:_,E=>(()=>{var v={155:r=>{r.exports=E}},M={};function c(r){var e=M[r];if(e!==void 0)return e.exports;var t=M[r]={exports:{}};return v[r](t,t.exports,c),t.exports}c.d=(r,e)=>{for(var t in e)c.o(e,t)&&!c.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:e[t]})},c.o=(r,e)=>Object.prototype.hasOwnProperty.call(r,e),c.r=r=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})};var h={};c.r(h),c.d(h,{default:()=>R,useStopwatch:()=>D,useTime:()=>N,useTimer:()=>C});var s=c(155);class k{static expiryTimestamp(e){const t=new Date(e).getTime()>0;return t||console.warn("react-timer-hook: { useTimer } Invalid expiryTimestamp settings",e),t}static onExpire(e){const t=e&&typeof e=="function";return e&&!t&&console.warn("react-timer-hook: { useTimer } Invalid onExpire settings function",e),t}}class o{static getTimeFromSeconds(e){const t=Math.ceil(e),n=Math.floor(t/86400),a=Math.floor(t%86400/3600),i=Math.floor(t%3600/60);return{totalSeconds:t,seconds:Math.floor(t%60),minutes:i,hours:a,days:n}}static getSecondsFromExpiry(e,t){const n=e-new Date().getTime();if(n>0){const a=n/1e3;return t?Math.round(a):a}return 0}static getSecondsFromPrevTime(e,t){const n=new Date().getTime()-e;if(n>0){const a=n/1e3;return t?Math.round(a):a}return 0}static getSecondsFromTimeNow(){const e=new Date;return e.getTime()/1e3-60*e.getTimezoneOffset()}static getFormattedTimeFromSeconds(e,t){const{seconds:n,minutes:a,hours:i}=o.getTimeFromSeconds(e);let u="",l=i;return t==="12-hour"&&(u=i>=12?"pm":"am",l=i%12),{seconds:n,minutes:a,hours:l,ampm:u}}}function y(r,e){const t=(0,s.useRef)();(0,s.useEffect)(()=>{t.current=r}),(0,s.useEffect)(()=>{if(!e)return()=>{};const n=setInterval(()=>{t.current&&t.current()},e);return()=>clearInterval(n)},[e])}const F=1e3;function P(r){if(!k.expiryTimestamp(r))return null;const e=o.getSecondsFromExpiry(r),t=Math.floor(1e3*(e-Math.floor(e)));return t>0?t:F}function C(){let{expiryTimestamp:r,onExpire:e,autoStart:t=!0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const[n,a]=(0,s.useState)(r),[i,u]=(0,s.useState)(o.getSecondsFromExpiry(n)),[l,d]=(0,s.useState)(t),[g,b]=(0,s.useState)(t),[x,T]=(0,s.useState)(P(n)),p=(0,s.useCallback)(()=>{k.onExpire(e)&&e(),d(!1),T(null)},[e]),w=(0,s.useCallback)(()=>{d(!1)},[]),f=(0,s.useCallback)(function(m){let O=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];T(P(m)),b(O),d(O),a(m),u(o.getSecondsFromExpiry(m))},[]),S=(0,s.useCallback)(()=>{const m=new Date;m.setMilliseconds(m.getMilliseconds()+1e3*i),f(m)},[i,f]),z=(0,s.useCallback)(()=>{g?(u(o.getSecondsFromExpiry(n)),d(!0)):S()},[n,g,S]);return y(()=>{x!==F&&T(F);const m=o.getSecondsFromExpiry(n);u(m),m<=0&&p()},l?x:null),{...o.getTimeFromSeconds(i),start:z,pause:w,resume:S,restart:f,isRunning:l}}function D(){let{autoStart:r,offsetTimestamp:e}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const[t,n]=(0,s.useState)(o.getSecondsFromExpiry(e,!0)||0),[a,i]=(0,s.useState)(new Date),[u,l]=(0,s.useState)(t+o.getSecondsFromPrevTime(a||0,!0)),[d,g]=(0,s.useState)(r);y(()=>{l(t+o.getSecondsFromPrevTime(a,!0))},d?1e3:null);const b=(0,s.useCallback)(()=>{const p=new Date;i(p),g(!0),l(t+o.getSecondsFromPrevTime(p,!0))},[t]),x=(0,s.useCallback)(()=>{n(u),g(!1)},[u]),T=(0,s.useCallback)(function(){let p=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,w=!(arguments.length>1&&arguments[1]!==void 0)||arguments[1];const f=o.getSecondsFromExpiry(p,!0)||0,S=new Date;i(S),n(f),g(w),l(f+o.getSecondsFromPrevTime(S,!0))},[]);return{...o.getTimeFromSeconds(u),start:b,pause:x,reset:T,isRunning:d}}function N(){let{format:r}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};const[e,t]=(0,s.useState)(o.getSecondsFromTimeNow());return y(()=>{t(o.getSecondsFromTimeNow())},1e3),{...o.getFormattedTimeFromSeconds(e,r)}}function R(r){if((0,s.useEffect)(()=>{console.warn("react-timer-hook: default export useTimer is deprecated, use named exports { useTimer, useStopwatch, useTime } instead")},[]),r.expiryTimestamp){const t=C(r);return{...t,startTimer:t.start,stopTimer:t.pause,resetTimer:()=>{}}}const e=D(r);return{...e,startTimer:e.start,stopTimer:e.pause,resetTimer:e.reset}}return h})())})(j);var B=j.exports;export{B as d};
