1import{c as C,j as e,B as v,V as ze,d as k,r as d,a as H,U as Me,s as Ie,b as Ae,W as Le,m as Oe}from"./index-B9xblx1X.js";import{l as Fe,I as He,m as oe,a as Re,u as Pe,o as Ve,p as Ue,q as $e,s as Be,t as qe,v as Ge,w as Ke,x as Je,f as Ye,d as G,y as K,e as le,z as We}from"./use-data-DnQuw-J8.js";import{T as Ze}from"./textarea-BoUB8h49.js";import{I as Qe}from"./input-BgkJCVH0.js";import{S as Xe,C as de}from"./StatusBadge-CJs5Fb83.js";import{C as h,a as u,b as T,c as z}from"./card-CK5sTH4r.js";import{T as es,a as ss,b as S,c as I}from"./tabs-DlNogeFX.js";import{B as ce}from"./badge-4Ub-F2rG.js";import{S as _}from"./skeleton-DfJRheVQ.js";import{E as A}from"./EmptyState-DUv8vX9o.js";import{V as Y,e as ts,c as as,r as rs,F as is,A as ns,a as os}from"./AddToCollectionDialog-k6YBsrf0.js";import{D as ls,a as ds,b as cs,d as J,e as ms}from"./dropdown-menu-t_q9iI-C.js";import{c as xs,e as ps,a as hs}from"./export-data-cVPFGmLe.js";import{D as us}from"./download-CH5ghwtu.js";import{C as fs}from"./copy-DQeglKOW.js";import{F as R}from"./file-text-CqCzlVtS.js";import{d as je,s as gs,A as me,C as bs}from"./ConnectExtensionButton-6V13zcPK.js";import{C as ws}from"./check-BUi6PNNz.js";import{T as js,S as vs}from"./StorageFullDialog-B9XpIEvJ.js";import{V as ys}from"./Vaulty-CnMBTxEs.js";import{t as Ns,a as ks,b as xe}from"./auto-organize-s2MOFVhk.js";import{A as pe}from"./archive-jRPkiiH2.js";import{A as he}from"./arrow-left-bJDptuwE.js";import{G as ve}from"./globe-L41XxYgC.js";import{E as ue}from"./external-link-BKp7hCh4.js";import{B as F}from"./book-open-lG7trVMX.js";import{T as fe}from"./triangle-alert-D0ZXp46o.js";import{P as Cs}from"./puzzle-C4d1Jhky.js";import{H as Ss}from"./hard-drive-DBe_STXy.js";import{M as _s}from"./mail-CduvjoWU.js";import"./circle-check-Bam9U-dU.js";import"./index-DKFJyVm0.js";import"./index-D45U-z8e.js";import"./index-ByduhlRr.js";import"./dialog-XBgjYxRF.js";import"./index-CaFA2jif.js";import"./Combination-R_zhYWsV.js";import"./checkbox-Bp09YZP1.js";import"./index-fou4DczH.js";import"./folder-open-DdVDU1ka.js";import"./plus-BdXsW8q0.js";import"./chrome-extension-CoBJCLit.js";import"./circle-BoK6zVHP.js";import"./refresh-cw-Dd5mVq7Z.js";import"./billing-Cmjo2gJi.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ds=C("Calendar",[["path",{d:"M8 2v4",key:"1cmpym"}],["path",{d:"M16 2v4",key:"4m81vk"}],["rect",{width:"18",height:"18",x:"3",y:"4",rx:"2",key:"1hopcy"}],["path",{d:"M3 10h18",key:"8toen8"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Es=C("FileJson",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1",key:"1oajmo"}],["path",{d:"M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1",key:"mpwhp6"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const Ts=C("Highlighter",[["path",{d:"m9 11-6 6v3h9l3-3",key:"1a3l36"}],["path",{d:"m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4",key:"14a9rk"}]]);/** 17 * @license lucide-react v0.462.0 - ISC 18 * 19 * This source code is licensed under the ISC license. 20 * See the LICENSE file in the root directory of this source tree. 21 */const zs=C("Maximize2",[["polyline",{points:"15 3 21 3 21 9",key:"mznyad"}],["polyline",{points:"9 21 3 21 3 15",key:"1avn1i"}],["line",{x1:"21",x2:"14",y1:"3",y2:"10",key:"ota7mn"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/** 22 * @license lucide-react v0.462.0 - ISC 23 * 24 * This source code is licensed under the ISC license. 25 * See the LICENSE file in the root directory of this source tree. 26 */const Ms=C("Minimize2",[["polyline",{points:"4 14 10 14 10 20",key:"11kfnr"}],["polyline",{points:"20 10 14 10 14 4",key:"rlmsce"}],["line",{x1:"14",x2:"21",y1:"10",y2:"3",key:"o5lafz"}],["line",{x1:"3",x2:"10",y1:"21",y2:"14",key:"1atl0r"}]]);/** 27 * @license lucide-react v0.462.0 - ISC 28 * 29 * This source code is licensed under the ISC license. 30 * See the LICENSE file in the root directory of this source tree. 31 */const Is=C("Pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]);/** 32 * @license lucide-react v0.462.0 - ISC 33 * 34 * This source code is licensed under the ISC license. 35 * See the LICENSE file in the root directory of this source tree. 36 */const As=C("Play",[["polygon",{points:"6 3 20 12 6 21 6 3",key:"1oa8hb"}]]);/** 37 * @license lucide-react v0.462.0 - ISC 38 * 39 * This source code is licensed under the ISC license. 40 * See the LICENSE file in the root directory of this source tree. 41 */const ge=C("StickyNote",[["path",{d:"M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z",key:"qazsjp"}],["path",{d:"M15 3v4a2 2 0 0 0 2 2h4",key:"40519r"}]]);function Ls({item:t,body:i,className:r}){const o=(s,p)=>{(async()=>{try{await p(),ze("item_exported",{format:s,item_type:t.type}),k.success(s==="clipboard"?"Copied as Markdown":"Export started")}catch(c){k.error("Export failed",{description:c instanceof Error?c.message:"Unknown error"})}})()};return e.jsxs(ls,{children:[e.jsx(ds,{asChild:!0,children:e.jsx(v,{variant:"ghost",size:"icon",className:r??"h-9 w-9 sm:h-8 sm:w-8 text-muted-foreground hover:text-foreground","aria-label":"Export item",children:e.jsx(us,{className:"h-4 w-4"})})}),e.jsxs(cs,{align:"end",className:"w-52",children:[e.jsxs(J,{onClick:()=>o("clipboard",()=>xs(t,i)),children:[e.jsx(fs,{className:"mr-2 h-4 w-4"})," Copy as Markdown"]}),e.jsxs(J,{onClick:()=>o("markdown",()=>ps(t,i)),children:[e.jsx(R,{className:"mr-2 h-4 w-4"})," Download Markdown"]}),e.jsxs(J,{onClick:()=>o("json",()=>hs(t,i)),children:[e.jsx(Es,{className:"mr-2 h-4 w-4"})," Download JSON"]})]})]})}function Os({itemId:t,title:i}
41){const r=je(i),[o,s]=d.useState(!1),[p,c]=d.useState(r),g=d.useRef(null),b=Fe();d.useEffect(()=>{o||c(r)},[r,o]),d.useEffect(()=>{if(!o)return;const n=g.current;n&&(n.focus(),n.select())},[o]),d.useLayoutEffect(()=>{const n=g.current;!n||!o||(n.style.height="0px",n.style.height=`${n.scrollHeight}px`)},[p,o]);const m=()=>{c(r),s(!0)},x=()=>{c(r),s(!1)},l=async()=>{const n=oe(p);if(!n){k.error("Title cannot be empty"),c(r),s(!1);return}if(n===oe(r)){s(!1);return}s(!1);try{await b.mutateAsync({itemId:t,title:n})}catch(w){k.error("Could not update title",{description:w instanceof Error?w.message:"Unknown error"})}};return o?e.jsxs("div",{className:"flex min-w-0 items-start gap-1","data-onboarding":"item-title",children:[e.jsx("label",{htmlFor:"item-title-input",className:"sr-only",children:"Item title"}),e.jsx("textarea",{id:"item-title-input",ref:g,rows:1,value:p,maxLength:He,disabled:b.isPending,onChange:n=>c(n.target.value),onBlur:()=>void l(),onKeyDown:n=>{n.key==="Enter"&&!n.shiftKey&&(n.preventDefault(),l()),n.key==="Escape"&&(n.preventDefault(),x())},className:H("min-h-[2.25rem] min-w-0 flex-1 resize-none rounded-md border border-input bg-background px-2 py-1.5","text-lg font-bold leading-snug sm:text-2xl sm:leading-tight","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2")}),e.jsx(v,{type:"button",variant:"ghost",size:"icon",className:"h-10 w-10 shrink-0 text-muted-foreground hover:text-foreground sm:h-8 sm:w-8","aria-label":"Save title",disabled:b.isPending,onMouseDown:n=>n.preventDefault(),onClick:()=>void l(),children:e.jsx(ws,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"flex min-w-0 items-start gap-1","data-onboarding":"item-title",children:[e.jsx("h1",{className:"min-w-0 flex-1 text-lg font-bold leading-snug sm:text-2xl sm:leading-tight",children:e.jsx("button",{type:"button",onClick:m,className:"w-full rounded-md text-left break-words hover:bg-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",children:r})}),e.jsx(v,{type:"button",variant:"ghost",size:"icon",className:"h-10 w-10 shrink-0 text-muted-foreground hover:text-foreground sm:h-8 sm:w-8","aria-label":"Edit title",onClick:m,children:e.jsx(Is,{className:"h-4 w-4"})})]})}function be(t,i=3600){return Me({queryKey:["media-signed-url",t,i],queryFn:async()=>{if(!t)return null;const{data:r,error:o}=await Ie.storage.from("media").createSignedUrl(t,i);if(o)throw o;return r.signedUrl},enabled:!!t,staleTime:(i-60)*1e3})}function Fs(t){try{const i=new URL(t);if(i.hostname.includes("youtube.com")||i.hostname.includes("youtu.be")){let r="";if(i.hostname.includes("youtu.be")?r=i.pathname.slice(1).split("/")[0]:r=i.searchParams.get("v")||i.pathname.split("/").pop()||"",r)return`https://www.youtube.com/embed/${r}`}if(i.hostname.includes("vimeo.com")){const r=i.pathname.split("/").filter(Boolean).pop();if(r)return`https://player.vimeo.com/video/${r}`}}catch{}return null}function Hs({url:t,status:i,mediaPath:r,posterPath:o,durationSeconds:s}){const{data:p,isLoading:c}=be(r),{data:g}=be(o),b=Fs(t),m=!!(r&&p);return e.jsxs("div",{className:"overflow-hidden rounded-lg border border-border/60 shadow-soft",children:[e.jsx("div",{className:"aspect-video bg-gradient-to-br from-muted to-muted/80",children:m&&p?e.jsx("video",{className:"h-full w-full bg-black",controls:!0,playsInline:!0,poster:g||void 0,src:p}):i==="original_unavailable"&&!r?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"space-y-2 text-center",children:[e.jsx("div",{className:"mx-auto flex h-14 w-14 items-center justify-center rounded-2xl bg-muted-foreground/5",children:e.jsx(Y,{className:"h-6 w-6 text-muted-foreground/50"})}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Video unavailable"}),e.jsx("p",{className:"text-2xs text-muted-foreground",children:"Transcript and notes are still accessible below"})]})}):r&&c?e.jsxs("div",{className:"flex h-full items-center justify-center gap-2 text-sm text-muted-foreground",children:[e.jsx(Ae,{className:"h-4 w-4 animate-spin"})," Loading archived videoâ¦"]}):b?e.jsx("iframe",{src:b,className:"h-full w-full border-0",allow:"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",allowFullScreen:!0,title:"Video player"}):e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"group space-y-2 text-center",children:[e.jsx("div",{className:"mx-auto flex h-16 w-16 items-center justify-center rounded-full bg-primary/10 transition-colors group-hover:bg-primary/15",children:e.jsx(As,{className:"ml-0.5 h-7 w-7 text-primary transition-transform group-hover:scale-105"})}),e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Open video in new tab"})]})})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 bg-card px-3 py-2 text-2xs text-muted-foreground",children:[r?e.jsx("span",{className:"rounded-md bg-success/10 px-2 py-0.5 font-medium text-success",children:"Archived copy"}):e.jsx("span",{className:"rounded-md bg-secondary px-2 py-0.5 font-medium",children:i==="processing"?"Archiv
41ing videoâ¦":"Embed fallback â archive pending"}),s?e.jsxs("span",{children:[Math.round(s/60)," min"]}):null,e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"ml-auto text-primary hover:underline",children:"Original source"})]})]})}const Rs=` 42 html[data-vaultshelf-site="reddit"], 43 body[data-vaultshelf-site="reddit"], 44 html:has(body[data-vaultshelf-site="reddit"]) { 45 background: #fff !important; 46 color: #1a1a1a !important; 47 } 48 body[data-vaultshelf-site="reddit"] { 49 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 50 line-height: 1.55; 51 max-width: 720px; 52 margin: 0 auto; 53 padding: 16px 14px 28px; 54 } 55 [data-vaultshelf-site="reddit"] shreddit-post, 56 [data-vaultshelf-site="reddit"] shreddit-comment, 57 [data-vaultshelf-site="reddit"] shreddit-comment-tree, 58 [data-vaultshelf-site="reddit"] shreddit-title, 59 [data-vaultshelf-site="reddit"] shreddit-post-title, 60 [data-vaultshelf-site="reddit"] shreddit-async-loader, 61 [data-vaultshelf-site="reddit"] comment-body-header, 62 [data-vaultshelf-site="reddit"] faceplate-tracker { 63 display: block !important; 64 max-width: 100%; 65 color: inherit !important; 66 background: transparent !important; 67 } 68 [data-vaultshelf-site="reddit"] shreddit-comment { 69 margin: 12px 0; 70 padding: 8px 0 8px 12px; 71 border-left: 2px solid #e5e5e5; 72 } 73`;function Ps(t){try{return new URL(t).hostname.replace(/^www\./i,"")}catch{return""}}function Vs(t){const i=Ps(t);return/(^|\.)reddit\.com$/i.test(i)||/(^|\.)redd\.it$/i.test(i)}function Us(t,i=""){return Vs(t)||/data-vaultshelf-site=["']reddit["']/i.test(i)?Rs:""}const $s=` 74 *, *::before, *::after { box-sizing: border-box; } 75 html { 76 width: 100%; 77 overflow-x: hidden; 78 -webkit-text-size-adjust: 100%; 79 text-size-adjust: 100%; 80 } 81 body { 82 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; 83 line-height: 1.7; 84 color: #1a1a1a !important; 85 background: #fff !important; 86 max-width: 720px; 87 margin: 0 auto; 88 padding: 12px 14px 24px; 89 font-size: 16px; 90 overflow-wrap: break-word; 91 overflow-x: hidden; 92 -webkit-font-smoothing: antialiased; 93 } 94 img, video, iframe, embed, object { 95 max-width: 100% !important; 96 height: auto !important; 97 } 98 img { border-radius: 8px; margin: 12px 0; display: block; } 99 svg[data-reader-icon] { 100 width: 1.15rem !important; 101 height: 1.15rem !important; 102 max-width: 1.15rem !important; 103 max-height: 1.15rem !important; 104 flex-shrink: 0; 105 vertical-align: -0.15em; 106 overflow: visible; 107 } 108 svg:not([data-reader-icon]) { 109 max-width: 100%; 110 height: auto; 111 } 112 a { color: #2563eb !important; word-break: break-word; padding: 0.05em 0; } 113 pre, code { 114 overflow-x: auto; 115 max-width: 100%; 116 font-size: 13px; 117 background: #f5f5f5; 118 padding: 2px 6px; 119 border-radius: 4px; 120 white-space: pre-wrap; 121 } 122 pre { padding: 12px; white-space: pre; } 123 pre code { background: transparent; padding: 0; } 124 [data-reader-table] { 125 overflow-x: auto; 126 max-width: 100%; 127 margin: 1rem 0; 128 -webkit-overflow-scrolling: touch; 129 } 130 table { 131 display: table; 132 border-collapse: collapse; 133 width: max-content; 134 min-width: 100%; 135 table-layout: auto; 136 } 137 th, td { 138 border: 1px solid #e5e5e5; 139 padding: 8px 10px; 140 text-align: left; 141 overflow-wrap: normal; 142 word-break: normal; 143 white-space: nowrap; 144 } 145 td code, th code { white-space: nowrap; } 146 blockquote { border-left: 3px solid #d4d4d4; margin-left: 0; padding-left: 16px; color: #525252; } 147 h1, h2, h3 { line-height: 1.3; font-size: clamp(1.1rem, 4.5vw, 1.6rem); } 148 h1 { font-size: clamp(1.25rem, 5.5vw, 1.85rem); } 149 p, li { font-size: inherit; } 150 shreddit-post, shreddit-comment, shreddit-comment-tree, shreddit-title, 151 shreddit-post-title, shreddit-async-loader, comment-body-header, 152 faceplate-tracker { 153 display: block; 154 max-width: 100%; 155 } 156 shreddit-comment { 157 margin: 12px 0; 158 padding: 8px 0 8px 12px; 159 border-left: 2px solid #e5e5e5; 160 } 161 @media (min-width: 640px) { 162 body { padding: 16px 20px 28px; font-size: 15px; } 163 } 164`;function Bs(t){return t.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi,"").replace(/<meta[^>]+http-equiv\s*=\s*["']?Content-Security-Policy["']?[^>]*>
164/gi,"").replace(/\son\w+\s*=\s*("[^"]*"|'[^']*'|[^\s>]+)/gi,"").replace(/javascript:/gi,"")}function ye(t,i,r=!1){const o=gs(t),s=[o?`<base href="${o}" target="_blank" />`:"",'<meta charset="utf-8" />'];return r||s.push('<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />'),i.trim()&&s.push(`<style>${i}</style>`),s.join("")}function qs(t){return/<html[\s>]/i.test(t)||/<head[\s>]/i.test(t)}function Gs(t,i){return/<head[^>]*>/i.test(t)?t.replace(/<head[^>]*>/i,r=>`${r}${i}`):/<html[^>]*>/i.test(t)?t.replace(/<html[^>]*>/i,r=>`${r}<head>${i}</head>`):`<!DOCTYPE html><html><head>${i}</head><body>${t}</body></html>`}function Ks(t,i){const r=t.trim();return r?`<!DOCTYPE html><html><head>${ye(i,$s)}</head><body>${r}</body></html>`:""}function Js(t,i){const r=Bs(t),o=Us(i,r),s=ye(i,o,!0);return qs(r)?Gs(r,s):`<!DOCTYPE html><html><head>${s}</head><body>${r}</body></html>`}const Ys={webpage:ve,pdf:os,video:Y,newsletter:_s,article:R};function we({html:t,baseUrl:i,mode:r}){const o=d.useRef(null),[s,p]=d.useState(!1),[c,g]=d.useState(360),b=d.useMemo(()=>r==="reader"?Ks(t,i):Js(t,i),[t,i,r]),m=d.useCallback(()=>{const x=o.current,l=x==null?void 0:x.contentDocument;if(!(l!=null&&l.body))return;const n=Math.ceil(Math.max(l.body.scrollHeight,l.documentElement.scrollHeight,240));g(w=>Math.abs(w-n)>2?n:w)},[]);return d.useEffect(()=>{const x=o.current;if(!x)return;let l=null,n=!1;const w=()=>{if(n)return;m();const f=x.contentDocument;!(f!=null&&f.body)||typeof ResizeObserver>"u"||(l==null||l.disconnect(),l=new ResizeObserver(()=>m()),l.observe(f.body),f.documentElement&&l.observe(f.documentElement))};x.addEventListener("load",w),w();const L=window.setTimeout(w,150);return()=>{n=!0,x.removeEventListener("load",w),window.clearTimeout(L),l==null||l.disconnect()}},[b,m]),d.useEffect(()=>{if(!s)return;const x=l=>{l.key==="Escape"&&p(!1)};return window.addEventListener("keydown",x),()=>window.removeEventListener("keydown",x)},[s]),e.jsxs("div",{className:H("relative",s&&"fixed inset-0 z-50 bg-background p-2 sm:p-4 flex flex-col"),children:[e.jsx(v,{variant:"ghost",size:"icon",className:H("absolute z-10 h-9 w-9 bg-background/90 backdrop-blur-sm shadow-sm border border-border/50",s?"top-3 right-3":"top-2 right-2"),onClick:()=>p(x=>!x),"aria-label":s?"Exit fullscreen reader":"Expand reader",children:s?e.jsx(Ms,{className:"h-4 w-4"}):e.jsx(zs,{className:"h-4 w-4"})}),e.jsx("iframe",{ref:o,srcDoc:b,sandbox:"allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-downloads allow-top-navigation-by-user-activation",referrerPolicy:"strict-origin-when-cross-origin",className:H("w-full border-0","bg-white",s?"flex-1 min-h-0 rounded-lg h-full":r==="snapshot"?"min-h-[70vh] overflow-auto":"rounded-lg min-h-[240px]"),style:s?void 0:{height:c},title:r==="reader"?"Article reader":"Original snapshot"})]})}function Ws(t){return new Date(t).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function Ut(){var te,ae,re,ie,ne;const{id:t}=Le(),i=Oe(),{isLoading:r,isFetching:o}=Re(),s=Pe(t||""),{data:p}=Ve(t),{data:c=[]}=Ue(t),[g,b]=d.useState(null),{data:m,isPending:x}=$e(t,g),l=Be(),n=qe(),w=Ge(),L=Ke(),f=ms(),[Ne,W]=d.useState(!1),[ke,Z]=d.useState(!1),[P,Q]=d.useState(""),[V,X]=d.useState(""),y=(m==null?void 0:m.html_content)??((te=s==null?void 0:s.snapshot)==null?void 0:te.html_content)??null,D=(m==null?void 0:m.reader_html)??((ae=s==null?void 0:s.snapshot)==null?void 0:ae.reader_html)??null,M=(m==null?void 0:m.text_content)??((re=s==null?void 0:s.snapshot)==null?void 0:re.text_content)??null,N=m||(s==null?void 0:s.snapshot),Ce=!!t&&!s&&(r||o);d.useEffect(()=>{b(null)},[t]),d.useEffect(()=>{c.length&&(g==null||!c.some(a=>a.version===g))&&b(c[0].version)},[c,g]),d.useEffect(()=>{!t||!s||n.mutate(t,{onError:a=>{console.error("Failed to mark item opened:",a)}})},[t,!!s]);const Se=!!(y!=null&&y.trim()),ee=!!(D!=null&&D.trim()),_e=d.useMemo(()=>ee||!(y!=null&&y.trim())?"":ts(y)||"",[ee,y]),se=((D==null?void 0:D.trim())||_e).trim(),E=!!se,U=d.useMemo(()=>E?"":as(M||""),[E,M]),De=async()=>{if(s&&confirm("Delete this item and all its data? This cannot be undone."))try{const a=!!(f!=null&&f.active)&&f.step===4;await l.mutateAsync(s.id),k.success("Item deleted"),await(f==null?void 0:f.onItemDeleted(s.id)),a||i("/app/library")}catch(a){k.error("Failed to delete",{description:a instanceof Error?a.message:"Unknown error"})}};if(r||Ce)return e.jsxs("div",{className:"p-4 sm:p-6 lg:p-8 max-w-4xl mx-auto
164space-y-6",children:[e.jsx(_,{className:"h-4 w-16"}),e.jsx(_,{className:"h-8 w-3/4"}),e.jsx(_,{className:"h-64"})]});if(!s)return e.jsx("div",{className:"p-6",children:e.jsx(A,{icon:pe,title:"Item not found",description:"This item may have been deleted or doesn't exist.",action:e.jsxs(v,{variant:"outline",onClick:()=>i(-1),children:[e.jsx(he,{className:"mr-2 h-4 w-4"})," Go back"]})})});const $=Ns(s.tags.map(a=>a.name),s.title,s.source_domain),B=s.collections.filter(a=>!ks(a.name,s.source_domain)),j=s.type==="video",Ee=Ys[s.type]||ve,O=Je(s),q=rs(s.summary,M);return e.jsxs("div",{className:"mx-auto w-full min-w-0 max-w-4xl animate-fade-in space-y-4 p-3 sm:space-y-6 sm:p-6 lg:p-8",children:[e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>i(-1),"aria-label":"Go back",className:"flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors mb-3 sm:mb-5 group",children:[e.jsx(he,{className:"h-4 w-4 group-hover:-translate-x-0.5 transition-transform"})," Back"]}),e.jsxs("div",{className:"flex flex-wrap items-start gap-3 sm:gap-4",children:[e.jsx("div",{className:"h-9 w-9 sm:h-10 sm:w-10 rounded-xl bg-primary/8 flex items-center justify-center shrink-0",children:e.jsx(Ee,{className:"h-4 w-4 sm:h-5 sm:w-5 text-primary"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(Os,{itemId:s.id,title:s.title}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mt-2",children:[e.jsxs("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline flex items-center gap-1 font-medium min-w-0",children:[e.jsx("span",{className:"truncate max-w-[60vw] sm:max-w-none",children:s.source_domain})," ",e.jsx(ue,{className:"h-3 w-3 shrink-0"})]}),e.jsx(Xe,{status:Ye(s)})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 sm:gap-1 shrink-0",children:[e.jsx(Ls,{item:p?{...s,transcript:p}:s,body:m??void 0}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 text-muted-foreground hover:text-foreground",onClick:()=>W(!0),"aria-label":"Add to collection",children:e.jsx(is,{className:"h-4 w-4"})}),e.jsx(v,{variant:"ghost",size:"icon",className:"h-9 w-9 sm:h-8 sm:w-8 text-muted-foreground hover:text-destructive",onClick:De,disabled:l.isPending,"data-onboarding":"delete-item","aria-label":"Delete item",children:e.jsx(js,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mt-4 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1.5 bg-secondary px-2 py-1 rounded-md",children:[e.jsx(Ds,{className:"h-3 w-3"})," Saved ",new Date(s.saved_at).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})]}),c.length>1&&e.jsxs("label",{className:"flex items-center gap-1.5 bg-secondary px-2 py-1 rounded-md",children:[e.jsx("span",{className:"sr-only",children:"Snapshot version"}),e.jsx("select",{className:"bg-transparent text-xs text-muted-foreground outline-none cursor-pointer max-w-[12rem]",value:g??((ie=c[0])==null?void 0:ie.version)??"",onChange:a=>b(Number(a.target.value)),"aria-label":"Snapshot version",children:c.map(a=>e.jsx("option",{value:a.version,children:`v${a.version} · ${Ws(a.captured_at)}`},a.id))})]}),s.last_opened_at&&e.jsxs("span",{className:"flex items-center gap-1.5 bg-secondary px-2 py-1 rounded-md",children:[e.jsx(de,{className:"h-3 w-3"})," Opened ",new Date(s.last_opened_at).toLocaleDateString("en-US",{month:"short",day:"numeric"})]}),O&&e.jsxs("span",{className:"flex items-center gap-1.5 bg-secondary px-2 py-1 rounded-md",children:[j?e.jsx(de,{className:"h-3 w-3","aria-hidden":!0}):e.jsx(F,{className:"h-3 w-3","aria-hidden":!0}),O," min"]}),s.word_count&&e.jsxs("span",{className:"bg-secondary px-2 py-1 rounded-md",children:[s.word_count.toLocaleString()," words"]})]}),$.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:$.map(a=>e.jsx(ce,{variant:"secondary",className:"text-2xs font-medium",children:xe(a)},a))}),B.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-2",children:B.map(a=>e.jsx(ce,{variant:"outline",className:"text-2xs font-medium",children:a.name},a.id))})]}),e.jsx(ns,{itemId:s.id,currentCollectionIds:s.collections.map(a=>a.id),open:Ne,onOpenChange:W}),e.jsx(vs,{open:ke,onOpenChange:Z}),s.status==="original_unavailable"&&e.jsx(h,{className:"border-warning/30 bg-warning/5 shadow-soft",children:e.jsxs(u,{className:"p-4 flex items-start gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-lg bg-warning/10 flex items-center justify-center shrink-0",children:e.jsx(fe,{className:"h-4 w-4 text-warning"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold",children:"Original unavailable"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 leading-relaxed",children:s.snapshot?"A saved copy is available from your archive.":"No archived snapshot was captured before the original went offline."})]}),e.jsx(me,{itemId:s.id,className:"shrink-0"})]})}),G(s)==="retry"&&s.status!=="original_unavailable"&&e.jsx(h,{className:"border-destructive/25 bg-destructive/5 shadow-soft",children:e.jsxs(u,{className:"p-4 flex flex-col sm:flex-row sm:items-center gap-3 justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"h-9 w-9 rounded-lg bg-destructive/10 flex items-center justify-center shrink-0",children:e.jsx(fe,{className:"h-4 w-4 text-destructive"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Archive failed"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 leading-relaxed",children:K(s.error_message)})]})]}),e.jsx(me,{itemId:s.id,className:"shrink-0"})]})}),G(s)==="extension"&&le(s)==="blocked_fetch"&&e.jsx(h,{className:"border-destructive/25 bg-destructive/5 shadow-soft",role:"alert",children:e.jsxs(u,{className:"p-4 flex flex-col sm:flex-row sm:items-center gap-3 justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"h-9 w-9 rounded-lg bg-destructive/10 flex items-center justify-center shrink-0",children:e.jsx(Cs,{className:"h-4 w-4 text-destructive"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"This site blocked our archive"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 leading-relaxed",children:K(s.error_message)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 shrink-0",children:[e.jsx(bs,{}),s.url&&e.jsx(v,{size:"sm",variant:"ghost",className:"h-7 text-xs gap-1.5",asChild:!0,children:e.jsxs("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ue,{className:"h-3.5 w-3.5","aria-hidden":!0}),"Open original"]})})]})]})}),G(s)==="extension"&&le(s)==="youtube"&&e.jsx(h,{className:"border-primary/25 bg-primary/[0.04] shadow-soft",children:e.jsxs(u,{className:"p-4 flex flex-col sm:flex-row sm:items-center gap-3 justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"h-9 w-9 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(Y,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Video file not stored"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 leading-relaxed",children:K(s.error_message||"youtube_needs_extension")})]})]}),e.jsx(v,{size:"sm",variant:"outline",className:"shrink-0",asChild:!0,children:e.jsx("a",{href:s.url,target:"_blank",rel:"noopener noreferrer",children:"Open on YouTube"})})]})}),s.error_message==="storage_limit"&&!s.media_path&&e.jsx(h,{className:"border-primary/30 bg-primary/[0.04] shadow-soft",children:e.jsxs(u,{className:"p-4 flex flex-col sm:flex-row sm:items-center gap-3 justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("div",{className:"h-9 w-9 rounded-lg bg-primary/10 flex items-center justify-center shrink-0",children:e.jsx(Ss,{className:"h-4 w-4 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"Vault storage full"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 leading-relaxed",children:"Video archive paused. Free space, upgrade, or add a storage booster to continue."})]})]}),e.jsx(v,{size:"sm",className:"shrink-0",onClick:()=>Z(!0),children:"Fix storage"})]})}),j&&e.jsx(Hs,{url:s.url,status:s.status,mediaPath:s.media_path,posterPath:s.media_poster_path,durationSeconds:s.media_duration_seconds}),e.jsxs(es,{defaultValue:j?"overview":"reader",children:[e.jsx("div",{className:"-mx-3 px-3 sm:mx-0 sm:px-0 overflow-x-auto [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:e.jsx(ss,{className:"w-max min-w-full sm:w-full justify-start bg-muted/50 p-1",children:j?e.jsxs(e.Fragment,{children:[e.jsx(S,{value:"overview",className:"text-xs shrink-0",children:"Overview"}),e.jsx(S,{value:"transcript",className:"text-xs shrink-0",children:"Transcript"}),e.jsx(S,{value:"notes",className:"text-xs shrink-0",children:"Notes"}),e.jsx(S,{value:"metadata",className:"text-xs shrink-0",children:"Metadata"})]}):e.jsxs(e.Fragment,{children:[e.jsx(S,{value:"reader",className:"text-xs shrink-0",children:"Reader View"}),e.jsx(S,{value:"snapshot",className:"text-xs shrink-0",children:"Original Snapshot"}),e.jsx(S,{value:"metadata",className:"text-xs shrink-0",children:"Metadata"})]})})}
164),e.jsxs(I,{value:j?"overview":"reader",className:"space-y-4 mt-3 sm:mt-4",children:[q&&e.jsxs(h,{className:"border-border/60 shadow-soft",children:[e.jsx(T,{className:"p-4 sm:p-6 pb-2",children:e.jsxs(z,{className:"text-sm font-semibold flex items-center gap-2.5",children:[e.jsx(ys,{mood:"working",size:28,label:"Vaulty wrote this summary"}),"Summary",e.jsx("span",{className:"text-2xs font-medium uppercase tracking-wider text-muted-foreground",children:"by Vaulty"})]})}),e.jsx(u,{className:"p-4 sm:p-6 pt-0",children:e.jsx("p",{className:"text-sm leading-relaxed text-muted-foreground",children:q})})]}),!j&&E&&e.jsxs(h,{className:"border-border/60 shadow-soft overflow-hidden",children:[e.jsx(T,{className:"p-3 sm:p-6 pb-2",children:e.jsxs(z,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-primary"})," Article Content"]})}),e.jsx(u,{className:"p-0 sm:p-6 sm:pt-0 relative",children:e.jsx(we,{html:se,baseUrl:s.url,mode:"reader"})})]}),!j&&!E&&x&&e.jsxs(h,{className:"border-border/60 shadow-soft",children:[e.jsx(T,{className:"p-4 sm:p-6 pb-2",children:e.jsxs(z,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-primary"})," Article Content"]})}),e.jsxs(u,{className:"p-4 sm:p-6 pt-0 space-y-2",children:[e.jsx(_,{className:"h-4 w-full"}),e.jsx(_,{className:"h-4 w-5/6"}),e.jsx(_,{className:"h-4 w-4/6"})]})]}),!j&&!E&&!x&&U&&e.jsxs(h,{className:"border-border/60 shadow-soft",children:[e.jsx(T,{className:"p-4 sm:p-6 pb-2",children:e.jsxs(z,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-primary"})," Article Content"]})}),e.jsx(u,{className:"p-4 sm:p-6 pt-0",children:e.jsx("div",{className:"prose prose-sm max-w-none dark:prose-invert",children:e.jsx("p",{className:"text-[15px] whitespace-pre-wrap leading-relaxed text-foreground/80",children:U})})})]}),!j&&!E&&!x&&!U&&!q&&e.jsx(A,{icon:R,title:"No content yet",description:s.status==="processing"?"This item is still being processed. Content will appear shortly.":"No readable content was extracted from this page.",className:"py-12"}),e.jsxs(h,{className:"border-border/60 shadow-soft",children:[e.jsx(T,{className:"pb-2",children:e.jsxs(z,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(Ts,{className:"h-4 w-4 text-warning"})," Highlights"]})}),e.jsxs(u,{className:"space-y-3",children:[s.highlights.map(a=>e.jsx("div",{className:"border-l-2 pl-4 py-1.5",style:{borderColor:a.color},children:e.jsx("p",{className:"text-sm italic leading-relaxed",children:a.text})},a.id)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Qe,{value:V,onChange:a=>X(a.target.value),placeholder:"Add a highlightâ¦",className:"h-9 text-sm"}),e.jsx(v,{size:"sm",disabled:!V.trim()||L.isPending,onClick:async()=>{await L.mutateAsync({itemId:s.id,text:V.trim()}),X(""),k.success("Highlight saved")},children:"Add"})]})]})]}),e.jsxs(h,{className:"border-border/60 shadow-soft",children:[e.jsx(T,{className:"pb-2",children:e.jsxs(z,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(ge,{className:"h-4 w-4 text-info"})," Notes"]})}),e.jsxs(u,{className:"space-y-3",children:[s.notes.map(a=>e.jsxs("div",{className:"bg-accent/40 rounded-xl p-4",children:[e.jsx("p",{className:"text-sm leading-relaxed",children:a.content}),e.jsx("p",{className:"text-2xs text-muted-foreground mt-2",children:new Date(a.created_at).toLocaleString()})]},a.id)),e.jsx(Ze,{value:P,onChange:a=>Q(a.target.value),placeholder:"Write a noteâ¦",className:"text-sm min-h-[80px]"}),e.jsx(v,{size:"sm",disabled:!P.trim()||w.isPending,onClick:async()=>{await w.mutateAsync({itemId:s.id,content:P.trim()}),Q(""),k.success("Note saved")},children:"Save note"})]})]})]}),j&&e.jsx(I,{value:"transcript",className:"mt-4",children:e.jsx(h,{className:"border-border/60 shadow-soft",children:e.jsx(u,{className:"p-5",children:p?e.jsx("pre",{className:"text-sm whitespace-pre-wrap font-sans leading-relaxed text-muted-foreground",children:p.content}):e.jsx(A,{icon:R,title:"No transcript",description:"No transcript is available for this video.",className:"py-12"})})})}),j&&e.jsx(I,{value:"notes",className:"mt-4 space-y-4",children:s.notes.length>0?s.notes.map(a=>e.jsx(h,{className:"border-border/60 shadow-soft",children:e.jsxs(u,{className:"p-5",children:[e.jsx("p",{className:"text-sm leading-relaxed",children:a.content}),e.jsx("p",{className:"text-2xs text-muted-foreground mt-2",children:new Date(a.created_at).toLocaleStr
164ing()})]})},a.id)):e.jsx(A,{icon:ge,title:"No notes yet",description:"Add notes to capture your thoughts.",className:"py-12"})}),!j&&e.jsx(I,{value:"snapshot",className:"mt-3 sm:mt-4",children:e.jsx(h,{className:"border-border/60 shadow-soft overflow-hidden",children:e.jsx(u,{className:"p-0",children:N||s.snapshot?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm px-3 pt-3",children:[e.jsx("span",{className:"font-semibold",children:"Archived snapshot"}),(N==null?void 0:N.captured_at)&&e.jsxs("span",{className:"text-2xs text-muted-foreground bg-secondary px-2 py-0.5 rounded-md",children:["Captured ",new Date(N.captured_at).toLocaleDateString()]}),typeof(N==null?void 0:N.size_bytes)=="number"&&e.jsxs("span",{className:"text-2xs text-muted-foreground bg-secondary px-2 py-0.5 rounded-md",children:[(N.size_bytes/1024).toFixed(0)," KB"]})]}),Se?e.jsx("div",{className:"relative",children:e.jsx(we,{html:y,baseUrl:s.url,mode:"snapshot"})}):x?e.jsx("div",{className:"px-3 pb-3 space-y-2",children:e.jsx(_,{className:"h-[70vh] w-full rounded-md"})}):M?e.jsx("div",{className:"mx-3 mb-3 sm:mx-0 sm:mb-0 p-4 sm:p-5 bg-accent/30 rounded-xl border border-border/40",children:e.jsx("p",{className:"text-sm whitespace-pre-wrap leading-relaxed text-muted-foreground",children:M})}):e.jsx("p",{className:"text-sm text-muted-foreground px-3 pb-3 sm:px-0 sm:pb-0",children:"Snapshot captured but no content was stored."})]}):e.jsx(A,{icon:pe,title:"No snapshot",description:"No snapshot was captured for this item.",className:"py-12"})})})}),e.jsx(I,{value:"metadata",className:"mt-4",children:e.jsx(h,{className:"border-border/60 shadow-soft",children:e.jsx(u,{className:"p-5",children:e.jsx("dl",{className:"space-y-3 text-sm",children:[["Title",je(s.title)],["URL",s.url],["Source",s.source_domain],["Type",s.type],["Status",s.status],["Saved",new Date(s.saved_at).toLocaleString()],["Last Opened",s.last_opened_at?new Date(s.last_opened_at).toLocaleString():"Never"],["Word Count",((ne=s.word_count)==null?void 0:ne.toLocaleString())||"N/A"],[We(s.type),O?`${O} min`:"N/A"],["Tags",$.map(a=>xe(a)).join(", ")||"None"],["Collections",B.map(a=>a.name).join(", ")||"None"]].map(([a,Te])=>e.jsxs("div",{className:"flex flex-col sm:flex-row sm:gap-4 py-1.5 border-b border-border/30 last:border-0",children:[e.jsx("dt",{className:"text-muted-foreground w-32 shrink-0 font-medium text-xs uppercase tracking-wider",children:a}),e.jsx("dd",{className:"break-all",children:Te})]},a))})})})})]})]})}export{Ut 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.