import{au as R,av as _,aw as $,ax as p,ay as Y,az as N,aA as H,aB as T,aC as b,aD as S,aE as L,aF as q,aG as v,aH as P,an as k,aI as C,aJ as D,ao as m,aK as O,aL as F,aM as u,aN as U,aO as j,aP as x,am as z,q as E}from"./index-CHfgriyV.js";function K(t,n,e){const s=R(t,e?.in);if(isNaN(n))return _(t,NaN);if(!n)return s;const o=s.getDate(),r=_(t,s.getTime());r.setMonth(s.getMonth()+n+1,0);const i=r.getDate();return o>=i?r:(s.setFullYear(r.getFullYear(),r.getMonth(),o),s)}function h(t,n,e){const{years:s=0,months:o=0,weeks:r=0,days:i=0,hours:c=0,minutes:a=0,seconds:l=0}=n,d=R(t,e?.in),f=o||s?K(d,o+s*12):d,g=i||r?$(f,i+r*7):f,y=a+c*60,M=(l+y*60)*1e3;return _(t,+g+M)}function J(t,n,e){const[s,o]=p(e?.in,t,n);return s.getFullYear()-o.getFullYear()}function W(t,n,e){const[s,o]=p(e?.in,t,n),r=A(s,o),i=Math.abs(Y(s,o));s.setDate(s.getDate()-r*i);const c=+(A(s,o)===-r),a=r*(i-c);return a===0?0:a}function A(t,n){const e=t.getFullYear()-n.getFullYear()||t.getMonth()-n.getMonth()||t.getDate()-n.getDate()||t.getHours()-n.getHours()||t.getMinutes()-n.getMinutes()||t.getSeconds()-n.getSeconds()||t.getMilliseconds()-n.getMilliseconds();return e<0?-1:e>0?1:e}function G(t,n,e){const[s,o]=p(e?.in,t,n),r=(+s-+o)/H;return N(e?.roundingMethod)(r)}function V(t,n,e){const s=T(t,n)/b;return N(e?.roundingMethod)(s)}function B(t,n,e){const[s,o]=p(e?.in,t,n),r=S(s,o),i=Math.abs(J(s,o));s.setFullYear(1584),o.setFullYear(1584);const c=S(s,o)===-r,a=r*(i-+c);return a===0?0:a}function Q(t,n){const[e,s]=p(t,n.start,n.end);return{start:e,end:s}}const X=["years","months","weeks","days","hours","minutes","seconds"];function Z(t,n){const s=L().locale??q,o=n?.format??X,r=" ";return s.formatDistance?o.reduce((c,a)=>{const l=`x${a.replace(/(^.)/,f=>f.toUpperCase())}`,d=t[a];return d!==void 0&&t[a]?c.concat(s.formatDistance(l,d)):c},[]).join(r):""}function nn(t,n){const{start:e,end:s}=Q(n?.in,t),o={},r=B(s,e);r&&(o.years=r);const i=h(e,{years:o.years}),c=v(s,i);c&&(o.months=c);const a=h(i,{months:o.months}),l=W(s,a);l&&(o.days=l);const d=h(a,{days:o.days}),f=G(s,d);f&&(o.hours=f);const g=h(d,{hours:o.hours}),y=V(s,g);y&&(o.minutes=y);const w=h(g,{minutes:o.minutes}),M=P(s,w);return M&&(o.seconds=M),o}function tn(t){const n=nn({start:0,end:t/1e6});return{Value:t,toHumanString:()=>{const e=Z(n);return e===""?"less than a second":e},toShortString:()=>{const e=[];return n.years&&e.push(`${n.years}y`),n.months&&e.push(`${n.months}mo`),n.weeks&&e.push(`${n.weeks}w`),n.days&&e.push(`${n.days}d`),n.hours&&e.push(`${n.hours}h`),n.minutes&&e.push(`${n.minutes}m`),n.seconds&&e.push(`${n.seconds}s`),e.length>0?e.join(""):"<1s"},toJSON(){return t}}}const en=k({type:F([u("maintenance"),u("backup"),u("check"),u("restore"),u("sync"),u("rm"),u("unknown")]).catch("unknown").transform(t=>({Value:t,HumanString:{maintenance:"maintenance",backup:"backup",check:"check",restore:"restore",sync:"sync",rm:"remove",unknown:"unknown"}[t]})),name:m(),start_time:m().transform(O),duration:D().transform(tn),status:F([u("OK"),u("FAILURE"),u("WARNING"),u("unknown")]).catch("unknown"),error_code:D(),error_message:m()}),sn=k({name:m()}),on=k({id:m(),timestamp:m().transform(O),report_task:en,report_repository:sn}),rn=k({total:D(),items:C(on)});async function an({repository:t,pagination:n}){const s=`/api/proxy/v1/reporting/reports?${new URLSearchParams({repository_id:t,reverse:"1",...U(n)})}`,o=await j(()=>z(s),x);if(o.error)return{__type:"unauthenticated"};let r;try{r=await o.data.json()}catch{throw new Error(`the API endpoint ${s} returned HTTP/${o.data.status} with an invalid JSON payload`)}return{__type:"ok",...rn.parse(r)}}const I={all:()=>["api","api.plakar.io","reporting"],lists:()=>[...I.all(),"list"],list:t=>[...I.lists(),t]},un=({repository:t,page:n,perPage:e})=>E({queryKey:I.list({repository:t,page:n,perPage:e}),refetchInterval:60*1e3,queryFn:()=>an({repository:t,pagination:{page:n,perPage:e}})});export{un as l};
