1import{u as E,r as h,m as b,b as N,a as q,F as $,ab as _,ac as K,B as M,j as e,L as U,R as Y,a4 as O,Y as F,e as A,f as D,N as P}from"./index-u0HMC9Vb.js";const j={book:{label:"Book",icon:M},podcast:{label:"Podcast",icon:K},article:{label:"Article",icon:$},youtube:{label:"YouTube",icon:_},pdf:{label:"PDF",icon:$}};function Q(t){const[n,c]=h.useState(t.cover_image_url||null);return h.useEffect(()=>{if(t.cover_image_url||t.type!=="book"||!t.title)return;const i=encodeURIComponent(`intitle:${t.title}${t.author?`+inauthor:${t.author}`:""}`);window.fetch(`https://www.googleapis.com/books/v1/volumes?q=${i}&maxResults=1`).then(l=>l.json()).then(l=>{var m,x,d,u;const a=(u=(d=(x=(m=l==null?void 0:l.items)==null?void 0:m[0])==null?void 0:x.volumeInfo)==null?void 0:d.imageLinks)==null?void 0:u.thumbnail;a&&c(a.replace("http://","https://"))}).catch(()=>{})},[t.id]),n}function y({saved:t,onClick:n}){return e.jsx("button",{onClick:c=>{c.stopPropagation(),c.preventDefault(),n()},className:`p-1 transition-colors flex-shrink-0 ${t?"text-stone-900":"text-stone-300 hover:text-stone-600"}`,children:e.jsx(O,{className:"w-3.5 h-3.5",strokeWidth:1.5,fill:t?"currentColor":"none"})})}function C({archetypes:t}){return!(t!=null&&t.length)||t.length===4?null:e.jsx("div",{className:"flex gap-1 flex-wrap mt-1.5",children:t.map(n=>e.jsx("span",{className:"text-[8px] font-meta uppercase tracking-widest px-1.5 py-0.5 bg-stone-100 text-stone-500",children:n},n))})}function I({read:t,saved:n,onToggleSave:c,courseName:i}){var x;const l=Q(t),{icon:a}=j[t.type]||j.book,m=d=>{if(!d)return null;const u=d.match(/(?:v=|youtu\.be\/)([^&?/]+)/);return u?u[1]:null};if(t.type==="youtube"){const d=m(t.url);return e.jsxs("div",{className:"bg-white border border-stone-100 overflow-hidden group",children:[d?e.jsx("a",{href:t.url,target:"_blank",rel:"noopener noreferrer",children:e.jsxs("div",{className:"relative aspect-video bg-stone-100 overflow-hidden",children:[e.jsx("img",{src:`https://img.youtube.com/vi/${d}/mqdefault.jpg`,alt:t.title,className:"w-full h-full object-cover group-hover:scale-[1.02] transition-transform duration-500"}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/20 group-hover:bg-black/30 transition-colors",children:e.jsx("div",{className:"w-10 h-10 bg-white/90 rounded-full flex items-center justify-center",children:e.jsx(_,{className:"w-5 h-5 text-stone-800",strokeWidth:1.5})})})]})}):e.jsx("div",{className:"aspect-video bg-stone-100 flex items-center justify-center",children:e.jsx(_,{className:"w-6 h-6 text-stone-400",strokeWidth:1.5})}),e.jsxs("div",{className:"p-3",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-[8px] font-meta uppercase tracking-widest text-stone-400 mb-0.5",children:["YouTube",i?` · ${i}`:""]}),e.jsx("p",{className:"text-xs font-semibold text-stone-900 leading-snug",children:t.title}),t.author&&e.jsx("p",{className:"text-[10px] text-stone-400 mt-0.5",children:t.author})]}),e.jsx(y,{saved:n,onClick:c})]}),e.jsx(C,{archetypes:t.tr_archetypes})]})]})}return t.type==="book"?e.jsxs("div",{className:"flex flex-col gap-2 cursor-pointer",onClick:()=>t.url&&window.open(t.url,"_blank"),children:[e.jsxs("div",{className:"relative aspect-[2/3] bg-stone-200 overflow-hidden flex items-center justify-center",children:[l?e.jsx("img",{src:l,alt:t.title,className:"w-full h-full object-cover"}):e.jsx(M,{className:"w-6 h-6 text-stone-400",strokeWidth:1.5}),e.jsx("div",{className:"absolute top-1 right-1",children:e.jsx(y,{saved:n,onClick:c})})]}),e.jsxs("div",{children:[i&&e.jsx("p",{className:"text-[8px] font-meta uppercase tracking-widest text-stone-300 mb-0.5",children:i}),e.jsx("p",{className:"text-xs font-semibold text-stone-900 leading-snug",children:t.title}),e.jsx("p",{className:"text-[10px] text-stone-400 mt-0.5",children:t.author}),e.jsx(C,{archetypes:t.tr_archetypes})]})]}):(t.type==="podcast"||t.type==="pdf"||t.type,e.jsxs("a",{href:t.url||"#",target:t.url?"_blank":void 0,rel:"noopener noreferrer",className:"flex items-center gap-3 p-3 bg-white border border-stone-100 hover:border-stone-300 transition-colors group",children:[e.jsx("div",{className:"w-10 h-10 bg-stone-100 flex items-center justify-center flex-shrink-0",children:t.cover_image_url?e.jsx("img",{src:t.cover_image_url,alt:t.title,className:"w-full h-full object-cover"}):e.jsx(a,{className:"w-4 h-4 text-stone-400",strokeWidth:1.5})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[8px] font-meta uppercase tracking-widest text-stone-400 mb-0.5",children:[(x=j[t.type])==null?void 0:x.label,i?` · ${i}`:""]}),e.jsx("p",{className:"text-xs font-semibold text-stone-900 truncate",children:t.title}),t.author&&e.jsx("p",{className:"text-[10px] text-stone-400",children:t.author}),t.description&&e.jsx("p",{className:"text-[10px] text-stone-300 mt-0.5 truncate",children:t.description}),e.jsx(C,{archetypes:t.tr_archetypes})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(y,{saved:n,onClick:c}),t.url&&e.jsx(P,{className:"w-3 h-3 text-stone-300 group-hover:text-stone-600 transition-colors",strokeWidth:1.5})]})]}))}function S({module:t,reads:n,savedReadIds:c,onToggleSave:i,courses:l}){const[a,m]=h.useState(!0),x=n.filter(s=>s.type==="book"),d=n.filter(s=>s.type!=="book"),u=s=>{var v;const r=l==null?void 0:l.find(f=>f.id===s);return r?{...r,label:`${r.code} ${((v=r.axis_scored)==null?void 0:v.toUpperCase())||r.title}`}:null};return e.jsxs("div",{className:"bg-stone-50 border border-stone-200",children:[e.jsxs("button",{onClick:()=>m(s=>!s),className:"w-full flex items-center justify-between px-5 py-3 border-b border-stone-200 hover:bg-stone-100 transition-colors",children:[e.jsx("span",{className:"text-[10px] font-meta uppercase tracking-[0.2em] text-stone-600",children:t.title}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] font-meta text-stone-300",children:n.length}),a?e.jsx(A,{className:"w-3 h-3 text-stone-400"}):e.jsx(D,{className:"w-3 h-3 text-stone-400"})]})]}),a&&e.jsxs("div",{className:"p-5 space-y-6",children:[x.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-widest text-stone-300 mb-3",children:"Books"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4",children:x.map(s=>{var r;return e.jsx(I,{read:s,saved:c.has(s.id),onToggleSave:()=>i(s.id),courseName:(r=u(s.course_id))==null?void 0:r.title},s.id)})})]}),d.length>0&&e.jsxs("div",{children:[x.length>0&&e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-widest text-stone-300 mb-3",children:"Other Resources"}),e.jsx("div",{className:"space-y-2",children:d.map(s=>{var r;return e.jsx(I,{read:s,saved:c.has(s.id),onToggleSave:()=>i(s.id),courseName:(r=u(s.course_id))==null?void 0:r.title},s.id)})})]})]})]})}function G({course:t,modules:n,reads:c,savedReadIds:i,onToggleSave:l,courses:a}){const m=c.filter(s=>s.course_id===t.id);if(m.length===0)return null;const d=n.filter(s=>s.course_id===t.id).map(s=>({...s,items:m.filter(r=>r.module_id===s.id)})).filter(s=>s.items.length>0),u=m.filter(s=>!s.module_id);return e.jsxs("div",{className:"mb-12",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5 pb-3 border-b border-stone-200",children:[e.jsx("span",{className:"text-[9px] font-meta uppercase tracking-widest text-stone-300",children:"Course"}),e.jsx("h2",{className:"text-sm font-heading font-semibold text-stone-800",children:t.title}),t.code&&e.jsx("span",{className:"text-[9px] font-meta uppercase tracking-widest text-stone-400 px-2 py-0.5 border border-stone-200",children:t.code}),e.jsx("div",{className:"flex-1 h-px bg-stone-200"}),e.jsxs("span",{className:"text-[9px] font-meta text-stone-300",children:[m.length," materials"]})]}),e.jsxs("div",{className:"space-y-4",children:[d.map(s=>e.jsx(S,{module:s,reads:s.items,savedReadIds:i,onToggleSave:l,courses:a},s.id)),u.length>0&&e.jsx(S,{module:{title:"General"},reads:u,savedReadIds:i,onToggleSave:l,courses:a})]})]})}
1function z(){const t=E(),[n,c]=h.useState(null),[i,l]=h.useState(!1),[a,m]=h.useState("all");h.useEffect(()=>{b.auth.me().then(c).catch(()=>{})},[]);const{data:x=[],isLoading:d}=N({queryKey:["courses"],queryFn:()=>b.entities.Course.list("order",20)}),{data:u=[],isLoading:s}=N({queryKey:["modules"],queryFn:()=>b.entities.Module.list("order",200)}),{data:r=[],isLoading:v}=N({queryKey:["reads"],queryFn:()=>b.entities.Read.list("-created_date",200)}),{data:f=[]}=N({queryKey:["savedItems",n==null?void 0:n.id],queryFn:()=>b.entities.SavedItem.filter({user_id:n.id}),enabled:!!(n!=null&&n.id)}),g=new Set(f.map(o=>o.read_id)),W=q({mutationFn:o=>b.entities.SavedItem.create({user_id:n.id,read_id:o}),onSuccess:()=>t.invalidateQueries({queryKey:["savedItems",n==null?void 0:n.id]})}),B=q({mutationFn:o=>{const p=f.find(k=>k.read_id===o);return b.entities.SavedItem.delete(p.id)},onSuccess:()=>t.invalidateQueries({queryKey:["savedItems",n==null?void 0:n.id]})});function R(o){g.has(o)?B.mutate(o):W.mutate(o)}const w=h.useMemo(()=>{let o=r;return i&&(o=o.filter(p=>g.has(p.id))),a!=="all"&&(o=o.filter(p=>(p.type||"book")===a)),o},[r,i,a,g]),L=w.filter(o=>!o.course_id),T=d||s||v;return[...Object.keys(j)],e.jsxs("div",{className:"mx-auto px-5 lg:px-10 pt-8 pb-8 max-w-6xl",children:[e.jsxs("header",{className:"mb-8 border-b border-stone-200 pb-4",children:[e.jsxs(U,{to:"/Library",className:"flex items-center gap-1 text-[10px] font-meta uppercase tracking-widest text-stone-400 hover:text-stone-600 mb-3",children:[e.jsx(Y,{className:"w-3 h-3"}),"Library"]}),e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.35em] text-stone-400",children:"The TRESDA Institute"}),e.jsx("h1",{className:"text-2xl font-heading font-semibold text-stone-900 mt-0.5 tracking-tight",children:"Reading Room"}),e.jsx("p",{className:"text-[9px] font-meta uppercase tracking-[0.25em] text-stone-400 mt-1",children:"Materials organised by course & module"})]}),e.jsxs("div",{className:"mb-8 flex flex-wrap gap-2",children:[e.jsx("button",{onClick:()=>l(!1),className:`text-[10px] font-meta uppercase tracking-widest px-3 py-1.5 border transition-colors ${i?"bg-white text-stone-500 border-stone-200 hover:border-stone-400":"bg-stone-900 text-white border-stone-900"}`,children:"All"}),e.jsxs("button",{onClick:()=>l(!0),className:`flex items-center gap-1.5 text-[10px] font-meta uppercase tracking-widest px-3 py-1.5 border transition-colors ${i?"bg-stone-900 text-white border-stone-900":"bg-white text-stone-500 border-stone-200 hover:border-stone-400"}`,children:[e.jsx(O,{className:"w-3 h-3",strokeWidth:1.5}),"Saved ",f.length>0&&`(${f.length})`]}),e.jsx("div",{className:"w-px bg-stone-200 mx-1"}),Object.entries(j).map(([o,{label:p,icon:k}])=>e.jsxs("button",{onClick:()=>m(a===o?"all":o),className:`flex items-center gap-1.5 text-[10px] font-meta uppercase tracking-widest px-3 py-1.5 border transition-colors ${a===o?"bg-stone-900 text-white border-stone-900":"bg-white text-stone-500 border-stone-200 hover:border-stone-400"}`,children:[e.jsx(k,{className:"w-3 h-3",strokeWidth:1.5}),p]},o))]}),T?e.jsx("div",{className:"space-y-8",children:[1,2,3].map(o=>e.jsxs("div",{className:"space-y-3",children:[e.jsx(F,{className:"h-6 w-48"}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-4",children:[1,2,3].map(p=>e.jsx(F,{className:"h-40"},p))})]},o))}):w.length===0?e.jsx("div",{className:"border border-dashed border-stone-300 p-12 text-center",children:e.jsx("p",{className:"text-[10px] font-meta uppercase tracking-widest text-stone-400",children:"Nothing found"})}):e.jsxs("div",{children:[x.map(o=>e.jsx(G,{course:o,modules:u,reads:w,savedReadIds:g,onToggleSave:R,courses:x},o.id)),L.length>0&&e.jsxs("div",{className:"mb-12",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-5 pb-3 border-b border-stone-200",children:[e.jsx("h2",{className:"text-sm font-heading font-semibold text-stone-500",children:"General Resources"}),e.jsx("div",{className:"flex-1 h-px bg-stone-200"})]}),e.jsx(S,{module:{title:"All"},reads:L,savedReadIds:g,onToggleSave:R,courses:x})]})]})]})}export{z as default};
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.