import{P as R,h as f,i}from"./index-CXwCk-SR.js";const $={MINUTE:{minMs:6e4,maxMs:4*60*6e4},HOUR:{minMs:60*6e4,maxMs:14*24*60*6e4},DAY:{minMs:24*60*6e4,maxMs:93*24*60*6e4}},d=6e4,M=60*d,o=24*M,c=[{id:"5m",label:"Last 5 minutes",step:"MINUTE",durationMs:5*d},{id:"15m",label:"Last 15 minutes",step:"MINUTE",durationMs:15*d},{id:"30m",label:"Last 30 minutes",step:"MINUTE",durationMs:30*d},{id:"1h",label:"Last 1 hour",step:"MINUTE",durationMs:60*d},{id:"2h",label:"Last 2 hours",step:"MINUTE",durationMs:2*M},{id:"4h",label:"Last 4 hours",step:"MINUTE",durationMs:4*M},{id:"6h",label:"Last 6 hours",step:"HOUR",durationMs:6*M},{id:"12h",label:"Last 12 hours",step:"HOUR",durationMs:12*M},{id:"1d",label:"Last 24 hours",step:"HOUR",durationMs:1*o},{id:"3d",label:"Last 3 days",step:"HOUR",durationMs:3*o},{id:"7d",label:"Last 7 days",step:"HOUR",durationMs:7*o},{id:"14d",label:"Last 14 days",step:"HOUR",durationMs:14*o},{id:"30d",label:"Last 30 days",step:"DAY",durationMs:30*o},{id:"60d",label:"Last 60 days",step:"DAY",durationMs:60*o},{id:"90d",label:"Last 90 days",step:"DAY",durationMs:90*o}],v=c.find(t=>t.id==="1h");function H(t,e){const a=$[t];return e>=a.minMs&&e<=a.maxMs}function I(t){const e=a=>String(a).padStart(2,"0");return`${t.getUTCFullYear()}-${e(t.getUTCMonth()+1)}-${e(t.getUTCDate())} ${e(t.getUTCHours())}${e(t.getUTCMinutes())}`}function y(t){const e=a=>String(a).padStart(2,"0");return`${t.getUTCFullYear()}-${e(t.getUTCMonth()+1)}-${e(t.getUTCDate())} ${e(t.getUTCHours())}`}function N(t){const e=a=>String(a).padStart(2,"0");return`${t.getUTCFullYear()}-${e(t.getUTCMonth()+1)}-${e(t.getUTCDate())}`}function g(t,e){return t==="DAY"?N(e):t==="HOUR"?y(e):I(e)}const Y=R("time-range",()=>{const t=f(v.id),e=f(Date.now()-v.durationMs),a=f(Date.now()),p=f(v.step),n=i(()=>t.value==="custom"?null:c.find(s=>s.id===t.value)??null),m=i(()=>{var s;return((s=n.value)==null?void 0:s.step)??p.value}),h=i(()=>n.value?n.value.durationMs:Math.max(0,a.value-e.value)),b=i(()=>{if(n.value){const s=Date.now();return{startMs:s-n.value.durationMs,endMs:s}}return{startMs:e.value,endMs:a.value}}),L=i(()=>{const s=b.value;return{start:g(m.value,new Date(s.startMs)),end:g(m.value,new Date(s.endMs)),step:m.value}}),D=i(()=>n.value?n.value.label:"Custom range");function S(s){c.some(u=>u.id===s)&&(t.value=s)}function E(s,u,r){if(u<=s)return;const l=u-s;H(r,l)&&(e.value=s,a.value=u,p.value=r,t.value="custom")}function C(s){if(!Number.isFinite(s)||s<=0)return;const u=s*6e4;let r=c[0],l=Math.abs(r.durationMs-u);for(const U of c){const T=Math.abs(U.durationMs-u);(T<l||T===l&&U.durationMs<r.durationMs)&&(r=U,l=T)}t.value=r.id}return{presetId:t,preset:n,step:m,durationMs:h,range:b,duration:L,label:D,selectPreset:S,selectCustom:E,selectByMinutes:C,customStartMs:e,customEndMs:a,customStep:p}});export{$ as S,c as T,H as i,Y as u};
