import{r as j,aQ as c,y as v,l as y,_ as S,ar as I,j as e,w as N,T as x,n as R,o as T,h as A,s as E,M,aq as z,at as C,as as P,x as _,aR as Q,aS as f}from"./index-CHfgriyV.js";import{A as V}from"./alert-ByJNgWtG.js";import{E as $,a as k}from"./expandable-list-3e49VSSb.js";import{D as O,F as B}from"./download-button-yu0ssjiN.js";import{u as D}from"./useSuspenseQuery-Cya_zjFk.js";import{M as L}from"./main-D1eRPv4V.js";const H="This repository uses a non-browsable storage, snapshots cannot be inspected.";function X(){const[o,m]=j.useState({}),g=c.useNavigate(),n=c.useSearch(),d=c.useRouteContext(),l=D(v(d.klosetAPI,{repository:void 0})).data.item.browsable,p=y(S(d.klosetAPI,{repository:void 0,importer:n.importer,pagination:{page:n.page,perPage:n.per_page}})),s=I(),i=[s.display({id:"identifier",header:()=>"ID",cell:a=>{const t=a.row.original,r=t.identifier.Value,w=t.total.errors;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(N,{value:r}),e.jsx($,{length:w})]})}}),s.accessor("timestamp",{header:()=>"Date",cell:a=>{const t=a.getValue();return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(x,{variant:"body",size:"md",className:"text-primary whitespace-nowrap",children:t.relativeToNow()}),e.jsx(x,{variant:"body",size:"sm",className:"text-secondary",children:t.toHumanString()})]})}}),s.display({id:"importer-type",header:()=>"Source",meta:{cellClassName:"w-[60%] max-w-0 min-w-80"},cell:({row:{original:a}})=>{const t=a.tags.filter(r=>r.trim());return e.jsxs("div",{className:"flex w-full min-w-0 items-baseline gap-4",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(k,{items:a.sources.map(r=>({tag:r.importer.type,value:r.importer.origin,subValue:r.importer.directory.toHumanString()}))})}),t.length>0&&e.jsx("span",{className:"flex min-w-0 max-w-[40%] flex-initial flex-wrap items-start gap-1",children:t.filter(r=>r.trim()).map(r=>e.jsx(R,{size:"sm",variant:"blue_borderless",radius:"sqrt",children:r},r))})]})}}),s.accessor("total",{id:"summary",header:()=>"Stats",cell:a=>{const t=a.getValue();return e.jsxs("div",{className:"flex flex-col gap-1 whitespace-nowrap",children:[e.jsx(x,{variant:"body",size:"md",className:"text-primary",children:t.size.Pretty}),e.jsxs(x,{variant:"body",size:"sm",className:"text-secondary",children:[t.files," ",t.files===1?"item":"items"]})]})}}),s.display({id:"actions",header:()=>"Actions",cell:({row:{original:a}})=>e.jsxs(T,{children:[e.jsx(A,{icon:"ellipsis","aria-label":"More",variant:"tertiary",className:"cursor-pointer"}),e.jsx(E,{placement:"bottom end",offset:4,children:e.jsx(M,{children:e.jsx(O,{snapshotId:a.identifier.Value,paths:[a.sources[0].importer.directory.Value]})})})]})})],u={pageIndex:n.page,pageSize:n.per_page},b=z({data:p.data?.items??[],rowCount:p.data?.total,columns:i,state:{pagination:u,rowSelection:o},onRowSelectionChange:m,enableMultiRowSelection:!1,onPaginationChange:a=>{const t=typeof a=="function"?a(u):a;g({search:r=>({...r,page:r.per_page!==t.pageSize?0:t.pageIndex,per_page:t.pageSize})})},manualPagination:!0,getCoreRowModel:C()});return e.jsx(L,{icon:"folder-tree",iconBadgeType:"store",title:"Snapshots",description:"Browse backups and restore files.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[!l&&e.jsx(V,{title:"This snapshot repository is not browsable.",variant:"warning",children:H}),e.jsx(P,{query:p,table:b,filters:e.jsx(q,{}),variant:"cards",skeleton:"two-rows",getLink:l?a=>({to:"/snapshots/$snapshotId/$source/browse",params:{snapshotId:a.identifier.Value,source:0},search:{path:a.sources[0].importer.directory.Value}}):void 0,ariaLabel:"Snapshots table"})]})})}function q(){const o=c.useSearch(),m=c.useNavigate(),{api:g}=_(),{data:n,isPending:d,isError:h}=y(Q(g,{repository:void 0})),l=n?.items.map(s=>({id:s.name,name:s.name}))||[],p=[{key:"importer",value:o.importer}];return e.jsxs("div",{className:"flex w-full items-center justify-end gap-2",children:[e.jsx(f,{label:"Applied filters",onRemove:s=>{m({search:i=>({...i,importer:s.has("importer")?"":i.importer,page:0})})},children:p.map(({key:s,value:i})=>i?e.jsx(f.Item,{id:s,value:p.find(({key:u})=>u===o.importer)?.value||o.importer},s):null)}),e.jsx(B,{items:[{id:"importer",label:"Source type",options:l,isInvalid:!!o.importer&&!l.some(s=>s.id===o.importer),isDisabled:d||h||l.length===0}],defaultSelected:{importer:o.importer?[o.importer]:null},onApply:s=>{m({search:i=>({...i,importer:s.importer?s.importer[0]:"",page:0})})}})]})}export{X as component};
