1import{j as e}from"./query-DzMrwxOc.js";import{k as Y,r as n}from"./router-BNmspi0x.js";import{b9 as H,by as F,cm as Q,bU as X,bd as q,cn as z,bC as G,bg as J,B as K,aX as Z}from"./index-NI0RHxq9.js";import{S as P,a as _,b as D,c as k,d as p}from"./select-Ygn_2dvs.js";import{u as $}from"./usePreloadEntities-CvCYHvy8.js";import{E as ee}from"./entityTypes-B7Uz9v6g.js";import{C as te}from"./CollectionCard-1W79VYvv.js";import{aB as R}from"./icons-and-animation-C-Yc4ku-.js";import"./react-vendor-BFjHA0Wy.js";import"./ui-components-C4kYX3wD.js";import"./radix-ui-5ncyoCxB.js";import"./utilities-BRQWscav.js";(function(){try{var s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};s.SENTRY_RELEASE={id:"2ecc7e431f5ea99c1855f803165b836ae53c68bb"}}catch{}})();try{(function(){var s=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},l=new s.Error().stack;l&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[l]="7b85292a-353f-426d-822e-ff17ba9963f5",s._sentryDebugIdIdentifier="sentry-dbid-7b85292a-353f-426d-822e-ff17ba9963f5")})()}catch{}function se({collections:s,isLoading:l}){return!l&&s.length===0?null:e.jsxs("section",{"data-layout-slot":"discover-collections",children:[e.jsx("h2",{className:"mb-3 text-sm font-semibold text-muted-foreground uppercase tracking-wider",children:"Public Collections"}),e.jsx("div",{className:"flex gap-3 overflow-x-auto pb-2 -mx-6 px-6 scrollbar-hide",children:l?null:s.slice(0,10).map(d=>e.jsx("div",{className:"w-36 flex-shrink-0",children:e.jsx(te,{collection:d})},d.collection_id))})]})}function he(){const[s,l]=Y(),d=H(),[u,j]=n.useState([]),[I,w]=n.useState(!0),{data:o=[],isLoading:v}=F({sort:"count",enabled:d}),y=Q(),L=n.useMemo(()=>y.data?.pages.flatMap(t=>t.items)??[],[y.data]),B=n.useMemo(()=>Math.round(o.reduce((t,a)=>t+a.count,0)/1.7),[o]),r=s.get("category")||"all",f=s.get("entity_type")||"all",g=s.get("sort")||"default",A=o.find(t=>t.name===r)?.id||null;$(u);const b=n.useCallback(async()=>{w(!0);try{const t={};f!=="all"&&(t.entity_type=f),r!=="all"&&(t.category=r);const a=await X.getEntities(t);a?.entities&&j(a.entities.filter(Boolean))}catch{j([])}finally{w(!1)}},[r,f]);n.useEffect(()=>{d&&b()},[b,d]);const M=n.useCallback(t=>{const a=o.find(N=>N.id===t);if(!a)return;const m=new URLSearchParams(s);r===a.name?m.delete("category"):m.set("category",a.name),l(m)},[o,r,s,l]),U=n.useCallback(t=>{const a=new URLSearchParams(s);t==="all"?a.delete("entity_type"):a.set("entity_type",t),l(a)},[s,l]),O=n.useCallback(t=>{const a=new URLSearchParams(s);t==="default"?a.delete("sort"):a.set("sort",t),l(a)},[s,l]),h=n.useMemo(()=>u.map(t=>t.entity_id).filter(t=>!!t),[u]),T=n.useMemo(()=>{if(g==="default")return h;const t=new Map(u.map(i=>[i.entity_id,i])),a=h.filter(i=>{const c=t.get(i);return!!(c?.dtstart||c?.calendar_data?.dtstart)}),m=h.filter(i=>{const c=t.get(i);return!(c?.dtstart||c?.calendar_data?.dtstart)});return[...[...a].sort((i,c)=>{const x=t.get(i),S=t.get(c),E=new Date(x?.dtstart||x?.calendar_data?.dtstart||0),C=new Date(S?.dtstart||S?.calendar_data?.dtstart||0);return g==="date_desc"?C.getTime()-E.getTime():g==="date_asc"?E.getTime()-C.getTime():0}),...m]},[h,u,g]),V=e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Sort"}),e.jsxs(P,{value:s.get("sort")||"default",onValueChange:O,children:[e.jsx(_,{className:"h-8 w-[140px]",children:e.jsx(D,{placeholder:"Default"})}),e.jsxs(k,{children:[e.jsx(p,{value:"default",children:"Default"}),e.jsx(p,{value:"date_desc",children:"Date (Newest)"}),e.jsx(p,{value:"date_asc",children:"Date (Oldest)"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Type"}),e.jsxs(P,{value:f,onValueChange:U,children:[e.jsx(_,{className:"h-8 w-[140px]",children:e.jsx(D,{placeholder:"All Types"})}),e.jsx(k,{children:ee.map(t=>e.jsx(p,{value:t.value,children:t.label},t.value))})]})]})]});if(I&&u.length===0)return e.jsx(q,{path:z()});const W=e.jsxs("div",{className:"mx-auto flex w-full max-w-[1440px] flex-col gap-6 px-6 py-8 pb-8 md:pb-12","data-page":"discover",children:[e.jsxs("header",{className:"flex flex-wrap items-center justify-between gap-4","data-layout-slot":"discover-header",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("h1",{className:"text-2xl font-semibold tracking-tight text-foreground flex items-center gap-2",children:[e.jsx(R,{className:"h-6 w-6 text-primary"}),"Discoveries"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Explore all entities and discoveries from your stashed content"})]}),e.jsx("div",{className:"flex items-center gap-2",children:V})]}),e.jsx(se,{collections:L,isLoading:y.isLoading}),(v||o.length>0)&&e.jsx("div",{"data-layout-slot":"discover-tags",children:v?null:e.jsx(G,{title:"Personal Tags",tags:[{id:"all",name:"All",color:"#64748b",count:B},...o],selectedTag:r==="all"?"all":A,tagDisplayStyle:"colored",onTagClick:t=>{if(t==="all"){const a=new URLSearchParams(s);a.delete("category"),l(a)}else M(t)}})}),e.jsx("section",{className:"min-h-[480px]","data-layout-slot":"discover-results",children:T.length>0?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:T.map(t=>e.jsx(J,{entityId:t,linkToEntity:!0},t))}):e.jsxs("div",{className:"py-12 text-center text-muted-foreground",children:[e.jsx(R,{className:"mx-auto mb-4 h-12 w-12 opacity-50"}),e.jsx("p",{children:"No discoveries found"}),r!=="all"&&e.jsxs("p",{className:"mt-2 text-sm",children:["Try selecting a different category or"," ",e.jsx(K,{variant:"link",className:"h-auto p-0 text-sm",onClick:()=>{const t=new URLSearchParams(s);t.delete("category"),l(t)},children:"view all discoveries"})]})]})})]});return e.jsx(Z,{onRefresh:b,children:W})}export{he as default}; 2//# sourceMappingURL=Discoveries-BcLuCP4l.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.