import{r as w,ap as m,V as b,j as e,T as d,aq as h,ar as j}from"./index-BX768Frx.js";import{A as v}from"./alert-BrzNrLBf.js";import{E as S,a as N}from"./expandable-list-BNiBLc_K.js";import{F as R}from"./filters-Dgl_na4J.js";import{I}from"./id-DHkDYjrH.js";import{T}from"./tag-DIbqHQC5.js";import{u as f}from"./useQuery-DHwdh6Ld.js";import{c as E,u as z,g as C,P as L}from"./paginated-table-BoD1fFcj.js";import{M as P}from"./main-B6XIaWoX.js";import"./select-fQyM9_P4.js";import"./useBaseQuery-DCSHiJ5h.js";import"./Table-CYzl-NNc.js";import"./useToggleState-DWs3jB3l.js";import"./empty-list-CHaQSvfG.js";const V="This repository uses a non-browsable storage, snapshots cannot be inspected.";function J(){const[o,c]=w.useState({}),u=m.useLoaderData(),g=m.useNavigate(),n=m.useSearch(),l=f(b({importer:n.importer,page:n.page,perPage:n.per_page})),p=E(),r=[p.display({id:"identifier",header:()=>"ID",cell:a=>{const t=a.row.original,s=t.identifier.Value,y=t.total.errors;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(I,{value:s,className:"text-primary"}),e.jsx(S,{length:y})]})}}),p.accessor("timestamp",{header:()=>"Date",cell:a=>{const t=a.getValue();return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(d,{variant:"body",size:"md",className:"text-primary whitespace-nowrap",children:t.relativeToNow()}),e.jsx(d,{variant:"body",size:"sm",className:"text-secondary",children:t.toHumanString()})]})}}),p.display({id:"importer-type",header:()=>"Source",meta:{cellClassName:"w-[60%] max-w-0"},cell:({row:{original:a}})=>{const t=a.tags.filter(s=>s.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(N,{items:a.sources.map(s=>({tag:s.importer.type,value:s.importer.origin,subValue:s.importer.directory.toHumanString()}))})}),t.length>0&&e.jsx("span",{className:"flex max-w-[40%] min-w-0 flex-initial flex-wrap items-start gap-1",children:t.filter(s=>s.trim()).map(s=>e.jsx(T,{size:"sm",variant:"blue",children:s},s))})]})}}),p.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(d,{variant:"body",size:"md",className:"text-primary",children:t.size.Pretty}),e.jsxs(d,{variant:"body",size:"sm",className:"text-secondary",children:[t.files," ",t.files===1?"item":"items"]})]})}})],i={pageIndex:n.page,pageSize:n.per_page},x=z({data:l.data?.items??[],rowCount:l.data?.total,columns:r,state:{pagination:i,rowSelection:o},onRowSelectionChange:c,enableMultiRowSelection:!1,onPaginationChange:a=>{const t=typeof a=="function"?a(i):a;g({search:s=>({...s,page:s.per_page!==t.pageSize?0:t.pageIndex,per_page:t.pageSize})})},manualPagination:!0,getCoreRowModel:C()});return e.jsx(P,{title:"Kloset Repository",description:"List your backups, browse their contents, and restore the files you need.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[!u.browsable&&e.jsx(v,{title:"This snapshot repository is not browsable.",variant:"warning",children:V}),e.jsx(L,{query:l,table:x,filters:e.jsx(_,{}),variant:"cards",skeleton:"two-rows",getLink:a=>({to:"/snapshots/$snapshotId/browse",params:{snapshotId:a.identifier.Value},search:{path:a.sources.length===1?a.sources[0].importer.directory.Value:void 0}}),ariaLabel:"Snapshots table"})]})})}function _(){const o=m.useSearch(),c=m.useNavigate(),{data:u,isPending:g,isError:n}=f(j()),l=u?.items.map(r=>({id:r.name,name:r.name}))||[],p=[{key:"importer",value:o.importer}];return e.jsxs("div",{className:"flex w-full items-center justify-end gap-2",children:[e.jsx(h,{label:"Applied filters",onRemove:r=>{c({search:i=>({...i,importer:r.has("importer")?"":i.importer,page:0})})},children:p.map(({key:r,value:i})=>i?e.jsx(h.Item,{id:r,value:p.find(({key:x})=>x===o.importer)?.value||o.importer},r):null)}),e.jsx(R,{items:[{id:"importer",label:"Source type",options:l,isInvalid:!!o.importer&&!l.some(r=>r.id===o.importer),isDisabled:g||n||l.length===0}],defaultSelected:{importer:o.importer||null},onApply:r=>{c({search:i=>({...i,importer:r.importer||"",page:0})})}})]})}export{J as component};
