diff --git a/crates/archivr-server/static/assets/index-9VVEGfc7.js b/crates/archivr-server/static/assets/index-BxBKvOHp.js similarity index 89% rename from crates/archivr-server/static/assets/index-9VVEGfc7.js rename to crates/archivr-server/static/assets/index-BxBKvOHp.js index df50044..a2a2b37 100644 --- a/crates/archivr-server/static/assets/index-9VVEGfc7.js +++ b/crates/archivr-server/static/assets/index-BxBKvOHp.js @@ -44,6 +44,6 @@ ${Te.map(ot=>` ${ot}`).join(` `)}`);const nt=ie.length>0?ie.join(` `):null;C.current(nt,null,$e,pe)}async function Ie(w,B){var Te,pe,$e;const O=v.current,$=((Te=crypto.randomUUID)==null?void 0:Te.call(crypto))??`job-${Date.now()}-${Math.random()}`;if(w.type==="text"){try{const ie=await om(O,{title:w.title,body:w.body,mime:w.mime}),nt=`text:${w.title}`;(pe=E.current)==null||pe.call(E,{id:$,jobUid:ie.job_uid,locator:nt,archiveId:O}),Se($,ie.job_uid,nt,O,B)}catch(ie){const nt=ie.message||"Submission failed.";C.current(nt,`text:${w.title}`),ce(B,"failed",`text:${w.title}`)}return}const F=w.locator,U=w.quality,ye=w.extraExtensions||{},ue={ublock_enabled:ne,reader_mode:se,cookie_ext_enabled:Be,modal_closer_enabled:M,via_freedium:V,...ye};try{const ie=await am(O,F,U,ue);($e=E.current)==null||$e.call(E,{id:$,jobUid:ie.job_uid,locator:F,archiveId:O}),Se($,ie.job_uid,F,O,B)}catch(ie){const nt=ie.message||"Submission failed.";C.current(nt,F),ce(B,"failed",F),F.startsWith("file://")&&ie.status&&Ei(O,F).catch(()=>{})}}function at(){var $,F;if(j.some(U=>U.kind==="file"&&U.uploadStatus==="uploading"))return;const w=j.filter(U=>U.kind==="file"?U.uploadStatus==="done"&&U.uploadLocator:U.kind==="text"?U.title.trim()&&U.body.trim():U.locator.trim());if(w.length===0||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&Ou(U))||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&(U.probeState==="probing"||Dn(U.locator)&&U.playlistProbeState!=="done"))||w.some(U=>U.kind!=="file"&&U.kind!=="text"&&Array.isArray(U.playlistItems)&&U.playlistItems.length===0))return;const B=w.length>1?(($=crypto.randomUUID)==null?void 0:$.call(crypto))??`batch-${Date.now()}`:null;B&&h.current.set(B,{total:w.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]});const O=w.map(U=>U.kind==="file"?{type:"file",locator:U.uploadLocator,quality:"best",extraExtensions:{}}:U.kind==="text"?{type:"text",title:U.title.trim(),body:U.body,mime:U.mime}:{type:"url",locator:U.locator.trim(),quality:U.playlistItems!==null?null:U.quality||"best",extraExtensions:U.playlistItems!==null?{per_item_quality:Object.fromEntries(U.playlistItems.map(ye=>[ye.id,ye.quality])),sync:U.syncEnabled}:{}});f.current=!0,P([Xn()]),(F=u.current)==null||F.close(),O.forEach(U=>Ie(U,B))}function ht(){P(w=>[...w,Xn()])}function Vt(w){var O;clearTimeout(g.current.get(w)),g.current.delete(w);const B=p.current.find($=>$.id===w);(B==null?void 0:B.kind)==="file"&&(B.uploadStatus==="uploading"?((O=m.current.get(w))==null||O(),m.current.delete(w)):B.uploadStatus==="done"&&B.uploadLocator&&Ei(v.current,B.uploadLocator).catch(()=>{})),P($=>{const F=$.filter(U=>U.id!==w);return F.length===0?[Xn()]:F})}function Qt(w,B){if(clearTimeout(g.current.get(w)),P(O=>O.map($=>$.id===w?{...$,locator:B,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best",playlistProbeState:"idle",playlistInfo:null,playlistItems:null,playlistQuality:null,playlistExpanded:!1}:$)),uf(B)){const O=setTimeout(async()=>{g.current.delete(w),P($=>$.map(F=>F.id===w?{...F,probeState:"probing"}:F));try{const $=await um(v.current,B.trim());P(F=>F.map(U=>{if(U.id!==w||U.locator!==B)return U;const ye=$.qualities??[],ue=$.has_audio??!1,Te=ye.length===0&&ue?"audio":"best";return{...U,probeState:"done",probeQualities:ye,probeHasAudio:ue,quality:Te}}))}catch{P($=>$.map(F=>F.id===w?{...F,probeState:"idle",probeQualities:null}:F))}},600);g.current.set(w,O)}else if(Dn(B)){const O=setTimeout(async()=>{g.current.delete(w),P($=>$.map(F=>F.id===w?{...F,playlistProbeState:"probing"}:F));try{const $=await cm(v.current,B.trim());P(F=>F.map(U=>U.id!==w||U.locator!==B?U:{...U,playlistProbeState:"done",playlistInfo:$,playlistItems:$.items.map(ye=>({...ye,quality:null})),playlistQuality:null}))}catch{P($=>$.map(F=>F.id===w?{...F,playlistProbeState:"error"}:F))}},800);g.current.set(w,O)}}function jt(w,B){P(O=>O.map($=>$.id===w?{...$,quality:B}:$))}function Oe(w,B){P(O=>O.map($=>{if($.id!==w)return $;const F=qm(B,$.playlistItems);return{...$,playlistQuality:B,playlistItems:F}}))}function Je(w,B,O){P($=>$.map(F=>F.id!==w?F:{...F,playlistItems:F.playlistItems.map(U=>U.id===B?{...U,quality:O}:U)}))}function tt(w){P(B=>B.map(O=>O.id===w?{...O,playlistExpanded:!O.playlistExpanded}:O))}function D(w,B){P(O=>O.map($=>$.id===w?{...$,syncEnabled:B}:$))}function K(w,B){P(O=>O.map($=>$.id!==w?$:{...$,playlistItems:$.playlistItems.filter(F=>F.id!==B)}))}function Ne(w){const B=Array.from(w);B.length!==0&&B.forEach(O=>{const $=Vm(O.name);P(ue=>ue.length===1&&!ue[0].kind&&!ue[0].locator.trim()?[$]:[...ue,$]);const F=v.current,{promise:U,abort:ye}=Fm(F,O,ue=>{P(Te=>Te.map(pe=>pe.id===$.id?{...pe,uploadProgress:ue}:pe))});m.current.set($.id,ye),U.then(ue=>{m.current.delete($.id),P(Te=>Te.map(pe=>pe.id===$.id?{...pe,uploadStatus:"done",uploadLocator:ue.locator,uploadProgress:100}:pe))}).catch(ue=>{m.current.delete($.id),ue.message!=="Upload cancelled"&&P(Te=>Te.map(pe=>pe.id===$.id?{...pe,uploadStatus:"error",uploadError:ue.message}:pe))})})}function Ve(w){w.preventDefault(),w.stopPropagation(),w.dataTransfer.types.includes("Files")&&N(!0)}function qt(w){w.currentTarget.contains(w.relatedTarget)||N(!1)}function Qe(w){w.preventDefault(),w.stopPropagation(),N(!1),Ne(w.dataTransfer.files)}function Kt(w){Ne(w.target.files),w.target.value=""}const Qn=j.some(w=>w.kind==="file"&&w.uploadStatus==="uploading"),Ot=j.filter(w=>w.kind==="file"?w.uploadStatus==="done"&&w.uploadLocator:w.kind==="text"?w.title.trim()&&w.body.trim():w.locator.trim()).length,Le=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&Ou(w)),bn=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&Array.isArray(w.playlistItems)&&w.playlistItems.length===0),At=j.some(w=>w.kind!=="file"&&w.kind!=="text"&&(w.probeState==="probing"||Dn(w.locator)&&w.playlistProbeState!=="done"));return s.jsx("dialog",{ref:u,className:`capture-dialog${S?" capture-dialog--dragover":""}`,onDragOver:Ve,onDragLeave:qt,onDrop:Qe,children:s.jsxs("div",{className:"capture-dialog-inner",children:[s.jsxs("div",{className:"capture-dialog-header",children:[s.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),s.jsx("button",{type:"button",className:"capture-dialog-close",onClick:()=>{var w;return(w=u.current)==null?void 0:w.close()},"aria-label":"Close",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),s.jsx("div",{className:"capture-rows",children:j.map((w,B)=>w.kind==="file"?s.jsx(Jm,{item:w,onRemove:()=>Vt(w.id)},w.id):w.kind==="text"?s.jsx(Gm,{item:w,autoFocus:B===j.length-1,onTitleChange:O=>P($=>$.map(F=>F.id===w.id?{...F,title:O}:F)),onBodyChange:O=>P($=>$.map(F=>F.id===w.id?{...F,body:O}:F)),onMimeChange:O=>P($=>$.map(F=>F.id===w.id?{...F,mime:O}:F)),onRemove:()=>Vt(w.id),onSubmit:at},w.id):s.jsx(Xm,{item:w,autoFocus:B===j.length-1,onLocatorChange:O=>Qt(w.id,O),onQualityChange:O=>jt(w.id,O),onRemove:()=>Vt(w.id),onSubmit:at,onPlaylistQualityChange:O=>Oe(w.id,O),onPlaylistItemQualityChange:(O,$)=>Je(w.id,O,$),onPlaylistToggle:()=>tt(w.id),onSyncChange:O=>D(w.id,O),onPlaylistItemDelete:O=>K(w.id,O)},w.id))}),s.jsx("input",{ref:x,type:"file",multiple:!0,hidden:!0,onChange:Kt,"aria-hidden":"true",tabIndex:-1}),s.jsxs("div",{className:"capture-add-row-group",children:[s.jsxs("button",{type:"button",className:"capture-add-row",onClick:ht,children:[s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),s.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add URL"]}),s.jsxs("button",{type:"button",className:"capture-add-row capture-add-file",onClick:()=>{var w;return(w=x.current)==null?void 0:w.click()},children:[s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1.5"}),s.jsx("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"5.5"}),s.jsx("line",{x1:"5.5",y1:"8",x2:"10.5",y2:"8"}),s.jsx("line",{x1:"5.5",y1:"10.5",x2:"8.5",y2:"10.5"})]}),"Upload file"]}),s.jsxs("button",{type:"button",className:"capture-add-row capture-add-text",onClick:()=>P(w=>[...w,Qm()]),children:[s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M2 3h12M2 7h12M2 11h8"})}),"Add text"]})]}),s.jsxs("div",{className:"capture-advanced",children:[s.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>X(w=>!w),"aria-expanded":R,children:[s.jsx("svg",{className:`capture-chevron${R?" capture-chevron--open":""}`,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("polyline",{points:"4 6 8 10 12 6"})}),"Advanced options"]}),R&&s.jsxs("div",{className:"capture-advanced-panel",children:[s.jsxs("label",{className:"capture-ext-row",children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"uBlock Origin Lite"}),s.jsx("span",{className:"capture-ext-desc",children:"Block ads during this capture"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":ne,className:`ext-toggle ext-toggle--sm${ne?" ext-toggle--on":""}`,onClick:()=>Y(w=>w===null?!ne:!w),"aria-label":"Toggle uBlock for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Block cookie banners"}),s.jsx("span",{className:"capture-ext-desc",children:"Dismiss cookie consent banners during this capture"}),!(te!=null&&te.cookie_ext_available)&&s.jsxs("span",{className:"capture-ext-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":Be,className:`ext-toggle ext-toggle--sm${Be?" ext-toggle--on":""}`,onClick:()=>we(w=>!w),"aria-label":"Toggle cookie banner blocking for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Reader mode"}),s.jsx("span",{className:"capture-ext-desc",children:"Distil to article text via Readability (off by default)"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":se,className:`ext-toggle ext-toggle--sm${se?" ext-toggle--on":""}`,onClick:()=>Z(w=>!w),"aria-label":"Toggle reader mode for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Close modals and dialogs"}),s.jsx("span",{className:"capture-ext-desc",children:"Auto-dismiss cookie banners and overlays during this capture"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":M,className:`ext-toggle ext-toggle--sm${M?" ext-toggle--on":""}`,onClick:()=>L(w=>!w),"aria-label":"Toggle modal closer for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]}),s.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[s.jsxs("span",{className:"capture-ext-label",children:[s.jsx("span",{className:"capture-ext-name",children:"Freedium mirror"}),s.jsx("span",{className:"capture-ext-desc",children:"Route paywalled articles through a Freedium mirror (Medium, NYT, WaPo, etc.)"})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":V,className:`ext-toggle ext-toggle--sm${V?" ext-toggle--on":""}`,onClick:()=>G(w=>!w),"aria-label":"Toggle Freedium mirror for this capture",children:s.jsx("span",{className:"ext-toggle-knob"})})]})]})]}),s.jsxs("div",{className:"capture-actions",children:[s.jsx("button",{type:"button",className:"capture-submit",onClick:at,disabled:Ot===0||Le||At||bn||Qn,children:Ot>1?`Archive ${Ot}`:"Archive"}),s.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var w;return(w=u.current)==null?void 0:w.close()},children:"Cancel"})]})]})})}function Xm({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onSubmit:i,onPlaylistQualityChange:a,onPlaylistItemQualityChange:o,onPlaylistToggle:u,onSyncChange:d,onPlaylistItemDelete:y}){const g=c.useRef(null);c.useEffect(()=>{var x;t&&((x=g.current)==null||x.focus())},[t]);const h=(()=>{if(Dn(e.locator)){if(e.playlistProbeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Probing playlist…",children:"…"});if(e.playlistProbeState==="done"){const x=[...new Set(e.playlistItems.flatMap(p=>p.qualities.map(f=>parseInt(f))))].sort((p,f)=>f-p),S=e.playlistItems.every(p=>p.has_audio),N=e.playlistItems.filter(p=>p.quality===null).length;return s.jsxs(s.Fragment,{children:[s.jsxs("select",{className:"capture-quality",value:e.playlistQuality??"",onChange:p=>a(p.target.value),"aria-label":"Playlist quality",children:[!e.playlistQuality&&s.jsx("option",{value:"",disabled:!0,children:"Select quality…"}),s.jsx("option",{value:"best",children:"Best quality"}),x.map(p=>s.jsxs("option",{value:`${p}p`,children:[p,"p"]},p)),S&&s.jsx("option",{value:"audio",children:"Audio only"})]}),N>0&&s.jsxs("span",{className:"capture-conflict-badge",children:[N," need selection"]})]})}return e.playlistProbeState==="error"?s.jsx("span",{className:"capture-quality-hint capture-quality-hint--error",children:"Probe failed — edit URL to retry"}):null}if(!uf(e.locator))return null;if(e.probeState==="probing")return s.jsx("span",{className:"capture-quality-probing","aria-label":"Checking available qualities",children:"…"});if(e.probeState==="done"){const x=e.probeQualities??[],S=e.probeHasAudio??!1;return x.length===0&&!S?s.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):x.length===0&&S?s.jsx("select",{className:"capture-quality",value:"audio",onChange:N=>r(N.target.value),"aria-label":"Video quality",children:s.jsx("option",{value:"audio",children:"Audio only"})}):s.jsxs("select",{className:"capture-quality",value:e.quality||"best",onChange:N=>r(N.target.value),"aria-label":"Video quality",children:[s.jsx("option",{value:"best",children:"Best quality"}),x.map(N=>s.jsx("option",{value:N,children:N},N)),S&&s.jsx("option",{value:"audio",children:"Audio only"})]})}return null})(),v=Dn(e.locator)&&e.playlistProbeState==="done"?s.jsxs("label",{className:"capture-sync-row",children:[s.jsx("input",{type:"checkbox",checked:e.syncEnabled,onChange:x=>d(x.target.checked)}),s.jsx("span",{children:"Sync — skip already-archived videos"})]}):null;return s.jsxs("div",{className:"capture-row",children:[s.jsxs("div",{className:"capture-row-main",children:[Dn(e.locator)&&e.playlistProbeState==="done"?s.jsx("button",{type:"button",className:"capture-playlist-toggle capture-playlist-toggle--left",onClick:u,"aria-label":e.playlistExpanded?"Collapse video list":"Expand video list","aria-expanded":e.playlistExpanded,children:e.playlistExpanded?"▲":"▼"}):null,s.jsx("input",{ref:g,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:x=>n(x.target.value),onKeyDown:x=>{x.key==="Enter"&&i()},autoComplete:"off",spellCheck:!1}),h,s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&s.jsx("p",{className:"capture-row-error",children:e.error}),Dn(e.locator)&&e.playlistProbeState==="done"&&e.playlistExpanded?s.jsxs("div",{className:"capture-playlist-items",children:[e.playlistItems.map(x=>s.jsxs("div",{className:`capture-playlist-item${x.quality===null?" capture-playlist-item--conflict":""}`,children:[s.jsx("span",{className:"capture-playlist-item-title",children:x.title||x.url}),s.jsxs("select",{className:"capture-item-quality",value:x.quality??"",onChange:S=>o(x.id,S.target.value),"aria-label":`Quality for ${x.title||x.url}`,children:[x.quality===null&&s.jsx("option",{value:"",disabled:!0,children:"Choose…"}),s.jsx("option",{value:"best",children:"Best quality"}),x.qualities.map(S=>s.jsx("option",{value:S,children:S},S)),x.has_audio&&s.jsx("option",{value:"audio",children:"Audio only"})]}),x.quality===null&&s.jsx("span",{className:"capture-playlist-conflict-badge",children:"Choose quality"}),s.jsx("button",{type:"button",className:"capture-playlist-item-remove","aria-label":`Remove ${x.title||x.url}`,onClick:()=>y(x.id),children:"×"})]},x.id)),v]}):v]})}function Jm({item:e,onRemove:t}){const n=e.uploadStatus==="uploading",r=e.uploadStatus==="done",l=e.uploadStatus==="error";return s.jsxs("div",{className:"capture-row",children:[s.jsxs("div",{className:"capture-row-main",children:[s.jsx("span",{className:"capture-file-icon","aria-hidden":"true",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",style:{width:14,height:14},children:[s.jsx("rect",{x:"3",y:"1",width:"10",height:"14",rx:"1.5"}),s.jsx("line",{x1:"5.5",y1:"5.5",x2:"10.5",y2:"5.5"}),s.jsx("line",{x1:"5.5",y1:"8",x2:"10.5",y2:"8"}),s.jsx("line",{x1:"5.5",y1:"10.5",x2:"8.5",y2:"10.5"})]})}),s.jsx("span",{className:`capture-file-name${l?" capture-file-name--error":""}`,children:e.filename}),n&&s.jsxs("span",{className:"capture-file-progress-wrap","aria-label":`Uploading ${e.uploadProgress}%`,children:[s.jsx("span",{className:"capture-file-progress-bar",children:s.jsx("span",{className:"capture-file-progress-fill",style:{width:`${e.uploadProgress}%`}})}),s.jsxs("span",{className:"capture-file-progress-pct",children:[e.uploadProgress,"%"]})]}),r&&s.jsx("span",{className:"capture-file-badge capture-file-badge--done","aria-label":"Upload complete",children:s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{width:11,height:11},children:s.jsx("polyline",{points:"3 8.5 6.5 12 13 5"})})}),l&&s.jsx("span",{className:"capture-file-badge capture-file-badge--error",children:"!"}),s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:t,"aria-label":"Remove",disabled:n,children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),l&&s.jsx("p",{className:"capture-row-error",children:e.uploadError||"Upload failed"})]})}function Gm({item:e,autoFocus:t,onTitleChange:n,onBodyChange:r,onMimeChange:l,onRemove:i,onSubmit:a}){const o=c.useRef(null);return c.useEffect(()=>{var u;t&&((u=o.current)==null||u.focus())},[t]),s.jsx("div",{className:"capture-row capture-text-row",children:s.jsxs("div",{className:"capture-row-main",children:[s.jsx("span",{className:"capture-text-icon","aria-hidden":"true",children:s.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",style:{width:14,height:14},children:s.jsx("path",{d:"M2 3h12M2 7h12M2 11h8"})})}),s.jsxs("div",{className:"capture-text-inputs",children:[s.jsx("input",{ref:o,className:"capture-text-input capture-text-title",type:"text",placeholder:"Title",value:e.title,onChange:u=>n(u.target.value),maxLength:500}),s.jsx("textarea",{className:"capture-text-input capture-text-body",placeholder:"Body (markdown or plain text)",value:e.body,onChange:u=>r(u.target.value),rows:6}),s.jsx("div",{className:"capture-text-footer",children:s.jsxs("select",{className:"capture-text-mime",value:e.mime,onChange:u=>l(u.target.value),children:[s.jsx("option",{value:"text/markdown",children:"Markdown"}),s.jsx("option",{value:"text/plain",children:"Plain text"})]})})]}),s.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:i,"aria-label":"Remove",children:s.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),s.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]})})}const Ym=["list=","/playlist/","/channel/","yt:playlist:","yt:channel:","ytm:playlist:","spotify:playlist:","spotify:album:"];function Zm(e){const t=e.toLowerCase();return Ym.some(n=>t.includes(n))}function eg(e){return e.length>80?`${e.slice(0,79)}…`:e}function tg({locator:e=""}){const t=String(e),n=Zm(t);return s.jsxs("div",{className:"in-progress-entry-row",role:"status","aria-live":"polite",children:[s.jsx("span",{className:"cap-spinner in-progress-entry-row__spinner","aria-hidden":"true"}),s.jsx("span",{className:"in-progress-entry-row__locator",title:t,children:eg(t)}),s.jsxs("span",{className:"in-progress-entry-row__status",children:["Archiving…",n&&s.jsx("span",{className:"in-progress-entry-row__kind",children:"(playlist)"})]})]})}function gl(e){if(!e)return"0 B";const t=["B","KB","MB","GB"];let n=e,r=0;for(;n>=1024&&r").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}function gt(e){return ng(e)??""}function ko(e){if(!e)return"";const t=new Date(e);if(isNaN(t))return e;const n=r=>String(r).padStart(2,"0");return`${t.getUTCFullYear()}-${n(t.getUTCMonth()+1)}-${n(t.getUTCDate())} ${n(t.getUTCHours())}:${n(t.getUTCMinutes())}`}const Au={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function Ws(e){return Au[e]??Au.other}function cf(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function rg({entry:e,index:t,onRowClick:n,selectedUids:r}){const l=(r==null?void 0:r.size)===1&&r.has(e.entry_uid),i=(r==null?void 0:r.size)>=2&&r.has(e.entry_uid),a=["child-entry-row",t%2===0?"child-entry-row--light":"child-entry-row--dark",l&&"is-selected",i&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:a,tabIndex:0,"data-entry-uid":e.entry_uid,onMouseDown:o=>{o.shiftKey&&o.preventDefault()},onClick:o=>n(e,o),onKeyDown:o=>{o.key==="Enter"&&n(e,o)},children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:ko(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[s.jsx("span",{className:"source-icon",children:s.jsx("span",{dangerouslySetInnerHTML:{__html:Ws(e.source_kind)}})}),s.jsx("span",{className:"entry-title",children:gt(e.title)||gt(e.entry_uid)})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:gt(e.entity_kind)})}),s.jsx("div",{className:"col-size",children:s.jsx("span",{className:"size-total",children:gl(e.total_artifact_bytes)})}),s.jsx("div",{className:"url-cell col-url",children:gt(e.original_url)})]})}function lg({entry:e,archiveId:t,rowIndex:n,isSelected:r,isMultiSelected:l,onRowClick:i,selectedUids:a,deletedUids:o,isPublicSession:u}){const[d,y]=c.useState(!1),[g,h]=c.useState(!1),[v,x]=c.useState(null),[S,N]=c.useState(!1),f=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!d?s.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>y(!0),style:{objectFit:"contain"}}):s.jsx("span",{dangerouslySetInnerHTML:{__html:Ws(e.source_kind)}}),m=r||l,k=e.child_count>0&&!u;function C(j){j.stopPropagation(),i(e,{ctrlKey:!0,metaKey:!1,shiftKey:!1,preventDefault(){}})}async function E(j){if(j.stopPropagation(),g){h(!1);return}if(h(!0),v===null&&!S){N(!0);try{const P=await Yh(t,e.entry_uid);x(P)}catch{x([])}finally{N(!1)}}}const T=["entry-row-outer",n%2===0?"entry-row-outer--light":"entry-row-outer--dark",r&&"is-selected",l&&"is-multi-selected"].filter(Boolean).join(" ");return s.jsxs("div",{className:T,"data-entry-uid":e.entry_uid,children:[s.jsxs("div",{className:"entry-row-main",tabIndex:0,onMouseDown:j=>{j.shiftKey&&j.preventDefault()},onClick:j=>i(e,j),onKeyDown:j=>{j.key==="Enter"&&i(e,j)},children:[s.jsx("div",{className:"col-check",children:s.jsx("button",{type:"button",className:`row-checkbox${m?" is-checked":""}`,"aria-pressed":m,"aria-label":m?"Deselect entry":"Select entry",onClick:C,onKeyDown:j=>j.stopPropagation()})}),s.jsx("div",{className:"col-added",children:ko(e.archived_at)}),s.jsxs("div",{className:"col-title",children:[k&&s.jsx("button",{type:"button",className:`entry-expand-btn${g?" is-expanded":""}`,"aria-label":g?"Collapse children":`Expand ${e.child_count} items`,"aria-expanded":g,onClick:E,onKeyDown:j=>j.stopPropagation()}),s.jsx("span",{className:"source-icon",children:f}),s.jsx("span",{className:"entry-title",children:gt(e.title)||gt(e.entry_uid)}),k&&s.jsx("span",{className:"child-count-badge","aria-hidden":"true",children:e.child_count})]}),s.jsx("div",{className:"col-type",children:s.jsx("span",{className:"type-pill",children:gt(e.entity_kind)})}),s.jsxs("div",{className:"col-size",children:[s.jsx("span",{className:"size-total",children:gl(e.total_artifact_bytes)}),e.cached_bytes>0&&e.cacheable_bytes>0&&s.jsxs("span",{className:"size-cached-pct",title:`${gl(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.cacheable_bytes*100),"% cached"]})]}),s.jsx("div",{className:"url-cell col-url",children:gt(e.original_url)})]}),g&&s.jsxs(s.Fragment,{children:[S&&s.jsx("div",{className:"child-entries-loading",children:"Loading…"}),s.jsx("div",{className:"child-entries","aria-label":`${e.child_count} child entries`,children:v&&v.filter(j=>!(o!=null&&o.has(j.entry_uid))).map((j,P)=>s.jsx(rg,{entry:j,index:P,onRowClick:i,selectedUids:a},j.entry_uid))})]})]})}function sg({entries:e,selectedUids:t,onRowClick:n,archiveId:r,pendingCaptures:l=[],deletedUids:i,isPublicSession:a}){return s.jsx("section",{id:"archive-view",className:"view is-active",children:s.jsxs("div",{className:"entry-table",children:[s.jsxs("div",{className:"entry-header-row",children:[s.jsx("div",{className:"col-check","aria-hidden":"true"}),s.jsx("div",{className:"col-added",children:"Added"}),s.jsx("div",{className:"col-title",children:"Title"}),s.jsx("div",{className:"col-type",children:"Type"}),s.jsx("div",{className:"col-size",children:"Size"}),s.jsx("div",{className:"col-url",children:"Original URL"})]}),s.jsxs("div",{id:"entries-body",children:[l.filter(o=>o.archiveId===r).reverse().map(o=>s.jsx(tg,{locator:o.locator},o.id)),e.map((o,u)=>s.jsx(lg,{entry:o,rowIndex:u,archiveId:r,isSelected:t.size===1&&t.has(o.entry_uid),isMultiSelected:t.size>=2&&t.has(o.entry_uid),onRowClick:n,selectedUids:t,deletedUids:i,isPublicSession:a},o.entry_uid))]})]})})}function ig(e){if(!e)return"—";try{return new Date(e).toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return e}}function ag({status:e}){const t=e==="completed"?"run-status--completed":e==="failed"?"run-status--failed":e==="in_progress"?"run-status--in-progress":"",n=e?e.replace(/_/g," "):"—";return s.jsx("span",{className:`run-status ${t}`,children:n})}function og({runs:e}){const[t,n]=c.useState(null);function r(l){n(i=>i===l?null:l)}return s.jsx("section",{id:"runs-view",className:"view is-active",children:s.jsxs("table",{className:"entry-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Started"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Requested"}),s.jsx("th",{children:"Completed"}),s.jsx("th",{children:"Failed"})]})}),s.jsx("tbody",{children:e.length===0?s.jsx("tr",{children:s.jsx("td",{colSpan:5,style:{color:"var(--muted)",padding:"24px 16px",textAlign:"center"},children:"No runs yet."})}):e.map(l=>{const i=l.status==="failed"&&l.error_summary,a=t===l.run_uid;return[s.jsxs("tr",{className:i?"run-row run-row--failed":"run-row",onClick:i?()=>r(l.run_uid):void 0,title:i?a?"Click to hide error":"Click to view error":void 0,children:[s.jsx("td",{children:ig(l.started_at)}),s.jsxs("td",{children:[s.jsx(ag,{status:l.status}),i&&s.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:a?"▴":"▾"})]}),s.jsx("td",{children:l.requested_count??"—"}),s.jsx("td",{children:l.completed_count??"—"}),s.jsx("td",{children:l.failed_count??"—"})]},l.run_uid),i&&a&&s.jsx("tr",{className:"run-error-row",children:s.jsx("td",{colSpan:5,children:s.jsx("pre",{className:"run-error-detail",children:l.error_summary})})},`${l.run_uid}-detail`)]})})]})})}const ug=4;function cg({archives:e}){const{currentUser:t}=c.useContext(Vs)??{},n=t&&(t.role_bits&ug)!==0,[r,l]=c.useState("users"),[i,a]=c.useState([]),[o,u]=c.useState([]),[d,y]=c.useState(!1),[g,h]=c.useState(null),[v,x]=c.useState(""),[S,N]=c.useState(""),[p,f]=c.useState(""),[m,k]=c.useState(null),[C,E]=c.useState(!1),[T,j]=c.useState(""),[P,R]=c.useState(""),[X,H]=c.useState(null),[Y,te]=c.useState(!1),fe=c.useCallback(async()=>{if(n){y(!0),h(null);try{const[L,V]=await Promise.all([jm(),_m()]);a(L),u(V)}catch(L){h(L.message)}finally{y(!1)}}},[n]);c.useEffect(()=>{fe()},[fe]);async function Be(L){const V=L.status==="active"?"disabled":"active";try{await Nm(L.user_uid,V),a(G=>G.map(ne=>ne.user_uid===L.user_uid?{...ne,status:V}:ne))}catch(G){h(G.message)}}async function we(L){if(L.preventDefault(),!v.trim()||!S){k("Username and password required");return}E(!0),k(null);try{await Sm(v.trim(),S,p.trim()||void 0),x(""),N(""),f(""),await fe()}catch(V){k(V.message)}finally{E(!1)}}async function M(L){if(L.preventDefault(),!T.trim()||!P.trim()){H("Slug and name required");return}te(!0),H(null);try{await Cm(T.trim(),P.trim()),j(""),R(""),await fe()}catch(V){H(V.message)}finally{te(!1)}}return n?s.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[s.jsx("h1",{children:"Admin"}),s.jsxs("div",{className:"view-tabs",children:[s.jsx("button",{className:`view-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),s.jsx("button",{className:`view-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),s.jsx("button",{className:`view-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),g&&s.jsx("div",{className:"form-msg form-msg--err",children:g}),r==="users"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Users"}),d?s.jsx("p",{className:"muted",children:"Loading…"}):s.jsxs("table",{className:"admin-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Username"}),s.jsx("th",{children:"Email"}),s.jsx("th",{children:"Roles"}),s.jsx("th",{children:"Status"}),s.jsx("th",{children:"Actions"})]})}),s.jsx("tbody",{children:i.map(L=>s.jsxs("tr",{className:L.status==="disabled"?"admin-row-disabled":"",children:[s.jsx("td",{children:L.username}),s.jsx("td",{className:"muted",children:L.email||"—"}),s.jsx("td",{children:L.role_slugs.join(", ")||"—"}),s.jsx("td",{children:s.jsx("span",{className:`status-badge status-${L.status}`,children:L.status})}),s.jsx("td",{children:s.jsx("button",{className:"admin-action-btn",onClick:()=>Be(L),children:L.status==="active"?"Ban":"Unban"})})]},L.user_uid))})]}),s.jsx("h3",{children:"Create User"}),s.jsxs("form",{className:"admin-form",onSubmit:we,children:[s.jsx("input",{className:"admin-input",placeholder:"Username",value:v,onChange:L=>x(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:S,onChange:L=>N(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:p,onChange:L=>f(L.target.value)}),m&&s.jsx("div",{className:"form-msg form-msg--err",children:m}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:C,children:C?"Creating…":"Create User"})]})]}),r==="roles"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Roles"}),d?s.jsx("p",{className:"muted",children:"Loading…"}):s.jsxs("table",{className:"admin-table",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Slug"}),s.jsx("th",{children:"Name"}),s.jsx("th",{children:"Level"}),s.jsx("th",{children:"Bit"}),s.jsx("th",{children:"Built-in"})]})}),s.jsx("tbody",{children:o.map(L=>s.jsxs("tr",{children:[s.jsx("td",{children:s.jsx("code",{children:L.slug})}),s.jsx("td",{children:L.name}),s.jsx("td",{children:L.level}),s.jsx("td",{children:L.bit_position}),s.jsx("td",{children:L.is_builtin?"✓":""})]},L.role_uid))})]}),s.jsx("h3",{children:"Create Custom Role"}),s.jsxs("form",{className:"admin-form",onSubmit:M,children:[s.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:T,onChange:L=>j(L.target.value),required:!0}),s.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:P,onChange:L=>R(L.target.value),required:!0}),X&&s.jsx("div",{className:"form-msg form-msg--err",children:X}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:Y,children:Y?"Creating…":"Create Role"})]})]}),r==="archives"&&s.jsxs("div",{className:"admin-section",children:[s.jsx("h2",{children:"Mounted Archives"}),s.jsx("div",{className:"admin-list",children:e.map(L=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:L.label}),s.jsx("div",{className:"muted",children:L.archive_path})]},L.id))})]})]}):s.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[s.jsx("h1",{children:"Admin"}),s.jsx("p",{className:"muted",children:"You need admin privileges to access this panel."}),s.jsx("h2",{children:"Mounted Archives"}),s.jsx("div",{className:"admin-list",children:e.map(L=>s.jsxs("div",{className:"admin-archive",children:[s.jsx("strong",{children:L.label}),s.jsx("div",{className:"muted",children:L.archive_path})]},L.id))})]})}function df({node:e,onPick:t}){var n;return s.jsxs("li",{children:[s.jsx("button",{className:"tag-picker-node-btn",title:e.tag.full_path,onClick:()=>t(e.tag),children:e.tag.slug}),((n=e.children)==null?void 0:n.length)>0&&s.jsx("div",{className:"tag-children",children:s.jsx("ul",{className:"tag-tree-list",children:e.children.map(r=>s.jsx(df,{node:r,onPick:t},r.tag.tag_uid))})})]})}function Mu({title:e,tagNodes:t,excludeUid:n,onPick:r,onCancel:l}){c.useEffect(()=>{function o(u){u.key==="Escape"&&(u.preventDefault(),u.stopPropagation(),l())}return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[l]);function i(o){return o.filter(u=>u.tag.tag_uid!==n).map(u=>({...u,children:i(u.children)}))}const a=n?i(t):t;return s.jsx("div",{className:"tag-picker-backdrop",onClick:o=>{o.target===o.currentTarget&&l()},children:s.jsxs("div",{className:"tag-picker-modal",role:"dialog","aria-modal":"true",children:[s.jsxs("div",{className:"tag-picker-header",children:[s.jsx("span",{className:"tag-picker-title",children:e}),s.jsx("button",{className:"tag-picker-close",onClick:l,title:"Cancel","aria-label":"Cancel",children:"×"})]}),s.jsxs("div",{className:"tag-picker-body",children:[s.jsx("button",{className:"tag-picker-root-btn",onClick:()=>r(null),title:"Place at root level (no parent)",children:"↑ Root tag (no parent)"}),a.length>0?s.jsx("ul",{className:"tag-tree-list tag-picker-tree",children:a.map(o=>s.jsx(df,{node:o,onPick:r},o.tag.tag_uid))}):s.jsx("p",{className:"tag-picker-empty",children:"No other tags available."})]})]})})}function ff({parentPath:e,archiveId:t,onDone:n,onCancel:r}){const[l,i]=c.useState(""),a=c.useRef(!1);async function o(){const u=l.trim();if(!u){r();return}const d=e?`${e}/${u}`:`/${u}`;try{await sm(t,d),n()}catch(y){alert(y.message||"Create failed"),r()}}return s.jsx("input",{className:"tag-rename-input",autoFocus:!0,placeholder:"tag name",value:l,onChange:u=>i(u.target.value),onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur(),u.key==="Escape"&&(a.current=!0,u.currentTarget.blur())},onBlur:()=>{a.current?(a.current=!1,r()):o()}})}function pf({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:d,onMoveSourceSelect:y,pendingCreateParentUid:g,onCreateDone:h,onCreateCancel:v}){var X;const x=n===e.tag.full_path,[S,N]=c.useState(!1),[p,f]=c.useState(""),m=c.useRef(!1);function k(){if(S)return;if(d){y(e);return}const H=x?null:e.tag.full_path;r(H),l("archive")}function C(H){H.stopPropagation(),!d&&(f(e.tag.slug),N(!0))}async function E(){const H=p.trim();if(!H||H===e.tag.slug){N(!1);return}try{const Y=await rm(t,e.tag.tag_uid,H);i(e.tag.full_path,Y.full_path),o()}catch{}finally{N(!1)}}async function T(H){var te;H.stopPropagation();const Y=((te=e.children)==null?void 0:te.length)>0?`Delete tag "${e.tag.full_path}" and all its child tags? This cannot be undone.`:`Delete tag "${e.tag.full_path}"? This cannot be undone.`;if(window.confirm(Y))try{await lm(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const j={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:d,onMoveSourceSelect:y,pendingCreateParentUid:g,onCreateDone:h,onCreateCancel:v},P=g===e.tag.tag_uid,R=((X=e.children)==null?void 0:X.length)>0;return s.jsxs("li",{children:[s.jsxs("div",{className:`tag-node-row${d?" tag-node-row--move-select":""}`,children:[S?s.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:p,onChange:H=>f(H.target.value),onKeyDown:H=>{H.key==="Enter"&&H.currentTarget.blur(),H.key==="Escape"&&(m.current=!0,H.currentTarget.blur())},onBlur:()=>{m.current?(m.current=!1,N(!1)):E()}}):s.jsxs("button",{className:`tag-node-btn${x?" is-active":""}${d?" tag-node-btn--move-select":""}`,title:d?`Select "${e.tag.full_path}" to move`:e.tag.full_path,onClick:k,onDoubleClick:d?void 0:C,children:[s.jsx("span",{className:"tag-node-label",children:u?e.tag.name:e.tag.slug}),s.jsx("span",{className:"tag-node-count",children:e.children.length===0?`(${e.entry_count})`:`(${e.entry_count}) (${e.subtree_count} Total)`}),!d&&s.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",title:"Rename tag",onClick:H=>{H.stopPropagation(),C(H)},children:s.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),!S&&!d&&s.jsx("button",{className:"remove tag-node-delete",title:`Delete "${e.tag.full_path}"`,onClick:T,"aria-label":`Delete "${e.tag.full_path}"`,children:"×"})]}),(R||P)&&s.jsx("div",{className:"tag-children",children:s.jsxs("ul",{className:"tag-tree-list",children:[e.children.map(H=>s.jsx(pf,{node:H,...j},H.tag.tag_uid)),P&&s.jsx("li",{children:s.jsx(ff,{parentPath:e.tag.full_path,archiveId:t,onDone:h,onCancel:v})})]})})]})}function dg({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){const[d,y]=c.useState(null),[g,h]=c.useState(null);function v(){y("select-source"),h(null)}function x(){y(null),h(null)}c.useEffect(()=>{if(d!=="select-source")return;function Y(te){te.key==="Escape"&&(te.preventDefault(),te.stopPropagation(),x())}return document.addEventListener("keydown",Y),()=>document.removeEventListener("keydown",Y)},[d]);function S(Y){h(Y),y("select-dest")}async function N(Y){const te=g.tag.full_path,fe=g.tag.tag_uid,Be=(Y==null?void 0:Y.tag_uid)??null;x();try{const we=await im(e,fe,Be);i(te,we.full_path),o()}catch(we){alert(we.message||"Move failed")}}const[p,f]=c.useState(null),[m,k]=c.useState(void 0);function C(){f("select-parent"),k(void 0)}function E(){f(null),k(void 0)}function T(Y){k(Y??null),f("input")}function j(){f(null),k(void 0),o()}const P=d==="select-source",R=p==="input"?m?m.tag_uid:"__root__":void 0,X={archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:i,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u,moveSelectMode:P,onMoveSourceSelect:S,pendingCreateParentUid:R,onCreateDone:j,onCreateCancel:E},H=R==="__root__";return s.jsxs("section",{id:"tags-view",className:"view is-active",children:[s.jsxs("div",{className:"tag-tree",children:[s.jsx("div",{className:"tag-tree-header",children:P?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"tag-tree-title tag-tree-title--move",children:"Select a tag to move"}),s.jsx("button",{className:"tag-tree-action-btn tag-tree-action-btn--cancel",onClick:x,children:"Cancel"})]}):s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&s.jsxs("span",{className:"tag-tree-active",title:n,children:["Filtering: ",n]}),s.jsxs("div",{className:"tag-tree-actions",children:[s.jsx("button",{className:"tag-tree-action-btn",onClick:C,title:"Create a new tag",disabled:!!p||!!d,children:"+ New"}),s.jsx("button",{className:"tag-tree-action-btn",onClick:v,title:"Move a tag to a different parent",disabled:!!p||!!d||t.length===0,children:"Move"})]})]})}),t.length===0&&!H?s.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):s.jsxs("ul",{className:"tag-tree-list",children:[t.map(Y=>s.jsx(pf,{node:Y,...X},Y.tag.tag_uid)),H&&s.jsx("li",{children:s.jsx(ff,{parentPath:null,archiveId:e,onDone:j,onCancel:E})})]})]}),p==="select-parent"&&s.jsx(Mu,{title:"Create tag under…",tagNodes:t,excludeUid:null,onPick:T,onCancel:E}),d==="select-dest"&&g&&s.jsx(Mu,{title:`Move "${g.tag.slug}" under…`,tagNodes:t,excludeUid:g.tag.tag_uid,onPick:N,onCancel:x})]})}const Ur=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],fg=e=>{var t;return((t=Ur.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function pg({archiveId:e}){const[t,n]=c.useState([]),[r,l]=c.useState(!1),[i,a]=c.useState(null),[o,u]=c.useState(null),[d,y]=c.useState(null),[g,h]=c.useState(!1),[v,x]=c.useState(null),[S,N]=c.useState(""),[p,f]=c.useState(""),[m,k]=c.useState(2),[C,E]=c.useState(!1),[T,j]=c.useState(!0),[P,R]=c.useState(null),[X,H]=c.useState(""),[Y,te]=c.useState(2),[fe,Be]=c.useState(!1),[we,M]=c.useState(null),[L,V]=c.useState(!1),[G,ne]=c.useState(""),se=c.useRef(null),Z=t.find(D=>D.collection_uid===o)??null,Se=(Z==null?void 0:Z.slug)==="_default_",ce=c.useCallback(async()=>{if(e){l(!0),a(null);try{const D=await wo(e);n(D)}catch(D){a(D.message)}finally{l(!1)}}},[e]),Ie=c.useCallback(async D=>{if(!D){y(null);return}h(!0),x(null);try{const K=await bm(e,D);y(K)}catch(K){x(K.message)}finally{h(!1)}},[e]);c.useEffect(()=>{ce()},[ce]),c.useEffect(()=>{Ie(o)},[o,Ie]),c.useEffect(()=>{L&&se.current&&se.current.focus()},[L]),c.useEffect(()=>{d!=null&&te(d.default_visibility_bits)},[d]);async function at(D){D.preventDefault();const K=S.trim(),Ne=p.trim();if(!(!K||!Ne)){E(!0),R(null);try{const Ve=await Em(e,K,Ne,m,T);N(""),f(""),k(2),j(!0),await ce(),u(Ve.collection_uid)}catch(Ve){R(Ve.message)}finally{E(!1)}}}async function ht(){const D=G.trim();if(!D||!Z){V(!1);return}try{await Ci(e,Z.collection_uid,{name:D}),await ce(),y(K=>K&&{...K,name:D})}catch(K){a(K.message)}finally{V(!1)}}async function Vt(D){if(Z)try{await Ci(e,Z.collection_uid,{default_visibility_bits:D}),await ce(),y(K=>K&&{...K,default_visibility_bits:D})}catch(K){a(K.message)}}async function Qt(D){if(Z)try{await Ci(e,Z.collection_uid,{requires_auth:D}),await ce(),y(K=>K&&{...K,requires_auth:D})}catch(K){a(K.message)}}async function jt(){if(Z&&window.confirm(`Delete collection "${Z.name}"? Entries will not be deleted.`))try{await Lm(e,Z.collection_uid),u(null),y(null),await ce()}catch(D){a(D.message)}}async function Oe(D){D.preventDefault();const K=X.trim();if(!(!K||!Z)){Be(!0),M(null);try{await Sa(e,Z.collection_uid,K,Y),H(""),await Ie(Z.collection_uid)}catch(Ne){M(Ne.message)}finally{Be(!1)}}}async function Je(D){if(Z)try{await Tm(e,Z.collection_uid,D),await Ie(Z.collection_uid)}catch(K){x(K.message)}}async function tt(D,K){if(Z)try{await Pm(e,Z.collection_uid,D,K),y(Ne=>Ne&&{...Ne,entries:Ne.entries.map(Ve=>Ve.entry_uid===D?{...Ve,collection_visibility_bits:K}:Ve)})}catch(Ne){x(Ne.message)}}return e?s.jsxs("div",{className:"collections-view",children:[s.jsx("h2",{className:"collections-heading",children:"Collections"}),r&&s.jsx("div",{className:"muted",children:"Loading…"}),i&&s.jsxs("div",{className:"collections-error",children:[i," ",s.jsx("button",{onClick:()=>a(null),className:"coll-dismiss",children:"×"})]}),s.jsxs("div",{className:"collections-layout",children:[s.jsxs("div",{className:"collections-sidebar",children:[t.map(D=>s.jsxs("button",{className:`coll-sidebar-row${o===D.collection_uid?" is-active":""}`,onClick:()=>u(D.collection_uid),children:[s.jsx("span",{className:"coll-row-name",children:D.name}),s.jsx("span",{className:"coll-row-meta",children:fg(D.default_visibility_bits)})]},D.collection_uid)),t.length===0&&!r&&s.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),Z?s.jsxs("div",{className:"coll-detail",children:[s.jsxs("div",{className:"coll-detail-header",children:[L?s.jsx("input",{ref:se,className:"coll-rename-input",value:G,onChange:D=>ne(D.target.value),onBlur:ht,onKeyDown:D=>{D.key==="Enter"&&ht(),D.key==="Escape"&&V(!1)}}):s.jsxs("h3",{className:`coll-detail-name${Se?"":" coll-detail-name--editable"}`,title:Se?void 0:"Click to rename",onClick:()=>{Se||(ne(Z.name),V(!0))},children:[(d==null?void 0:d.name)??Z.name,!Se&&s.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!Se&&s.jsx("button",{className:"coll-delete-btn",onClick:jt,title:"Delete collection",children:"Delete"})]}),s.jsxs("div",{className:"coll-detail-vis",children:[s.jsx("span",{className:"coll-vis-label",children:"Entries' default visibility"}),s.jsx("select",{className:"coll-vis-select",value:(d==null?void 0:d.default_visibility_bits)??Z.default_visibility_bits,onChange:D=>Vt(Number(D.target.value)),children:Ur.map(D=>s.jsx("option",{value:D.value,children:D.label},D.value))})]}),s.jsxs("div",{className:"coll-detail-vis",children:[s.jsx("span",{className:"coll-vis-label",children:"Collection access"}),s.jsxs("label",{className:"coll-auth-label",children:[s.jsx("input",{type:"checkbox",checked:!!((d==null?void 0:d.requires_auth)??Z.requires_auth),onChange:D=>Qt(D.target.checked)})," Require authentication to view"]})]}),s.jsxs("div",{className:"coll-entries-section",children:[s.jsx("div",{className:"coll-section-heading",children:"Entries"}),g&&s.jsx("div",{className:"muted",children:"Loading…"}),v&&s.jsx("div",{className:"collections-error",children:v}),!g&&d&&(d.entries.length===0?s.jsx("div",{className:"muted",children:"No entries in this collection."}):s.jsx("ul",{className:"coll-entries-list",children:d.entries.map(D=>s.jsxs("li",{className:"coll-entry-row",children:[s.jsxs("div",{className:"coll-entry-info",children:[s.jsx("span",{className:"coll-entry-title",children:D.title||D.entry_uid}),s.jsx("span",{className:"coll-entry-kind muted",children:D.source_kind})]}),s.jsxs("div",{className:"coll-entry-actions",children:[s.jsx("select",{className:"coll-entry-vis-select",value:D.collection_visibility_bits,onChange:K=>tt(D.entry_uid,Number(K.target.value)),children:Ur.map(K=>s.jsx("option",{value:K.value,children:K.label},K.value))}),!Se&&s.jsx("button",{className:"coll-entry-remove",onClick:()=>Je(D.entry_uid),title:"Remove from collection",children:"×"})]})]},D.entry_uid))}))]}),!Se&&s.jsxs("form",{className:"coll-add-entry-form",onSubmit:Oe,children:[s.jsx("div",{className:"coll-section-heading",children:"Add entry"}),s.jsxs("div",{className:"coll-add-entry-row",children:[s.jsx("input",{className:"coll-add-entry-input",type:"text",value:X,onChange:D=>H(D.target.value),placeholder:"entry_uid",required:!0}),s.jsx("select",{className:"coll-vis-select",value:Y,onChange:D=>te(Number(D.target.value)),children:Ur.map(D=>s.jsx("option",{value:D.value,children:D.label},D.value))}),s.jsx("button",{className:"coll-add-btn",type:"submit",disabled:fe,children:fe?"…":"Add"})]}),we&&s.jsx("div",{className:"collections-error",style:{marginTop:4},children:we})]})]}):s.jsx("div",{className:"coll-detail coll-detail--empty",children:s.jsx("div",{className:"muted",children:"Select a collection to view details."})})]}),s.jsxs("details",{className:"coll-create-details",children:[s.jsx("summary",{children:"+ Create collection"}),s.jsxs("form",{className:"coll-create-form",onSubmit:at,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-name",children:"Name"}),s.jsx("input",{className:"capture-input",id:"coll-name",type:"text",value:S,onChange:D=>{N(D.target.value),p||f(D.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),s.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:p,onChange:D=>f(D.target.value),placeholder:"my-collection",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Entries' default visibility"}),s.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:m,onChange:D=>k(Number(D.target.value)),children:Ur.map(D=>s.jsx("option",{value:D.value,children:D.label},D.value))})]}),s.jsx("div",{className:"form-field",children:s.jsxs("label",{className:"form-label",children:[s.jsx("input",{type:"checkbox",checked:T,onChange:D=>j(D.target.checked)})," Require authentication to view"]})}),P&&s.jsx("div",{className:"collections-error",children:P}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:C,children:C?"Creating…":"Create collection"})]})]})]}):s.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const hg=4;function mg({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=c.useContext(Vs)??{},i=r&&(r.role_bits&hg)!==0,a=["profile","tokens",...i?["instance","cookies","extensions","storage"]:[]],o={profile:"Profile",tokens:"API Tokens",instance:"Instance",cookies:"Cookies",extensions:"Extensions",storage:"Storage"};return s.jsxs("section",{className:"admin-view",children:[s.jsx("h1",{children:"Settings"}),s.jsx("div",{className:"view-tabs",children:a.map(u=>s.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:o[u]},u))}),e==="profile"&&s.jsx(gg,{currentUser:r,setCurrentUser:l}),e==="tokens"&&s.jsx(yg,{}),e==="instance"&&i&&s.jsx(vg,{}),e==="cookies"&&i&&s.jsx(wg,{}),e==="extensions"&&i&&s.jsx(kg,{}),e==="storage"&&i&&s.jsx(xg,{archiveId:n})]})}function gg({currentUser:e,setCurrentUser:t}){const[n,r]=c.useState((e==null?void 0:e.display_name)??""),[l,i]=c.useState(!1),[a,o]=c.useState(null),[u,d]=c.useState(""),[y,g]=c.useState(""),[h,v]=c.useState(""),[x,S]=c.useState(!1),[N,p]=c.useState(null);async function f(k){k.preventDefault(),i(!0),o(null);try{await gm(n),t(C=>({...C,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(C){o({ok:!1,text:C.message})}finally{i(!1)}}async function m(k){if(k.preventDefault(),y!==h){p({ok:!1,text:"Passwords do not match."});return}S(!0),p(null);try{await vm(u,y),d(""),g(""),v(""),p({ok:!0,text:"Password changed."})}catch(C){p({ok:!1,text:C.message})}finally{S(!1)}}return s.jsxs("div",{style:{maxWidth:440},children:[s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Display Name"}),s.jsxs("form",{onSubmit:f,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),s.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:k=>r(k.target.value)})]}),a&&s.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Display Preferences"}),s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:(e==null?void 0:e.humanize_slugs)??!1,onChange:async k=>{const C=k.target.checked;try{await ym({humanize_slugs:C}),t(E=>({...E,humanize_slugs:C}))}catch{}}}),s.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),s.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Change Password"}),s.jsxs("form",{onSubmit:m,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),s.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:k=>d(k.target.value),required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),s.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:y,onChange:k=>g(k.target.value),required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",htmlFor:"confirm-pw",children:"Confirm new password"}),s.jsx("input",{className:"field-input",id:"confirm-pw",type:"password",value:h,onChange:k=>v(k.target.value),required:!0})]}),N&&s.jsx("div",{className:`form-msg form-msg--${N.ok?"ok":"err"}`,children:N.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Changing…":"Change Password"})]})]})]})}function yg(){const[e,t]=c.useState([]),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState(""),[u,d]=c.useState(!1),[y,g]=c.useState(null),h=c.useCallback(async()=>{r(!0),i(null);try{t(await xm())}catch(S){i(S.message)}finally{r(!1)}},[]);c.useEffect(()=>{h()},[h]);async function v(S){if(S.preventDefault(),!!a.trim()){d(!0);try{const N=await wm(a.trim());g(N),o(""),h()}catch(N){i(N.message)}finally{d(!1)}}}async function x(S){try{await km(S),t(N=>N.filter(p=>p.token_uid!==S))}catch(N){i(N.message)}}return s.jsx("div",{style:{maxWidth:600},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"API Tokens"}),y&&s.jsxs("div",{className:"token-banner",children:[s.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",s.jsx("code",{children:y.raw_token}),s.jsx("button",{className:"token-dismiss",onClick:()=>g(null),children:"Dismiss"})]}),s.jsxs("form",{className:"token-create-row",onSubmit:v,children:[s.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:S=>o(S.target.value),required:!0}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:u,children:u?"Creating…":"Create token"})]}),l&&s.jsx("div",{className:"form-msg form-msg--err",children:l}),n?s.jsx("div",{className:"muted",children:"Loading…"}):s.jsxs("div",{children:[e.length===0&&s.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(S=>s.jsxs("div",{className:"token-row",children:[s.jsxs("div",{className:"token-row-info",children:[s.jsx("strong",{children:S.name}),s.jsxs("div",{className:"muted",children:["Created ",S.created_at.slice(0,10),S.last_used_at&&` · Last used ${S.last_used_at.slice(0,10)}`]})]}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>x(S.token_uid),children:"Revoke"})]},S.token_uid))]})]})})}function vg(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState(!1),[u,d]=c.useState(null);c.useEffect(()=>{(async()=>{try{t(await xo())}catch(g){i(g.message)}finally{r(!1)}})()},[]);async function y(g){g.preventDefault(),o(!0),d(null);try{await ts(e),d({ok:!0,text:"Saved."})}catch(h){d({ok:!1,text:h.message})}finally{o(!1)}}return n?s.jsx("div",{className:"muted",children:"Loading…"}):l?s.jsx("div",{className:"form-msg form-msg--err",children:l}):e?s.jsx("div",{style:{maxWidth:440},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Instance Settings"}),s.jsxs("form",{onSubmit:y,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([g,h])=>s.jsxs("label",{className:"checkbox-row",children:[s.jsx("input",{type:"checkbox",checked:!!e[g],onChange:v=>t(x=>({...x,[g]:v.target.checked}))}),h]},g)),s.jsxs("div",{className:"form-field",style:{marginTop:4},children:[s.jsx("label",{className:"form-label",children:"Default entry visibility"}),s.jsxs("select",{className:"field-input",value:e.default_entry_visibility,onChange:g=>t(h=>({...h,default_entry_visibility:Number(g.target.value)})),children:[s.jsx("option",{value:0,children:"Private"}),s.jsx("option",{value:2,children:"Unlisted"}),s.jsx("option",{value:3,children:"Public"})]})]}),u&&s.jsx("div",{className:`form-msg form-msg--${u.ok?"ok":"err"}`,children:u.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:a,children:a?"Saving…":"Save Settings"})]})]})}):null}function bi(e){if(e===0)return"0 B";const t=["B","KB","MB","GB","TB"],n=Math.floor(Math.log(e)/Math.log(1024));return`${(e/Math.pow(1024,n)).toFixed(n===0?0:1)} ${t[n]}`}function xg({archiveId:e}){const[t,n]=c.useState("idle"),[r,l]=c.useState(null),[i,a]=c.useState(null),[o,u]=c.useState(null);function d(){n("idle"),l(null),a(null),u(null)}async function y(){n("scanning"),u(null),l(null);try{const v=await Rm(e);l(v),n("scanned")}catch(v){u(v.message),n("error")}}async function g(){n("deleting"),u(null);try{const v=await zm(e);a(v),n("done")}catch(v){u(v.message),n("error")}}const h=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return s.jsx("div",{style:{maxWidth:440},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Orphan Cleanup"}),s.jsxs("p",{className:"muted",style:{marginBottom:16},children:["Scan for blob files and database records that are no longer referenced by any archive entry and safely delete them."," ",s.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&s.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&s.jsx("button",{className:"btn-ghost",onClick:y,children:"Scan for orphaned blobs"}),t==="scanning"&&s.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&h&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"form-msg form-msg--ok",children:"Archive is clean — nothing to remove."}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Done"})]}),t==="scanned"&&r&&!h&&s.jsxs("div",{children:[s.jsxs("div",{style:{marginBottom:14,lineHeight:1.6},children:["Found ",s.jsx("strong",{children:r.deletable_files})," unreferenced file",r.deletable_files!==1?"s":""," ","and ",s.jsx("strong",{children:r.orphaned_blob_rows})," orphaned DB record",r.orphaned_blob_rows!==1?"s":""," ","— ",s.jsx("strong",{children:bi(r.total_bytes)})," recoverable."]}),s.jsxs("div",{style:{display:"flex",gap:8},children:[s.jsxs("button",{className:"btn-danger",onClick:g,children:["Delete (",bi(r.total_bytes),")"]}),s.jsx("button",{className:"btn-ghost",onClick:d,children:"Cancel"})]})]}),t==="deleting"&&s.jsx("div",{className:"muted",children:"Deleting…"}),t==="done"&&i&&s.jsxs("div",{children:[s.jsxs("div",{className:"form-msg form-msg--ok",children:["Freed ",s.jsx("strong",{children:bi(i.freed_bytes)})," ","— removed ",i.deleted_files," file",i.deleted_files!==1?"s":""," ","and ",i.deleted_blob_rows," DB record",i.deleted_blob_rows!==1?"s":"","."]}),i.errors&&i.errors.length>0&&s.jsxs("div",{className:"form-msg form-msg--err",style:{marginTop:6},children:[i.errors.length," file",i.errors.length!==1?"s":""," could not be deleted."]}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Scan again"})]}),t==="error"&&s.jsxs("div",{children:[s.jsx("div",{className:"form-msg form-msg--err",children:o}),s.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:d,children:"Try again"})]})]})})}function wg(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(null),[a,o]=c.useState("global"),[u,d]=c.useState(""),[y,g]=c.useState("{}"),[h,v]=c.useState(null),[x,S]=c.useState(!1),[N,p]=c.useState({});c.useEffect(()=>{f()},[]);async function f(){r(!0),i(null);try{t(await Dm())}catch(j){i(j.message)}finally{r(!1)}}async function m(j){j.preventDefault();try{JSON.parse(y)}catch{v({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}S(!0),v(null);try{await Om(a==="global"?null:u.trim(),a,y),d(""),g("{}"),o("global"),v({ok:!0,text:"Rule added."}),await f()}catch(P){v({ok:!1,text:P.message})}finally{S(!1)}}async function k(j){try{await Mm(j),await f()}catch(P){i(P.message)}}function C(j){p(P=>({...P,[j.rule_uid]:{cookiesInput:j.cookies_json,saving:!1,msg:null}}))}function E(j){p(P=>{const R={...P};return delete R[j],R})}async function T(j){const P=N[j.rule_uid];try{JSON.parse(P.cookiesInput)}catch{p(R=>({...R,[j.rule_uid]:{...R[j.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}p(R=>({...R,[j.rule_uid]:{...R[j.rule_uid],saving:!0,msg:null}}));try{await Am(j.rule_uid,{cookies_json:P.cookiesInput}),E(j.rule_uid),await f()}catch(R){p(X=>({...X,[j.rule_uid]:{...X[j.rule_uid],saving:!1,msg:{ok:!1,text:R.message}}}))}}return n?s.jsx("div",{className:"muted",children:"Loading…"}):l?s.jsx("div",{className:"form-msg form-msg--err",children:l}):s.jsx("div",{style:{maxWidth:560},children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Cookie Rules"}),s.jsx("p",{className:"muted",style:{marginBottom:12},children:"Cookies are injected into every capture network request (yt-dlp, HTTP downloads, web-page snapshots). Global rules apply to all URLs; wildcard and regex rules apply only to matching URLs."}),e&&e.length>0?s.jsxs("table",{className:"data-table",style:{width:"100%",marginBottom:16},children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{children:"Pattern"}),s.jsx("th",{children:"Cookies"}),s.jsx("th",{style:{width:100},children:"Actions"})]})}),s.jsx("tbody",{children:e.map(j=>{const P=N[j.rule_uid],R=j.url_pattern?s.jsxs(s.Fragment,{children:[s.jsxs("span",{className:"muted",children:[j.pattern_kind,":"]})," ",s.jsx("code",{children:j.url_pattern})]}):s.jsx("span",{className:"muted",children:"global (all URLs)"});return s.jsxs("tr",{children:[s.jsx("td",{children:R}),s.jsx("td",{children:P?s.jsxs(s.Fragment,{children:[s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:P.cookiesInput,onChange:X=>p(H=>({...H,[j.rule_uid]:{...H[j.rule_uid],cookiesInput:X.target.value}}))}),P.msg&&s.jsx("div",{className:`form-msg form-msg--${P.msg.ok?"ok":"err"}`,children:P.msg.text}),s.jsxs("div",{style:{display:"flex",gap:8,marginTop:4},children:[s.jsx("button",{className:"btn-primary",style:{fontSize:12,padding:"2px 8px"},disabled:P.saving,onClick:()=>T(j),children:P.saving?"Saving…":"Save"}),s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>E(j.rule_uid),children:"Cancel"})]})]}):s.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:j.cookies_json})}),s.jsx("td",{children:!P&&s.jsxs("div",{style:{display:"flex",gap:6},children:[s.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>C(j),children:"Edit"}),s.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>k(j.rule_uid),children:"Del"})]})})]},j.rule_uid)})})]}):s.jsx("p",{className:"muted",style:{marginBottom:16},children:"No cookie rules defined."}),s.jsx("h3",{style:{marginBottom:8},children:"Add Rule"}),s.jsxs("form",{onSubmit:m,children:[s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Pattern type"}),s.jsxs("select",{className:"field-input",value:a,onChange:j=>o(j.target.value),children:[s.jsx("option",{value:"global",children:"Global (all URLs)"}),s.jsx("option",{value:"wildcard",children:"Wildcard (e.g. *.youtube.com)"}),s.jsx("option",{value:"regex",children:"Regex (matched against full URL)"})]})]}),a!=="global"&&s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:a==="wildcard"?"URL/hostname pattern":"Regex pattern"}),s.jsx("input",{className:"field-input",type:"text",value:u,onChange:j=>d(j.target.value),placeholder:a==="wildcard"?"*.youtube.com or https://example.com/*":".*\\.youtube\\.com.*",required:!0})]}),s.jsxs("div",{className:"form-field",children:[s.jsx("label",{className:"form-label",children:"Cookies (JSON object)"}),s.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:13,minHeight:70},value:y,onChange:j=>g(j.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),h&&s.jsx("div",{className:`form-msg form-msg--${h.ok?"ok":"err"}`,children:h.text}),s.jsx("button",{className:"btn-primary",type:"submit",disabled:x,children:x?"Adding…":"Add Rule"})]})]})})}function kg(){const[e,t]=c.useState(null),[n,r]=c.useState(!0),[l,i]=c.useState(!1),[a,o]=c.useState(null);c.useEffect(()=>{(async()=>{try{t(await xo())}catch(N){o({ok:!1,text:N.message})}finally{r(!1)}})()},[]);async function u(N){i(!0),o(null);try{await ts({ublock_enabled:N}),t(p=>({...p,ublock_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function d(N){i(!0),o(null);try{await ts({cookie_ext_enabled:N}),t(p=>({...p,cookie_ext_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}async function y(N){i(!0),o(null);try{await ts({modal_closer_enabled:N}),t(p=>({...p,modal_closer_enabled:N})),o({ok:!0,text:"Saved."})}catch(p){o({ok:!1,text:p.message})}finally{i(!1)}}if(n)return s.jsx("div",{className:"muted",children:"Loading\\u2026"});const g=(e==null?void 0:e.ublock_ext_available)??!1,h=(e==null?void 0:e.ublock_enabled)??!0,v=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0,S=(e==null?void 0:e.modal_closer_enabled)??!0;return s.jsx("div",{children:s.jsxs("div",{className:"form-section",children:[s.jsx("h2",{children:"Extensions"}),s.jsx("p",{className:"form-hint",style:{marginBottom:20},children:"Extensions run inside the browser during WebPage captures and can block ads, accept cookie banners, and more. Changes take effect on the next capture."}),s.jsxs("div",{className:"ext-grid",children:[s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"uBlock Origin Lite"}),s.jsx("span",{className:"ext-card-desc",children:"Blocks ads, trackers, and other page clutter during archiving via Chrome’s declarativeNetRequest API (Manifest V3)."}),!g&&s.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_UBLOCK_EXT"})," to the unpacked extension directory to enable."]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":h,className:`ext-toggle${h?" ext-toggle--on":""}`,onClick:()=>u(!h),disabled:l,"aria-label":"Toggle uBlock Origin Lite",children:s.jsx("span",{className:"ext-toggle-knob"})})]})}),s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"I Still Don’t Care About Cookies"}),s.jsx("span",{className:"ext-card-desc",children:"Dismiss cookie consent banners during archiving."}),!v&&s.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",s.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})," to the unpacked extension directory to enable."]})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":x,className:`ext-toggle${x?" ext-toggle--on":""}`,onClick:()=>d(!x),disabled:l,"aria-label":"Toggle I Still Don't Care About Cookies",children:s.jsx("span",{className:"ext-toggle-knob"})})]})}),s.jsx("div",{className:"ext-card",children:s.jsxs("div",{className:"ext-card-header",children:[s.jsxs("div",{className:"ext-card-info",children:[s.jsx("span",{className:"ext-card-name",children:"Modal & Dialog Closer"}),s.jsx("span",{className:"ext-card-desc",children:"Auto-dismiss cookie banners, consent overlays, and other modal dialogs before a WebPage capture is taken. Implemented as an injected browser script; no external extension required."})]}),s.jsx("button",{type:"button",role:"switch","aria-checked":S,className:`ext-toggle${S?" ext-toggle--on":""}`,onClick:()=>y(!S),disabled:l,"aria-label":"Toggle Modal and Dialog Closer",children:s.jsx("span",{className:"ext-toggle-knob"})})]})})]}),a&&s.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text})]})})}const Fu={0:"Private",1:"Public",2:"Users only",3:"Public"},ns=[{value:"anthropic_http",label:"Anthropic API"},{value:"openai_compatible",label:"OpenAI-compatible API"},{value:"claude_cli",label:"Claude CLI"},{value:"codex_cli",label:"Codex CLI"}],jg=Object.fromEntries(ns.map(e=>[e.value,e.label])),Bu="archivr:summary:provider",Sg=1500,hf="This entry can’t be summarized yet.",mf="It doesn’t contain archived text that a summary provider can read. Summaries currently support text notes, web pages, X posts and threads, and X Articles. Video, audio, and image-only entries need a transcript or text source.",Uu=`${hf} -${mf}`;function Ng(e){if(!e)return null;try{const t=JSON.parse(e);if(t&&typeof t=="object")return{tldr:typeof t.tldr=="string"?t.tldr:"",summary:typeof t.summary=="string"?t.summary:"",tags:Array.isArray(t.tags)?t.tags.filter(n=>typeof n=="string"):[]}}catch{}return{tldr:"",summary:e,tags:[]}}const _g=()=>s.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function Cg({archiveId:e,selectedEntry:t,selectedUids:n,selectedEntries:r,detail:l,onTagFilterSet:i,tagNodes:a,onTagsRefresh:o,onEntryTitleChange:u,onEntryDeleted:d,onBulkDeleted:y,humanizeTags:g,onDetailRefresh:h,onOpenPreview:v,onPlay:x,isPublicSession:S}){var qn,Cr,Er;const[N,p]=c.useState([]),[f,m]=c.useState(""),[k,C]=c.useState([]),[E,T]=c.useState(""),j=c.useRef(0),P=c.useRef(!1),[R,X]=c.useState(!1),[H,Y]=c.useState(""),[te,fe]=c.useState("idle"),[Be,we]=c.useState(""),M=c.useRef(null),[L,V]=c.useState(!1);c.useEffect(()=>{V(!1)},[(qn=l==null?void 0:l.summary)==null?void 0:qn.entry_uid]);const[G,ne]=c.useState(null),[se,Z]=c.useState(null),[Se,ce]=c.useState(""),[Ie,at]=c.useState(!1),[ht,Vt]=c.useState(()=>{try{return sessionStorage.getItem(Bu)||ns[0].value}catch{return ns[0].value}}),[Qt,jt]=c.useState(!1),Oe=c.useRef(null),Je=c.useRef(null),tt=c.useRef(null),D=c.useRef(null),K=e&&(t!=null&&t.entry_uid)?`${e}:${t.entry_uid}`:null;D.current=K;const Ne=(n==null?void 0:n.size)>=2,[Ve,qt]=c.useState(""),[Qe,Kt]=c.useState("idle"),[Qn,Ot]=c.useState(""),[Le,bn]=c.useState([]),[At,w]=c.useState(""),[B,O]=c.useState("idle"),[$,F]=c.useState(""),[U,ye]=c.useState("idle"),[ue,Te]=c.useState(""),[pe,$e]=c.useState("idle"),[ie,nt]=c.useState("");c.useEffect(()=>{const b=++j.current;if(M.current&&(clearInterval(M.current),M.current=null),fe("idle"),we(""),!t||!e){p([]),C([]);return}if(S){p([]),C([]);return}X(!1),Y(""),P.current=!1,p([]),Promise.all([Bl(e,t.entry_uid),Du(e,t.entry_uid)]).then(([q,ae])=>{b===j.current&&(p(q),C(ae))}).catch(()=>{})},[t,e,S]),c.useEffect(()=>()=>{clearInterval(M.current)},[]),c.useLayoutEffect(()=>{var q,ae,he;clearInterval(Oe.current),Oe.current=null,(q=Je.current)==null||q.abort(),Je.current=null,(ae=tt.current)==null||ae.abort(),tt.current=null;const b=((he=l==null?void 0:l.summary)==null?void 0:he.entry_uid)===(t==null?void 0:t.entry_uid);ne(b?l.latest_summary??null:null),Z(b?l.summary_attempt??null:null),ce(""),at(!1),jt(!1)},[e,t==null?void 0:t.entry_uid,(Cr=l==null?void 0:l.summary)==null?void 0:Cr.entry_uid]);const ot=se==null?void 0:se.status;c.useEffect(()=>{var sn;if(clearInterval(Oe.current),Oe.current=null,ot!=="pending"&&ot!=="running"||!e||!((sn=l==null?void 0:l.summary)!=null&&sn.entry_uid))return;const b=l.summary.entry_uid,q=`${e}:${b}`;if(K!==q)return;const ae=new AbortController;Je.current=ae;const St=setInterval(async()=>{var me;try{const an=await Xh(e,b,{signal:ae.signal});if(ae.signal.aborted||D.current!==q)return;ne(an.summary??null),Z(an.attempt??null);const Ys=(me=an.attempt)==null?void 0:me.status;Ys!=="pending"&&Ys!=="running"&&(clearInterval(St),Oe.current===St&&(Oe.current=null),at(!1),Ys==="completed"&&D.current===q&&(h==null||h()))}catch{if(ae.signal.aborted||D.current!==q)return}},Sg);return Oe.current=St,()=>{clearInterval(St),Oe.current===St&&(Oe.current=null),ae.abort(),Je.current===ae&&(Je.current=null)}},[ot,e,t==null?void 0:t.entry_uid,(Er=l==null?void 0:l.summary)==null?void 0:Er.entry_uid,K]),c.useEffect(()=>()=>{var b,q;clearInterval(Oe.current),(b=Je.current)==null||b.abort(),(q=tt.current)==null||q.abort()},[]);async function Qs(b=!1){var St,sn;if(!e||!((St=l==null?void 0:l.summary)!=null&&St.entry_uid)||Ie)return;const q=l.summary.entry_uid,ae=`${e}:${q}`;if(D.current!==ae)return;const he=new AbortController;(sn=tt.current)==null||sn.abort(),tt.current=he,at(!0),ce("");try{const me=await Jh(e,q,{provider:ht,force:b,includeImages:Qt,signal:he.signal});if(he.signal.aborted||D.current!==ae)return;me.status==="completed"?(ne(me),Z(null),at(!1),D.current===ae&&(h==null||h())):Z({...me??{},status:"pending"})}catch(me){if(he.signal.aborted||D.current!==ae)return;ce(me.message||"Summary request failed"),at(!1)}finally{tt.current===he&&(tt.current=null)}}function qs(b){Vt(b),b==="claude_cli"&&jt(!1);try{sessionStorage.setItem(Bu,b)}catch{}}c.useEffect(()=>{if(!e){bn([]);return}wo(e).then(bn).catch(()=>bn([]))},[e]),c.useEffect(()=>{qt(""),Kt("idle"),Ot(""),w(""),O("idle"),F(""),ye("idle"),Te(""),$e("idle"),nt("")},[n]);async function Ks(){const b=n.size;if(!window.confirm(`Delete ${b} entr${b===1?"y":"ies"}? This cannot be undone.`))return;ye("running");const q=new Set;for(const ae of n)try{await $u(e,ae),q.add(ae)}catch{}ye("idle"),y==null||y(q)}async function Tn(){const b=Ve.trim();if(b){Kt("running"),Ot("");try{for(const q of n)await Iu(e,q,b);qt(""),Kt("done"),o==null||o(),setTimeout(()=>Kt("idle"),1800)}catch(q){Ot(q.message),Kt("error")}}}async function _r(){if(!At)return;O("running"),F("");const b=[],q=Le.find(ae=>ae.collection_uid===At);for(const ae of n)try{await Sa(e,At,ae,(q==null?void 0:q.default_visibility_bits)??2)}catch{b.push(ae)}b.length>0?(F(`Failed for ${b.length} entr${b.length===1?"y":"ies"}.`),O("error")):(O("done"),setTimeout(()=>O("idle"),1800))}async function Pn(){if(!ue||!t)return;$e("running"),nt("");const b=Le.find(q=>q.collection_uid===ue);try{await Sa(e,ue,t.entry_uid,(b==null?void 0:b.default_visibility_bits)??2),$e("done"),Te("");const q=await Du(e,t.entry_uid);C(q),setTimeout(()=>$e("idle"),1800)}catch(q){nt(q.message),$e("error")}}async function jl(){const b=H.trim()||null;try{await tm(e,t.entry_uid,b),u==null||u(t.entry_uid,b)}catch{}finally{X(!1)}}async function Sl(){const b=f.trim();if(!(!b||!t))try{await Iu(e,t.entry_uid,b),m(""),T("");const q=await Bl(e,t.entry_uid);p(q),o()}catch(q){T(q.message)}}async function Xs(b){try{await nm(e,t.entry_uid,b);const q=await Bl(e,t.entry_uid);p(q),o()}catch{}}async function Js(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await $u(e,t.entry_uid),d==null||d(t.entry_uid)}catch{}}async function Gs(){if(!t||!e||te==="running")return;const b=j.current,q=t.entry_uid;fe("running"),we("");try{const{job_uid:ae}=await Im(e,q);if(j.current!==b)return;M.current=setInterval(async()=>{try{const he=await of(e,ae);if(he.status==="completed"){if(clearInterval(M.current),M.current=null,j.current!==b)return;fe("done");const St=await Bl(e,q);if(j.current!==b)return;p(St),h==null||h()}else if(he.status==="failed"){if(clearInterval(M.current),M.current=null,j.current!==b)return;fe("error"),we(he.error_text||"Re-archive failed.")}}catch{if(clearInterval(M.current),M.current=null,j.current!==b)return;fe("error"),we("Network error while polling.")}},500)}catch(ae){if(j.current!==b)return;fe("error"),we(ae.message||"Failed to start re-archive.")}}const _=l?[["Added",ko(l.summary.archived_at)],["Source",l.summary.source_kind],["Type",l.summary.entity_kind],["Visibility",Fu[l.summary.visibility]??l.summary.visibility],["Root",l.structured_root_relpath]]:[],z=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),A=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","md","markdown","txt","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Q=l?l.artifacts.findIndex(b=>b.artifact_role==="primary_media"):-1,J=Q>=0?l.artifacts[Q]:null,le=J?J.relpath.split(".").pop().toLowerCase():"",_e=J&&z.has(le),Ue=Q>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${Q}`:null,ke=l&&!_e&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread"||J&&A.has(le));return s.jsxs("aside",{className:"context-rail",children:[s.jsx("div",{className:"rail-eyebrow",children:"Context"}),Ne?S?s.jsxs("p",{className:"bulk-count",children:[s.jsx("span",{className:"bulk-count-num",children:n.size})," entries selected"]}):s.jsxs("div",{className:"bulk-panel",children:[s.jsxs("p",{className:"bulk-count",children:[s.jsx("span",{className:"bulk-count-num",children:n.size})," entries selected"]}),s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Assign tag"}),Qn&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:Qn}),s.jsxs("div",{className:"tag-input-wrap",children:[s.jsx("span",{className:"hash",children:"/"}),s.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:Ve,onChange:b=>qt(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Tn()}}),s.jsx("button",{className:"tag-add-btn",onClick:Tn,disabled:Qe==="running"||!Ve.trim(),children:Qe==="running"?"…":Qe==="done"?"✓":"Add"})]})]}),Le.length>0&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Add to collection"}),s.jsxs("div",{className:"bulk-coll-row",children:[s.jsxs("select",{className:"bulk-coll-select",value:At,onChange:b=>w(b.target.value),children:[s.jsx("option",{value:"",children:"Pick a collection…"}),Le.filter(b=>b.slug!=="_default_").map(b=>s.jsx("option",{value:b.collection_uid,children:b.name},b.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:_r,disabled:!At||B==="running",children:B==="running"?"…":B==="done"?"✓":B==="error"?"!":"Add"})]}),$&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"6px 0 0"},children:$})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Ks,disabled:U==="running",children:U==="running"?"Deleting…":`Delete ${n.size} entr${n.size===1?"y":"ies"}`})})]}):t?l?s.jsxs(s.Fragment,{children:[S?s.jsx("h2",{className:"rail-title",children:gt(l.summary.title)||gt(l.summary.entry_uid)}):R?s.jsx("input",{className:"rail-title-input",autoFocus:!0,value:H,onChange:b=>Y(b.target.value),onKeyDown:b=>{b.key==="Enter"&&b.currentTarget.blur(),b.key==="Escape"&&(P.current=!0,b.currentTarget.blur())},onBlur:()=>{P.current?X(!1):jl(),P.current=!1}}):s.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{Y(l.summary.title??""),X(!0)},children:[gt(l.summary.title)||gt(l.summary.entry_uid),s.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:s.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),l.summary.original_url&&s.jsxs("a",{className:"url-tile",href:l.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[s.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:Ws(l.summary.source_kind)}}),s.jsx("span",{className:"u-text",children:l.summary.original_url}),s.jsx("span",{className:"ext",children:s.jsx(_g,{})})]}),_e&&x&&s.jsx("button",{className:"rail-preview-btn",onClick:()=>x(Ue,t),children:"▶ Play"}),ke&&v&&s.jsx("button",{className:"rail-preview-btn",onClick:v,children:"Preview"}),(()=>{const b=(G==null?void 0:G.status)==="completed"?Ng(G.summary_text):null,q=(se==null?void 0:se.status)==="pending"||(se==null?void 0:se.status)==="running",ae=(se==null?void 0:se.status)==="failed"&&se.error_text===Uu||Se===Uu;return S&&!b?null:s.jsxs("div",{className:"rail-section rail-summary",children:[s.jsx("div",{className:"rail-section-heading",children:"Summary"}),b&&s.jsxs("div",{className:"rail-summary-body",children:[b.tldr&&s.jsx("p",{className:"rail-summary-tldr",children:b.tldr}),b.summary&&s.jsx("p",{className:"rail-summary-text",children:b.summary}),b.tags.length>0&&s.jsx("div",{className:"rail-summary-tags",children:b.tags.map(he=>s.jsx("span",{className:"rail-summary-tag",children:he},he))}),s.jsxs("p",{className:"rail-summary-provider",children:[jg[G.provider_kind]||G.provider_kind,G.resolved_model||G.provider_model?` · ${G.resolved_model||G.provider_model}`:""]})]}),q&&s.jsxs("p",{className:"rail-summary-status",children:[s.jsx("span",{className:"rail-summary-spinner","aria-hidden":"true"}),"Generating…"]}),ae&&!S&&s.jsxs("div",{className:"rail-summary-info",role:"status",children:[s.jsx("p",{className:"rail-summary-info__heading",children:hf}),s.jsx("p",{className:"rail-summary-info__detail",children:mf})]}),(se==null?void 0:se.status)==="failed"&&se.error_text&&!ae&&!S&&s.jsx("p",{className:"form-msg form-msg--err rail-summary-error",children:se.error_text}),Se&&!ae&&s.jsx("p",{className:"form-msg form-msg--err rail-summary-error",children:Se}),!S&&!q&&s.jsxs("div",{className:"rail-summary-controls",children:[s.jsx("select",{className:"rail-summary-select",value:ht,onChange:he=>qs(he.target.value),"aria-label":"Summary provider",children:ns.map(he=>s.jsx("option",{value:he.value,children:he.label},he.value))}),s.jsxs("div",{className:`rail-summary-image-option${ht==="claude_cli"?" rail-summary-image-option--disabled":""}`,children:[s.jsxs("label",{className:"rail-summary-image-option__label",children:[s.jsx("input",{type:"checkbox",checked:Qt,disabled:ht==="claude_cli",onChange:he=>jt(he.target.checked)}),"Include attached images"]}),s.jsx("p",{className:"rail-summary-image-option__note",children:ht==="claude_cli"?"Claude CLI cannot attach local images. Choose an HTTP provider or Codex CLI.":"Selected archived images are sent to the chosen provider. Up to 4 supported images (5 MiB each, 12 MiB total) can be attached; unsupported or oversized artifacts are skipped."})]}),s.jsx("button",{className:"rail-rearchive-btn",onClick:()=>Qs(!!b),disabled:Ie,children:Ie?"…":b?"Regenerate":"Generate"})]})]})})(),s.jsx("div",{className:"meta-list",children:_.filter(([,b])=>b!=null&&b!=="").map(([b,q])=>s.jsxs("div",{className:"meta-item",children:[s.jsx("span",{className:"meta-k",children:b}),s.jsx("span",{className:`meta-v${b==="Root"?" mono":""}`,children:gt(q)})]},b))}),l.artifacts.length>0&&(()=>{const b=l.artifacts.map((me,an)=>({...me,_idx:an})),q=b.filter(me=>me.artifact_role==="font"),ae=b.filter(me=>me.artifact_role!=="font"),he=q.reduce((me,an)=>me+(an.byte_size||0),0),St=l.summary.entry_uid,sn=me=>s.jsx("li",{children:s.jsxs("a",{href:`/api/archives/${e}/entries/${St}/artifacts/${me._idx}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[s.jsx("span",{className:"artifact-name",children:me.artifact_role==="font"?me.relpath.split("/").pop():me.artifact_role.replace(/_/g," ")}),s.jsx("span",{className:"artifact-size",children:me.byte_size!=null?gl(me.byte_size):"—"})]})},me._idx);return s.jsxs("div",{className:"rail-section",children:[s.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",s.jsx("span",{className:"num",children:l.artifacts.length})]}),s.jsxs("ul",{className:"artifact-list",children:[ae.map(sn),q.length>0&&s.jsxs("li",{className:"artifact-group",children:[s.jsxs("button",{type:"button",className:"artifact-group-header artifact-link","aria-expanded":L,onClick:()=>V(me=>!me),children:[s.jsxs("span",{className:"artifact-name",children:[s.jsx("span",{"aria-hidden":"true",className:`artifact-group-chevron${L?" open":""}`,children:"›"}),` fonts (${q.length})`]}),s.jsx("span",{className:"artifact-size",children:gl(he)})]}),L&&s.jsx("ul",{className:"artifact-list artifact-group-body",children:q.map(sn)})]})]})]})})()]}):s.jsx("p",{className:"tags-empty",children:"Loading\\u2026"}):s.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&!Ne&&!S&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Tags"}),N.length===0?s.jsx("p",{className:"tags-empty",children:"No tags yet."}):s.jsx("div",{className:"tags-wrap",children:N.map(b=>s.jsxs("span",{className:"tag-pill",title:b.full_path,children:[g?cf(b.full_path):b.full_path,s.jsx("button",{className:"remove",title:`Remove tag ${b.full_path}`,onClick:()=>Xs(b.tag_uid),children:"×"})]},b.tag_uid))}),E&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:E}),s.jsxs("div",{className:"tag-input-wrap",children:[s.jsx("span",{className:"hash",children:"/"}),s.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:f,onChange:b=>m(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Sl()}}),s.jsx("button",{className:"tag-add-btn",onClick:Sl,children:"Add"})]})]}),(k.length>0||Le.filter(b=>b.slug!=="_default_").length>0)&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Collections"}),k.map(b=>s.jsxs("div",{className:"coll-row",children:[s.jsx("span",{className:"coll-name",children:b.name}),s.jsx("span",{className:"vis-badge",children:Fu[b.visibility_bits]??`bits:${b.visibility_bits}`})]},b.collection_uid)),Le.filter(b=>b.slug!=="_default_").length>0&&s.jsxs("div",{className:"bulk-coll-row",style:{marginTop:8},children:[s.jsxs("select",{className:"bulk-coll-select",value:ue,onChange:b=>Te(b.target.value),children:[s.jsx("option",{value:"",children:"Add to collection…"}),Le.filter(b=>b.slug!=="_default_").map(b=>s.jsx("option",{value:b.collection_uid,children:b.name},b.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:Pn,disabled:!ue||pe==="running",children:pe==="running"?"…":pe==="done"?"✓":pe==="error"?"!":"Add"})]}),ie&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"4px 0 0"},children:ie})]}),l&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread")&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Actions"}),s.jsx("button",{className:"rail-rearchive-btn",onClick:Gs,disabled:te==="running",children:te==="running"?"Re-archiving…":"Re-archive"}),te==="done"&&s.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),te==="error"&&s.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:Be})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Js,children:"Delete entry"})})]})]})}const Eg=/\/api\/archives\/([^/]+)\/entries\/([^/]+)\/artifacts\/(\d+)/;function bg(){return s.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[s.jsx("path",{d:"M5 17H3a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h18a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2"}),s.jsx("polygon",{points:"12 15 17 21 7 21 12 15"})]})}function Tg({src:e,contentType:t="video/mp4"}){const n=c.useRef(null),[r,l]=c.useState(null),[i,a]=c.useState(!1),[o,u]=c.useState(!1);c.useEffect(()=>{if(!e){l(null);return}const g=e.match(Eg);if(!g){l(e);return}let h=!1;return l(null),$m(g[1],g[2],parseInt(g[3],10)).then(({url:v})=>{h||l(v)}).catch(()=>{h||l(e)}),()=>{h=!0}},[e]),c.useEffect(()=>{n.current&&n.current.load()},[r]),c.useEffect(()=>{u(typeof HTMLVideoElement<"u"&&"webkitShowPlaybackTargetPicker"in HTMLVideoElement.prototype)},[]),c.useEffect(()=>{var h;const g=v=>{if(v)try{cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),a(!0)}catch{}};if((h=window.cast)!=null&&h.framework)g(!0);else if(window.__onGCastApiAvailable=g,!document.querySelector('script[src*="cast_sender"]')){const v=document.createElement("script");v.src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",document.head.appendChild(v)}},[]),c.useEffect(()=>{if(!i||!r)return;const g=cast.framework.CastContext.getInstance(),{CastContextEventType:h,SessionState:v}=cast.framework,x=N=>{if(!N)return;const p=new chrome.cast.media.MediaInfo(window.location.origin+r,t);N.loadMedia(new chrome.cast.media.LoadRequest(p)).catch(()=>{})};x(g.getCurrentSession());const S=N=>{(N.sessionState===v.SESSION_STARTED||N.sessionState===v.SESSION_RESUMED)&&x(g.getCurrentSession())};return g.addEventListener(h.SESSION_STATE_CHANGED,S),()=>g.removeEventListener(h.SESSION_STATE_CHANGED,S)},[i,r,t]);const d=()=>{var g,h;(h=(g=n.current)==null?void 0:g.webkitShowPlaybackTargetPicker)==null||h.call(g)},y=i||o;return s.jsx("div",{className:"preview-video-wrap",style:{position:"relative"},children:e?s.jsxs(s.Fragment,{children:[r?s.jsxs("video",{ref:n,controls:!0,autoPlay:!1,playsInline:!0,"x-webkit-airplay":"allow",style:{width:"100%",maxHeight:"100%",display:"block"},children:[s.jsx("source",{src:r}),"Your browser does not support the video element."]}):s.jsx("div",{className:"video-tv-loading","aria-label":"Loading video…"}),y&&r&&s.jsxs("div",{className:"video-tv-controls",children:[o&&s.jsx("button",{className:"video-tv-btn",title:"AirPlay to device","aria-label":"AirPlay to device",onClick:d,children:s.jsx(bg,{})}),i&&s.jsx("google-cast-launcher",{className:"video-tv-btn",title:"Cast to TV"})]})]}):s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function Hu({src:e,type:t,title:n,originalUrl:r}){const l=r||e,i=n||null;return s.jsxs("div",{className:"preview-iframe-wrap",style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[s.jsxs("div",{className:"preview-iframe-toolbar",style:{display:"flex",flexDirection:"column",gap:"2px",padding:"6px 12px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0},children:[i&&s.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600,color:"var(--ink)",fontFamily:"var(--sans)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[s.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.78rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:l}),s.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{fontSize:"0.78rem",color:"var(--accent)",textDecoration:"none",whiteSpace:"nowrap",fontFamily:"var(--sans)",flexShrink:0},children:t==="pdf"?"Open PDF ↗":"Open in new tab ↗"})]})]}),s.jsx("iframe",{src:e,sandbox:"allow-same-origin allow-popups",allow:"autoplay 'none'",referrerPolicy:"no-referrer",style:{flex:1,border:"none",width:"100%",minHeight:0},title:i||(t==="pdf"?"PDF preview":"Page preview")})]})}function Pg({src:e,alt:t}){return s.jsx("div",{className:"preview-image-wrap",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",background:"var(--paper-2)",overflow:"hidden"},children:s.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{display:"contents"},children:s.jsx("img",{src:e,alt:t||"",style:{objectFit:"contain",maxHeight:"100%",maxWidth:"100%",display:"block",cursor:"pointer"}})})})}function gf(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function Wu(e){return!e||!e.includes("&")?e:e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}const ee={card:{background:"var(--paper)",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},threadOuter:{border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},tweetRow:{display:"flex",gap:"10px",padding:"10px 12px"},tweetRowThread:{display:"flex",gap:"10px",padding:"10px 12px 0"},leftCol:{display:"flex",flexDirection:"column",alignItems:"center",flexShrink:0,width:"36px"},rightCol:{flex:1,minWidth:0,paddingBottom:"8px"},avatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},avatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},threadLine:{flex:1,width:"2px",background:"var(--line-soft, var(--line))",margin:"4px 0",minHeight:"12px",borderRadius:"1px"},authorRow:{display:"flex",alignItems:"baseline",gap:"4px",flexWrap:"wrap",marginBottom:"4px",lineHeight:"1.3"},authorName:{fontWeight:"700",fontSize:"14px",color:"var(--ink)"},authorHandle:{fontSize:"13px",color:"var(--muted)"},datePart:{fontSize:"13px",color:"var(--muted)"},tweetText:{fontSize:"14px",lineHeight:"1.5",color:"var(--ink)",whiteSpace:"pre-line",marginBottom:"8px",wordBreak:"break-word"},stats:{display:"flex",gap:"12px",fontSize:"13px",color:"var(--muted)"},link:{color:"var(--accent)",textDecoration:"none"},loading:{padding:"24px 16px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},error:{padding:"24px 16px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},mediaGrid:{marginBottom:"8px",borderRadius:"10px",overflow:"hidden",border:"1px solid var(--line)"},mediaImg:{display:"block",width:"100%",objectFit:"cover",maxHeight:"260px"},mediaVideo:{display:"block",width:"100%",maxHeight:"260px",background:"#000"},article:{maxWidth:"560px",margin:"0 auto",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"280px"},aMeta:{padding:"10px 14px 0"},aTweetTitle:{fontSize:"20px",fontWeight:"800",letterSpacing:"-0.3px",color:"var(--ink)",lineHeight:"1.3",marginBottom:"8px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},aAvatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},aAuthorName:{fontSize:"14px",fontWeight:"700",color:"var(--ink)",lineHeight:"1.3"},aAuthorSub:{fontSize:"13px",color:"var(--muted)",lineHeight:"1.3"},aDivider:{border:"none",borderTop:"1px solid var(--line)",margin:"0"},aBody:{padding:"4px 14px 16px"},bH1:{fontSize:"22px",fontWeight:"800",letterSpacing:"-0.4px",color:"var(--ink)",lineHeight:"1.25",margin:"16px 0 6px"},bH2:{fontSize:"18px",fontWeight:"700",letterSpacing:"-0.2px",color:"var(--ink)",lineHeight:"1.3",margin:"14px 0 4px"},bP:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.65",marginBottom:"12px",marginTop:"0"},bSpacer:{height:"4px",display:"block"},bQuote:{borderLeft:"3px solid var(--line)",padding:"2px 12px",margin:"12px 0",color:"var(--muted)",fontSize:"15px",lineHeight:"1.6"},bHr:{border:"none",borderTop:"1px solid var(--line)",margin:"14px 0"},bImg:{width:"100%",display:"block",borderRadius:"8px",margin:"12px 0"},bUl:{margin:"8px 0 12px",paddingLeft:"24px"},bOl:{margin:"8px 0 12px",paddingLeft:"24px"},bLi:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.6",marginBottom:"4px"},bTweet:{display:"flex",alignItems:"center",gap:"10px",border:"1px solid var(--line)",borderRadius:"10px",padding:"10px 14px",margin:"12px 0",color:"var(--muted)",fontSize:"14px",textDecoration:"none"},bMdPre:{borderRadius:"8px",margin:"10px 0",overflow:"auto",background:"var(--paper-3, var(--field))",padding:"12px 14px"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"12px",lineHeight:"1.6",color:"var(--ink)",background:"transparent",display:"block"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:"var(--paper-3, var(--field))",padding:"1px 5px",borderRadius:"4px",color:"var(--ink)"},qtBadge:{fontSize:"11px",color:"var(--muted)",display:"inline-flex",alignItems:"center",gap:"2px",marginLeft:"4px",letterSpacing:"0.03em",flexShrink:0},lightboxBackdrop:{position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.92)",display:"flex",alignItems:"center",justifyContent:"center",padding:"20px"},lightboxContent:{display:"flex",flexDirection:"column",alignItems:"center",gap:"10px",maxWidth:"90vw",maxHeight:"90vh"},lightboxToolbar:{display:"flex",alignItems:"center",gap:"10px",alignSelf:"flex-end"},lightboxImg:{maxWidth:"88vw",maxHeight:"80vh",objectFit:"contain",borderRadius:"6px",display:"block"},lightboxNav:{display:"flex",gap:"12px",alignItems:"center"},lightboxNavBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"20px",cursor:"pointer",borderRadius:"50%",width:"36px",height:"36px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"16px",cursor:"pointer",borderRadius:"50%",width:"30px",height:"30px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxLink:{color:"rgba(255,255,255,0.7)",textDecoration:"none",fontSize:"14px"},lightboxCounter:{color:"rgba(255,255,255,0.6)",fontSize:"13px"}},Ae={bg:"#000000",border:"#2f3336",text:"#e7e9ea",dim:"#71767b",accent:"#1d9bf0",codeBg:"#16181c"},Ti={article:{background:Ae.bg,color:Ae.text,minHeight:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'},articleInner:{maxWidth:"598px",margin:"0 auto",paddingBottom:"80px"},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"420px"},aMeta:{padding:"20px 16px 0"},aTweetTitle:{fontSize:"34px",fontWeight:"800",letterSpacing:"-0.5px",color:Ae.text,lineHeight:"44px",marginBottom:"16px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"16px"},aAvatar:{width:"40px",height:"40px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"40px",height:"40px",borderRadius:"50%",background:Ae.border,flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:Ae.text,lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:Ae.dim,lineHeight:"1.3"},aDivider:{border:"none",borderTop:`1px solid ${Ae.border}`,margin:"0"},aBody:{padding:"4px 16px 0"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Ae.text,lineHeight:"36px",margin:"24px 0 10px"},bH2:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Ae.text,lineHeight:"36px",margin:"24px 0 10px"},bP:{fontSize:"17px",color:Ae.text,lineHeight:"1.5",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:`3px solid ${Ae.border}`,padding:"2px 14px",margin:"14px 0",color:Ae.dim,fontSize:"17px",lineHeight:"1.5"},bHr:{border:"none",borderTop:`1px solid ${Ae.border}`,margin:"28px 0"},bImg:{width:"100%",display:"block",borderRadius:"12px",margin:"16px 0"},bUl:{margin:"10px 0 16px",paddingLeft:"28px"},bOl:{margin:"10px 0 16px",paddingLeft:"28px"},bLi:{fontSize:"17px",color:Ae.text,lineHeight:"1.5",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:`1px solid ${Ae.border}`,borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:Ae.dim,fontSize:"15px",textDecoration:"none"},bMdPre:{borderRadius:"12px",margin:"12px 0",overflow:"auto",background:"#1e2029"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"13px",lineHeight:"1.65",padding:"18px 20px",display:"block",color:Ae.text,background:"transparent"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:Ae.codeBg,padding:"2px 6px",borderRadius:"4px",color:"#e6edf3"},link:{color:Ae.accent,textDecoration:"none"}};function Lg(e,t,n){const r={};return n&&n.forEach((l,i)=>{l.relpath&&(r[l.relpath]=`/api/archives/${e}/entries/${t}/artifacts/${i}`)}),r}function hr(e,t,n){return e&&n[e]?n[e]:t||null}function yf(){return s.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",style:{flexShrink:0,color:"var(--ink)"},children:s.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.748l7.73-8.835L1.254 2.25H8.08l4.259 5.63L18.244 2.25zm-1.161 17.52h1.833L7.084 4.126H5.117L17.083 19.77z"})})}function jo(e,t,...n){var r;if(e.fromIndex!=null&&e.toIndex!=null)return{s:e.fromIndex,e:e.toIndex};if(((r=e.indices)==null?void 0:r.length)===2)return{s:e.indices[0],e:e.indices[1]};if(t)for(const l of n){if(!l)continue;const i=t.indexOf(l);if(i!==-1)return{s:i,e:i+l.length}}return null}function vf(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=jo(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function xf(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=jo(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const Vu=/https?:\/\/[^\s<>"'\])]+/g,Rg=/[.,;:!?)()]+$/;function Es(e,t){const n=[];let r=0,l;for(Vu.lastIndex=0;(l=Vu.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let i=l[0].replace(Rg,"");n.push(s.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:t,children:i},l.index));const a=l[0].slice(i.length);a&&n.push(a),r=l.index+l[0].length}return r===0?e:(rvf(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>xf(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return Es(Wu(e),ee.link);const l=new Set([0,e.length]);for(const o of r)o.s>=0&&o.s<=e.length&&l.add(o.s),o.e>=0&&o.e<=e.length&&l.add(o.e);for(const[o,u]of n)o>=0&&o<=e.length&&l.add(o),u>=0&&u<=e.length&&l.add(u);const i=(o,u)=>n.some(([d,y])=>d<=o&&y>=u),a=[...l].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const d=a[u+1];if(i(o,d))return null;const y=e.slice(o,d),g=r.filter(x=>x.s<=o&&x.e>=d),h=g.find(x=>x.kind==="url");if(h)return s.jsx("a",{href:h.href,target:"_blank",rel:"noopener noreferrer",style:ee.link,children:h.display||y},u);const v=g.find(x=>x.kind==="mention");return v?s.jsx("a",{href:`https://x.com/${v.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:ee.link,children:y},u):s.jsx("span",{children:Es(Wu(y),ee.link)},u)}).filter(o=>o!==null)}function Ig(e,t,n,r,l=ee){if(!e)return null;t=t||[],n=n||[],r=r||[];const i=[];for(const u of t)u.length>0&&i.push({s:u.offset,e:u.offset+u.length,kind:"style",style:u.style});for(const u of n){const d=vf(u,e);d&&i.push(d)}for(const u of r){const d=xf(u,e);d&&i.push(d)}if(i.length===0)return Es(e,l.link);const a=new Set([0,e.length]);for(const u of i)u.s>=0&&u.s<=e.length&&a.add(u.s),u.e>=0&&u.e<=e.length&&a.add(u.e);const o=[...a].sort((u,d)=>u-d);return o.slice(0,-1).map((u,d)=>{const y=o[d+1],g=i.filter(N=>N.s<=u&&N.e>=y),h=e.slice(u,y);let v;if(h.includes(` +${mf}`;function Ng(e){if(!e)return null;try{const t=JSON.parse(e);if(t&&typeof t=="object")return{tldr:typeof t.tldr=="string"?t.tldr:"",summary:typeof t.summary=="string"?t.summary:"",tags:Array.isArray(t.tags)?t.tags.filter(n=>typeof n=="string"):[]}}catch{}return{tldr:"",summary:e,tags:[]}}const _g=()=>s.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:s.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function Cg({archiveId:e,selectedEntry:t,selectedUids:n,selectedEntries:r,detail:l,onTagFilterSet:i,tagNodes:a,onTagsRefresh:o,onEntryTitleChange:u,onEntryDeleted:d,onBulkDeleted:y,humanizeTags:g,onDetailRefresh:h,onOpenPreview:v,onPlay:x,isPublicSession:S}){var qn,Cr,Er;const[N,p]=c.useState([]),[f,m]=c.useState(""),[k,C]=c.useState([]),[E,T]=c.useState(""),j=c.useRef(0),P=c.useRef(!1),[R,X]=c.useState(!1),[H,Y]=c.useState(""),[te,fe]=c.useState("idle"),[Be,we]=c.useState(""),M=c.useRef(null),[L,V]=c.useState(!1);c.useEffect(()=>{V(!1)},[(qn=l==null?void 0:l.summary)==null?void 0:qn.entry_uid]);const[G,ne]=c.useState(null),[se,Z]=c.useState(null),[Se,ce]=c.useState(""),[Ie,at]=c.useState(!1),[ht,Vt]=c.useState(()=>{try{return sessionStorage.getItem(Bu)||ns[0].value}catch{return ns[0].value}}),[Qt,jt]=c.useState(!1),Oe=c.useRef(null),Je=c.useRef(null),tt=c.useRef(null),D=c.useRef(null),K=e&&(t!=null&&t.entry_uid)?`${e}:${t.entry_uid}`:null;D.current=K;const Ne=(n==null?void 0:n.size)>=2,[Ve,qt]=c.useState(""),[Qe,Kt]=c.useState("idle"),[Qn,Ot]=c.useState(""),[Le,bn]=c.useState([]),[At,w]=c.useState(""),[B,O]=c.useState("idle"),[$,F]=c.useState(""),[U,ye]=c.useState("idle"),[ue,Te]=c.useState(""),[pe,$e]=c.useState("idle"),[ie,nt]=c.useState("");c.useEffect(()=>{const b=++j.current;if(M.current&&(clearInterval(M.current),M.current=null),fe("idle"),we(""),!t||!e){p([]),C([]);return}if(S){p([]),C([]);return}X(!1),Y(""),P.current=!1,p([]),Promise.all([Bl(e,t.entry_uid),Du(e,t.entry_uid)]).then(([q,ae])=>{b===j.current&&(p(q),C(ae))}).catch(()=>{})},[t,e,S]),c.useEffect(()=>()=>{clearInterval(M.current)},[]),c.useLayoutEffect(()=>{var q,ae,he;clearInterval(Oe.current),Oe.current=null,(q=Je.current)==null||q.abort(),Je.current=null,(ae=tt.current)==null||ae.abort(),tt.current=null;const b=(t==null?void 0:t.entry_uid)!=null&&((he=l==null?void 0:l.summary)==null?void 0:he.entry_uid)===(t==null?void 0:t.entry_uid);ne(b?l.latest_summary??null:null),Z(b?l.summary_attempt??null:null),ce(""),at(!1),jt(!1)},[e,t==null?void 0:t.entry_uid,(Cr=l==null?void 0:l.summary)==null?void 0:Cr.entry_uid]);const ot=se==null?void 0:se.status;c.useEffect(()=>{var sn;if(clearInterval(Oe.current),Oe.current=null,ot!=="pending"&&ot!=="running"||!e||!((sn=l==null?void 0:l.summary)!=null&&sn.entry_uid))return;const b=l.summary.entry_uid,q=`${e}:${b}`;if(K!==q)return;const ae=new AbortController;Je.current=ae;const St=setInterval(async()=>{var me;try{const an=await Xh(e,b,{signal:ae.signal});if(ae.signal.aborted||D.current!==q)return;ne(an.summary??null),Z(an.attempt??null);const Ys=(me=an.attempt)==null?void 0:me.status;Ys!=="pending"&&Ys!=="running"&&(clearInterval(St),Oe.current===St&&(Oe.current=null),at(!1),Ys==="completed"&&D.current===q&&(h==null||h()))}catch{if(ae.signal.aborted||D.current!==q)return}},Sg);return Oe.current=St,()=>{clearInterval(St),Oe.current===St&&(Oe.current=null),ae.abort(),Je.current===ae&&(Je.current=null)}},[ot,e,t==null?void 0:t.entry_uid,(Er=l==null?void 0:l.summary)==null?void 0:Er.entry_uid,K]),c.useEffect(()=>()=>{var b,q;clearInterval(Oe.current),(b=Je.current)==null||b.abort(),(q=tt.current)==null||q.abort()},[]);async function Qs(b=!1){var St,sn;if(!e||!((St=l==null?void 0:l.summary)!=null&&St.entry_uid)||Ie)return;const q=l.summary.entry_uid,ae=`${e}:${q}`;if(D.current!==ae)return;const he=new AbortController;(sn=tt.current)==null||sn.abort(),tt.current=he,at(!0),ce("");try{const me=await Jh(e,q,{provider:ht,force:b,includeImages:Qt,signal:he.signal});if(he.signal.aborted||D.current!==ae)return;me.status==="completed"?(ne(me),Z(null),at(!1),D.current===ae&&(h==null||h())):Z({...me??{},status:"pending"})}catch(me){if(he.signal.aborted||D.current!==ae)return;ce(me.message||"Summary request failed"),at(!1)}finally{tt.current===he&&(tt.current=null)}}function qs(b){Vt(b),b==="claude_cli"&&jt(!1);try{sessionStorage.setItem(Bu,b)}catch{}}c.useEffect(()=>{if(!e){bn([]);return}wo(e).then(bn).catch(()=>bn([]))},[e]),c.useEffect(()=>{qt(""),Kt("idle"),Ot(""),w(""),O("idle"),F(""),ye("idle"),Te(""),$e("idle"),nt("")},[n]);async function Ks(){const b=n.size;if(!window.confirm(`Delete ${b} entr${b===1?"y":"ies"}? This cannot be undone.`))return;ye("running");const q=new Set;for(const ae of n)try{await $u(e,ae),q.add(ae)}catch{}ye("idle"),y==null||y(q)}async function Tn(){const b=Ve.trim();if(b){Kt("running"),Ot("");try{for(const q of n)await Iu(e,q,b);qt(""),Kt("done"),o==null||o(),setTimeout(()=>Kt("idle"),1800)}catch(q){Ot(q.message),Kt("error")}}}async function _r(){if(!At)return;O("running"),F("");const b=[],q=Le.find(ae=>ae.collection_uid===At);for(const ae of n)try{await Sa(e,At,ae,(q==null?void 0:q.default_visibility_bits)??2)}catch{b.push(ae)}b.length>0?(F(`Failed for ${b.length} entr${b.length===1?"y":"ies"}.`),O("error")):(O("done"),setTimeout(()=>O("idle"),1800))}async function Pn(){if(!ue||!t)return;$e("running"),nt("");const b=Le.find(q=>q.collection_uid===ue);try{await Sa(e,ue,t.entry_uid,(b==null?void 0:b.default_visibility_bits)??2),$e("done"),Te("");const q=await Du(e,t.entry_uid);C(q),setTimeout(()=>$e("idle"),1800)}catch(q){nt(q.message),$e("error")}}async function jl(){const b=H.trim()||null;try{await tm(e,t.entry_uid,b),u==null||u(t.entry_uid,b)}catch{}finally{X(!1)}}async function Sl(){const b=f.trim();if(!(!b||!t))try{await Iu(e,t.entry_uid,b),m(""),T("");const q=await Bl(e,t.entry_uid);p(q),o()}catch(q){T(q.message)}}async function Xs(b){try{await nm(e,t.entry_uid,b);const q=await Bl(e,t.entry_uid);p(q),o()}catch{}}async function Js(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await $u(e,t.entry_uid),d==null||d(t.entry_uid)}catch{}}async function Gs(){if(!t||!e||te==="running")return;const b=j.current,q=t.entry_uid;fe("running"),we("");try{const{job_uid:ae}=await Im(e,q);if(j.current!==b)return;M.current=setInterval(async()=>{try{const he=await of(e,ae);if(he.status==="completed"){if(clearInterval(M.current),M.current=null,j.current!==b)return;fe("done");const St=await Bl(e,q);if(j.current!==b)return;p(St),h==null||h()}else if(he.status==="failed"){if(clearInterval(M.current),M.current=null,j.current!==b)return;fe("error"),we(he.error_text||"Re-archive failed.")}}catch{if(clearInterval(M.current),M.current=null,j.current!==b)return;fe("error"),we("Network error while polling.")}},500)}catch(ae){if(j.current!==b)return;fe("error"),we(ae.message||"Failed to start re-archive.")}}const _=l?[["Added",ko(l.summary.archived_at)],["Source",l.summary.source_kind],["Type",l.summary.entity_kind],["Visibility",Fu[l.summary.visibility]??l.summary.visibility],["Root",l.structured_root_relpath]]:[],z=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),A=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","md","markdown","txt","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Q=l?l.artifacts.findIndex(b=>b.artifact_role==="primary_media"):-1,J=Q>=0?l.artifacts[Q]:null,le=J?J.relpath.split(".").pop().toLowerCase():"",_e=J&&z.has(le),Ue=Q>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${Q}`:null,ke=l&&!_e&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread"||J&&A.has(le));return s.jsxs("aside",{className:"context-rail",children:[s.jsx("div",{className:"rail-eyebrow",children:"Context"}),Ne?S?s.jsxs("p",{className:"bulk-count",children:[s.jsx("span",{className:"bulk-count-num",children:n.size})," entries selected"]}):s.jsxs("div",{className:"bulk-panel",children:[s.jsxs("p",{className:"bulk-count",children:[s.jsx("span",{className:"bulk-count-num",children:n.size})," entries selected"]}),s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Assign tag"}),Qn&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:Qn}),s.jsxs("div",{className:"tag-input-wrap",children:[s.jsx("span",{className:"hash",children:"/"}),s.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:Ve,onChange:b=>qt(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Tn()}}),s.jsx("button",{className:"tag-add-btn",onClick:Tn,disabled:Qe==="running"||!Ve.trim(),children:Qe==="running"?"…":Qe==="done"?"✓":"Add"})]})]}),Le.length>0&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Add to collection"}),s.jsxs("div",{className:"bulk-coll-row",children:[s.jsxs("select",{className:"bulk-coll-select",value:At,onChange:b=>w(b.target.value),children:[s.jsx("option",{value:"",children:"Pick a collection…"}),Le.filter(b=>b.slug!=="_default_").map(b=>s.jsx("option",{value:b.collection_uid,children:b.name},b.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:_r,disabled:!At||B==="running",children:B==="running"?"…":B==="done"?"✓":B==="error"?"!":"Add"})]}),$&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"6px 0 0"},children:$})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Ks,disabled:U==="running",children:U==="running"?"Deleting…":`Delete ${n.size} entr${n.size===1?"y":"ies"}`})})]}):t?l?s.jsxs(s.Fragment,{children:[S?s.jsx("h2",{className:"rail-title",children:gt(l.summary.title)||gt(l.summary.entry_uid)}):R?s.jsx("input",{className:"rail-title-input",autoFocus:!0,value:H,onChange:b=>Y(b.target.value),onKeyDown:b=>{b.key==="Enter"&&b.currentTarget.blur(),b.key==="Escape"&&(P.current=!0,b.currentTarget.blur())},onBlur:()=>{P.current?X(!1):jl(),P.current=!1}}):s.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{Y(l.summary.title??""),X(!0)},children:[gt(l.summary.title)||gt(l.summary.entry_uid),s.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:s.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),l.summary.original_url&&s.jsxs("a",{className:"url-tile",href:l.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[s.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:Ws(l.summary.source_kind)}}),s.jsx("span",{className:"u-text",children:l.summary.original_url}),s.jsx("span",{className:"ext",children:s.jsx(_g,{})})]}),_e&&x&&s.jsx("button",{className:"rail-preview-btn",onClick:()=>x(Ue,t),children:"▶ Play"}),ke&&v&&s.jsx("button",{className:"rail-preview-btn",onClick:v,children:"Preview"}),(()=>{const b=(G==null?void 0:G.status)==="completed"?Ng(G.summary_text):null,q=(se==null?void 0:se.status)==="pending"||(se==null?void 0:se.status)==="running",ae=(se==null?void 0:se.status)==="failed"&&se.error_text===Uu||Se===Uu;return S&&!b?null:s.jsxs("div",{className:"rail-section rail-summary",children:[s.jsx("div",{className:"rail-section-heading",children:"Summary"}),b&&s.jsxs("div",{className:"rail-summary-body",children:[b.tldr&&s.jsx("p",{className:"rail-summary-tldr",children:b.tldr}),b.summary&&s.jsx("p",{className:"rail-summary-text",children:b.summary}),b.tags.length>0&&s.jsx("div",{className:"rail-summary-tags",children:b.tags.map(he=>s.jsx("span",{className:"rail-summary-tag",children:he},he))}),s.jsxs("p",{className:"rail-summary-provider",children:[jg[G.provider_kind]||G.provider_kind,G.resolved_model||G.provider_model?` · ${G.resolved_model||G.provider_model}`:""]})]}),q&&s.jsxs("p",{className:"rail-summary-status",children:[s.jsx("span",{className:"rail-summary-spinner","aria-hidden":"true"}),"Generating…"]}),ae&&!S&&s.jsxs("div",{className:"rail-summary-info",role:"status",children:[s.jsx("p",{className:"rail-summary-info__heading",children:hf}),s.jsx("p",{className:"rail-summary-info__detail",children:mf})]}),(se==null?void 0:se.status)==="failed"&&se.error_text&&!ae&&!S&&s.jsx("p",{className:"form-msg form-msg--err rail-summary-error",children:se.error_text}),Se&&!ae&&s.jsx("p",{className:"form-msg form-msg--err rail-summary-error",children:Se}),!S&&!q&&s.jsxs("div",{className:"rail-summary-controls",children:[s.jsx("select",{className:"rail-summary-select",value:ht,onChange:he=>qs(he.target.value),"aria-label":"Summary provider",children:ns.map(he=>s.jsx("option",{value:he.value,children:he.label},he.value))}),s.jsxs("div",{className:`rail-summary-image-option${ht==="claude_cli"?" rail-summary-image-option--disabled":""}`,children:[s.jsxs("label",{className:"rail-summary-image-option__label",children:[s.jsx("input",{type:"checkbox",checked:Qt,disabled:ht==="claude_cli",onChange:he=>jt(he.target.checked)}),"Include attached images"]}),s.jsx("p",{className:"rail-summary-image-option__note",children:ht==="claude_cli"?"Claude CLI cannot attach local images. Choose an HTTP provider or Codex CLI.":"Selected archived images are sent to the chosen provider. Up to 4 supported images (5 MiB each, 12 MiB total) can be attached; unsupported or oversized artifacts are skipped."})]}),s.jsx("button",{className:"rail-rearchive-btn",onClick:()=>Qs(!!b),disabled:Ie,children:Ie?"…":b?"Regenerate":"Generate"})]})]})})(),s.jsx("div",{className:"meta-list",children:_.filter(([,b])=>b!=null&&b!=="").map(([b,q])=>s.jsxs("div",{className:"meta-item",children:[s.jsx("span",{className:"meta-k",children:b}),s.jsx("span",{className:`meta-v${b==="Root"?" mono":""}`,children:gt(q)})]},b))}),l.artifacts.length>0&&(()=>{const b=l.artifacts.map((me,an)=>({...me,_idx:an})),q=b.filter(me=>me.artifact_role==="font"),ae=b.filter(me=>me.artifact_role!=="font"),he=q.reduce((me,an)=>me+(an.byte_size||0),0),St=l.summary.entry_uid,sn=me=>s.jsx("li",{children:s.jsxs("a",{href:`/api/archives/${e}/entries/${St}/artifacts/${me._idx}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[s.jsx("span",{className:"artifact-name",children:me.artifact_role==="font"?me.relpath.split("/").pop():me.artifact_role.replace(/_/g," ")}),s.jsx("span",{className:"artifact-size",children:me.byte_size!=null?gl(me.byte_size):"—"})]})},me._idx);return s.jsxs("div",{className:"rail-section",children:[s.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",s.jsx("span",{className:"num",children:l.artifacts.length})]}),s.jsxs("ul",{className:"artifact-list",children:[ae.map(sn),q.length>0&&s.jsxs("li",{className:"artifact-group",children:[s.jsxs("button",{type:"button",className:"artifact-group-header artifact-link","aria-expanded":L,onClick:()=>V(me=>!me),children:[s.jsxs("span",{className:"artifact-name",children:[s.jsx("span",{"aria-hidden":"true",className:`artifact-group-chevron${L?" open":""}`,children:"›"}),` fonts (${q.length})`]}),s.jsx("span",{className:"artifact-size",children:gl(he)})]}),L&&s.jsx("ul",{className:"artifact-list artifact-group-body",children:q.map(sn)})]})]})]})})()]}):s.jsx("p",{className:"tags-empty",children:"Loading\\u2026"}):s.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&!Ne&&!S&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Tags"}),N.length===0?s.jsx("p",{className:"tags-empty",children:"No tags yet."}):s.jsx("div",{className:"tags-wrap",children:N.map(b=>s.jsxs("span",{className:"tag-pill",title:b.full_path,children:[g?cf(b.full_path):b.full_path,s.jsx("button",{className:"remove",title:`Remove tag ${b.full_path}`,onClick:()=>Xs(b.tag_uid),children:"×"})]},b.tag_uid))}),E&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:E}),s.jsxs("div",{className:"tag-input-wrap",children:[s.jsx("span",{className:"hash",children:"/"}),s.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:f,onChange:b=>m(b.target.value),onKeyDown:b=>{b.key==="Enter"&&Sl()}}),s.jsx("button",{className:"tag-add-btn",onClick:Sl,children:"Add"})]})]}),(k.length>0||Le.filter(b=>b.slug!=="_default_").length>0)&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Collections"}),k.map(b=>s.jsxs("div",{className:"coll-row",children:[s.jsx("span",{className:"coll-name",children:b.name}),s.jsx("span",{className:"vis-badge",children:Fu[b.visibility_bits]??`bits:${b.visibility_bits}`})]},b.collection_uid)),Le.filter(b=>b.slug!=="_default_").length>0&&s.jsxs("div",{className:"bulk-coll-row",style:{marginTop:8},children:[s.jsxs("select",{className:"bulk-coll-select",value:ue,onChange:b=>Te(b.target.value),children:[s.jsx("option",{value:"",children:"Add to collection…"}),Le.filter(b=>b.slug!=="_default_").map(b=>s.jsx("option",{value:b.collection_uid,children:b.name},b.collection_uid))]}),s.jsx("button",{className:"tag-add-btn",onClick:Pn,disabled:!ue||pe==="running",children:pe==="running"?"…":pe==="done"?"✓":pe==="error"?"!":"Add"})]}),ie&&s.jsx("p",{className:"form-msg form-msg--err",style:{margin:"4px 0 0"},children:ie})]}),l&&(l.summary.entity_kind==="tweet"||l.summary.entity_kind==="tweet_thread")&&s.jsxs("div",{className:"rail-section",children:[s.jsx("div",{className:"rail-section-heading",children:"Actions"}),s.jsx("button",{className:"rail-rearchive-btn",onClick:Gs,disabled:te==="running",children:te==="running"?"Re-archiving…":"Re-archive"}),te==="done"&&s.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),te==="error"&&s.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:Be})]}),s.jsx("div",{className:"rail-delete-zone",children:s.jsx("button",{className:"rail-delete-btn",onClick:Js,children:"Delete entry"})})]})]})}const Eg=/\/api\/archives\/([^/]+)\/entries\/([^/]+)\/artifacts\/(\d+)/;function bg(){return s.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[s.jsx("path",{d:"M5 17H3a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h18a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-2"}),s.jsx("polygon",{points:"12 15 17 21 7 21 12 15"})]})}function Tg({src:e,contentType:t="video/mp4"}){const n=c.useRef(null),[r,l]=c.useState(null),[i,a]=c.useState(!1),[o,u]=c.useState(!1);c.useEffect(()=>{if(!e){l(null);return}const g=e.match(Eg);if(!g){l(e);return}let h=!1;return l(null),$m(g[1],g[2],parseInt(g[3],10)).then(({url:v})=>{h||l(v)}).catch(()=>{h||l(e)}),()=>{h=!0}},[e]),c.useEffect(()=>{n.current&&n.current.load()},[r]),c.useEffect(()=>{u(typeof HTMLVideoElement<"u"&&"webkitShowPlaybackTargetPicker"in HTMLVideoElement.prototype)},[]),c.useEffect(()=>{var h;const g=v=>{if(v)try{cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),a(!0)}catch{}};if((h=window.cast)!=null&&h.framework)g(!0);else if(window.__onGCastApiAvailable=g,!document.querySelector('script[src*="cast_sender"]')){const v=document.createElement("script");v.src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",document.head.appendChild(v)}},[]),c.useEffect(()=>{if(!i||!r)return;const g=cast.framework.CastContext.getInstance(),{CastContextEventType:h,SessionState:v}=cast.framework,x=N=>{if(!N)return;const p=new chrome.cast.media.MediaInfo(window.location.origin+r,t);N.loadMedia(new chrome.cast.media.LoadRequest(p)).catch(()=>{})};x(g.getCurrentSession());const S=N=>{(N.sessionState===v.SESSION_STARTED||N.sessionState===v.SESSION_RESUMED)&&x(g.getCurrentSession())};return g.addEventListener(h.SESSION_STATE_CHANGED,S),()=>g.removeEventListener(h.SESSION_STATE_CHANGED,S)},[i,r,t]);const d=()=>{var g,h;(h=(g=n.current)==null?void 0:g.webkitShowPlaybackTargetPicker)==null||h.call(g)},y=i||o;return s.jsx("div",{className:"preview-video-wrap",style:{position:"relative"},children:e?s.jsxs(s.Fragment,{children:[r?s.jsxs("video",{ref:n,controls:!0,autoPlay:!1,playsInline:!0,"x-webkit-airplay":"allow",style:{width:"100%",maxHeight:"100%",display:"block"},children:[s.jsx("source",{src:r}),"Your browser does not support the video element."]}):s.jsx("div",{className:"video-tv-loading","aria-label":"Loading video…"}),y&&r&&s.jsxs("div",{className:"video-tv-controls",children:[o&&s.jsx("button",{className:"video-tv-btn",title:"AirPlay to device","aria-label":"AirPlay to device",onClick:d,children:s.jsx(bg,{})}),i&&s.jsx("google-cast-launcher",{className:"video-tv-btn",title:"Cast to TV"})]})]}):s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function Hu({src:e,type:t,title:n,originalUrl:r}){const l=r||e,i=n||null;return s.jsxs("div",{className:"preview-iframe-wrap",style:{flex:1,minHeight:0,display:"flex",flexDirection:"column"},children:[s.jsxs("div",{className:"preview-iframe-toolbar",style:{display:"flex",flexDirection:"column",gap:"2px",padding:"6px 12px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0},children:[i&&s.jsx("span",{style:{fontSize:"0.85rem",fontWeight:600,color:"var(--ink)",fontFamily:"var(--sans)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:i}),s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[s.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.78rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:l}),s.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{fontSize:"0.78rem",color:"var(--accent)",textDecoration:"none",whiteSpace:"nowrap",fontFamily:"var(--sans)",flexShrink:0},children:t==="pdf"?"Open PDF ↗":"Open in new tab ↗"})]})]}),s.jsx("iframe",{src:e,sandbox:"allow-same-origin allow-popups",allow:"autoplay 'none'",referrerPolicy:"no-referrer",style:{flex:1,border:"none",width:"100%",minHeight:0},title:i||(t==="pdf"?"PDF preview":"Page preview")})]})}function Pg({src:e,alt:t}){return s.jsx("div",{className:"preview-image-wrap",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",background:"var(--paper-2)",overflow:"hidden"},children:s.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{display:"contents"},children:s.jsx("img",{src:e,alt:t||"",style:{objectFit:"contain",maxHeight:"100%",maxWidth:"100%",display:"block",cursor:"pointer"}})})})}function gf(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}function Wu(e){return!e||!e.includes("&")?e:e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'").replace(/'/g,"'")}const ee={card:{background:"var(--paper)",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},threadOuter:{border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",maxWidth:"560px",margin:"0 auto",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},tweetRow:{display:"flex",gap:"10px",padding:"10px 12px"},tweetRowThread:{display:"flex",gap:"10px",padding:"10px 12px 0"},leftCol:{display:"flex",flexDirection:"column",alignItems:"center",flexShrink:0,width:"36px"},rightCol:{flex:1,minWidth:0,paddingBottom:"8px"},avatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},avatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},threadLine:{flex:1,width:"2px",background:"var(--line-soft, var(--line))",margin:"4px 0",minHeight:"12px",borderRadius:"1px"},authorRow:{display:"flex",alignItems:"baseline",gap:"4px",flexWrap:"wrap",marginBottom:"4px",lineHeight:"1.3"},authorName:{fontWeight:"700",fontSize:"14px",color:"var(--ink)"},authorHandle:{fontSize:"13px",color:"var(--muted)"},datePart:{fontSize:"13px",color:"var(--muted)"},tweetText:{fontSize:"14px",lineHeight:"1.5",color:"var(--ink)",whiteSpace:"pre-line",marginBottom:"8px",wordBreak:"break-word"},stats:{display:"flex",gap:"12px",fontSize:"13px",color:"var(--muted)"},link:{color:"var(--accent)",textDecoration:"none"},loading:{padding:"24px 16px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},error:{padding:"24px 16px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},mediaGrid:{marginBottom:"8px",borderRadius:"10px",overflow:"hidden",border:"1px solid var(--line)"},mediaImg:{display:"block",width:"100%",objectFit:"cover",maxHeight:"260px"},mediaVideo:{display:"block",width:"100%",maxHeight:"260px",background:"#000"},article:{maxWidth:"560px",margin:"0 auto",border:"1px solid var(--line)",borderRadius:"12px",overflow:"hidden",background:"var(--paper)",fontFamily:'var(--sans, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif)'},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"280px"},aMeta:{padding:"10px 14px 0"},aTweetTitle:{fontSize:"20px",fontWeight:"800",letterSpacing:"-0.3px",color:"var(--ink)",lineHeight:"1.3",marginBottom:"8px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"8px"},aAvatar:{width:"36px",height:"36px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"36px",height:"36px",borderRadius:"50%",background:"var(--line)",flexShrink:0},aAuthorName:{fontSize:"14px",fontWeight:"700",color:"var(--ink)",lineHeight:"1.3"},aAuthorSub:{fontSize:"13px",color:"var(--muted)",lineHeight:"1.3"},aDivider:{border:"none",borderTop:"1px solid var(--line)",margin:"0"},aBody:{padding:"4px 14px 16px"},bH1:{fontSize:"22px",fontWeight:"800",letterSpacing:"-0.4px",color:"var(--ink)",lineHeight:"1.25",margin:"16px 0 6px"},bH2:{fontSize:"18px",fontWeight:"700",letterSpacing:"-0.2px",color:"var(--ink)",lineHeight:"1.3",margin:"14px 0 4px"},bP:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.65",marginBottom:"12px",marginTop:"0"},bSpacer:{height:"4px",display:"block"},bQuote:{borderLeft:"3px solid var(--line)",padding:"2px 12px",margin:"12px 0",color:"var(--muted)",fontSize:"15px",lineHeight:"1.6"},bHr:{border:"none",borderTop:"1px solid var(--line)",margin:"14px 0"},bImg:{width:"100%",display:"block",borderRadius:"8px",margin:"12px 0"},bUl:{margin:"8px 0 12px",paddingLeft:"24px"},bOl:{margin:"8px 0 12px",paddingLeft:"24px"},bLi:{fontSize:"15px",color:"var(--ink)",lineHeight:"1.6",marginBottom:"4px"},bTweet:{display:"flex",alignItems:"center",gap:"10px",border:"1px solid var(--line)",borderRadius:"10px",padding:"10px 14px",margin:"12px 0",color:"var(--muted)",fontSize:"14px",textDecoration:"none"},bMdPre:{borderRadius:"8px",margin:"10px 0",overflow:"auto",background:"var(--paper-3, var(--field))",padding:"12px 14px"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"12px",lineHeight:"1.6",color:"var(--ink)",background:"transparent",display:"block"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:"var(--paper-3, var(--field))",padding:"1px 5px",borderRadius:"4px",color:"var(--ink)"},qtBadge:{fontSize:"11px",color:"var(--muted)",display:"inline-flex",alignItems:"center",gap:"2px",marginLeft:"4px",letterSpacing:"0.03em",flexShrink:0},lightboxBackdrop:{position:"fixed",inset:0,zIndex:500,background:"rgba(0,0,0,0.92)",display:"flex",alignItems:"center",justifyContent:"center",padding:"20px"},lightboxContent:{display:"flex",flexDirection:"column",alignItems:"center",gap:"10px",maxWidth:"90vw",maxHeight:"90vh"},lightboxToolbar:{display:"flex",alignItems:"center",gap:"10px",alignSelf:"flex-end"},lightboxImg:{maxWidth:"88vw",maxHeight:"80vh",objectFit:"contain",borderRadius:"6px",display:"block"},lightboxNav:{display:"flex",gap:"12px",alignItems:"center"},lightboxNavBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"20px",cursor:"pointer",borderRadius:"50%",width:"36px",height:"36px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxBtn:{background:"rgba(255,255,255,0.18)",border:"none",color:"#fff",fontSize:"16px",cursor:"pointer",borderRadius:"50%",width:"30px",height:"30px",display:"flex",alignItems:"center",justifyContent:"center",lineHeight:1,flexShrink:0},lightboxLink:{color:"rgba(255,255,255,0.7)",textDecoration:"none",fontSize:"14px"},lightboxCounter:{color:"rgba(255,255,255,0.6)",fontSize:"13px"}},Ae={bg:"#000000",border:"#2f3336",text:"#e7e9ea",dim:"#71767b",accent:"#1d9bf0",codeBg:"#16181c"},Ti={article:{background:Ae.bg,color:Ae.text,minHeight:"100%",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'},articleInner:{maxWidth:"598px",margin:"0 auto",paddingBottom:"80px"},aCover:{width:"100%",display:"block",objectFit:"cover",maxHeight:"420px"},aMeta:{padding:"20px 16px 0"},aTweetTitle:{fontSize:"34px",fontWeight:"800",letterSpacing:"-0.5px",color:Ae.text,lineHeight:"44px",marginBottom:"16px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"12px",marginBottom:"16px"},aAvatar:{width:"40px",height:"40px",borderRadius:"50%",objectFit:"cover",flexShrink:0,display:"block"},aAvatarPh:{width:"40px",height:"40px",borderRadius:"50%",background:Ae.border,flexShrink:0},aAuthorName:{fontSize:"15px",fontWeight:"700",color:Ae.text,lineHeight:"1.3"},aAuthorSub:{fontSize:"15px",color:Ae.dim,lineHeight:"1.3"},aDivider:{border:"none",borderTop:`1px solid ${Ae.border}`,margin:"0"},aBody:{padding:"4px 16px 0"},bH1:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Ae.text,lineHeight:"36px",margin:"24px 0 10px"},bH2:{fontSize:"26px",fontWeight:"800",letterSpacing:"-0.4px",color:Ae.text,lineHeight:"36px",margin:"24px 0 10px"},bP:{fontSize:"17px",color:Ae.text,lineHeight:"1.5",marginBottom:"16px",marginTop:"0"},bSpacer:{height:"6px",display:"block"},bQuote:{borderLeft:`3px solid ${Ae.border}`,padding:"2px 14px",margin:"14px 0",color:Ae.dim,fontSize:"17px",lineHeight:"1.5"},bHr:{border:"none",borderTop:`1px solid ${Ae.border}`,margin:"28px 0"},bImg:{width:"100%",display:"block",borderRadius:"12px",margin:"16px 0"},bUl:{margin:"10px 0 16px",paddingLeft:"28px"},bOl:{margin:"10px 0 16px",paddingLeft:"28px"},bLi:{fontSize:"17px",color:Ae.text,lineHeight:"1.5",marginBottom:"6px"},bTweet:{display:"flex",alignItems:"center",gap:"12px",border:`1px solid ${Ae.border}`,borderRadius:"12px",padding:"14px 16px",margin:"14px 0",color:Ae.dim,fontSize:"15px",textDecoration:"none"},bMdPre:{borderRadius:"12px",margin:"12px 0",overflow:"auto",background:"#1e2029"},bMdCode:{fontFamily:"ui-monospace, 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace",fontSize:"13px",lineHeight:"1.65",padding:"18px 20px",display:"block",color:Ae.text,background:"transparent"},iCode:{fontFamily:"ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace",fontSize:"0.875em",background:Ae.codeBg,padding:"2px 6px",borderRadius:"4px",color:"#e6edf3"},link:{color:Ae.accent,textDecoration:"none"}};function Lg(e,t,n){const r={};return n&&n.forEach((l,i)=>{l.relpath&&(r[l.relpath]=`/api/archives/${e}/entries/${t}/artifacts/${i}`)}),r}function hr(e,t,n){return e&&n[e]?n[e]:t||null}function yf(){return s.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",style:{flexShrink:0,color:"var(--ink)"},children:s.jsx("path",{d:"M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-4.714-6.231-5.401 6.231H2.748l7.73-8.835L1.254 2.25H8.08l4.259 5.63L18.244 2.25zm-1.161 17.52h1.833L7.084 4.126H5.117L17.083 19.77z"})})}function jo(e,t,...n){var r;if(e.fromIndex!=null&&e.toIndex!=null)return{s:e.fromIndex,e:e.toIndex};if(((r=e.indices)==null?void 0:r.length)===2)return{s:e.indices[0],e:e.indices[1]};if(t)for(const l of n){if(!l)continue;const i=t.indexOf(l);if(i!==-1)return{s:i,e:i+l.length}}return null}function vf(e,t){const n=e.expanded_url||e.url||e.text||"",r=e.display_url||e.expanded_url||e.url||e.text||"",l=jo(e,t,e.url,e.text,e.display_url,e.expanded_url);return!l||!n?null:{...l,kind:"url",href:n,display:r}}function xf(e,t){const n=e.screen_name||e.name||e.text||"",r=n?`@${n}`:null,l=jo(e,t,r);return!l||!n?null:{...l,kind:"mention",screen_name:n}}const Vu=/https?:\/\/[^\s<>"'\])]+/g,Rg=/[.,;:!?)()]+$/;function Es(e,t){const n=[];let r=0,l;for(Vu.lastIndex=0;(l=Vu.exec(e))!==null;){l.index>r&&n.push(e.slice(r,l.index));let i=l[0].replace(Rg,"");n.push(s.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",style:t,children:i},l.index));const a=l[0].slice(i.length);a&&n.push(a),r=l.index+l[0].length}return r===0?e:(rvf(o,e)).filter(Boolean),...(t.user_mentions||[]).map(o=>xf(o,e)).filter(Boolean)];if(r.length===0&&n.length===0)return Es(Wu(e),ee.link);const l=new Set([0,e.length]);for(const o of r)o.s>=0&&o.s<=e.length&&l.add(o.s),o.e>=0&&o.e<=e.length&&l.add(o.e);for(const[o,u]of n)o>=0&&o<=e.length&&l.add(o),u>=0&&u<=e.length&&l.add(u);const i=(o,u)=>n.some(([d,y])=>d<=o&&y>=u),a=[...l].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const d=a[u+1];if(i(o,d))return null;const y=e.slice(o,d),g=r.filter(x=>x.s<=o&&x.e>=d),h=g.find(x=>x.kind==="url");if(h)return s.jsx("a",{href:h.href,target:"_blank",rel:"noopener noreferrer",style:ee.link,children:h.display||y},u);const v=g.find(x=>x.kind==="mention");return v?s.jsx("a",{href:`https://x.com/${v.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:ee.link,children:y},u):s.jsx("span",{children:Es(Wu(y),ee.link)},u)}).filter(o=>o!==null)}function Ig(e,t,n,r,l=ee){if(!e)return null;t=t||[],n=n||[],r=r||[];const i=[];for(const u of t)u.length>0&&i.push({s:u.offset,e:u.offset+u.length,kind:"style",style:u.style});for(const u of n){const d=vf(u,e);d&&i.push(d)}for(const u of r){const d=xf(u,e);d&&i.push(d)}if(i.length===0)return Es(e,l.link);const a=new Set([0,e.length]);for(const u of i)u.s>=0&&u.s<=e.length&&a.add(u.s),u.e>=0&&u.e<=e.length&&a.add(u.e);const o=[...a].sort((u,d)=>u-d);return o.slice(0,-1).map((u,d)=>{const y=o[d+1],g=i.filter(N=>N.s<=u&&N.e>=y),h=e.slice(u,y);let v;if(h.includes(` `)){const N=h.split(` `);v=N.flatMap((p,f)=>fN.kind==="style"&&N.style==="Code")&&(v=s.jsx("code",{style:l.iCode,children:v})),g.some(N=>N.kind==="style"&&N.style==="Bold")&&(v=s.jsx("strong",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Italic")&&(v=s.jsx("em",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Underline")&&(v=s.jsx("u",{children:v})),g.some(N=>N.kind==="style"&&N.style==="Strikethrough")&&(v=s.jsx("s",{children:v}));const x=g.find(N=>N.kind==="url");if(x){const N=/^https?:\/\/t\.co\//i.test(v);v=s.jsx("a",{href:x.href,target:"_blank",rel:"noopener noreferrer",style:l.link,children:N?x.display:v})}const S=g.find(N=>N.kind==="mention");return S&&(v=s.jsx("a",{href:`https://x.com/${S.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:l.link,children:v})),s.jsx("span",{children:typeof v=="string"?Es(v,l.link):v},d)})}function $g(e,t,n){const r=(n==null?void 0:n.st)||ee,l=e.resolved_entities||[];return l.length===0?null:l.map((i,a)=>{var o;switch(i.type){case"divider":return s.jsx("hr",{style:r.bHr},a);case"media":{const u=hr(i.local_path,i.url,t);return u?s.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:d=>{var y;!d.metaKey&&!d.ctrlKey&&(d.preventDefault(),(y=n==null?void 0:n.onImgClick)==null||y.call(n,u))},children:s.jsx("img",{src:u,style:r.bImg,loading:"lazy",alt:""})},a):null}case"tweet":return i.tweet_id?s.jsxs("a",{href:`https://x.com/i/status/${i.tweet_id}`,target:"_blank",rel:"noopener noreferrer",style:r.bTweet,children:[s.jsx(yf,{}),"View post on X"]},a):null;case"link":return i.url?s.jsx("p",{style:r.bP,children:s.jsx("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",style:r.link,children:i.url})},a):null;case"markdown":{const u=i.markdown??((o=i.data)==null?void 0:o.markdown)??"";return s.jsx("pre",{style:r.bMdPre,children:s.jsx("code",{style:r.bMdCode,children:u})},a)}case"emoji":return i.url?s.jsx("img",{src:i.url,alt:"",style:{height:"1.2em",verticalAlign:"middle",margin:"0 1px"}},a):null;default:return null}})}function Pi(e,t,n,r){const l=(r==null?void 0:r.st)||ee,i=e.type||"",a=e.text||"",o=e.inline_style_ranges||[],u=e.data||{},d=Ig(a,o,u.urls||[],u.mentions||[],l);switch(i){case"header-one":return s.jsx("h1",{style:l.bH1,children:d},t);case"header-two":{const y=a.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return y?s.jsxs("a",{href:`https://x.com/i/status/${y[1]}`,target:"_blank",rel:"noopener noreferrer",style:l.bTweet,children:[s.jsx(yf,{}),"View post on X"]},t):s.jsx("h2",{style:l.bH2,children:d},t)}case"unstyled":return a.trim()?s.jsx("p",{style:l.bP,children:d},t):s.jsx("span",{style:l.bSpacer},t);case"blockquote":return s.jsx("blockquote",{style:l.bQuote,children:d},t);case"unordered-list-item":case"ordered-list-item":return s.jsx("li",{style:l.bLi,children:d},t);case"atomic":return s.jsx("span",{children:$g(e,n,r)},t);default:return a?s.jsx("p",{style:l.bP,children:d},t):null}}function Dg(e,t,n){const r=(n==null?void 0:n.st)||ee,l=[];let i=0;for(;i{r&&(l==null||l(!0))},[r,l]);const o=r?Ti:ee,u=e.cover_media||{},d=e.author||t||{},y=e.first_published_at_secs?gf(e.first_published_at_secs):"",h=[d.screen_name?`@${d.screen_name}`:"",y].filter(Boolean).join(" · "),v=hr(u.local_path,u.url,n),x=hr(d.avatar_local_path,d.avatar_url,n),S=s.jsxs(s.Fragment,{children:[i&&s.jsx(wf,{items:[{src:i,alt:""}],startIndex:0,onClose:()=>a(null)}),v&&s.jsx("a",{href:v,target:"_blank",rel:"noopener noreferrer",style:{display:"block",cursor:"zoom-in"},onClick:N=>{!N.metaKey&&!N.ctrlKey&&(N.preventDefault(),a(v))},children:s.jsx("img",{src:v,style:o.aCover,alt:"Article cover"})}),s.jsxs("div",{style:o.aMeta,children:[e.title&&s.jsx("div",{style:o.aTweetTitle,children:e.title}),s.jsxs("div",{style:o.aAuthorRow,children:[x?s.jsx("img",{src:x,style:o.aAvatar,alt:d.name||""}):s.jsx("div",{style:o.aAvatarPh}),s.jsxs("div",{children:[s.jsx("div",{style:o.aAuthorName,children:d.name||d.screen_name||"Unknown"}),h&&s.jsx("div",{style:o.aAuthorSub,children:h})]})]})]}),s.jsx("hr",{style:o.aDivider}),s.jsx("div",{style:o.aBody,children:Dg(e.blocks||[],n,{onImgClick:a,st:o})})]});return r?s.jsx("div",{style:Ti.article,children:s.jsx("div",{style:Ti.articleInner,children:S})}):s.jsx("div",{style:ee.article,children:S})}function Ag({photos:e,onOpen:t}){const n=e.length;if(n===0)return null;if(n===1)return s.jsx("a",{href:e[0].src,target:"_blank",rel:"noopener noreferrer",style:{display:"block"},onClick:l=>{!l.metaKey&&!l.ctrlKey&&(l.preventDefault(),t(0))},children:s.jsx("img",{src:e[0].src,alt:e[0].alt||"",style:ee.mediaImg,loading:"lazy"})});const r=n<=2?"180px":"140px";return s.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gridTemplateRows:n===2?r:`${r} ${r}`,gap:"2px"},children:e.map((l,i)=>s.jsx("a",{href:l.src,target:"_blank",rel:"noopener noreferrer",style:{display:"block",overflow:"hidden",gridRow:n===3&&i===0?"span 2":void 0},onClick:a=>{!a.metaKey&&!a.ctrlKey&&(a.preventDefault(),t(i))},children:s.jsx("img",{src:l.src,alt:l.alt||"",loading:"lazy",style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})},i))})}function wf({items:e,startIndex:t,onClose:n}){const[r,l]=c.useState(t);c.useEffect(()=>{const a=o=>{(o.key==="Escape"||o.key==="ArrowLeft"||o.key==="ArrowRight")&&(o.stopPropagation(),o.preventDefault()),o.key==="Escape"&&n(),o.key==="ArrowRight"&&l(u=>Math.min(u+1,e.length-1)),o.key==="ArrowLeft"&&l(u=>Math.max(u-1,0))};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[n,e.length]);const i=e[r];return s.jsx("div",{style:ee.lightboxBackdrop,onClick:n,children:s.jsxs("div",{style:ee.lightboxContent,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{style:ee.lightboxToolbar,children:[e.length>1&&s.jsxs("span",{style:ee.lightboxCounter,children:[r+1," / ",e.length]}),s.jsx("a",{href:i.src,target:"_blank",rel:"noopener noreferrer",style:ee.lightboxLink,title:"Open in new tab",children:"↗"}),s.jsx("button",{style:ee.lightboxBtn,onClick:n,"aria-label":"Close",children:"×"})]}),s.jsx("img",{src:i.src,alt:i.alt||"",style:ee.lightboxImg}),e.length>1&&s.jsxs("div",{style:ee.lightboxNav,children:[s.jsx("button",{style:ee.lightboxNavBtn,onClick:()=>l(a=>Math.max(a-1,0)),disabled:r===0,children:"‹"}),s.jsx("button",{style:ee.lightboxNavBtn,onClick:()=>l(a=>Math.min(a+1,e.length-1)),disabled:r===e.length-1,children:"›"})]})]})})}function Qu({tweet:e,isInThread:t,isLast:n,artifactMap:r}){var f,m;const[l,i]=c.useState(null),a=e.author||{},o=e.created_at_secs?gf(e.created_at_secs):"",u=e.entities||{},d=hr(a.avatar_local_path,a.avatar_url,r),y=t&&!n,g=e.is_quote_status===!0,h=t?ee.tweetRowThread:ee.tweetRow,v=e.full_text||"",x=((m=(f=e.extended_entities)==null?void 0:f.media)!=null&&m.length?e.extended_entities.media:u.media)||[],S=[],N=[];for(const k of x)if(k.type==="photo"){const C=hr(k.local_path,k.media_url_https,r);C&&S.push({kind:"photo",src:C,alt:k.alt_text||""})}else if(k.type==="video"||k.type==="animated_gif"){const C=k.local_path&&r[k.local_path]||(()=>{var T,j;return(j=(((T=k.video_info)==null?void 0:T.variants)||[]).filter(P=>P.content_type==="video/mp4").sort((P,R)=>(R.bitrate||0)-(P.bitrate||0))[0])==null?void 0:j.url})();C&&N.push({kind:k.type==="animated_gif"?"gif":"video",src:C})}const p=[];for(const k of x){if(!k.url||!(k.type==="photo"?S.some(T=>T.src===hr(k.local_path,k.media_url_https,r)):N.length>0))continue;const E=jo(k,v,k.url);E&&p.push([E.s,E.e])}return s.jsxs(s.Fragment,{children:[l!==null&&s.jsx(wf,{items:S,startIndex:l,onClose:()=>i(null)}),s.jsxs("div",{style:h,children:[s.jsxs("div",{style:ee.leftCol,children:[d?s.jsx("img",{src:d,style:ee.avatar,alt:a.name||""}):s.jsx("div",{style:ee.avatarPh}),y&&s.jsx("div",{style:ee.threadLine})]}),s.jsxs("div",{style:ee.rightCol,children:[s.jsxs("div",{style:ee.authorRow,children:[s.jsx("span",{style:ee.authorName,children:a.name||a.screen_name||"Unknown"}),a.screen_name&&s.jsxs("span",{style:ee.authorHandle,children:["@",a.screen_name]}),o&&s.jsxs("span",{style:ee.datePart,children:["· ",o]}),g&&s.jsx("span",{style:ee.qtBadge,title:"Quote tweet",children:"↻ QT"})]}),s.jsx("div",{style:ee.tweetText,children:zg(v,u,p)}),S.length>0&&s.jsx("div",{style:ee.mediaGrid,children:s.jsx(Ag,{photos:S,onOpen:k=>i(k)})}),N.map((k,C)=>s.jsx("div",{style:ee.mediaGrid,children:s.jsx("video",{src:k.src,style:ee.mediaVideo,controls:!0,loop:k.kind==="gif",muted:k.kind==="gif",autoPlay:k.kind==="gif"})},C)),(e.retweet_count>0||e.favorite_count>0)&&s.jsxs("div",{style:ee.stats,children:[e.favorite_count>0&&s.jsxs("span",{children:["❤️ ",e.favorite_count.toLocaleString()]}),e.retweet_count>0&&s.jsxs("span",{children:["🔁 ",e.retweet_count.toLocaleString()]})]})]})]})]})}function Mg({archiveId:e,entryUid:t,artifacts:n,entityKind:r,fullPage:l,onXArticle:i}){const[a,o]=c.useState(!0),[u,d]=c.useState(null),[y,g]=c.useState([]);if(c.useEffect(()=>{if(o(!0),d(null),g([]),!n||!e||!t){o(!1);return}const x=n.map((N,p)=>({...N,index:p})).filter(N=>N.artifact_role==="raw_tweet_json");if(x.length===0){d("No tweet data found."),o(!1);return}let S=!1;return Zh(e,t,x.map(N=>N.index)).then(async N=>{if(S)return;const p=/https?:\/\/t\.co\/[A-Za-z0-9]+/g,f=T=>{var P;const j=T.full_text||"";return(((P=T.entities)==null?void 0:P.urls)||[]).map(R=>{var X;if(R.fromIndex!=null&&R.toIndex!=null)return[R.fromIndex,R.toIndex];if(((X=R.indices)==null?void 0:X.length)===2)return[R.indices[0],R.indices[1]];if(R.url){const H=j.indexOf(R.url);if(H!==-1)return[H,H+R.url.length]}return null}).filter(Boolean)},m=(T,j,P)=>T.some(([R,X])=>R<=j&&X>=P),k=new Set;for(const T of N){const j=T.full_text||"",P=f(T);let R;for(p.lastIndex=0;(R=p.exec(j))!==null;)m(P,R.index,R.index+R[0].length)||k.add(R[0])}const C=k.size>0?await em([...k]).catch(()=>({})):{},E=N.map(T=>{var H;const j=T.full_text||"",P=f(T),R=[];let X;for(p.lastIndex=0;(X=p.exec(j))!==null;){const Y=X[0],te=C[Y];te&&te!==Y&&!m(P,X.index,X.index+Y.length)&&R.push({url:Y,expanded_url:te,display_url:(()=>{try{const fe=new URL(te);return fe.hostname+(fe.pathname.length>1?"/…":"")}catch{return te}})(),fromIndex:X.index,toIndex:X.index+Y.length})}return R.length===0?T:{...T,entities:{...T.entities||{},urls:[...((H=T.entities)==null?void 0:H.urls)||[],...R]}}});S||g(E)}).catch(N=>{S||d(N.message||"Failed to load tweet.")}).finally(()=>{S||o(!1)}),()=>{S=!0}},[e,t,n]),a)return s.jsx("div",{style:ee.loading,children:"Loading…"});if(u)return s.jsxs("div",{style:ee.error,children:["Error: ",u]});if(y.length===0)return null;const h=Lg(e,t,n);if(r==="tweet_thread")return s.jsx("div",{style:ee.threadOuter,children:y.map((x,S)=>s.jsx(Qu,{tweet:x,isInThread:!0,isLast:S===y.length-1,artifactMap:h},x.id||S))});const v=y[0];return v.is_article&&v.article?s.jsx(Og,{article:v.article,tweetAuthor:v.author,artifactMap:h,fullPage:l,onXArticle:i}):s.jsx("div",{style:ee.card,children:s.jsx(Qu,{tweet:v,isInThread:!1,isLast:!0,artifactMap:h})})}function Fg({src:e,mime:t,title:n}){const[r,l]=c.useState(null),[i,a]=c.useState(null);return c.useEffect(()=>{const o=new AbortController;return l(null),a(null),Gh(e,{signal:o.signal}).then(l).catch(u=>{u.name!=="AbortError"&&a(u.message||String(u))}),()=>o.abort()},[e]),i?s.jsxs("div",{className:"text-preview text-preview--error",children:["Failed to load text: ",i]}):r===null?s.jsx("div",{className:"text-preview text-preview--loading",children:"Loading…"}):s.jsxs("div",{className:"text-preview",children:[n&&s.jsx("h1",{className:"text-preview__title",children:n}),s.jsx("pre",{className:"text-preview__body",children:r}),t&&s.jsx("div",{className:"text-preview__mime",children:t})]})}const Bg=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),Ug=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),Hg=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]),Wg=new Set(["md","markdown","txt"]),Vg={mp4:"video/mp4",webm:"video/webm",mov:"video/quicktime",mkv:"video/x-matroska",avi:"video/x-msvideo",m4v:"video/mp4",ogv:"video/ogg"};function kf({archiveId:e,entry:t,detail:n,fullPage:r,onXArticle:l}){if(!t)return s.jsx("div",{className:"preview-panel preview-panel--empty",children:s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Select an entry to preview"})});if(!n)return s.jsx("div",{className:"preview-panel preview-panel--loading",children:s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Loading…"})});const{summary:i,artifacts:a}=n,o=i.entry_uid,u=i.entity_kind;if(u==="tweet"||u==="tweet_thread"){const v=s.jsx(Mg,{archiveId:e,entryUid:o,artifacts:a,entityKind:u,fullPage:r,onXArticle:l});return r?v:s.jsx("div",{className:"preview-tweet-wrap",children:v})}const d=a.findIndex(v=>v.artifact_role==="primary_media");if(d===-1)return s.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),a.length>0&&s.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:a.map((v,x)=>s.jsxs("li",{children:[v.artifact_role,": ",v.relpath]},x))})]});const y=a[d],g=`/api/archives/${e}/entries/${o}/artifacts/${d}`,h=y.relpath.split(".").pop().toLowerCase();return Bg.has(h)?s.jsx("div",{className:"preview-panel",children:s.jsx(Tg,{src:g,contentType:Vg[h]||"video/mp4"})}):Ug.has(h)?s.jsxs("div",{className:"preview-panel preview-panel--audio",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"12px",padding:"24px",fontFamily:"var(--sans)"},children:[s.jsx("span",{style:{fontSize:"2rem"},children:"🎵"}),s.jsx("span",{style:{color:"var(--ink)",fontSize:"0.95rem",fontWeight:600},children:i.title||o}),s.jsx("audio",{src:g,controls:!0,style:{marginTop:"8px",width:"100%",maxWidth:"400px"}})]}):h==="pdf"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx(Hu,{src:g,type:"pdf",title:i.title,originalUrl:i.original_url})}):h==="html"||h==="htm"?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0},children:s.jsx(Hu,{src:g,type:"page",title:i.title,originalUrl:i.original_url})}):Wg.has(h)?s.jsx("div",{className:"preview-panel",style:{flex:1,minHeight:0,overflow:"auto"},children:s.jsx(Fg,{src:g,mime:y.mime_type,title:i.title})}):Hg.has(h)?s.jsx("div",{className:"preview-panel",style:{height:"100%"},children:s.jsx(Pg,{src:g,alt:i.title||"Image"})}):s.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[s.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),s.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:a.map((v,x)=>s.jsxs("li",{children:[v.artifact_role,": ",v.relpath]},x))})]})}function Qg({archiveId:e,entry:t,detail:n,onClose:r}){var l,i;return c.useEffect(()=>{const a=o=>{o.key==="Escape"&&r()};return window.addEventListener("keydown",a),()=>window.removeEventListener("keydown",a)},[r]),s.jsx("div",{className:"preview-modal-backdrop",onClick:r,children:s.jsxs("div",{className:`preview-modal${((l=n==null?void 0:n.summary)==null?void 0:l.entity_kind)==="tweet"||((i=n==null?void 0:n.summary)==null?void 0:i.entity_kind)==="tweet_thread"?"":" preview-modal--full"}`,onClick:a=>a.stopPropagation(),children:[s.jsxs("div",{className:"preview-modal-header",children:[s.jsx("span",{className:"preview-modal-title",children:(t==null?void 0:t.title)||(t==null?void 0:t.entry_uid)||"Preview"}),s.jsx("a",{className:"preview-modal-newtab",href:`/preview/${e}/${t==null?void 0:t.entry_uid}`,target:"_blank",rel:"noopener noreferrer",title:"Open in new tab",children:"↗"}),s.jsx("button",{className:"preview-modal-close",onClick:r,"aria-label":"Close preview",children:"×"})]}),s.jsx("div",{className:"preview-modal-body",children:s.jsx(kf,{archiveId:e,entry:t,detail:n})})]})})}function qu(e){if(!isFinite(e)||isNaN(e))return"--:--";const t=Math.floor(e/60),n=Math.floor(e%60);return`${t}:${String(n).padStart(2,"0")}`}function qg({entry:e,src:t,archiveId:n,onClose:r}){const l=c.useRef(null),[i,a]=c.useState(!1),[o,u]=c.useState(0),[d,y]=c.useState(NaN),[g,h]=c.useState(1);c.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),y(NaN),a(!1))},[t]),c.useEffect(()=>{l.current&&(l.current.volume=g)},[g]);function v(){const f=l.current;f&&(i?f.pause():f.play().catch(()=>{}))}function x(f){const m=l.current;if(!m||!isFinite(d))return;const k=Number(f.target.value);m.currentTime=k,u(k)}function S(f){h(Number(f.target.value))}const N=(e==null?void 0:e.title)||(e==null?void 0:e.entry_uid)||"Unknown",p=(e==null?void 0:e.source_kind)||"other";return s.jsxs(s.Fragment,{children:[s.jsx("audio",{ref:l,src:t||void 0,preload:"auto",onPlay:()=>a(!0),onPause:()=>a(!1),onEnded:()=>a(!1),onTimeUpdate:()=>{var f;return u(((f=l.current)==null?void 0:f.currentTime)??0)},onLoadedMetadata:()=>{var f;return y(((f=l.current)==null?void 0:f.duration)??NaN)},onDurationChange:()=>{var f;return y(((f=l.current)==null?void 0:f.duration)??NaN)},style:{display:"none"}}),s.jsxs("div",{className:"audio-bar",style:{position:"fixed",bottom:0,left:0,right:0,zIndex:100,background:"var(--paper-3)",borderTop:"1px solid var(--line)",display:"flex",alignItems:"center",gap:"16px",padding:"0 16px",height:"56px",fontFamily:"var(--sans)"},children:[s.jsxs("div",{className:"audio-bar-info",style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0,flex:"0 1 220px",overflow:"hidden"},children:[s.jsx("span",{className:"source-icon",style:{flexShrink:0,width:"18px",height:"18px",display:"flex",alignItems:"center"},dangerouslySetInnerHTML:{__html:Ws(p)}}),s.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:N,children:N})]}),s.jsxs("div",{className:"audio-bar-controls",style:{display:"flex",alignItems:"center",gap:"10px",flex:"1 1 0",minWidth:0},children:[s.jsx("button",{onClick:v,"aria-label":i?"Pause":"Play",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--ink)",flexShrink:0,fontSize:"1.2rem",lineHeight:1},children:i?"⏸":"▶"}),s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:qu(o)}),s.jsx("input",{type:"range",min:0,max:isFinite(d)?d:0,step:.1,value:isFinite(o)?o:0,onChange:x,"aria-label":"Seek",style:{flex:1,minWidth:0,accentColor:"var(--accent)"}}),s.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:qu(d)})]}),s.jsxs("div",{className:"audio-bar-right",style:{display:"flex",alignItems:"center",gap:"8px",flex:"0 1 160px"},children:[s.jsx("span",{style:{fontSize:"0.85rem",color:"var(--muted)",flexShrink:0},children:"🔊"}),s.jsx("input",{type:"range",min:0,max:1,step:.01,value:g,onChange:S,"aria-label":"Volume",style:{width:"80px",accentColor:"var(--accent)"}}),s.jsx("button",{onClick:r,"aria-label":"Close audio player",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--muted)",fontSize:"1rem",lineHeight:1,marginLeft:"4px"},children:"✕"})]})]})]})}function Kg({archiveId:e,entryUid:t}){var h,v;const[n,r]=c.useState(null),[l,i]=c.useState(!0),[a,o]=c.useState(null),[u,d]=c.useState(!1);c.useEffect(()=>{if(!u)return;const x=document.documentElement,S=document.body,N=x.style.colorScheme,p=S.style.background;return x.style.colorScheme="dark",S.style.background="#000",()=>{x.style.colorScheme=N,S.style.background=p}},[u]),c.useEffect(()=>{d(!1),Br(e,t).then(x=>{r(x),i(!1)}).catch(x=>{o((x==null?void 0:x.message)||"Failed to load entry"),i(!1)})},[e,t]);const y=((h=n==null?void 0:n.summary)==null?void 0:h.title)||t,g=(v=n==null?void 0:n.summary)==null?void 0:v.original_url;return s.jsxs("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column",background:u?"#000":"var(--paper)",fontFamily:"var(--sans)"},children:[s.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:u?"8px 12px":"10px 16px",borderBottom:u?"none":"1px solid var(--line)",flexShrink:0,position:u?"sticky":"relative",top:0,zIndex:20,background:u?"rgba(0,0,0,0.82)":"var(--paper-2)",backdropFilter:u?"blur(12px)":"none",WebkitBackdropFilter:u?"blur(12px)":"none"},children:[s.jsx("a",{href:"/",style:{color:u?"#1d9bf0":"var(--accent)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"← Archive"}),s.jsx("span",{style:{flex:1,fontSize:"14px",fontWeight:600,color:u?"#e7e9ea":"var(--ink)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:y}),g&&s.jsx("a",{href:g,target:"_blank",rel:"noopener noreferrer",style:{color:u?"#71767b":"var(--muted)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"Original ↗"})]}),s.jsxs("div",{style:u?{flex:1}:{flex:1,minHeight:0,overflow:"auto",display:"flex",flexDirection:"column"},children:[l&&s.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},children:"Loading…"}),a&&s.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},children:a}),n&&s.jsx(kf,{archiveId:e,entry:n.summary,detail:n,fullPage:!0,onXArticle:d})]})]})}const Xg=7e3;function Jg({toasts:e,onDismiss:t,onIgnoreUblock:n}){return e.length?s.jsx("div",{className:"toast-stack",role:"log","aria-live":"polite","aria-label":"Notifications",children:e.map(r=>s.jsx(Yg,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function Gg(e){if(!e)return null;if(e.length<=52)return e;try{const{hostname:t,pathname:n,search:r}=new URL(e),l=n.split("/").filter(Boolean),i=(l[l.length-1]??"")+r,a=i?`${t}/…/${i}`:t;return a.length<=56?a:a.slice(0,53)+"…"}catch{return"…"+e.slice(-51)}}function Yg({toast:e,onDismiss:t,onIgnoreUblock:n}){const[r,l]=c.useState(!1),i=e.type==="warning",a=e.type==="success";c.useEffect(()=>{if(r)return;const u=setTimeout(()=>t(e.id),Xg);return()=>clearTimeout(u)},[r,e.id,t]);const o=Gg(e.locator);return a?s.jsx("div",{className:"toast toast--success",role:"alert","aria-atomic":"true",children:s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✓"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Archived"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsx("div",{className:"toast-btns",children:s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})})]})}):i?s.jsxs("div",{className:"toast toast--warning",role:"alert","aria-atomic":"true",children:[s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"⚠"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Archived with warnings"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsxs("div",{className:"toast-btns",children:[e.text&&s.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),"aria-expanded":r,children:r?"Hide":"Details"}),e.locator&&s.jsx("button",{type:"button",className:"toast-view-btn toast-ignore-btn",onClick:()=>{n==null||n(),t(e.id)},children:"Ignore"}),s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&s.jsx("p",{className:"toast-warning-detail",children:e.text||"The page was captured but one or more browser extensions were unavailable (ad-blocking or cookie-consent). Check ARCHIVR_UBLOCK_EXT and ARCHIVR_COOKIE_EXT in your server config."})]}):s.jsxs("div",{className:"toast toast--error",role:"alert","aria-atomic":"true",children:[s.jsxs("div",{className:"toast-top",children:[s.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✕"}),s.jsxs("div",{className:"toast-body",children:[s.jsx("span",{className:"toast-headline",children:e.headline||"Capture failed"}),o&&s.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),s.jsxs("div",{className:"toast-btns",children:[e.text&&s.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),children:r?"Hide":"View error"}),s.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&e.text&&s.jsx("pre",{className:"toast-error-detail",children:e.text})]})}const Vs=c.createContext(null),Zg=["archive","tags","collections","runs","admin","settings"],ey=["profile","tokens","instance","cookies","extensions","storage"],Dr=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})();function Ft(){const e=window.location.pathname.split("/").filter(Boolean),t=Zg.includes(e[0])?e[0]:"archive",n=t==="settings"&&ey.includes(e[1])?e[1]:"profile",r=new URLSearchParams(window.location.search),l=r.get("q")??"",i=t==="archive"?r.get("tag")??null:null,a=t==="archive"?r.get("entry")??null:null,o=t==="archive"?r.get("collection")??null:null,u=o==="main"?null:o,d=r.get("archive")??null;return{view:t,settingsTab:n,q:l,tag:i,entry:a,collection:u,archive:d}}function ty(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function ny(){const[e,t]=c.useState("loading"),[n,r]=c.useState(null);c.useEffect(()=>{(async()=>{var A,Q,J;if(await dm()){t("setup");return}const z=await mm();if(!z){const{collection:le,archive:_e}=Ft();try{const Ue=await Ru(),ke=_e?((A=Ue.find(qn=>qn.id===_e))==null?void 0:A.id)??((Q=Ue[0])==null?void 0:Q.id):(J=Ue[0])==null?void 0:J.id;if(ke){await zu(ke,le),i(Ue),o(ke),d(le),t("authenticated");return}}catch{}t("login");return}r(z),t("authenticated")})()},[]),c.useEffect(()=>{const _=()=>{n&&(r(null),t("login"))};return window.addEventListener("auth:expired",_),()=>window.removeEventListener("auth:expired",_)},[n]),c.useEffect(()=>{const _=()=>{const{view:z,settingsTab:A,q:Q,tag:J,entry:le,collection:_e}=Ft();P(z),X(A),Y(Q),T(J),p(le),m(null),C(le?new Set([le]):new Set),d(_e)};return window.addEventListener("popstate",_),()=>window.removeEventListener("popstate",_)},[]);const[l,i]=c.useState([]),[a,o]=c.useState(null),[u,d]=c.useState(()=>Ft().collection),[y,g]=c.useState([]),[h,v]=c.useState([]),[x,S]=c.useState(()=>new Set),[N,p]=c.useState(()=>Ft().entry),[f,m]=c.useState(null),[k,C]=c.useState(()=>{const _=Ft().entry;return _?new Set([_]):new Set}),[E,T]=c.useState(()=>Ft().tag),[j,P]=c.useState(()=>Ft().view),[R,X]=c.useState(()=>Ft().settingsTab),[H,Y]=c.useState(()=>Ft().q),[te,fe]=c.useState(""),[Be,we]=c.useState(!1),[M,L]=c.useState([]),[V,G]=c.useState([]),[ne,se]=c.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[Z,Se]=c.useState([]),ce=c.useRef(0),[Ie,at]=c.useState(()=>{try{const _=JSON.parse(sessionStorage.getItem("pendingCaptures")||"[]");if(Array.isArray(_))return _}catch{}return[]});c.useEffect(()=>{sessionStorage.setItem("pendingCaptures",JSON.stringify(Ie))},[Ie]);const[ht,Vt]=c.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[Qt,jt]=c.useState(null),Oe=c.useRef(0),Je=c.useRef(null),tt=c.useRef(!1),D=c.useRef(!0),K=c.useRef(null),Ne=c.useRef(0),Ve=c.useRef(new Map),qt=(n==null?void 0:n.humanize_slugs)??!1;c.useEffect(()=>{const _=++Oe.current;jt(null),!(!f||!a)&&Br(a,f.entry_uid).then(z=>{_===Oe.current&&jt(z)}).catch(()=>{})},[f,a]),c.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",ne)},[ne]);const Qe=c.useCallback(async(_,z,A,Q)=>{if(_){we(!0);try{let J;z||A?J=await Kh(_,z,A,Q):J=await zu(_,Q),v(J),C(le=>{if(le.size<2)return le;const _e=new Set(J.map(ke=>ke.entry_uid)),Ue=new Set([...le].filter(ke=>_e.has(ke)));return Ue.size===le.size?le:Ue}),fe(J.length===0?"No results":`${J.length} result${J.length===1?"":"s"}`)}catch{v([]),fe("Search failed. Try again.")}finally{we(!1)}}},[]);c.useEffect(()=>{e==="authenticated"&&(a||Ru().then(_=>{if(i(_),_.length>0){const{archive:z}=Ft(),A=z?_.find(Q=>Q.id===z):null;o((A==null?void 0:A.id)??_[0].id)}}))},[e,a]),c.useEffect(()=>{if(!a)return;const _=!n;if(D.current){D.current=!1;const A=[];_||(A.push(_i(a).then(L)),A.push(Ul(a).then(G))),A.length&&Promise.all(A);return}T(null),m(null),p(null),C(new Set),d(null);const z=[Qe(a,"",null,null)];_||(z.push(_i(a).then(L)),z.push(Ul(a).then(G))),Promise.all(z)},[a,n]),c.useEffect(()=>{if(a===null)return;const _=setTimeout(()=>{Qe(a,H,E,u)},300);return()=>clearTimeout(_)},[H,a,u]),c.useEffect(()=>{a!==null&&(E!==null&&P("archive"),Qe(a,H,E,u))},[E,a,u]);const Kt=c.useCallback(_=>{o(_),d(null);const z=new URLSearchParams(window.location.search);z.set("archive",_),z.delete("collection");const A=z.toString();history.replaceState(null,"",window.location.pathname+(A?"?"+A:""))},[]);c.useEffect(()=>{if(!a){g([]);return}wo(a).then(g).catch(()=>g([]))},[a]);const Qn=c.useCallback(_=>{if(!n){const Q=_?y.find(J=>J.collection_uid===_):y.find(J=>J.slug==="_default_");if(Q!=null&&Q.requires_auth){t("login");return}}d(_),m(null),p(null),C(new Set),Qe(a,H,E,_);const z=new URLSearchParams(window.location.search);_?(z.set("collection",_),z.set("archive",a)):(z.delete("collection"),a&&z.set("archive",a));const A=z.toString();history.replaceState(null,"",window.location.pathname+(A?"?"+A:""))},[a,H,E,n,y,Qe]),Ot=c.useCallback(_=>{P(_),_==="tags"&&a&&Ul(a).then(G)},[a]);c.useEffect(()=>{if(Dr)return;const _=ty(j,R);window.location.pathname!==_&&history.pushState(null,"",_+window.location.search)},[j,R]);const Le=c.useCallback(_=>{p(_?_.entry_uid:null),m(_)},[]),bn=c.useCallback((_,z)=>{if(Ve.current.set(_.entry_uid,_),++Ne.current,z.shiftKey&&K.current!==null){z.preventDefault();const A=[...document.querySelectorAll("#entries-body [data-entry-uid]")],Q=A.findIndex(ke=>ke.dataset.entryUid===K.current),J=A.findIndex(ke=>ke.dataset.entryUid===_.entry_uid);if(Q===-1||J===-1){K.current=_.entry_uid,C(new Set([_.entry_uid])),Le(_);return}const le=Math.min(Q,J),_e=Math.max(Q,J),Ue=new Set(A.slice(le,_e+1).map(ke=>ke.dataset.entryUid));C(Ue),Ue.size===1&&Le(_)}else if(z.ctrlKey||z.metaKey){K.current=_.entry_uid;const A=new Set(k);if(A.has(_.entry_uid)?A.delete(_.entry_uid):A.add(_.entry_uid),C(A),A.size===0)Le(null);else if(A.size===1){const[Q]=A,J=Ve.current.get(Q)??h.find(le=>le.entry_uid===Q)??null;if(J)Le(J);else{const le=++Ne.current;Br(a,Q).then(_e=>{le===Ne.current&&(_e!=null&&_e.summary)&&Le(_e.summary)}).catch(()=>{})}}else Le(null)}else K.current=_.entry_uid,C(new Set([_.entry_uid])),Le(_)},[h,k,Le,a]),At=c.useCallback(_=>{T(_)},[]),w=c.useCallback(()=>{T(null)},[]),B=c.useCallback(()=>{a&&Ul(a).then(G)},[a]),O=c.useCallback((_,z)=>{E===_?T(z):E!=null&&E.startsWith(_+"/")&&T(z+E.slice(_.length))},[E]),$=c.useCallback(_=>{(E===_||E!=null&&E.startsWith(_+"/"))&&T(null)},[E]),F=c.useCallback((_,z)=>{v(A=>A.map(Q=>Q.entry_uid===_?{...Q,title:z}:Q)),m(A=>A&&A.entry_uid===_?{...A,title:z}:A),jt(A=>A&&A.summary.entry_uid===_?{...A,summary:{...A.summary,title:z}}:A)},[]),U=c.useCallback(()=>{if(!a||!f)return;const _=++Oe.current;Br(a,f.entry_uid).then(z=>{_===Oe.current&&jt(z)}).catch(()=>{})},[a,f]),ye=c.useCallback(_=>{const z=h.some(A=>A.entry_uid===_);S(A=>{const Q=new Set(A);return Q.add(_),Q}),v(A=>A.filter(Q=>Q.entry_uid!==_)),m(A=>(A==null?void 0:A.entry_uid)===_?null:A),p(A=>A===_?null:A),C(A=>{const Q=new Set(A);return Q.delete(_),Q}),z||Qe(a,H,E,u)},[h,a,H,E,u,Qe]),ue=c.useCallback(_=>{const z=new Set(h.map(Q=>Q.entry_uid)),A=[..._].some(Q=>!z.has(Q));S(Q=>{const J=new Set(Q);return _.forEach(le=>J.add(le)),J}),v(Q=>Q.filter(J=>!_.has(J.entry_uid))),C(new Set),m(null),p(null),A&&Qe(a,H,E,u)},[h,a,H,E,u,Qe]);c.useEffect(()=>{if(k.size>=2)p(null),m(null);else if(k.size===1){const[_]=k;p(_)}else p(null),m(null)},[k]);const Te=c.useMemo(()=>h.filter(_=>k.has(_.entry_uid)),[h,k]);c.useEffect(()=>{if(!N||f)return;const _=h.find(z=>z.entry_uid===N);_&&m(_)},[h,N,f]),c.useEffect(()=>{if(Dr)return;const _=new URLSearchParams(window.location.search).get("archive"),z=new URLSearchParams;H&&z.set("q",H),j==="archive"&&E&&z.set("tag",E),j==="archive"&&N&&z.set("entry",N),j==="archive"&&u?(z.set("collection",u),a&&z.set("archive",a)):_&&a&&z.set("archive",a);const A=z.toString(),Q=window.location.pathname+(A?"?"+A:"");window.location.pathname+window.location.search!==Q&&history.replaceState(null,"",Q)},[H,E,N,u,a,j]),c.useEffect(()=>{const _=z=>{var le,_e,Ue,ke;const A=z.key==="/"&&!z.metaKey&&!z.ctrlKey&&!z.altKey,Q=(z.metaKey||z.ctrlKey)&&z.key==="k";if(!A&&!Q)return;const J=(le=document.activeElement)==null?void 0:le.tagName;A&&(J==="INPUT"||J==="TEXTAREA"||J==="SELECT")||A&&((_e=document.activeElement)!=null&&_e.isContentEditable)||(z.preventDefault(),j==="archive"?((Ue=Je.current)==null||Ue.focus(),(ke=Je.current)==null||ke.select()):(tt.current=!0,P("archive")))};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[j]),c.useEffect(()=>{const _=z=>{var Er,b;if(z.metaKey||z.ctrlKey||z.altKey||z.key!=="j"&&z.key!=="k")return;const A=(Er=document.activeElement)==null?void 0:Er.tagName;if(A==="INPUT"||A==="TEXTAREA"||A==="SELECT"||(b=document.activeElement)!=null&&b.isContentEditable)return;const Q=[...document.querySelectorAll("#entries-body [data-entry-uid]")];if(Q.length===0)return;const[J]=k.size===1?k:[null],le=J?Q.findIndex(q=>q.dataset.entryUid===J):-1,_e=z.key==="j"?Math.min(le+1,Q.length-1):Math.max(le-1,0);if(_e===le&&le!==-1)return;const Ue=Q[_e<0?0:_e],ke=Ue.dataset.entryUid;K.current=ke;const qn=++Ne.current;C(new Set([ke]));const Cr=Ve.current.get(ke)??h.find(q=>q.entry_uid===ke)??null;Cr?Le(Cr):Br(a,ke).then(q=>{qn===Ne.current&&(q!=null&&q.summary)&&Le(q.summary)}).catch(()=>{}),Ue.scrollIntoView({block:"nearest"}),z.preventDefault()};return document.addEventListener("keydown",_),()=>document.removeEventListener("keydown",_)},[k,h,Le,a]),c.useEffect(()=>{j==="archive"&&tt.current&&(tt.current=!1,requestAnimationFrame(()=>{var _,z;(_=Je.current)==null||_.focus(),(z=Je.current)==null||z.select()}))},[j]);const pe=c.useCallback(()=>{se(!0)},[]),$e=c.useCallback(()=>{se(!1)},[]),ie=c.useCallback(()=>{if(a)return Promise.allSettled([Qe(a,H,E,u),_i(a).then(L)])},[a,H,E,u,Qe]),nt=c.useCallback((_,z,A="error",Q=null)=>{if(A==="warning"&&ht&&z)return;const J=++ce.current;Se(le=>[...le,{id:J,text:_,locator:z,type:A,headline:Q}])},[ht]),ot=c.useCallback(_=>{Se(z=>z.filter(A=>A.id!==_))},[]),Qs=c.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),Vt(!0),Se(_=>_.filter(z=>!(z.type==="warning"&&z.locator)))},[]),qs=c.useCallback(_=>{at(z=>[...z,_])},[]),Ks=c.useCallback(_=>{at(z=>z.filter(A=>A.id!==_))},[]),[Tn,_r]=c.useState(null),[Pn,jl]=c.useState(null),Sl=c.useCallback(()=>{f&&_r(f.entry_uid)},[f]),Xs=c.useCallback(()=>_r(null),[]),Js=c.useCallback((_,z)=>{jl({src:_,entry:z})},[]),Gs=c.useCallback(()=>jl(null),[]);return c.useEffect(()=>{_r(null)},[f]),c.useEffect(()=>{const _=z=>{var Q,J,le;if(z.key!=="Escape"||ne||Tn)return;const A=(Q=document.activeElement)==null?void 0:Q.tagName;A==="INPUT"||A==="TEXTAREA"||A==="SELECT"||k.size>0&&(z.preventDefault(),C(new Set),(le=(J=document.activeElement)==null?void 0:J.blur)==null||le.call(J))};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[ne,Tn,k]),c.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!Pn),()=>document.body.classList.remove("has-audio-bar")),[Pn]),Dr?s.jsx(Kg,{archiveId:Dr.archiveId,entryUid:Dr.entryUid}):e==="loading"?s.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?s.jsx(Hm,{onComplete:()=>t("login")}):e==="login"?s.jsx(Um,{onLogin:_=>{r(_),t("authenticated")}}):s.jsx(Vs.Provider,{value:{currentUser:n,setCurrentUser:r},children:s.jsxs(s.Fragment,{children:[s.jsx(Wm,{archives:l,archiveId:a,onArchiveChange:Kt,view:j,onViewChange:Ot,onCaptureClick:pe,collections:y,selectedCollectionUid:u,onCollectionChange:Qn,isPublicSession:!n,onSignInClick:()=>t("login")}),s.jsxs("main",{className:"app-shell",children:[s.jsxs("div",{className:"workspace",children:[j==="archive"&&s.jsxs("div",{className:"toolbar",children:[s.jsxs("div",{className:"search-field",children:[s.jsx("span",{className:"ico","aria-hidden":"true",children:s.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[s.jsx("circle",{cx:"11",cy:"11",r:"7"}),s.jsx("line",{x1:"16.5",y1:"16.5",x2:"21",y2:"21"})]})}),s.jsx("input",{ref:Je,className:"search-input",type:"search","aria-label":"Search archive","aria-busy":Be,placeholder:"Search titles, URLs, types, tags…",value:H,onChange:_=>Y(_.target.value)}),s.jsx("span",{className:"kbd",children:"⌘K"})]}),s.jsxs("span",{className:"result-count",children:[te&&s.jsxs(s.Fragment,{children:[s.jsx("b",{children:te.split(" ")[0]})," ",te.split(" ").slice(1).join(" ")]}),E&&s.jsxs("button",{className:"tag-filter-badge",onClick:w,children:["× ",qt?cf(E):E]})]})]}),j==="archive"&&s.jsx(sg,{entries:h,selectedUids:k,onRowClick:bn,archiveId:a,pendingCaptures:Ie,deletedUids:x,isPublicSession:!n}),j==="runs"&&s.jsx(og,{runs:M}),j==="admin"&&s.jsx(cg,{archives:l}),j==="tags"&&s.jsx(dg,{archiveId:a,tagNodes:V,tagFilter:E,onTagFilterSet:At,onViewChange:Ot,onTagRenamed:O,onTagDeleted:$,onTagsRefresh:B,humanizeTags:qt}),j==="collections"&&s.jsx(pg,{archiveId:a}),j==="settings"&&s.jsx(mg,{tab:R,onTabChange:X,archiveId:a})]}),s.jsx(Cg,{archiveId:a,selectedEntry:f,selectedUids:k,selectedEntries:Te,detail:Qt,onTagFilterSet:At,tagNodes:V,onTagsRefresh:B,onEntryTitleChange:F,onEntryDeleted:ye,onBulkDeleted:ue,humanizeTags:qt,onDetailRefresh:U,onOpenPreview:Sl,onPlay:Js,isPublicSession:!n})]}),Tn&&f&&f.entry_uid===Tn&&s.jsx(Qg,{archiveId:a,entry:f,detail:Qt,onClose:Xs}),Pn&&s.jsx(qg,{entry:Pn.entry,src:Pn.src,archiveId:a,onClose:Gs}),s.jsx(Km,{open:ne,archiveId:a,onClose:$e,onCaptured:ie,onToast:nt,activeJobs:Ie,onJobStarted:qs,onJobSettled:Ks}),s.jsx(Jg,{toasts:Z,onDismiss:ot,onIgnoreUblock:Qs})]})})}af(document.getElementById("root")).render(s.jsx(c.StrictMode,{children:s.jsx(ny,{})})); diff --git a/crates/archivr-server/static/index.html b/crates/archivr-server/static/index.html index 4af5c5f..3c6ab36 100644 --- a/crates/archivr-server/static/index.html +++ b/crates/archivr-server/static/index.html @@ -6,7 +6,7 @@ Archivr - + diff --git a/frontend/src/components/ContextRail.jsx b/frontend/src/components/ContextRail.jsx index ae7d635..b187a31 100644 --- a/frontend/src/components/ContextRail.jsx +++ b/frontend/src/components/ContextRail.jsx @@ -143,7 +143,8 @@ export default function ContextRail({ archiveId, selectedEntry, selectedUids, se summaryPollAbortRef.current = null summaryGenerateAbortRef.current?.abort() summaryGenerateAbortRef.current = null - const detailMatchesSelection = detail?.summary?.entry_uid === selectedEntry?.entry_uid + const detailMatchesSelection = selectedEntry?.entry_uid != null && + detail?.summary?.entry_uid === selectedEntry?.entry_uid setSummary(detailMatchesSelection ? detail.latest_summary ?? null : null) setSummaryAttempt(detailMatchesSelection ? detail.summary_attempt ?? null : null) setSummaryError('')