diff --git a/crates/archivr-server/static/assets/index-DekfKifP.js b/crates/archivr-server/static/assets/index-CGUwr6HO.js similarity index 98% rename from crates/archivr-server/static/assets/index-DekfKifP.js rename to crates/archivr-server/static/assets/index-CGUwr6HO.js index bdc3883..837dffb 100644 --- a/crates/archivr-server/static/assets/index-DekfKifP.js +++ b/crates/archivr-server/static/assets/index-CGUwr6HO.js @@ -42,6 +42,6 @@ ${J.map(H=>` ${H}`).join(` `)}`),L.length>0&&Ve.push(`With warnings: ${L.map(H=>` ${H}`).join(` `)}`);const z=Ve.length>0?Ve.join(` -`):null;f.current(z,null,We,X)}async function ce(j,C=null){if(!j.locator.trim())return;const F=t,A=j.locator.trim(),U=j.quality||"best";y(G=>G.map(Q=>Q.id===j.id?{...Q,status:"submitting",error:null}:Q));try{const Q=await Xp(F,A,U,{ublock_enabled:P,reader_mode:N,cookie_ext_enabled:S});y(J=>J.map(L=>L.id===j.id?{...L,status:"running",jobUid:Q.job_uid,archiveId:F}:L)),O(j.id,Q.job_uid,A,F,C)}catch(G){const Q=G.message||"Submission failed.";y(J=>J.map(L=>L.id===j.id?{...L,status:"failed",error:Q}:L)),f.current(Q,A),V(C,"failed",A)}}function re(){var F,A;const j=x.filter(U=>U.status==="idle"&&U.locator.trim());if(j.length===0)return;const C=j.length>1?((F=crypto.randomUUID)==null?void 0:F.call(crypto))??`batch-${Date.now()}`:null;C&&c.current.set(C,{total:j.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]}),j.forEach(U=>ce(U,C)),(A=s.current)==null||A.close()}function Z(){y(j=>[...j,Un()])}function je(j){clearTimeout(u.current.get(j)),u.current.delete(j),y(C=>{const F=C.filter(A=>A.id!==j);return F.length===0?[Un()]:F})}function Ee(j){y(C=>C.map(F=>F.id===j?{...F,status:"idle",error:null}:F))}function ye(j,C){if(clearTimeout(u.current.get(j)),y(A=>A.map(U=>U.id===j?{...U,locator:C,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best"}:U)),!Kc(C))return;const F=setTimeout(async()=>{u.current.delete(j),y(A=>A.map(U=>U.id===j?{...U,probeState:"probing"}:U));try{const A=await Jp(g.current,C.trim());y(U=>U.map(G=>{if(G.id!==j||G.locator!==C)return G;const Q=A.qualities??[],J=A.has_audio??!1,L=Q.length===0&&J?"audio":"best";return{...G,probeState:"done",probeQualities:Q,probeHasAudio:J,quality:L}}))}catch{y(A=>A.map(U=>U.id===j?{...U,probeState:"idle",probeQualities:null}:U))}},600);u.current.set(j,F)}function R(j,C){y(F=>F.map(A=>A.id===j?{...A,quality:C}:A))}const _=x.filter(j=>j.status==="idle"&&j.locator.trim()).length,b=Eo(x);return i.jsx("dialog",{ref:s,className:"capture-dialog",children:i.jsxs("div",{className:"capture-dialog-inner",children:[i.jsxs("div",{className:"capture-dialog-header",children:[i.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),i.jsx("button",{type:"button",className:"capture-dialog-close",onClick:()=>{var j;return(j=s.current)==null?void 0:j.close()},"aria-label":"Close",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),i.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),i.jsx("div",{className:"capture-rows",children:x.map((j,C)=>i.jsx(zh,{item:j,autoFocus:C===x.length-1&&j.status==="idle",onLocatorChange:F=>ye(j.id,F),onQualityChange:F=>R(j.id,F),onRemove:()=>je(j.id),onReset:()=>Ee(j.id),onSubmit:re},j.id))}),i.jsxs("button",{type:"button",className:"capture-add-row",onClick:Z,children:[i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),i.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add another"]}),i.jsxs("div",{className:"capture-advanced",children:[i.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>D(j=>!j),"aria-expanded":w,children:[i.jsx("svg",{className:`capture-chevron${w?" capture-chevron--open":""}`,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("polyline",{points:"4 6 8 10 12 6"})}),"Advanced options"]}),w&&i.jsxs("div",{className:"capture-advanced-panel",children:[i.jsxs("label",{className:"capture-ext-row",children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"uBlock Origin Lite"}),i.jsx("span",{className:"capture-ext-desc",children:"Block ads during this capture"})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":P,className:`ext-toggle ext-toggle--sm${P?" ext-toggle--on":""}`,onClick:()=>d(j=>j===null?!P:!j),"aria-label":"Toggle uBlock for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]}),i.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"Block cookie banners"}),i.jsx("span",{className:"capture-ext-desc",children:"Dismiss cookie consent banners during this capture"}),!(v!=null&&v.cookie_ext_available)&&i.jsxs("span",{className:"capture-ext-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})]})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":S,className:`ext-toggle ext-toggle--sm${S?" ext-toggle--on":""}`,onClick:()=>T(j=>!j),"aria-label":"Toggle cookie banner blocking for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]}),i.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"Reader mode"}),i.jsx("span",{className:"capture-ext-desc",children:"Distil to article text via Readability (off by default)"})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":N,className:`ext-toggle ext-toggle--sm${N?" ext-toggle--on":""}`,onClick:()=>M(j=>!j),"aria-label":"Toggle reader mode for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]})]})]}),i.jsxs("div",{className:"capture-actions",children:[i.jsx("button",{type:"button",className:"capture-submit",onClick:re,disabled:_===0,children:_>1?`Archive ${_}`:"Archive"}),i.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var j;return(j=s.current)==null?void 0:j.close()},children:b?"Close":"Cancel"})]})]})})}function zh({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onReset:s,onSubmit:a}){const o=p.useRef(null),u=e.status==="submitting"||e.status==="running";p.useEffect(()=>{var g;t&&e.status==="idle"&&((g=o.current)==null||g.focus())},[t]);const c=(()=>{if(e.status==="completed"||u||!Kc(e.locator))return null;if(e.probeState==="probing")return i.jsx("span",{className:"capture-quality-probing","aria-label":"Checking available qualities",children:"…"});if(e.probeState==="done"){const g=e.probeQualities??[],h=e.probeHasAudio??!1;return g.length===0&&!h?i.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):g.length===0&&h?i.jsx("select",{className:"capture-quality",value:"audio",onChange:f=>r(f.target.value),"aria-label":"Video quality",children:i.jsx("option",{value:"audio",children:"Audio only"})}):i.jsxs("select",{className:"capture-quality",value:e.quality||"best",onChange:f=>r(f.target.value),"aria-label":"Video quality",children:[i.jsx("option",{value:"best",children:"Best quality"}),g.map(f=>i.jsx("option",{value:f,children:f},f)),h&&i.jsx("option",{value:"audio",children:"Audio only"})]})}return null})();return i.jsxs("div",{className:`capture-row capture-row--${e.status}`,children:[i.jsxs("div",{className:"capture-row-main",children:[i.jsx(Dh,{status:e.status}),i.jsx("input",{ref:o,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:g=>n(g.target.value),onKeyDown:g=>{g.key==="Enter"&&a()},disabled:u||e.status==="completed",autoComplete:"off",spellCheck:!1}),c,e.status==="failed"&&i.jsx("button",{type:"button",className:"capture-row-action",onClick:s,title:"Retry",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M13 2.5A7 7 0 1 1 6.5 1"}),i.jsx("polyline",{points:"6.5 1 4 3.5 6.5 6"})]})}),!u&&e.status!=="completed"&&e.status!=="failed"&&i.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),i.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&i.jsx("p",{className:"capture-row-error",children:e.error})]})}function Dh({status:e}){return e==="submitting"||e==="running"?i.jsx("span",{className:"cap-dot cap-dot--running","aria-label":"Running",children:i.jsx("span",{className:"cap-spinner"})}):e==="completed"?i.jsx("span",{className:"cap-dot cap-dot--ok","aria-label":"Done",children:"✓"}):e==="failed"?i.jsx("span",{className:"cap-dot cap-dot--err","aria-label":"Failed",children:"✕"}):i.jsx("span",{className:"cap-dot cap-dot--idle","aria-hidden":"true"})}function gi(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 Kt(e){return $h(e)??""}function Xc(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 To={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function fa(e){return To[e]??To.other}function Jc(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function Oh({entry:e,archiveId:t,isSelected:n,onSelect:r}){const[l,s]=p.useState(!1),o=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!l?i.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>s(!0),style:{objectFit:"contain"}}):i.jsx("span",{dangerouslySetInnerHTML:{__html:fa(e.source_kind)}});return i.jsxs("div",{className:n?"is-selected":void 0,tabIndex:0,"data-entry-uid":e.entry_uid,onClick:r,onKeyDown:u=>{u.key==="Enter"&&r()},children:[i.jsx("div",{className:"col-added",children:Xc(e.archived_at)}),i.jsxs("div",{className:"col-title",children:[i.jsx("span",{className:"source-icon",children:o}),i.jsx("span",{className:"entry-title",children:Kt(e.title)||Kt(e.entry_uid)})]}),i.jsx("div",{className:"col-type",children:i.jsx("span",{className:"type-pill",children:Kt(e.entity_kind)})}),i.jsxs("div",{className:"col-size",children:[i.jsx("span",{className:"size-total",children:gi(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&i.jsxs("span",{className:"size-cached-pct",title:`${gi(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.total_artifact_bytes*100),"% cached"]})]}),i.jsx("div",{className:"url-cell col-url",children:Kt(e.original_url)})]})}function Ih({entries:e,selectedEntryUid:t,onSelectEntry:n,archiveId:r}){return i.jsx("section",{id:"archive-view",className:"view is-active",children:i.jsxs("div",{className:"entry-table",children:[i.jsxs("div",{className:"entry-header-row",children:[i.jsx("div",{className:"col-added",children:"Added"}),i.jsx("div",{className:"col-title",children:"Title"}),i.jsx("div",{className:"col-type",children:"Type"}),i.jsx("div",{className:"col-size",children:"Size"}),i.jsx("div",{className:"col-url",children:"Original URL"})]}),i.jsx("div",{id:"entries-body",children:e.map(l=>i.jsx(Oh,{entry:l,archiveId:r,isSelected:l.entry_uid===t,onSelect:()=>n(l)},l.entry_uid))})]})})}function Fh(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 Ah({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 i.jsx("span",{className:`run-status ${t}`,children:n})}function Mh({runs:e}){const[t,n]=p.useState(null);function r(l){n(s=>s===l?null:l)}return i.jsx("section",{id:"runs-view",className:"view is-active",children:i.jsxs("table",{className:"entry-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Started"}),i.jsx("th",{children:"Status"}),i.jsx("th",{children:"Requested"}),i.jsx("th",{children:"Completed"}),i.jsx("th",{children:"Failed"})]})}),i.jsx("tbody",{children:e.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:5,style:{color:"var(--muted)",padding:"24px 16px",textAlign:"center"},children:"No runs yet."})}):e.map(l=>{const s=l.status==="failed"&&l.error_summary,a=t===l.run_uid;return[i.jsxs("tr",{className:s?"run-row run-row--failed":"run-row",onClick:s?()=>r(l.run_uid):void 0,title:s?a?"Click to hide error":"Click to view error":void 0,children:[i.jsx("td",{children:Fh(l.started_at)}),i.jsxs("td",{children:[i.jsx(Ah,{status:l.status}),s&&i.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:a?"▴":"▾"})]}),i.jsx("td",{children:l.requested_count??"—"}),i.jsx("td",{children:l.completed_count??"—"}),i.jsx("td",{children:l.failed_count??"—"})]},l.run_uid),s&&a&&i.jsx("tr",{className:"run-error-row",children:i.jsx("td",{colSpan:5,children:i.jsx("pre",{className:"run-error-detail",children:l.error_summary})})},`${l.run_uid}-detail`)]})})]})})}const bh=4;function Bh({archives:e}){const{currentUser:t}=p.useContext(Hl)??{},n=t&&(t.role_bits&bh)!==0,[r,l]=p.useState("users"),[s,a]=p.useState([]),[o,u]=p.useState([]),[c,g]=p.useState(!1),[h,f]=p.useState(null),[x,y]=p.useState(""),[w,D]=p.useState(""),[m,d]=p.useState(""),[v,k]=p.useState(null),[S,T]=p.useState(!1),[P,N]=p.useState(""),[M,O]=p.useState(""),[V,ce]=p.useState(null),[re,Z]=p.useState(!1),je=p.useCallback(async()=>{if(n){g(!0),f(null);try{const[_,b]=await Promise.all([ah(),ch()]);a(_),u(b)}catch(_){f(_.message)}finally{g(!1)}}},[n]);p.useEffect(()=>{je()},[je]);async function Ee(_){const b=_.status==="active"?"disabled":"active";try{await uh(_.user_uid,b),a(j=>j.map(C=>C.user_uid===_.user_uid?{...C,status:b}:C))}catch(j){f(j.message)}}async function ye(_){if(_.preventDefault(),!x.trim()||!w){k("Username and password required");return}T(!0),k(null);try{await oh(x.trim(),w,m.trim()||void 0),y(""),D(""),d(""),await je()}catch(b){k(b.message)}finally{T(!1)}}async function R(_){if(_.preventDefault(),!P.trim()||!M.trim()){ce("Slug and name required");return}Z(!0),ce(null);try{await dh(P.trim(),M.trim()),N(""),O(""),await je()}catch(b){ce(b.message)}finally{Z(!1)}}return n?i.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[i.jsx("h1",{children:"Admin"}),i.jsxs("div",{className:"view-tabs",children:[i.jsx("button",{className:`view-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),i.jsx("button",{className:`view-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),i.jsx("button",{className:`view-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),h&&i.jsx("div",{className:"form-msg form-msg--err",children:h}),r==="users"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Users"}),c?i.jsx("p",{className:"muted",children:"Loading…"}):i.jsxs("table",{className:"admin-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Username"}),i.jsx("th",{children:"Email"}),i.jsx("th",{children:"Roles"}),i.jsx("th",{children:"Status"}),i.jsx("th",{children:"Actions"})]})}),i.jsx("tbody",{children:s.map(_=>i.jsxs("tr",{className:_.status==="disabled"?"admin-row-disabled":"",children:[i.jsx("td",{children:_.username}),i.jsx("td",{className:"muted",children:_.email||"—"}),i.jsx("td",{children:_.role_slugs.join(", ")||"—"}),i.jsx("td",{children:i.jsx("span",{className:`status-badge status-${_.status}`,children:_.status})}),i.jsx("td",{children:i.jsx("button",{className:"admin-action-btn",onClick:()=>Ee(_),children:_.status==="active"?"Ban":"Unban"})})]},_.user_uid))})]}),i.jsx("h3",{children:"Create User"}),i.jsxs("form",{className:"admin-form",onSubmit:ye,children:[i.jsx("input",{className:"admin-input",placeholder:"Username",value:x,onChange:_=>y(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:w,onChange:_=>D(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:m,onChange:_=>d(_.target.value)}),v&&i.jsx("div",{className:"form-msg form-msg--err",children:v}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:S,children:S?"Creating…":"Create User"})]})]}),r==="roles"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Roles"}),c?i.jsx("p",{className:"muted",children:"Loading…"}):i.jsxs("table",{className:"admin-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Slug"}),i.jsx("th",{children:"Name"}),i.jsx("th",{children:"Level"}),i.jsx("th",{children:"Bit"}),i.jsx("th",{children:"Built-in"})]})}),i.jsx("tbody",{children:o.map(_=>i.jsxs("tr",{children:[i.jsx("td",{children:i.jsx("code",{children:_.slug})}),i.jsx("td",{children:_.name}),i.jsx("td",{children:_.level}),i.jsx("td",{children:_.bit_position}),i.jsx("td",{children:_.is_builtin?"✓":""})]},_.role_uid))})]}),i.jsx("h3",{children:"Create Custom Role"}),i.jsxs("form",{className:"admin-form",onSubmit:R,children:[i.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:P,onChange:_=>N(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:M,onChange:_=>O(_.target.value),required:!0}),V&&i.jsx("div",{className:"form-msg form-msg--err",children:V}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:re,children:re?"Creating…":"Create Role"})]})]}),r==="archives"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Mounted Archives"}),i.jsx("div",{className:"admin-list",children:e.map(_=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:_.label}),i.jsx("div",{className:"muted",children:_.archive_path})]},_.id))})]})]}):i.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[i.jsx("h1",{children:"Admin"}),i.jsx("p",{className:"muted",children:"You need admin privileges to access this panel."}),i.jsx("h2",{children:"Mounted Archives"}),i.jsx("div",{className:"admin-list",children:e.map(_=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:_.label}),i.jsx("div",{className:"muted",children:_.archive_path})]},_.id))})]})}function Yc({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){var k;const c=n===e.tag.full_path,[g,h]=p.useState(!1),[f,x]=p.useState(""),y=p.useRef(!1);function w(){if(g)return;const S=c?null:e.tag.full_path;r(S),l("archive")}function D(S){S.stopPropagation(),x(e.tag.slug),h(!0)}async function m(){const S=f.trim();if(!S||S===e.tag.slug){h(!1);return}try{const T=await Qp(t,e.tag.tag_uid,S);s(e.tag.full_path,T.full_path),o()}catch{}finally{h(!1)}}async function d(S){var P;S.stopPropagation();const T=((P=e.children)==null?void 0:P.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(T))try{await Kp(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const v={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u};return i.jsxs("li",{children:[i.jsxs("div",{className:"tag-node-row",children:[g?i.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:f,onChange:S=>x(S.target.value),onKeyDown:S=>{S.key==="Enter"&&S.currentTarget.blur(),S.key==="Escape"&&(y.current=!0,S.currentTarget.blur())},onBlur:()=>{y.current?(y.current=!1,h(!1)):m()}}):i.jsxs("button",{className:`tag-node-btn${c?" is-active":""}`,title:e.tag.full_path,onClick:w,onDoubleClick:D,children:[u?e.tag.name:e.tag.slug,i.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",onClick:S=>{S.stopPropagation(),D(S)},children:i.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),i.jsx("button",{className:"remove tag-node-delete",title:`Delete tag ${e.tag.full_path}`,onClick:d,"aria-label":`Delete tag ${e.tag.full_path}`,children:"×"})]}),((k=e.children)==null?void 0:k.length)>0&&i.jsx("div",{className:"tag-children",children:i.jsx("ul",{className:"tag-tree-list",children:e.children.map(S=>i.jsx(Yc,{node:S,...v},S.tag.tag_uid))})})]})}function Uh({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){return i.jsx("section",{id:"tags-view",className:"view is-active",children:i.jsxs("div",{className:"tag-tree",children:[i.jsxs("div",{className:"tag-tree-header",children:[i.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&i.jsxs("span",{className:"tag-tree-active",children:["Filtering: ",n]})]}),t.length===0?i.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):i.jsx("ul",{className:"tag-tree-list",children:t.map(c=>i.jsx(Yc,{node:c,archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u},c.tag.tag_uid))})]})})}const Kn=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],Hh=e=>{var t;return((t=Kn.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function Wh({archiveId:e}){const[t,n]=p.useState([]),[r,l]=p.useState(!1),[s,a]=p.useState(null),[o,u]=p.useState(null),[c,g]=p.useState(null),[h,f]=p.useState(!1),[x,y]=p.useState(null),[w,D]=p.useState(""),[m,d]=p.useState(""),[v,k]=p.useState(2),[S,T]=p.useState(!1),[P,N]=p.useState(null),[M,O]=p.useState(""),[V,ce]=p.useState(2),[re,Z]=p.useState(!1),[je,Ee]=p.useState(null),[ye,R]=p.useState(!1),[_,b]=p.useState(""),j=p.useRef(null),C=t.find(z=>z.collection_uid===o)??null,F=(C==null?void 0:C.slug)==="_default_",A=p.useCallback(async()=>{if(e){l(!0),a(null);try{const z=await fh(e);n(z)}catch(z){a(z.message)}finally{l(!1)}}},[e]),U=p.useCallback(async z=>{if(!z){g(null);return}f(!0),y(null);try{const H=await hh(e,z);g(H)}catch(H){y(H.message)}finally{f(!1)}},[e]);p.useEffect(()=>{A()},[A]),p.useEffect(()=>{U(o)},[o,U]),p.useEffect(()=>{ye&&j.current&&j.current.focus()},[ye]);async function G(z){z.preventDefault();const H=w.trim(),Fe=m.trim();if(!(!H||!Fe)){T(!0),N(null);try{const dt=await ph(e,H,Fe,v);D(""),d(""),k(2),await A(),u(dt.collection_uid)}catch(dt){N(dt.message)}finally{T(!1)}}}async function Q(){const z=_.trim();if(!z||!C){R(!1);return}try{await Co(e,C.collection_uid,{name:z}),await A(),g(H=>H&&{...H,name:z})}catch(H){a(H.message)}finally{R(!1)}}async function J(z){if(C)try{await Co(e,C.collection_uid,{default_visibility_bits:z}),await A(),g(H=>H&&{...H,default_visibility_bits:z})}catch(H){a(H.message)}}async function L(){if(C&&window.confirm(`Delete collection "${C.name}"? Entries will not be deleted.`))try{await xh(e,C.collection_uid),u(null),g(null),await A()}catch(z){a(z.message)}}async function X(z){z.preventDefault();const H=M.trim();if(!(!H||!C)){Z(!0),Ee(null);try{await mh(e,C.collection_uid,H,V),O(""),await U(C.collection_uid)}catch(Fe){Ee(Fe.message)}finally{Z(!1)}}}async function We(z){if(C)try{await gh(e,C.collection_uid,z),await U(C.collection_uid)}catch(H){y(H.message)}}async function Ve(z,H){if(C)try{await vh(e,C.collection_uid,z,H),g(Fe=>Fe&&{...Fe,entries:Fe.entries.map(dt=>dt.entry_uid===z?{...dt,collection_visibility_bits:H}:dt)})}catch(Fe){y(Fe.message)}}return e?i.jsxs("div",{className:"collections-view",children:[i.jsx("h2",{className:"collections-heading",children:"Collections"}),r&&i.jsx("div",{className:"muted",children:"Loading…"}),s&&i.jsxs("div",{className:"collections-error",children:[s," ",i.jsx("button",{onClick:()=>a(null),className:"coll-dismiss",children:"×"})]}),i.jsxs("div",{className:"collections-layout",children:[i.jsxs("div",{className:"collections-sidebar",children:[t.map(z=>i.jsxs("button",{className:`coll-sidebar-row${o===z.collection_uid?" is-active":""}`,onClick:()=>u(z.collection_uid),children:[i.jsx("span",{className:"coll-row-name",children:z.name}),i.jsx("span",{className:"coll-row-meta",children:Hh(z.default_visibility_bits)})]},z.collection_uid)),t.length===0&&!r&&i.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),C?i.jsxs("div",{className:"coll-detail",children:[i.jsxs("div",{className:"coll-detail-header",children:[ye?i.jsx("input",{ref:j,className:"coll-rename-input",value:_,onChange:z=>b(z.target.value),onBlur:Q,onKeyDown:z=>{z.key==="Enter"&&Q(),z.key==="Escape"&&R(!1)}}):i.jsxs("h3",{className:`coll-detail-name${F?"":" coll-detail-name--editable"}`,title:F?void 0:"Click to rename",onClick:()=>{F||(b(C.name),R(!0))},children:[(c==null?void 0:c.name)??C.name,!F&&i.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!F&&i.jsx("button",{className:"coll-delete-btn",onClick:L,title:"Delete collection",children:"Delete"})]}),i.jsxs("div",{className:"coll-detail-vis",children:[i.jsx("span",{className:"coll-vis-label",children:"Default visibility"}),i.jsx("select",{className:"coll-vis-select",value:(c==null?void 0:c.default_visibility_bits)??C.default_visibility_bits,onChange:z=>J(Number(z.target.value)),disabled:F,children:Kn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.value))})]}),i.jsxs("div",{className:"coll-entries-section",children:[i.jsx("div",{className:"coll-section-heading",children:"Entries"}),h&&i.jsx("div",{className:"muted",children:"Loading…"}),x&&i.jsx("div",{className:"collections-error",children:x}),!h&&c&&(c.entries.length===0?i.jsx("div",{className:"muted",children:"No entries in this collection."}):i.jsx("ul",{className:"coll-entries-list",children:c.entries.map(z=>i.jsxs("li",{className:"coll-entry-row",children:[i.jsxs("div",{className:"coll-entry-info",children:[i.jsx("span",{className:"coll-entry-title",children:z.title||z.entry_uid}),i.jsx("span",{className:"coll-entry-kind muted",children:z.source_kind})]}),i.jsxs("div",{className:"coll-entry-actions",children:[i.jsx("select",{className:"coll-entry-vis-select",value:z.collection_visibility_bits,onChange:H=>Ve(z.entry_uid,Number(H.target.value)),children:Kn.map(H=>i.jsx("option",{value:H.value,children:H.label},H.value))}),!F&&i.jsx("button",{className:"coll-entry-remove",onClick:()=>We(z.entry_uid),title:"Remove from collection",children:"×"})]})]},z.entry_uid))}))]}),!F&&i.jsxs("form",{className:"coll-add-entry-form",onSubmit:X,children:[i.jsx("div",{className:"coll-section-heading",children:"Add entry"}),i.jsxs("div",{className:"coll-add-entry-row",children:[i.jsx("input",{className:"coll-add-entry-input",type:"text",value:M,onChange:z=>O(z.target.value),placeholder:"entry_uid",required:!0}),i.jsx("select",{className:"coll-vis-select",value:V,onChange:z=>ce(Number(z.target.value)),children:Kn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.value))}),i.jsx("button",{className:"coll-add-btn",type:"submit",disabled:re,children:re?"…":"Add"})]}),je&&i.jsx("div",{className:"collections-error",style:{marginTop:4},children:je})]})]}):i.jsx("div",{className:"coll-detail coll-detail--empty",children:i.jsx("div",{className:"muted",children:"Select a collection to view details."})})]}),i.jsxs("details",{className:"coll-create-details",children:[i.jsx("summary",{children:"+ Create collection"}),i.jsxs("form",{className:"coll-create-form",onSubmit:G,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-name",children:"Name"}),i.jsx("input",{className:"capture-input",id:"coll-name",type:"text",value:w,onChange:z=>{D(z.target.value),m||d(z.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),i.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:m,onChange:z=>d(z.target.value),placeholder:"my-collection",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),i.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:v,onChange:z=>k(Number(z.target.value)),children:Kn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.value))})]}),P&&i.jsx("div",{className:"collections-error",children:P}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:S,children:S?"Creating…":"Create collection"})]})]})]}):i.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const Vh=4;function Qh({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=p.useContext(Hl)??{},s=r&&(r.role_bits&Vh)!==0,a=["profile","tokens",...s?["instance","cookies","extensions","storage"]:[]],o={profile:"Profile",tokens:"API Tokens",instance:"Instance",cookies:"Cookies",extensions:"Extensions",storage:"Storage"};return i.jsxs("section",{className:"admin-view",children:[i.jsx("h1",{children:"Settings"}),i.jsx("div",{className:"view-tabs",children:a.map(u=>i.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:o[u]},u))}),e==="profile"&&i.jsx(Kh,{currentUser:r,setCurrentUser:l}),e==="tokens"&&i.jsx(Xh,{}),e==="instance"&&s&&i.jsx(Jh,{}),e==="cookies"&&s&&i.jsx(Gh,{}),e==="extensions"&&s&&i.jsx(qh,{}),e==="storage"&&s&&i.jsx(Yh,{archiveId:n})]})}function Kh({currentUser:e,setCurrentUser:t}){const[n,r]=p.useState((e==null?void 0:e.display_name)??""),[l,s]=p.useState(!1),[a,o]=p.useState(null),[u,c]=p.useState(""),[g,h]=p.useState(""),[f,x]=p.useState(""),[y,w]=p.useState(!1),[D,m]=p.useState(null);async function d(k){k.preventDefault(),s(!0),o(null);try{await th(n),t(S=>({...S,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(S){o({ok:!1,text:S.message})}finally{s(!1)}}async function v(k){if(k.preventDefault(),g!==f){m({ok:!1,text:"Passwords do not match."});return}w(!0),m(null);try{await rh(u,g),c(""),h(""),x(""),m({ok:!0,text:"Password changed."})}catch(S){m({ok:!1,text:S.message})}finally{w(!1)}}return i.jsxs("div",{style:{maxWidth:440},children:[i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Display Name"}),i.jsxs("form",{onSubmit:d,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),i.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:k=>r(k.target.value)})]}),a&&i.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Display Preferences"}),i.jsxs("label",{className:"checkbox-row",children:[i.jsx("input",{type:"checkbox",checked:(e==null?void 0:e.humanize_slugs)??!1,onChange:async k=>{const S=k.target.checked;try{await nh({humanize_slugs:S}),t(T=>({...T,humanize_slugs:S}))}catch{}}}),i.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),i.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Change Password"}),i.jsxs("form",{onSubmit:v,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),i.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:k=>c(k.target.value),required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),i.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:g,onChange:k=>h(k.target.value),required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"confirm-pw",children:"Confirm new password"}),i.jsx("input",{className:"field-input",id:"confirm-pw",type:"password",value:f,onChange:k=>x(k.target.value),required:!0})]}),D&&i.jsx("div",{className:`form-msg form-msg--${D.ok?"ok":"err"}`,children:D.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:y,children:y?"Changing…":"Change Password"})]})]})]})}function Xh(){const[e,t]=p.useState([]),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState(""),[u,c]=p.useState(!1),[g,h]=p.useState(null),f=p.useCallback(async()=>{r(!0),s(null);try{t(await lh())}catch(w){s(w.message)}finally{r(!1)}},[]);p.useEffect(()=>{f()},[f]);async function x(w){if(w.preventDefault(),!!a.trim()){c(!0);try{const D=await sh(a.trim());h(D),o(""),f()}catch(D){s(D.message)}finally{c(!1)}}}async function y(w){try{await ih(w),t(D=>D.filter(m=>m.token_uid!==w))}catch(D){s(D.message)}}return i.jsx("div",{style:{maxWidth:600},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"API Tokens"}),g&&i.jsxs("div",{className:"token-banner",children:[i.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",i.jsx("code",{children:g.raw_token}),i.jsx("button",{className:"token-dismiss",onClick:()=>h(null),children:"Dismiss"})]}),i.jsxs("form",{className:"token-create-row",onSubmit:x,children:[i.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:w=>o(w.target.value),required:!0}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:u,children:u?"Creating…":"Create token"})]}),l&&i.jsx("div",{className:"form-msg form-msg--err",children:l}),n?i.jsx("div",{className:"muted",children:"Loading…"}):i.jsxs("div",{children:[e.length===0&&i.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(w=>i.jsxs("div",{className:"token-row",children:[i.jsxs("div",{className:"token-row-info",children:[i.jsx("strong",{children:w.name}),i.jsxs("div",{className:"muted",children:["Created ",w.created_at.slice(0,10),w.last_used_at&&` · Last used ${w.last_used_at.slice(0,10)}`]})]}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>y(w.token_uid),children:"Revoke"})]},w.token_uid))]})]})})}function Jh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState(!1),[u,c]=p.useState(null);p.useEffect(()=>{(async()=>{try{t(await da())}catch(h){s(h.message)}finally{r(!1)}})()},[]);async function g(h){h.preventDefault(),o(!0),c(null);try{await hi(e),c({ok:!0,text:"Saved."})}catch(f){c({ok:!1,text:f.message})}finally{o(!1)}}return n?i.jsx("div",{className:"muted",children:"Loading…"}):l?i.jsx("div",{className:"form-msg form-msg--err",children:l}):e?i.jsx("div",{style:{maxWidth:440},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Instance Settings"}),i.jsxs("form",{onSubmit:g,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([h,f])=>i.jsxs("label",{className:"checkbox-row",children:[i.jsx("input",{type:"checkbox",checked:!!e[h],onChange:x=>t(y=>({...y,[h]:x.target.checked}))}),f]},h)),i.jsxs("div",{className:"form-field",style:{marginTop:4},children:[i.jsx("label",{className:"form-label",children:"Default entry visibility"}),i.jsxs("select",{className:"field-input",value:e.default_entry_visibility,onChange:h=>t(f=>({...f,default_entry_visibility:Number(h.target.value)})),children:[i.jsx("option",{value:0,children:"Private"}),i.jsx("option",{value:2,children:"Unlisted"}),i.jsx("option",{value:3,children:"Public"})]})]}),u&&i.jsx("div",{className:`form-msg form-msg--${u.ok?"ok":"err"}`,children:u.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:a,children:a?"Saving…":"Save Settings"})]})]})}):null}function ys(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 Yh({archiveId:e}){const[t,n]=p.useState("idle"),[r,l]=p.useState(null),[s,a]=p.useState(null),[o,u]=p.useState(null);function c(){n("idle"),l(null),a(null),u(null)}async function g(){n("scanning"),u(null),l(null);try{const x=await wh(e);l(x),n("scanned")}catch(x){u(x.message),n("error")}}async function h(){n("deleting"),u(null);try{const x=await kh(e);a(x),n("done")}catch(x){u(x.message),n("error")}}const f=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return i.jsx("div",{style:{maxWidth:440},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Orphan Cleanup"}),i.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."," ",i.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&i.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&i.jsx("button",{className:"btn-ghost",onClick:g,children:"Scan for orphaned blobs"}),t==="scanning"&&i.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&f&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"form-msg form-msg--ok",children:"Archive is clean — nothing to remove."}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Done"})]}),t==="scanned"&&r&&!f&&i.jsxs("div",{children:[i.jsxs("div",{style:{marginBottom:14,lineHeight:1.6},children:["Found ",i.jsx("strong",{children:r.deletable_files})," unreferenced file",r.deletable_files!==1?"s":""," ","and ",i.jsx("strong",{children:r.orphaned_blob_rows})," orphaned DB record",r.orphaned_blob_rows!==1?"s":""," ","— ",i.jsx("strong",{children:ys(r.total_bytes)})," recoverable."]}),i.jsxs("div",{style:{display:"flex",gap:8},children:[i.jsxs("button",{className:"btn-danger",onClick:h,children:["Delete (",ys(r.total_bytes),")"]}),i.jsx("button",{className:"btn-ghost",onClick:c,children:"Cancel"})]})]}),t==="deleting"&&i.jsx("div",{className:"muted",children:"Deleting…"}),t==="done"&&s&&i.jsxs("div",{children:[i.jsxs("div",{className:"form-msg form-msg--ok",children:["Freed ",i.jsx("strong",{children:ys(s.freed_bytes)})," ","— removed ",s.deleted_files," file",s.deleted_files!==1?"s":""," ","and ",s.deleted_blob_rows," DB record",s.deleted_blob_rows!==1?"s":"","."]}),s.errors&&s.errors.length>0&&i.jsxs("div",{className:"form-msg form-msg--err",style:{marginTop:6},children:[s.errors.length," file",s.errors.length!==1?"s":""," could not be deleted."]}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Scan again"})]}),t==="error"&&i.jsxs("div",{children:[i.jsx("div",{className:"form-msg form-msg--err",children:o}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Try again"})]})]})})}function Gh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState("global"),[u,c]=p.useState(""),[g,h]=p.useState("{}"),[f,x]=p.useState(null),[y,w]=p.useState(!1),[D,m]=p.useState({});p.useEffect(()=>{d()},[]);async function d(){r(!0),s(null);try{t(await Sh())}catch(N){s(N.message)}finally{r(!1)}}async function v(N){N.preventDefault();try{JSON.parse(g)}catch{x({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}w(!0),x(null);try{await Nh(a==="global"?null:u.trim(),a,g),c(""),h("{}"),o("global"),x({ok:!0,text:"Rule added."}),await d()}catch(M){x({ok:!1,text:M.message})}finally{w(!1)}}async function k(N){try{await Ch(N),await d()}catch(M){s(M.message)}}function S(N){m(M=>({...M,[N.rule_uid]:{cookiesInput:N.cookies_json,saving:!1,msg:null}}))}function T(N){m(M=>{const O={...M};return delete O[N],O})}async function P(N){const M=D[N.rule_uid];try{JSON.parse(M.cookiesInput)}catch{m(O=>({...O,[N.rule_uid]:{...O[N.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}m(O=>({...O,[N.rule_uid]:{...O[N.rule_uid],saving:!0,msg:null}}));try{await _h(N.rule_uid,{cookies_json:M.cookiesInput}),T(N.rule_uid),await d()}catch(O){m(V=>({...V,[N.rule_uid]:{...V[N.rule_uid],saving:!1,msg:{ok:!1,text:O.message}}}))}}return n?i.jsx("div",{className:"muted",children:"Loading…"}):l?i.jsx("div",{className:"form-msg form-msg--err",children:l}):i.jsx("div",{style:{maxWidth:560},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Cookie Rules"}),i.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?i.jsxs("table",{className:"data-table",style:{width:"100%",marginBottom:16},children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Pattern"}),i.jsx("th",{children:"Cookies"}),i.jsx("th",{style:{width:100},children:"Actions"})]})}),i.jsx("tbody",{children:e.map(N=>{const M=D[N.rule_uid],O=N.url_pattern?i.jsxs(i.Fragment,{children:[i.jsxs("span",{className:"muted",children:[N.pattern_kind,":"]})," ",i.jsx("code",{children:N.url_pattern})]}):i.jsx("span",{className:"muted",children:"global (all URLs)"});return i.jsxs("tr",{children:[i.jsx("td",{children:O}),i.jsx("td",{children:M?i.jsxs(i.Fragment,{children:[i.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:M.cookiesInput,onChange:V=>m(ce=>({...ce,[N.rule_uid]:{...ce[N.rule_uid],cookiesInput:V.target.value}}))}),M.msg&&i.jsx("div",{className:`form-msg form-msg--${M.msg.ok?"ok":"err"}`,children:M.msg.text}),i.jsxs("div",{style:{display:"flex",gap:8,marginTop:4},children:[i.jsx("button",{className:"btn-primary",style:{fontSize:12,padding:"2px 8px"},disabled:M.saving,onClick:()=>P(N),children:M.saving?"Saving…":"Save"}),i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>T(N.rule_uid),children:"Cancel"})]})]}):i.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:N.cookies_json})}),i.jsx("td",{children:!M&&i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>S(N),children:"Edit"}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>k(N.rule_uid),children:"Del"})]})})]},N.rule_uid)})})]}):i.jsx("p",{className:"muted",style:{marginBottom:16},children:"No cookie rules defined."}),i.jsx("h3",{style:{marginBottom:8},children:"Add Rule"}),i.jsxs("form",{onSubmit:v,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:"Pattern type"}),i.jsxs("select",{className:"field-input",value:a,onChange:N=>o(N.target.value),children:[i.jsx("option",{value:"global",children:"Global (all URLs)"}),i.jsx("option",{value:"wildcard",children:"Wildcard (e.g. *.youtube.com)"}),i.jsx("option",{value:"regex",children:"Regex (matched against full URL)"})]})]}),a!=="global"&&i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:a==="wildcard"?"URL/hostname pattern":"Regex pattern"}),i.jsx("input",{className:"field-input",type:"text",value:u,onChange:N=>c(N.target.value),placeholder:a==="wildcard"?"*.youtube.com or https://example.com/*":".*\\.youtube\\.com.*",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:"Cookies (JSON object)"}),i.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:13,minHeight:70},value:g,onChange:N=>h(N.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),f&&i.jsx("div",{className:`form-msg form-msg--${f.ok?"ok":"err"}`,children:f.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:y,children:y?"Adding…":"Add Rule"})]})]})})}function qh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(!1),[a,o]=p.useState(null);p.useEffect(()=>{(async()=>{try{t(await da())}catch(y){o({ok:!1,text:y.message})}finally{r(!1)}})()},[]);async function u(y){s(!0),o(null);try{await hi({ublock_enabled:y}),t(w=>({...w,ublock_enabled:y})),o({ok:!0,text:"Saved."})}catch(w){o({ok:!1,text:w.message})}finally{s(!1)}}async function c(y){s(!0),o(null);try{await hi({cookie_ext_enabled:y}),t(w=>({...w,cookie_ext_enabled:y})),o({ok:!0,text:"Saved."})}catch(w){o({ok:!1,text:w.message})}finally{s(!1)}}if(n)return i.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,f=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0;return i.jsx("div",{style:{maxWidth:560},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Extensions"}),i.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."}),i.jsx("div",{className:"ext-card",children:i.jsxs("div",{className:"ext-card-header",children:[i.jsxs("div",{className:"ext-card-info",children:[i.jsx("span",{className:"ext-card-name",children:"uBlock Origin Lite"}),i.jsx("span",{className:"ext-card-desc",children:"Blocks ads, trackers, and other page clutter during archiving via Chrome’s declarativeNetRequest API (Manifest V3)."}),!g&&i.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_UBLOCK_EXT"})," to the unpacked extension directory to enable."]})]}),i.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:i.jsx("span",{className:"ext-toggle-knob"})})]})}),i.jsx("div",{className:"ext-card",children:i.jsxs("div",{className:"ext-card-header",children:[i.jsxs("div",{className:"ext-card-info",children:[i.jsx("span",{className:"ext-card-name",children:"I Still Don’t Care About Cookies"}),i.jsx("span",{className:"ext-card-desc",children:"Dismiss cookie consent banners during archiving."}),!f&&i.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})," to the unpacked extension directory to enable."]})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":x,className:`ext-toggle${x?" ext-toggle--on":""}`,onClick:()=>c(!x),disabled:l,"aria-label":"Toggle I Still Don't Care About Cookies",children:i.jsx("span",{className:"ext-toggle-knob"})})]})}),a&&i.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text})]})})}const Po={0:"Private",1:"Public",2:"Users only",3:"Public"},Zh=()=>i.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function em({archiveId:e,selectedEntry:t,detail:n,onTagFilterSet:r,tagNodes:l,onTagsRefresh:s,onEntryTitleChange:a,onEntryDeleted:o,humanizeTags:u,onDetailRefresh:c,onOpenPreview:g,onPlay:h}){const[f,x]=p.useState([]),[y,w]=p.useState(""),[D,m]=p.useState([]),[d,v]=p.useState(""),k=p.useRef(0),S=p.useRef(!1),[T,P]=p.useState(!1),[N,M]=p.useState(""),[O,V]=p.useState("idle"),[ce,re]=p.useState(""),Z=p.useRef(null);p.useEffect(()=>{const L=++k.current;if(Z.current&&(clearInterval(Z.current),Z.current=null),V("idle"),re(""),!t||!e){x([]),m([]);return}P(!1),M(""),S.current=!1,x([]),Promise.all([Hr(e,t.entry_uid),yh(e,t.entry_uid)]).then(([X,We])=>{L===k.current&&(x(X),m(We))}).catch(()=>{})},[t,e]),p.useEffect(()=>()=>{clearInterval(Z.current)},[]);async function je(){const L=N.trim()||null;try{await Up(e,t.entry_uid,L),a==null||a(t.entry_uid,L)}catch{}finally{P(!1)}}async function Ee(){const L=y.trim();if(!(!L||!t))try{await Hp(e,t.entry_uid,L),w(""),v("");const X=await Hr(e,t.entry_uid);x(X),s()}catch(X){v(X.message)}}async function ye(L){try{await Wp(e,t.entry_uid,L);const X=await Hr(e,t.entry_uid);x(X),s()}catch{}}async function R(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await Vp(e,t.entry_uid),o==null||o(t.entry_uid)}catch{}}async function _(){if(!t||!e||O==="running")return;const L=k.current,X=t.entry_uid;V("running"),re("");try{const{job_uid:We}=await jh(e,X);if(k.current!==L)return;Z.current=setInterval(async()=>{try{const Ve=await Qc(e,We);if(Ve.status==="completed"){if(clearInterval(Z.current),Z.current=null,k.current!==L)return;V("done");const z=await Hr(e,X);if(k.current!==L)return;x(z),c==null||c()}else if(Ve.status==="failed"){if(clearInterval(Z.current),Z.current=null,k.current!==L)return;V("error"),re(Ve.error_text||"Re-archive failed.")}}catch{if(clearInterval(Z.current),Z.current=null,k.current!==L)return;V("error"),re("Network error while polling.")}},500)}catch(We){if(k.current!==L)return;V("error"),re(We.message||"Failed to start re-archive.")}}const b=n?[["Added",Xc(n.summary.archived_at)],["Source",n.summary.source_kind],["Type",n.summary.entity_kind],["Visibility",Po[n.summary.visibility]??n.summary.visibility],["Root",n.structured_root_relpath]]:[],j=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),C=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),F=n?n.artifacts.findIndex(L=>L.artifact_role==="primary_media"):-1,A=F>=0?n.artifacts[F]:null,U=A?A.relpath.split(".").pop().toLowerCase():"",G=A&&j.has(U),Q=F>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${F}`:null,J=n&&!G&&(n.summary.entity_kind==="tweet"||n.summary.entity_kind==="tweet_thread"||A&&C.has(U));return i.jsxs("aside",{className:"context-rail",children:[i.jsx("div",{className:"rail-eyebrow",children:"Context"}),t?n?i.jsxs(i.Fragment,{children:[T?i.jsx("input",{className:"rail-title-input",autoFocus:!0,value:N,onChange:L=>M(L.target.value),onKeyDown:L=>{L.key==="Enter"&&L.currentTarget.blur(),L.key==="Escape"&&(S.current=!0,L.currentTarget.blur())},onBlur:()=>{S.current?P(!1):je(),S.current=!1}}):i.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{M(n.summary.title??""),P(!0)},children:[Kt(n.summary.title)||Kt(n.summary.entry_uid),i.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:i.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),n.summary.original_url&&i.jsxs("a",{className:"url-tile",href:n.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[i.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:fa(n.summary.source_kind)}}),i.jsx("span",{className:"u-text",children:n.summary.original_url}),i.jsx("span",{className:"ext",children:i.jsx(Zh,{})})]}),G&&h&&i.jsx("button",{className:"rail-preview-btn",onClick:()=>h(Q,t),children:"▶ Play"}),J&&g&&i.jsx("button",{className:"rail-preview-btn",onClick:g,children:"Preview"}),i.jsx("div",{className:"meta-list",children:b.filter(([,L])=>L!=null&&L!=="").map(([L,X])=>i.jsxs("div",{className:"meta-item",children:[i.jsx("span",{className:"meta-k",children:L}),i.jsx("span",{className:`meta-v${L==="Root"?" mono":""}`,children:Kt(X)})]},L))}),n.artifacts.length>0&&i.jsxs("div",{className:"rail-section",children:[i.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",i.jsx("span",{className:"num",children:n.artifacts.length})]}),i.jsx("ul",{className:"artifact-list",children:n.artifacts.map((L,X)=>i.jsx("li",{children:i.jsxs("a",{href:`/api/archives/${e}/entries/${n.summary.entry_uid}/artifacts/${X}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[i.jsx("span",{className:"artifact-name",children:L.artifact_role.replace(/_/g," ")}),i.jsx("span",{className:"artifact-size",children:L.byte_size!=null?gi(L.byte_size):"—"})]})},X))})]})]}):i.jsx("p",{className:"tags-empty",children:"Loading…"}):i.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Tags"}),f.length===0?i.jsx("p",{className:"tags-empty",children:"No tags yet."}):i.jsx("div",{className:"tags-wrap",children:f.map(L=>i.jsxs("span",{className:"tag-pill",title:L.full_path,children:[u?Jc(L.full_path):L.full_path,i.jsx("button",{className:"remove",title:`Remove tag ${L.full_path}`,onClick:()=>ye(L.tag_uid),children:"×"})]},L.tag_uid))}),d&&i.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:d}),i.jsxs("div",{className:"tag-input-wrap",children:[i.jsx("span",{className:"hash",children:"/"}),i.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:y,onChange:L=>w(L.target.value),onKeyDown:L=>{L.key==="Enter"&&Ee()}}),i.jsx("button",{className:"tag-add-btn",onClick:Ee,children:"Add"})]})]}),D.length>0&&i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Collections"}),D.map(L=>i.jsxs("div",{className:"coll-row",children:[i.jsx("span",{className:"coll-name",children:L.collection_uid}),i.jsx("span",{className:"vis-badge",children:Po[L.visibility_bits]??`bits:${L.visibility_bits}`})]},L.collection_uid))]}),n&&(n.summary.entity_kind==="tweet"||n.summary.entity_kind==="tweet_thread")&&i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Actions"}),i.jsx("button",{className:"rail-rearchive-btn",onClick:_,disabled:O==="running",children:O==="running"?"Re-archiving…":"Re-archive"}),O==="done"&&i.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),O==="error"&&i.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:ce})]}),i.jsx("div",{className:"rail-delete-zone",children:i.jsx("button",{className:"rail-delete-btn",onClick:R,children:"Delete entry"})})]})]})}function tm({src:e}){const t=p.useRef(null);return p.useEffect(()=>{t.current&&t.current.load()},[e]),i.jsx("div",{className:"preview-video-wrap",style:{background:"#111",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",minHeight:"240px"},children:e?i.jsxs("video",{ref:t,controls:!0,autoPlay:!1,style:{width:"100%",maxHeight:"100%",display:"block"},children:[i.jsx("source",{src:e}),"Your browser does not support the video element."]}):i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function Lo({src:e,type:t}){return i.jsx("div",{className:"preview-iframe-wrap",style:{height:"100%",display:"flex",flexDirection:"column"},children:t==="page"?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"preview-iframe-toolbar",style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0},children:[i.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:e}),i.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{fontSize:"0.8rem",color:"var(--accent)",textDecoration:"none",whiteSpace:"nowrap",fontFamily:"var(--sans)"},children:"Open in new tab ↗"})]}),i.jsx("iframe",{src:e,sandbox:"allow-same-origin allow-popups",allow:"autoplay 'none'",referrerPolicy:"no-referrer",style:{flex:1,border:"none",width:"100%"},title:"Page preview"})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0,fontSize:"0.85rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:"PDF Document"}),i.jsx("iframe",{src:e,allow:"autoplay 'none'",style:{flex:1,border:"none",width:"100%"},title:"PDF preview"})]})})}function nm({src:e,alt:t}){return i.jsx("div",{className:"preview-image-wrap",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",background:"var(--paper-2)",overflow:"hidden"},children:i.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{display:"contents"},children:i.jsx("img",{src:e,alt:t||"",style:{objectFit:"contain",maxHeight:"100%",maxWidth:"100%",display:"block",cursor:"pointer"}})})})}function Gc(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}const B={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:"14px 14px 0"},aTweetTitle:{fontSize:"20px",fontWeight:"800",letterSpacing:"-0.3px",color:"var(--ink)",lineHeight:"1.3",marginBottom:"10px"},aAuthorRow:{display:"flex",alignItems:"center",gap:"8px",marginBottom:"10px"},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:"20px 0 8px"},bH2:{fontSize:"18px",fontWeight:"700",letterSpacing:"-0.2px",color:"var(--ink)",lineHeight:"1.3",margin:"18px 0 6px"},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:"20px 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)"}};function rm(e,t,n){const r={};return n&&n.forEach((l,s)=>{l.relpath&&(r[l.relpath]=`/api/archives/${e}/entries/${t}/artifacts/${s}`)}),r}function wr(e,t,n){return e&&n[e]?n[e]:t||null}function qc(){return i.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",style:{flexShrink:0,color:"var(--ink)"},children:i.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 lm(e,t){if(!e)return null;const n=(t.urls||[]).filter(o=>o.fromIndex!=null&&o.toIndex!=null),r=(t.user_mentions||[]).filter(o=>o.fromIndex!=null&&o.toIndex!=null);if(n.length===0&&r.length===0)return e;const l=[...n.map(o=>({s:o.fromIndex,e:o.toIndex,kind:"url",href:o.expanded_url,display:o.display_url})),...r.map(o=>({s:o.fromIndex,e:o.toIndex,kind:"mention",screen_name:o.screen_name}))],s=new Set([0,e.length]);for(const o of l)o.s>=0&&o.s<=e.length&&s.add(o.s),o.e>=0&&o.e<=e.length&&s.add(o.e);const a=[...s].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1],g=e.slice(o,c),h=l.filter(y=>y.s<=o&&y.e>=c),f=h.find(y=>y.kind==="url");if(f)return i.jsx("a",{href:f.href,target:"_blank",rel:"noopener noreferrer",style:B.link,children:f.display||g},u);const x=h.find(y=>y.kind==="mention");return x?i.jsx("a",{href:`https://x.com/${x.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:B.link,children:g},u):i.jsx("span",{children:g},u)})}function sm(e,t,n,r){if(!e)return null;t=t||[],n=n||[],r=r||[];const l=[];for(const o of t)o.length>0&&l.push({s:o.offset,e:o.offset+o.length,kind:"style",style:o.style});for(const o of n)l.push({s:o.fromIndex,e:o.toIndex,kind:"url",href:o.text});for(const o of r)l.push({s:o.fromIndex,e:o.toIndex,kind:"mention",name:o.text});if(l.length===0)return e;const s=new Set([0,e.length]);for(const o of l)o.s>=0&&o.s<=e.length&&s.add(o.s),o.e>=0&&o.e<=e.length&&s.add(o.e);const a=[...s].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1],g=l.filter(w=>w.s<=o&&w.e>=c),h=e.slice(o,c);let f;if(h.includes(` +`):null;f.current(z,null,We,X)}async function ce(j,C=null){if(!j.locator.trim())return;const F=t,A=j.locator.trim(),U=j.quality||"best";y(G=>G.map(Q=>Q.id===j.id?{...Q,status:"submitting",error:null}:Q));try{const Q=await Xp(F,A,U,{ublock_enabled:P,reader_mode:N,cookie_ext_enabled:S});y(J=>J.map(L=>L.id===j.id?{...L,status:"running",jobUid:Q.job_uid,archiveId:F}:L)),O(j.id,Q.job_uid,A,F,C)}catch(G){const Q=G.message||"Submission failed.";y(J=>J.map(L=>L.id===j.id?{...L,status:"failed",error:Q}:L)),f.current(Q,A),V(C,"failed",A)}}function re(){var F,A;const j=x.filter(U=>U.status==="idle"&&U.locator.trim());if(j.length===0)return;const C=j.length>1?((F=crypto.randomUUID)==null?void 0:F.call(crypto))??`batch-${Date.now()}`:null;C&&c.current.set(C,{total:j.length,archived:0,warnings:0,failed:0,failedLocators:[],warningLocators:[]}),j.forEach(U=>ce(U,C)),(A=s.current)==null||A.close()}function Z(){y(j=>[...j,Un()])}function je(j){clearTimeout(u.current.get(j)),u.current.delete(j),y(C=>{const F=C.filter(A=>A.id!==j);return F.length===0?[Un()]:F})}function Ee(j){y(C=>C.map(F=>F.id===j?{...F,status:"idle",error:null}:F))}function ye(j,C){if(clearTimeout(u.current.get(j)),y(A=>A.map(U=>U.id===j?{...U,locator:C,probeState:"idle",probeQualities:null,probeHasAudio:!1,quality:"best"}:U)),!Kc(C))return;const F=setTimeout(async()=>{u.current.delete(j),y(A=>A.map(U=>U.id===j?{...U,probeState:"probing"}:U));try{const A=await Jp(g.current,C.trim());y(U=>U.map(G=>{if(G.id!==j||G.locator!==C)return G;const Q=A.qualities??[],J=A.has_audio??!1,L=Q.length===0&&J?"audio":"best";return{...G,probeState:"done",probeQualities:Q,probeHasAudio:J,quality:L}}))}catch{y(A=>A.map(U=>U.id===j?{...U,probeState:"idle",probeQualities:null}:U))}},600);u.current.set(j,F)}function R(j,C){y(F=>F.map(A=>A.id===j?{...A,quality:C}:A))}const _=x.filter(j=>j.status==="idle"&&j.locator.trim()).length,b=Eo(x);return i.jsx("dialog",{ref:s,className:"capture-dialog",children:i.jsxs("div",{className:"capture-dialog-inner",children:[i.jsxs("div",{className:"capture-dialog-header",children:[i.jsx("h2",{className:"capture-dialog-title",children:"Capture"}),i.jsx("button",{type:"button",className:"capture-dialog-close",onClick:()=>{var j;return(j=s.current)==null?void 0:j.close()},"aria-label":"Close",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),i.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),i.jsx("div",{className:"capture-rows",children:x.map((j,C)=>i.jsx(zh,{item:j,autoFocus:C===x.length-1&&j.status==="idle",onLocatorChange:F=>ye(j.id,F),onQualityChange:F=>R(j.id,F),onRemove:()=>je(j.id),onReset:()=>Ee(j.id),onSubmit:re},j.id))}),i.jsxs("button",{type:"button",className:"capture-add-row",onClick:Z,children:[i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"8",y1:"2",x2:"8",y2:"14"}),i.jsx("line",{x1:"2",y1:"8",x2:"14",y2:"8"})]}),"Add another"]}),i.jsxs("div",{className:"capture-advanced",children:[i.jsxs("button",{type:"button",className:"capture-advanced-toggle",onClick:()=>D(j=>!j),"aria-expanded":w,children:[i.jsx("svg",{className:`capture-chevron${w?" capture-chevron--open":""}`,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("polyline",{points:"4 6 8 10 12 6"})}),"Advanced options"]}),w&&i.jsxs("div",{className:"capture-advanced-panel",children:[i.jsxs("label",{className:"capture-ext-row",children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"uBlock Origin Lite"}),i.jsx("span",{className:"capture-ext-desc",children:"Block ads during this capture"})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":P,className:`ext-toggle ext-toggle--sm${P?" ext-toggle--on":""}`,onClick:()=>d(j=>j===null?!P:!j),"aria-label":"Toggle uBlock for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]}),i.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"Block cookie banners"}),i.jsx("span",{className:"capture-ext-desc",children:"Dismiss cookie consent banners during this capture"}),!(v!=null&&v.cookie_ext_available)&&i.jsxs("span",{className:"capture-ext-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})]})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":S,className:`ext-toggle ext-toggle--sm${S?" ext-toggle--on":""}`,onClick:()=>T(j=>!j),"aria-label":"Toggle cookie banner blocking for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]}),i.jsxs("label",{className:"capture-ext-row",style:{marginTop:8},children:[i.jsxs("span",{className:"capture-ext-label",children:[i.jsx("span",{className:"capture-ext-name",children:"Reader mode"}),i.jsx("span",{className:"capture-ext-desc",children:"Distil to article text via Readability (off by default)"})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":N,className:`ext-toggle ext-toggle--sm${N?" ext-toggle--on":""}`,onClick:()=>M(j=>!j),"aria-label":"Toggle reader mode for this capture",children:i.jsx("span",{className:"ext-toggle-knob"})})]})]})]}),i.jsxs("div",{className:"capture-actions",children:[i.jsx("button",{type:"button",className:"capture-submit",onClick:re,disabled:_===0,children:_>1?`Archive ${_}`:"Archive"}),i.jsx("button",{type:"button",className:"capture-cancel",onClick:()=>{var j;return(j=s.current)==null?void 0:j.close()},children:b?"Close":"Cancel"})]})]})})}function zh({item:e,autoFocus:t,onLocatorChange:n,onQualityChange:r,onRemove:l,onReset:s,onSubmit:a}){const o=p.useRef(null),u=e.status==="submitting"||e.status==="running";p.useEffect(()=>{var g;t&&e.status==="idle"&&((g=o.current)==null||g.focus())},[t]);const c=(()=>{if(e.status==="completed"||u||!Kc(e.locator))return null;if(e.probeState==="probing")return i.jsx("span",{className:"capture-quality-probing","aria-label":"Checking available qualities",children:"…"});if(e.probeState==="done"){const g=e.probeQualities??[],h=e.probeHasAudio??!1;return g.length===0&&!h?i.jsx("span",{className:"capture-quality-hint",children:"No media detected"}):g.length===0&&h?i.jsx("select",{className:"capture-quality",value:"audio",onChange:f=>r(f.target.value),"aria-label":"Video quality",children:i.jsx("option",{value:"audio",children:"Audio only"})}):i.jsxs("select",{className:"capture-quality",value:e.quality||"best",onChange:f=>r(f.target.value),"aria-label":"Video quality",children:[i.jsx("option",{value:"best",children:"Best quality"}),g.map(f=>i.jsx("option",{value:f,children:f},f)),h&&i.jsx("option",{value:"audio",children:"Audio only"})]})}return null})();return i.jsxs("div",{className:`capture-row capture-row--${e.status}`,children:[i.jsxs("div",{className:"capture-row-main",children:[i.jsx(Dh,{status:e.status}),i.jsx("input",{ref:o,className:"capture-input",type:"text",placeholder:"https://… · yt:ID · ytm:ID · tweet:ID · x:ID",value:e.locator,onChange:g=>n(g.target.value),onKeyDown:g=>{g.key==="Enter"&&a()},disabled:u||e.status==="completed",autoComplete:"off",spellCheck:!1}),c,e.status==="failed"&&i.jsx("button",{type:"button",className:"capture-row-action",onClick:s,title:"Retry",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[i.jsx("path",{d:"M13 2.5A7 7 0 1 1 6.5 1"}),i.jsx("polyline",{points:"6.5 1 4 3.5 6.5 6"})]})}),!u&&e.status!=="completed"&&e.status!=="failed"&&i.jsx("button",{type:"button",className:"capture-row-action capture-row-remove",onClick:l,"aria-label":"Remove",children:i.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("line",{x1:"3",y1:"3",x2:"13",y2:"13"}),i.jsx("line",{x1:"13",y1:"3",x2:"3",y2:"13"})]})})]}),e.error&&i.jsx("p",{className:"capture-row-error",children:e.error})]})}function Dh({status:e}){return e==="submitting"||e==="running"?i.jsx("span",{className:"cap-dot cap-dot--running","aria-label":"Running",children:i.jsx("span",{className:"cap-spinner"})}):e==="completed"?i.jsx("span",{className:"cap-dot cap-dot--ok","aria-label":"Done",children:"✓"}):e==="failed"?i.jsx("span",{className:"cap-dot cap-dot--err","aria-label":"Failed",children:"✕"}):i.jsx("span",{className:"cap-dot cap-dot--idle","aria-hidden":"true"})}function gi(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 Kt(e){return $h(e)??""}function Xc(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 To={youtube:'',youtube_music:'',spotify:'',x:'',instagram:'',facebook:'',tiktok:'',reddit:'',snapchat:'',local:'',web:'',other:'?'};function fa(e){return To[e]??To.other}function Jc(e){return e.split("/").map(t=>t?t.split("-").map(n=>n.charAt(0).toUpperCase()+n.slice(1)).join(" "):"").join("/")}function Oh({entry:e,archiveId:t,isSelected:n,onSelect:r}){const[l,s]=p.useState(!1),o=e.source_kind==="web"&&e.entity_kind==="page"&&e.has_favicon&&t&&!l?i.jsx("img",{src:`/api/archives/${t}/entries/${e.entry_uid}/favicon`,width:"16",height:"16",alt:"",onError:()=>s(!0),style:{objectFit:"contain"}}):i.jsx("span",{dangerouslySetInnerHTML:{__html:fa(e.source_kind)}});return i.jsxs("div",{className:n?"is-selected":void 0,tabIndex:0,"data-entry-uid":e.entry_uid,onClick:r,onKeyDown:u=>{u.key==="Enter"&&r()},children:[i.jsx("div",{className:"col-added",children:Xc(e.archived_at)}),i.jsxs("div",{className:"col-title",children:[i.jsx("span",{className:"source-icon",children:o}),i.jsx("span",{className:"entry-title",children:Kt(e.title)||Kt(e.entry_uid)})]}),i.jsx("div",{className:"col-type",children:i.jsx("span",{className:"type-pill",children:Kt(e.entity_kind)})}),i.jsxs("div",{className:"col-size",children:[i.jsx("span",{className:"size-total",children:gi(e.total_artifact_bytes)}),e.cached_bytes>0&&e.total_artifact_bytes>0&&i.jsxs("span",{className:"size-cached-pct",title:`${gi(e.cached_bytes)} already on disk from an earlier entry`,children:[Math.round(e.cached_bytes/e.total_artifact_bytes*100),"% cached"]})]}),i.jsx("div",{className:"url-cell col-url",children:Kt(e.original_url)})]})}function Ih({entries:e,selectedEntryUid:t,onSelectEntry:n,archiveId:r}){return i.jsx("section",{id:"archive-view",className:"view is-active",children:i.jsxs("div",{className:"entry-table",children:[i.jsxs("div",{className:"entry-header-row",children:[i.jsx("div",{className:"col-added",children:"Added"}),i.jsx("div",{className:"col-title",children:"Title"}),i.jsx("div",{className:"col-type",children:"Type"}),i.jsx("div",{className:"col-size",children:"Size"}),i.jsx("div",{className:"col-url",children:"Original URL"})]}),i.jsx("div",{id:"entries-body",children:e.map(l=>i.jsx(Oh,{entry:l,archiveId:r,isSelected:l.entry_uid===t,onSelect:()=>n(l)},l.entry_uid))})]})})}function Fh(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 Ah({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 i.jsx("span",{className:`run-status ${t}`,children:n})}function Mh({runs:e}){const[t,n]=p.useState(null);function r(l){n(s=>s===l?null:l)}return i.jsx("section",{id:"runs-view",className:"view is-active",children:i.jsxs("table",{className:"entry-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Started"}),i.jsx("th",{children:"Status"}),i.jsx("th",{children:"Requested"}),i.jsx("th",{children:"Completed"}),i.jsx("th",{children:"Failed"})]})}),i.jsx("tbody",{children:e.length===0?i.jsx("tr",{children:i.jsx("td",{colSpan:5,style:{color:"var(--muted)",padding:"24px 16px",textAlign:"center"},children:"No runs yet."})}):e.map(l=>{const s=l.status==="failed"&&l.error_summary,a=t===l.run_uid;return[i.jsxs("tr",{className:s?"run-row run-row--failed":"run-row",onClick:s?()=>r(l.run_uid):void 0,title:s?a?"Click to hide error":"Click to view error":void 0,children:[i.jsx("td",{children:Fh(l.started_at)}),i.jsxs("td",{children:[i.jsx(Ah,{status:l.status}),s&&i.jsx("span",{className:"run-expand-hint","aria-hidden":"true",children:a?"▴":"▾"})]}),i.jsx("td",{children:l.requested_count??"—"}),i.jsx("td",{children:l.completed_count??"—"}),i.jsx("td",{children:l.failed_count??"—"})]},l.run_uid),s&&a&&i.jsx("tr",{className:"run-error-row",children:i.jsx("td",{colSpan:5,children:i.jsx("pre",{className:"run-error-detail",children:l.error_summary})})},`${l.run_uid}-detail`)]})})]})})}const bh=4;function Bh({archives:e}){const{currentUser:t}=p.useContext(Hl)??{},n=t&&(t.role_bits&bh)!==0,[r,l]=p.useState("users"),[s,a]=p.useState([]),[o,u]=p.useState([]),[c,g]=p.useState(!1),[h,f]=p.useState(null),[x,y]=p.useState(""),[w,D]=p.useState(""),[m,d]=p.useState(""),[v,k]=p.useState(null),[S,T]=p.useState(!1),[P,N]=p.useState(""),[M,O]=p.useState(""),[V,ce]=p.useState(null),[re,Z]=p.useState(!1),je=p.useCallback(async()=>{if(n){g(!0),f(null);try{const[_,b]=await Promise.all([ah(),ch()]);a(_),u(b)}catch(_){f(_.message)}finally{g(!1)}}},[n]);p.useEffect(()=>{je()},[je]);async function Ee(_){const b=_.status==="active"?"disabled":"active";try{await uh(_.user_uid,b),a(j=>j.map(C=>C.user_uid===_.user_uid?{...C,status:b}:C))}catch(j){f(j.message)}}async function ye(_){if(_.preventDefault(),!x.trim()||!w){k("Username and password required");return}T(!0),k(null);try{await oh(x.trim(),w,m.trim()||void 0),y(""),D(""),d(""),await je()}catch(b){k(b.message)}finally{T(!1)}}async function R(_){if(_.preventDefault(),!P.trim()||!M.trim()){ce("Slug and name required");return}Z(!0),ce(null);try{await dh(P.trim(),M.trim()),N(""),O(""),await je()}catch(b){ce(b.message)}finally{Z(!1)}}return n?i.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[i.jsx("h1",{children:"Admin"}),i.jsxs("div",{className:"view-tabs",children:[i.jsx("button",{className:`view-tab${r==="users"?" is-active":""}`,onClick:()=>l("users"),children:"Users"}),i.jsx("button",{className:`view-tab${r==="roles"?" is-active":""}`,onClick:()=>l("roles"),children:"Roles"}),i.jsx("button",{className:`view-tab${r==="archives"?" is-active":""}`,onClick:()=>l("archives"),children:"Archives"})]}),h&&i.jsx("div",{className:"form-msg form-msg--err",children:h}),r==="users"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Users"}),c?i.jsx("p",{className:"muted",children:"Loading…"}):i.jsxs("table",{className:"admin-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Username"}),i.jsx("th",{children:"Email"}),i.jsx("th",{children:"Roles"}),i.jsx("th",{children:"Status"}),i.jsx("th",{children:"Actions"})]})}),i.jsx("tbody",{children:s.map(_=>i.jsxs("tr",{className:_.status==="disabled"?"admin-row-disabled":"",children:[i.jsx("td",{children:_.username}),i.jsx("td",{className:"muted",children:_.email||"—"}),i.jsx("td",{children:_.role_slugs.join(", ")||"—"}),i.jsx("td",{children:i.jsx("span",{className:`status-badge status-${_.status}`,children:_.status})}),i.jsx("td",{children:i.jsx("button",{className:"admin-action-btn",onClick:()=>Ee(_),children:_.status==="active"?"Ban":"Unban"})})]},_.user_uid))})]}),i.jsx("h3",{children:"Create User"}),i.jsxs("form",{className:"admin-form",onSubmit:ye,children:[i.jsx("input",{className:"admin-input",placeholder:"Username",value:x,onChange:_=>y(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"password",placeholder:"Password (min 8 chars)",value:w,onChange:_=>D(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",type:"email",placeholder:"Email (optional)",value:m,onChange:_=>d(_.target.value)}),v&&i.jsx("div",{className:"form-msg form-msg--err",children:v}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:S,children:S?"Creating…":"Create User"})]})]}),r==="roles"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Roles"}),c?i.jsx("p",{className:"muted",children:"Loading…"}):i.jsxs("table",{className:"admin-table",children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Slug"}),i.jsx("th",{children:"Name"}),i.jsx("th",{children:"Level"}),i.jsx("th",{children:"Bit"}),i.jsx("th",{children:"Built-in"})]})}),i.jsx("tbody",{children:o.map(_=>i.jsxs("tr",{children:[i.jsx("td",{children:i.jsx("code",{children:_.slug})}),i.jsx("td",{children:_.name}),i.jsx("td",{children:_.level}),i.jsx("td",{children:_.bit_position}),i.jsx("td",{children:_.is_builtin?"✓":""})]},_.role_uid))})]}),i.jsx("h3",{children:"Create Custom Role"}),i.jsxs("form",{className:"admin-form",onSubmit:R,children:[i.jsx("input",{className:"admin-input",placeholder:"Slug (e.g. moderator)",value:P,onChange:_=>N(_.target.value),required:!0}),i.jsx("input",{className:"admin-input",placeholder:"Display Name (e.g. Moderator)",value:M,onChange:_=>O(_.target.value),required:!0}),V&&i.jsx("div",{className:"form-msg form-msg--err",children:V}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:re,children:re?"Creating…":"Create Role"})]})]}),r==="archives"&&i.jsxs("div",{className:"admin-section",children:[i.jsx("h2",{children:"Mounted Archives"}),i.jsx("div",{className:"admin-list",children:e.map(_=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:_.label}),i.jsx("div",{className:"muted",children:_.archive_path})]},_.id))})]})]}):i.jsxs("section",{id:"admin-view",className:"view admin-view is-active",children:[i.jsx("h1",{children:"Admin"}),i.jsx("p",{className:"muted",children:"You need admin privileges to access this panel."}),i.jsx("h2",{children:"Mounted Archives"}),i.jsx("div",{className:"admin-list",children:e.map(_=>i.jsxs("div",{className:"admin-archive",children:[i.jsx("strong",{children:_.label}),i.jsx("div",{className:"muted",children:_.archive_path})]},_.id))})]})}function Yc({node:e,archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){var k;const c=n===e.tag.full_path,[g,h]=p.useState(!1),[f,x]=p.useState(""),y=p.useRef(!1);function w(){if(g)return;const S=c?null:e.tag.full_path;r(S),l("archive")}function D(S){S.stopPropagation(),x(e.tag.slug),h(!0)}async function m(){const S=f.trim();if(!S||S===e.tag.slug){h(!1);return}try{const T=await Qp(t,e.tag.tag_uid,S);s(e.tag.full_path,T.full_path),o()}catch{}finally{h(!1)}}async function d(S){var P;S.stopPropagation();const T=((P=e.children)==null?void 0:P.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(T))try{await Kp(t,e.tag.tag_uid),a(e.tag.full_path),o()}catch{}}const v={archiveId:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u};return i.jsxs("li",{children:[i.jsxs("div",{className:"tag-node-row",children:[g?i.jsx("input",{className:"tag-rename-input",autoFocus:!0,value:f,onChange:S=>x(S.target.value),onKeyDown:S=>{S.key==="Enter"&&S.currentTarget.blur(),S.key==="Escape"&&(y.current=!0,S.currentTarget.blur())},onBlur:()=>{y.current?(y.current=!1,h(!1)):m()}}):i.jsxs("button",{className:`tag-node-btn${c?" is-active":""}`,title:e.tag.full_path,onClick:w,onDoubleClick:D,children:[u?e.tag.name:e.tag.slug,i.jsx("svg",{className:"edit-icon",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",onClick:S=>{S.stopPropagation(),D(S)},children:i.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),i.jsx("button",{className:"remove tag-node-delete",title:`Delete tag ${e.tag.full_path}`,onClick:d,"aria-label":`Delete tag ${e.tag.full_path}`,children:"×"})]}),((k=e.children)==null?void 0:k.length)>0&&i.jsx("div",{className:"tag-children",children:i.jsx("ul",{className:"tag-tree-list",children:e.children.map(S=>i.jsx(Yc,{node:S,...v},S.tag.tag_uid))})})]})}function Uh({archiveId:e,tagNodes:t,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u}){return i.jsx("section",{id:"tags-view",className:"view is-active",children:i.jsxs("div",{className:"tag-tree",children:[i.jsxs("div",{className:"tag-tree-header",children:[i.jsx("span",{className:"tag-tree-title",children:"Tags"}),n&&i.jsxs("span",{className:"tag-tree-active",children:["Filtering: ",n]})]}),t.length===0?i.jsx("p",{className:"muted",style:{padding:"8px 0"},children:"No tags yet."}):i.jsx("ul",{className:"tag-tree-list",children:t.map(c=>i.jsx(Yc,{node:c,archiveId:e,tagFilter:n,onTagFilterSet:r,onViewChange:l,onTagRenamed:s,onTagDeleted:a,onTagsRefresh:o,humanizeTags:u},c.tag.tag_uid))})]})})}const Kn=[{value:0,label:"Private"},{value:2,label:"Users only"},{value:3,label:"Public"}],Hh=e=>{var t;return((t=Kn.find(n=>n.value===e))==null?void 0:t.label)??String(e)};function Wh({archiveId:e}){const[t,n]=p.useState([]),[r,l]=p.useState(!1),[s,a]=p.useState(null),[o,u]=p.useState(null),[c,g]=p.useState(null),[h,f]=p.useState(!1),[x,y]=p.useState(null),[w,D]=p.useState(""),[m,d]=p.useState(""),[v,k]=p.useState(2),[S,T]=p.useState(!1),[P,N]=p.useState(null),[M,O]=p.useState(""),[V,ce]=p.useState(2),[re,Z]=p.useState(!1),[je,Ee]=p.useState(null),[ye,R]=p.useState(!1),[_,b]=p.useState(""),j=p.useRef(null),C=t.find(z=>z.collection_uid===o)??null,F=(C==null?void 0:C.slug)==="_default_",A=p.useCallback(async()=>{if(e){l(!0),a(null);try{const z=await fh(e);n(z)}catch(z){a(z.message)}finally{l(!1)}}},[e]),U=p.useCallback(async z=>{if(!z){g(null);return}f(!0),y(null);try{const H=await hh(e,z);g(H)}catch(H){y(H.message)}finally{f(!1)}},[e]);p.useEffect(()=>{A()},[A]),p.useEffect(()=>{U(o)},[o,U]),p.useEffect(()=>{ye&&j.current&&j.current.focus()},[ye]);async function G(z){z.preventDefault();const H=w.trim(),Fe=m.trim();if(!(!H||!Fe)){T(!0),N(null);try{const dt=await ph(e,H,Fe,v);D(""),d(""),k(2),await A(),u(dt.collection_uid)}catch(dt){N(dt.message)}finally{T(!1)}}}async function Q(){const z=_.trim();if(!z||!C){R(!1);return}try{await Co(e,C.collection_uid,{name:z}),await A(),g(H=>H&&{...H,name:z})}catch(H){a(H.message)}finally{R(!1)}}async function J(z){if(C)try{await Co(e,C.collection_uid,{default_visibility_bits:z}),await A(),g(H=>H&&{...H,default_visibility_bits:z})}catch(H){a(H.message)}}async function L(){if(C&&window.confirm(`Delete collection "${C.name}"? Entries will not be deleted.`))try{await xh(e,C.collection_uid),u(null),g(null),await A()}catch(z){a(z.message)}}async function X(z){z.preventDefault();const H=M.trim();if(!(!H||!C)){Z(!0),Ee(null);try{await mh(e,C.collection_uid,H,V),O(""),await U(C.collection_uid)}catch(Fe){Ee(Fe.message)}finally{Z(!1)}}}async function We(z){if(C)try{await gh(e,C.collection_uid,z),await U(C.collection_uid)}catch(H){y(H.message)}}async function Ve(z,H){if(C)try{await vh(e,C.collection_uid,z,H),g(Fe=>Fe&&{...Fe,entries:Fe.entries.map(dt=>dt.entry_uid===z?{...dt,collection_visibility_bits:H}:dt)})}catch(Fe){y(Fe.message)}}return e?i.jsxs("div",{className:"collections-view",children:[i.jsx("h2",{className:"collections-heading",children:"Collections"}),r&&i.jsx("div",{className:"muted",children:"Loading…"}),s&&i.jsxs("div",{className:"collections-error",children:[s," ",i.jsx("button",{onClick:()=>a(null),className:"coll-dismiss",children:"×"})]}),i.jsxs("div",{className:"collections-layout",children:[i.jsxs("div",{className:"collections-sidebar",children:[t.map(z=>i.jsxs("button",{className:`coll-sidebar-row${o===z.collection_uid?" is-active":""}`,onClick:()=>u(z.collection_uid),children:[i.jsx("span",{className:"coll-row-name",children:z.name}),i.jsx("span",{className:"coll-row-meta",children:Hh(z.default_visibility_bits)})]},z.collection_uid)),t.length===0&&!r&&i.jsx("div",{className:"muted",style:{padding:"8px 12px"},children:"No collections yet."})]}),C?i.jsxs("div",{className:"coll-detail",children:[i.jsxs("div",{className:"coll-detail-header",children:[ye?i.jsx("input",{ref:j,className:"coll-rename-input",value:_,onChange:z=>b(z.target.value),onBlur:Q,onKeyDown:z=>{z.key==="Enter"&&Q(),z.key==="Escape"&&R(!1)}}):i.jsxs("h3",{className:`coll-detail-name${F?"":" coll-detail-name--editable"}`,title:F?void 0:"Click to rename",onClick:()=>{F||(b(C.name),R(!0))},children:[(c==null?void 0:c.name)??C.name,!F&&i.jsx("span",{className:"coll-edit-hint",children:" ✎"})]}),!F&&i.jsx("button",{className:"coll-delete-btn",onClick:L,title:"Delete collection",children:"Delete"})]}),i.jsxs("div",{className:"coll-detail-vis",children:[i.jsx("span",{className:"coll-vis-label",children:"Default visibility"}),i.jsx("select",{className:"coll-vis-select",value:(c==null?void 0:c.default_visibility_bits)??C.default_visibility_bits,onChange:z=>J(Number(z.target.value)),disabled:F,children:Kn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.value))})]}),i.jsxs("div",{className:"coll-entries-section",children:[i.jsx("div",{className:"coll-section-heading",children:"Entries"}),h&&i.jsx("div",{className:"muted",children:"Loading…"}),x&&i.jsx("div",{className:"collections-error",children:x}),!h&&c&&(c.entries.length===0?i.jsx("div",{className:"muted",children:"No entries in this collection."}):i.jsx("ul",{className:"coll-entries-list",children:c.entries.map(z=>i.jsxs("li",{className:"coll-entry-row",children:[i.jsxs("div",{className:"coll-entry-info",children:[i.jsx("span",{className:"coll-entry-title",children:z.title||z.entry_uid}),i.jsx("span",{className:"coll-entry-kind muted",children:z.source_kind})]}),i.jsxs("div",{className:"coll-entry-actions",children:[i.jsx("select",{className:"coll-entry-vis-select",value:z.collection_visibility_bits,onChange:H=>Ve(z.entry_uid,Number(H.target.value)),children:Kn.map(H=>i.jsx("option",{value:H.value,children:H.label},H.value))}),!F&&i.jsx("button",{className:"coll-entry-remove",onClick:()=>We(z.entry_uid),title:"Remove from collection",children:"×"})]})]},z.entry_uid))}))]}),!F&&i.jsxs("form",{className:"coll-add-entry-form",onSubmit:X,children:[i.jsx("div",{className:"coll-section-heading",children:"Add entry"}),i.jsxs("div",{className:"coll-add-entry-row",children:[i.jsx("input",{className:"coll-add-entry-input",type:"text",value:M,onChange:z=>O(z.target.value),placeholder:"entry_uid",required:!0}),i.jsx("select",{className:"coll-vis-select",value:V,onChange:z=>ce(Number(z.target.value)),children:Kn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.value))}),i.jsx("button",{className:"coll-add-btn",type:"submit",disabled:re,children:re?"…":"Add"})]}),je&&i.jsx("div",{className:"collections-error",style:{marginTop:4},children:je})]})]}):i.jsx("div",{className:"coll-detail coll-detail--empty",children:i.jsx("div",{className:"muted",children:"Select a collection to view details."})})]}),i.jsxs("details",{className:"coll-create-details",children:[i.jsx("summary",{children:"+ Create collection"}),i.jsxs("form",{className:"coll-create-form",onSubmit:G,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-name",children:"Name"}),i.jsx("input",{className:"capture-input",id:"coll-name",type:"text",value:w,onChange:z=>{D(z.target.value),m||d(z.target.value.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""))},placeholder:"My Collection",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-slug",children:"Slug"}),i.jsx("input",{className:"capture-input",id:"coll-slug",type:"text",value:m,onChange:z=>d(z.target.value),placeholder:"my-collection",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"coll-vis",children:"Default visibility"}),i.jsx("select",{className:"capture-input",id:"coll-vis",style:{height:42},value:v,onChange:z=>k(Number(z.target.value)),children:Kn.map(z=>i.jsx("option",{value:z.value,children:z.label},z.value))})]}),P&&i.jsx("div",{className:"collections-error",children:P}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:S,children:S?"Creating…":"Create collection"})]})]})]}):i.jsx("div",{className:"view-placeholder",children:"Select an archive."})}const Vh=4;function Qh({tab:e,onTabChange:t,archiveId:n}){const{currentUser:r,setCurrentUser:l}=p.useContext(Hl)??{},s=r&&(r.role_bits&Vh)!==0,a=["profile","tokens",...s?["instance","cookies","extensions","storage"]:[]],o={profile:"Profile",tokens:"API Tokens",instance:"Instance",cookies:"Cookies",extensions:"Extensions",storage:"Storage"};return i.jsxs("section",{className:"admin-view",children:[i.jsx("h1",{children:"Settings"}),i.jsx("div",{className:"view-tabs",children:a.map(u=>i.jsx("button",{className:`view-tab${e===u?" is-active":""}`,onClick:()=>t(u),children:o[u]},u))}),e==="profile"&&i.jsx(Kh,{currentUser:r,setCurrentUser:l}),e==="tokens"&&i.jsx(Xh,{}),e==="instance"&&s&&i.jsx(Jh,{}),e==="cookies"&&s&&i.jsx(Gh,{}),e==="extensions"&&s&&i.jsx(qh,{}),e==="storage"&&s&&i.jsx(Yh,{archiveId:n})]})}function Kh({currentUser:e,setCurrentUser:t}){const[n,r]=p.useState((e==null?void 0:e.display_name)??""),[l,s]=p.useState(!1),[a,o]=p.useState(null),[u,c]=p.useState(""),[g,h]=p.useState(""),[f,x]=p.useState(""),[y,w]=p.useState(!1),[D,m]=p.useState(null);async function d(k){k.preventDefault(),s(!0),o(null);try{await th(n),t(S=>({...S,display_name:n||null})),o({ok:!0,text:"Saved."})}catch(S){o({ok:!1,text:S.message})}finally{s(!1)}}async function v(k){if(k.preventDefault(),g!==f){m({ok:!1,text:"Passwords do not match."});return}w(!0),m(null);try{await rh(u,g),c(""),h(""),x(""),m({ok:!0,text:"Password changed."})}catch(S){m({ok:!1,text:S.message})}finally{w(!1)}}return i.jsxs("div",{style:{maxWidth:440},children:[i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Display Name"}),i.jsxs("form",{onSubmit:d,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"display-name",children:"Name shown in the UI"}),i.jsx("input",{className:"field-input",id:"display-name",placeholder:(e==null?void 0:e.username)??"",value:n,onChange:k=>r(k.target.value)})]}),a&&i.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:l,children:l?"Saving…":"Save"})]})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Display Preferences"}),i.jsxs("label",{className:"checkbox-row",children:[i.jsx("input",{type:"checkbox",checked:(e==null?void 0:e.humanize_slugs)??!1,onChange:async k=>{const S=k.target.checked;try{await nh({humanize_slugs:S}),t(T=>({...T,humanize_slugs:S}))}catch{}}}),i.jsx("span",{className:"form-label",style:{margin:0},children:"Humanize tag display"})]}),i.jsx("p",{className:"muted",style:{fontSize:13,margin:"4px 0 0"},children:'When on, tag paths show as "X / Articles" instead of "x/articles".'})]}),i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Change Password"}),i.jsxs("form",{onSubmit:v,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"cur-pw",children:"Current password"}),i.jsx("input",{className:"field-input",id:"cur-pw",type:"password",value:u,onChange:k=>c(k.target.value),required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"new-pw",children:"New password"}),i.jsx("input",{className:"field-input",id:"new-pw",type:"password",value:g,onChange:k=>h(k.target.value),required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",htmlFor:"confirm-pw",children:"Confirm new password"}),i.jsx("input",{className:"field-input",id:"confirm-pw",type:"password",value:f,onChange:k=>x(k.target.value),required:!0})]}),D&&i.jsx("div",{className:`form-msg form-msg--${D.ok?"ok":"err"}`,children:D.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:y,children:y?"Changing…":"Change Password"})]})]})]})}function Xh(){const[e,t]=p.useState([]),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState(""),[u,c]=p.useState(!1),[g,h]=p.useState(null),f=p.useCallback(async()=>{r(!0),s(null);try{t(await lh())}catch(w){s(w.message)}finally{r(!1)}},[]);p.useEffect(()=>{f()},[f]);async function x(w){if(w.preventDefault(),!!a.trim()){c(!0);try{const D=await sh(a.trim());h(D),o(""),f()}catch(D){s(D.message)}finally{c(!1)}}}async function y(w){try{await ih(w),t(D=>D.filter(m=>m.token_uid!==w))}catch(D){s(D.message)}}return i.jsx("div",{style:{maxWidth:600},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"API Tokens"}),g&&i.jsxs("div",{className:"token-banner",children:[i.jsx("strong",{children:"Token created."})," Copy it now — it won't be shown again.",i.jsx("code",{children:g.raw_token}),i.jsx("button",{className:"token-dismiss",onClick:()=>h(null),children:"Dismiss"})]}),i.jsxs("form",{className:"token-create-row",onSubmit:x,children:[i.jsx("input",{className:"field-input field-input--flex",placeholder:"Token name",value:a,onChange:w=>o(w.target.value),required:!0}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:u,children:u?"Creating…":"Create token"})]}),l&&i.jsx("div",{className:"form-msg form-msg--err",children:l}),n?i.jsx("div",{className:"muted",children:"Loading…"}):i.jsxs("div",{children:[e.length===0&&i.jsx("div",{className:"muted",children:"No tokens yet."}),e.map(w=>i.jsxs("div",{className:"token-row",children:[i.jsxs("div",{className:"token-row-info",children:[i.jsx("strong",{children:w.name}),i.jsxs("div",{className:"muted",children:["Created ",w.created_at.slice(0,10),w.last_used_at&&` · Last used ${w.last_used_at.slice(0,10)}`]})]}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"4px 10px"},onClick:()=>y(w.token_uid),children:"Revoke"})]},w.token_uid))]})]})})}function Jh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState(!1),[u,c]=p.useState(null);p.useEffect(()=>{(async()=>{try{t(await da())}catch(h){s(h.message)}finally{r(!1)}})()},[]);async function g(h){h.preventDefault(),o(!0),c(null);try{await hi(e),c({ok:!0,text:"Saved."})}catch(f){c({ok:!1,text:f.message})}finally{o(!1)}}return n?i.jsx("div",{className:"muted",children:"Loading…"}):l?i.jsx("div",{className:"form-msg form-msg--err",children:l}):e?i.jsx("div",{style:{maxWidth:440},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Instance Settings"}),i.jsxs("form",{onSubmit:g,children:[[["public_index_enabled","Public index (unauthenticated browsing)"],["public_entry_content_enabled","Public entry content"],["open_registration_enabled","Open registration"]].map(([h,f])=>i.jsxs("label",{className:"checkbox-row",children:[i.jsx("input",{type:"checkbox",checked:!!e[h],onChange:x=>t(y=>({...y,[h]:x.target.checked}))}),f]},h)),i.jsxs("div",{className:"form-field",style:{marginTop:4},children:[i.jsx("label",{className:"form-label",children:"Default entry visibility"}),i.jsxs("select",{className:"field-input",value:e.default_entry_visibility,onChange:h=>t(f=>({...f,default_entry_visibility:Number(h.target.value)})),children:[i.jsx("option",{value:0,children:"Private"}),i.jsx("option",{value:2,children:"Unlisted"}),i.jsx("option",{value:3,children:"Public"})]})]}),u&&i.jsx("div",{className:`form-msg form-msg--${u.ok?"ok":"err"}`,children:u.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:a,children:a?"Saving…":"Save Settings"})]})]})}):null}function ys(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 Yh({archiveId:e}){const[t,n]=p.useState("idle"),[r,l]=p.useState(null),[s,a]=p.useState(null),[o,u]=p.useState(null);function c(){n("idle"),l(null),a(null),u(null)}async function g(){n("scanning"),u(null),l(null);try{const x=await wh(e);l(x),n("scanned")}catch(x){u(x.message),n("error")}}async function h(){n("deleting"),u(null);try{const x=await kh(e);a(x),n("done")}catch(x){u(x.message),n("error")}}const f=r&&r.deletable_files===0&&r.orphaned_blob_rows===0;return i.jsx("div",{style:{maxWidth:440},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Orphan Cleanup"}),i.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."," ",i.jsx("strong",{children:"Cleanup is blocked while captures are running."})]}),!e&&i.jsx("div",{className:"muted",children:"No archive selected."}),e&&t==="idle"&&i.jsx("button",{className:"btn-ghost",onClick:g,children:"Scan for orphaned blobs"}),t==="scanning"&&i.jsx("div",{className:"muted",children:"Scanning…"}),t==="scanned"&&r&&f&&i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"form-msg form-msg--ok",children:"Archive is clean — nothing to remove."}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Done"})]}),t==="scanned"&&r&&!f&&i.jsxs("div",{children:[i.jsxs("div",{style:{marginBottom:14,lineHeight:1.6},children:["Found ",i.jsx("strong",{children:r.deletable_files})," unreferenced file",r.deletable_files!==1?"s":""," ","and ",i.jsx("strong",{children:r.orphaned_blob_rows})," orphaned DB record",r.orphaned_blob_rows!==1?"s":""," ","— ",i.jsx("strong",{children:ys(r.total_bytes)})," recoverable."]}),i.jsxs("div",{style:{display:"flex",gap:8},children:[i.jsxs("button",{className:"btn-danger",onClick:h,children:["Delete (",ys(r.total_bytes),")"]}),i.jsx("button",{className:"btn-ghost",onClick:c,children:"Cancel"})]})]}),t==="deleting"&&i.jsx("div",{className:"muted",children:"Deleting…"}),t==="done"&&s&&i.jsxs("div",{children:[i.jsxs("div",{className:"form-msg form-msg--ok",children:["Freed ",i.jsx("strong",{children:ys(s.freed_bytes)})," ","— removed ",s.deleted_files," file",s.deleted_files!==1?"s":""," ","and ",s.deleted_blob_rows," DB record",s.deleted_blob_rows!==1?"s":"","."]}),s.errors&&s.errors.length>0&&i.jsxs("div",{className:"form-msg form-msg--err",style:{marginTop:6},children:[s.errors.length," file",s.errors.length!==1?"s":""," could not be deleted."]}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Scan again"})]}),t==="error"&&i.jsxs("div",{children:[i.jsx("div",{className:"form-msg form-msg--err",children:o}),i.jsx("button",{className:"btn-ghost",style:{marginTop:10},onClick:c,children:"Try again"})]})]})})}function Gh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(null),[a,o]=p.useState("global"),[u,c]=p.useState(""),[g,h]=p.useState("{}"),[f,x]=p.useState(null),[y,w]=p.useState(!1),[D,m]=p.useState({});p.useEffect(()=>{d()},[]);async function d(){r(!0),s(null);try{t(await Sh())}catch(N){s(N.message)}finally{r(!1)}}async function v(N){N.preventDefault();try{JSON.parse(g)}catch{x({ok:!1,text:'cookies must be valid JSON, e.g. {"session": "abc"}'});return}w(!0),x(null);try{await Nh(a==="global"?null:u.trim(),a,g),c(""),h("{}"),o("global"),x({ok:!0,text:"Rule added."}),await d()}catch(M){x({ok:!1,text:M.message})}finally{w(!1)}}async function k(N){try{await Ch(N),await d()}catch(M){s(M.message)}}function S(N){m(M=>({...M,[N.rule_uid]:{cookiesInput:N.cookies_json,saving:!1,msg:null}}))}function T(N){m(M=>{const O={...M};return delete O[N],O})}async function P(N){const M=D[N.rule_uid];try{JSON.parse(M.cookiesInput)}catch{m(O=>({...O,[N.rule_uid]:{...O[N.rule_uid],msg:{ok:!1,text:"Invalid JSON"}}}));return}m(O=>({...O,[N.rule_uid]:{...O[N.rule_uid],saving:!0,msg:null}}));try{await _h(N.rule_uid,{cookies_json:M.cookiesInput}),T(N.rule_uid),await d()}catch(O){m(V=>({...V,[N.rule_uid]:{...V[N.rule_uid],saving:!1,msg:{ok:!1,text:O.message}}}))}}return n?i.jsx("div",{className:"muted",children:"Loading…"}):l?i.jsx("div",{className:"form-msg form-msg--err",children:l}):i.jsx("div",{style:{maxWidth:560},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Cookie Rules"}),i.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?i.jsxs("table",{className:"data-table",style:{width:"100%",marginBottom:16},children:[i.jsx("thead",{children:i.jsxs("tr",{children:[i.jsx("th",{children:"Pattern"}),i.jsx("th",{children:"Cookies"}),i.jsx("th",{style:{width:100},children:"Actions"})]})}),i.jsx("tbody",{children:e.map(N=>{const M=D[N.rule_uid],O=N.url_pattern?i.jsxs(i.Fragment,{children:[i.jsxs("span",{className:"muted",children:[N.pattern_kind,":"]})," ",i.jsx("code",{children:N.url_pattern})]}):i.jsx("span",{className:"muted",children:"global (all URLs)"});return i.jsxs("tr",{children:[i.jsx("td",{children:O}),i.jsx("td",{children:M?i.jsxs(i.Fragment,{children:[i.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:12,width:"100%",minHeight:60},value:M.cookiesInput,onChange:V=>m(ce=>({...ce,[N.rule_uid]:{...ce[N.rule_uid],cookiesInput:V.target.value}}))}),M.msg&&i.jsx("div",{className:`form-msg form-msg--${M.msg.ok?"ok":"err"}`,children:M.msg.text}),i.jsxs("div",{style:{display:"flex",gap:8,marginTop:4},children:[i.jsx("button",{className:"btn-primary",style:{fontSize:12,padding:"2px 8px"},disabled:M.saving,onClick:()=>P(N),children:M.saving?"Saving…":"Save"}),i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>T(N.rule_uid),children:"Cancel"})]})]}):i.jsx("code",{style:{fontSize:12,wordBreak:"break-all"},children:N.cookies_json})}),i.jsx("td",{children:!M&&i.jsxs("div",{style:{display:"flex",gap:6},children:[i.jsx("button",{className:"btn-secondary",style:{fontSize:12,padding:"2px 8px"},onClick:()=>S(N),children:"Edit"}),i.jsx("button",{className:"btn-danger",style:{fontSize:12,padding:"2px 8px"},onClick:()=>k(N.rule_uid),children:"Del"})]})})]},N.rule_uid)})})]}):i.jsx("p",{className:"muted",style:{marginBottom:16},children:"No cookie rules defined."}),i.jsx("h3",{style:{marginBottom:8},children:"Add Rule"}),i.jsxs("form",{onSubmit:v,children:[i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:"Pattern type"}),i.jsxs("select",{className:"field-input",value:a,onChange:N=>o(N.target.value),children:[i.jsx("option",{value:"global",children:"Global (all URLs)"}),i.jsx("option",{value:"wildcard",children:"Wildcard (e.g. *.youtube.com)"}),i.jsx("option",{value:"regex",children:"Regex (matched against full URL)"})]})]}),a!=="global"&&i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:a==="wildcard"?"URL/hostname pattern":"Regex pattern"}),i.jsx("input",{className:"field-input",type:"text",value:u,onChange:N=>c(N.target.value),placeholder:a==="wildcard"?"*.youtube.com or https://example.com/*":".*\\.youtube\\.com.*",required:!0})]}),i.jsxs("div",{className:"form-field",children:[i.jsx("label",{className:"form-label",children:"Cookies (JSON object)"}),i.jsx("textarea",{className:"field-input",style:{fontFamily:"monospace",fontSize:13,minHeight:70},value:g,onChange:N=>h(N.target.value),placeholder:'{"SESSION": "abc123", "token": "xyz"}',required:!0})]}),f&&i.jsx("div",{className:`form-msg form-msg--${f.ok?"ok":"err"}`,children:f.text}),i.jsx("button",{className:"btn-primary",type:"submit",disabled:y,children:y?"Adding…":"Add Rule"})]})]})})}function qh(){const[e,t]=p.useState(null),[n,r]=p.useState(!0),[l,s]=p.useState(!1),[a,o]=p.useState(null);p.useEffect(()=>{(async()=>{try{t(await da())}catch(y){o({ok:!1,text:y.message})}finally{r(!1)}})()},[]);async function u(y){s(!0),o(null);try{await hi({ublock_enabled:y}),t(w=>({...w,ublock_enabled:y})),o({ok:!0,text:"Saved."})}catch(w){o({ok:!1,text:w.message})}finally{s(!1)}}async function c(y){s(!0),o(null);try{await hi({cookie_ext_enabled:y}),t(w=>({...w,cookie_ext_enabled:y})),o({ok:!0,text:"Saved."})}catch(w){o({ok:!1,text:w.message})}finally{s(!1)}}if(n)return i.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,f=(e==null?void 0:e.cookie_ext_available)??!1,x=(e==null?void 0:e.cookie_ext_enabled)??!0;return i.jsx("div",{style:{maxWidth:560},children:i.jsxs("div",{className:"form-section",children:[i.jsx("h2",{children:"Extensions"}),i.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."}),i.jsx("div",{className:"ext-card",children:i.jsxs("div",{className:"ext-card-header",children:[i.jsxs("div",{className:"ext-card-info",children:[i.jsx("span",{className:"ext-card-name",children:"uBlock Origin Lite"}),i.jsx("span",{className:"ext-card-desc",children:"Blocks ads, trackers, and other page clutter during archiving via Chrome’s declarativeNetRequest API (Manifest V3)."}),!g&&i.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_UBLOCK_EXT"})," to the unpacked extension directory to enable."]})]}),i.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:i.jsx("span",{className:"ext-toggle-knob"})})]})}),i.jsx("div",{className:"ext-card",children:i.jsxs("div",{className:"ext-card-header",children:[i.jsxs("div",{className:"ext-card-info",children:[i.jsx("span",{className:"ext-card-name",children:"I Still Don’t Care About Cookies"}),i.jsx("span",{className:"ext-card-desc",children:"Dismiss cookie consent banners during archiving."}),!f&&i.jsxs("span",{className:"ext-card-hint",children:["Not configured — set ",i.jsx("code",{children:"ARCHIVR_COOKIE_EXT"})," to the unpacked extension directory to enable."]})]}),i.jsx("button",{type:"button",role:"switch","aria-checked":x,className:`ext-toggle${x?" ext-toggle--on":""}`,onClick:()=>c(!x),disabled:l,"aria-label":"Toggle I Still Don't Care About Cookies",children:i.jsx("span",{className:"ext-toggle-knob"})})]})}),a&&i.jsx("div",{className:`form-msg form-msg--${a.ok?"ok":"err"}`,children:a.text})]})})}const Po={0:"Private",1:"Public",2:"Users only",3:"Public"},Zh=()=>i.jsx("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:i.jsx("path",{d:"M7 17 17 7M9 7h8v8"})});function em({archiveId:e,selectedEntry:t,detail:n,onTagFilterSet:r,tagNodes:l,onTagsRefresh:s,onEntryTitleChange:a,onEntryDeleted:o,humanizeTags:u,onDetailRefresh:c,onOpenPreview:g,onPlay:h}){const[f,x]=p.useState([]),[y,w]=p.useState(""),[D,m]=p.useState([]),[d,v]=p.useState(""),k=p.useRef(0),S=p.useRef(!1),[T,P]=p.useState(!1),[N,M]=p.useState(""),[O,V]=p.useState("idle"),[ce,re]=p.useState(""),Z=p.useRef(null);p.useEffect(()=>{const L=++k.current;if(Z.current&&(clearInterval(Z.current),Z.current=null),V("idle"),re(""),!t||!e){x([]),m([]);return}P(!1),M(""),S.current=!1,x([]),Promise.all([Hr(e,t.entry_uid),yh(e,t.entry_uid)]).then(([X,We])=>{L===k.current&&(x(X),m(We))}).catch(()=>{})},[t,e]),p.useEffect(()=>()=>{clearInterval(Z.current)},[]);async function je(){const L=N.trim()||null;try{await Up(e,t.entry_uid,L),a==null||a(t.entry_uid,L)}catch{}finally{P(!1)}}async function Ee(){const L=y.trim();if(!(!L||!t))try{await Hp(e,t.entry_uid,L),w(""),v("");const X=await Hr(e,t.entry_uid);x(X),s()}catch(X){v(X.message)}}async function ye(L){try{await Wp(e,t.entry_uid,L);const X=await Hr(e,t.entry_uid);x(X),s()}catch{}}async function R(){if(!(!t||!e)&&window.confirm("Delete this entry? This cannot be undone."))try{await Vp(e,t.entry_uid),o==null||o(t.entry_uid)}catch{}}async function _(){if(!t||!e||O==="running")return;const L=k.current,X=t.entry_uid;V("running"),re("");try{const{job_uid:We}=await jh(e,X);if(k.current!==L)return;Z.current=setInterval(async()=>{try{const Ve=await Qc(e,We);if(Ve.status==="completed"){if(clearInterval(Z.current),Z.current=null,k.current!==L)return;V("done");const z=await Hr(e,X);if(k.current!==L)return;x(z),c==null||c()}else if(Ve.status==="failed"){if(clearInterval(Z.current),Z.current=null,k.current!==L)return;V("error"),re(Ve.error_text||"Re-archive failed.")}}catch{if(clearInterval(Z.current),Z.current=null,k.current!==L)return;V("error"),re("Network error while polling.")}},500)}catch(We){if(k.current!==L)return;V("error"),re(We.message||"Failed to start re-archive.")}}const b=n?[["Added",Xc(n.summary.archived_at)],["Source",n.summary.source_kind],["Type",n.summary.entity_kind],["Visibility",Po[n.summary.visibility]??n.summary.visibility],["Root",n.structured_root_relpath]]:[],j=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),C=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv","pdf","html","htm","jpg","jpeg","png","gif","webp","avif","svg","bmp"]),F=n?n.artifacts.findIndex(L=>L.artifact_role==="primary_media"):-1,A=F>=0?n.artifacts[F]:null,U=A?A.relpath.split(".").pop().toLowerCase():"",G=A&&j.has(U),Q=F>=0&&t?`/api/archives/${e}/entries/${t.entry_uid}/artifacts/${F}`:null,J=n&&!G&&(n.summary.entity_kind==="tweet"||n.summary.entity_kind==="tweet_thread"||A&&C.has(U));return i.jsxs("aside",{className:"context-rail",children:[i.jsx("div",{className:"rail-eyebrow",children:"Context"}),t?n?i.jsxs(i.Fragment,{children:[T?i.jsx("input",{className:"rail-title-input",autoFocus:!0,value:N,onChange:L=>M(L.target.value),onKeyDown:L=>{L.key==="Enter"&&L.currentTarget.blur(),L.key==="Escape"&&(S.current=!0,L.currentTarget.blur())},onBlur:()=>{S.current?P(!1):je(),S.current=!1}}):i.jsxs("h2",{className:"rail-title rail-title--editable",title:"Click to rename",onClick:()=>{M(n.summary.title??""),P(!0)},children:[Kt(n.summary.title)||Kt(n.summary.entry_uid),i.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:i.jsx("path",{d:"M11.5 2.5a1.5 1.5 0 0 1 2 2L5 13l-3 1 1-3 8.5-8.5z"})})]}),n.summary.original_url&&i.jsxs("a",{className:"url-tile",href:n.summary.original_url,target:"_blank",rel:"noopener noreferrer",children:[i.jsx("span",{className:"ico",dangerouslySetInnerHTML:{__html:fa(n.summary.source_kind)}}),i.jsx("span",{className:"u-text",children:n.summary.original_url}),i.jsx("span",{className:"ext",children:i.jsx(Zh,{})})]}),G&&h&&i.jsx("button",{className:"rail-preview-btn",onClick:()=>h(Q,t),children:"▶ Play"}),J&&g&&i.jsx("button",{className:"rail-preview-btn",onClick:g,children:"Preview"}),i.jsx("div",{className:"meta-list",children:b.filter(([,L])=>L!=null&&L!=="").map(([L,X])=>i.jsxs("div",{className:"meta-item",children:[i.jsx("span",{className:"meta-k",children:L}),i.jsx("span",{className:`meta-v${L==="Root"?" mono":""}`,children:Kt(X)})]},L))}),n.artifacts.length>0&&i.jsxs("div",{className:"rail-section",children:[i.jsxs("div",{className:"rail-section-heading",children:["Artifacts ",i.jsx("span",{className:"num",children:n.artifacts.length})]}),i.jsx("ul",{className:"artifact-list",children:n.artifacts.map((L,X)=>i.jsx("li",{children:i.jsxs("a",{href:`/api/archives/${e}/entries/${n.summary.entry_uid}/artifacts/${X}`,target:"_blank",rel:"noopener noreferrer",className:"artifact-link",children:[i.jsx("span",{className:"artifact-name",children:L.artifact_role.replace(/_/g," ")}),i.jsx("span",{className:"artifact-size",children:L.byte_size!=null?gi(L.byte_size):"—"})]})},X))})]})]}):i.jsx("p",{className:"tags-empty",children:"Loading…"}):i.jsx("p",{className:"tags-empty",children:"Select an entry."}),t&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Tags"}),f.length===0?i.jsx("p",{className:"tags-empty",children:"No tags yet."}):i.jsx("div",{className:"tags-wrap",children:f.map(L=>i.jsxs("span",{className:"tag-pill",title:L.full_path,children:[u?Jc(L.full_path):L.full_path,i.jsx("button",{className:"remove",title:`Remove tag ${L.full_path}`,onClick:()=>ye(L.tag_uid),children:"×"})]},L.tag_uid))}),d&&i.jsx("p",{className:"form-msg form-msg--err",style:{margin:"0 0 8px"},children:d}),i.jsxs("div",{className:"tag-input-wrap",children:[i.jsx("span",{className:"hash",children:"/"}),i.jsx("input",{className:"tag-input",type:"text",placeholder:"science/cs",autoComplete:"off",value:y,onChange:L=>w(L.target.value),onKeyDown:L=>{L.key==="Enter"&&Ee()}}),i.jsx("button",{className:"tag-add-btn",onClick:Ee,children:"Add"})]})]}),D.length>0&&i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Collections"}),D.map(L=>i.jsxs("div",{className:"coll-row",children:[i.jsx("span",{className:"coll-name",children:L.collection_uid}),i.jsx("span",{className:"vis-badge",children:Po[L.visibility_bits]??`bits:${L.visibility_bits}`})]},L.collection_uid))]}),n&&(n.summary.entity_kind==="tweet"||n.summary.entity_kind==="tweet_thread")&&i.jsxs("div",{className:"rail-section",children:[i.jsx("div",{className:"rail-section-heading",children:"Actions"}),i.jsx("button",{className:"rail-rearchive-btn",onClick:_,disabled:O==="running",children:O==="running"?"Re-archiving…":"Re-archive"}),O==="done"&&i.jsx("p",{className:"form-msg form-msg--ok",style:{marginTop:"6px"},children:"Re-archived successfully."}),O==="error"&&i.jsx("p",{className:"form-msg form-msg--err",style:{marginTop:"6px"},children:ce})]}),i.jsx("div",{className:"rail-delete-zone",children:i.jsx("button",{className:"rail-delete-btn",onClick:R,children:"Delete entry"})})]})]})}function tm({src:e}){const t=p.useRef(null);return p.useEffect(()=>{t.current&&t.current.load()},[e]),i.jsx("div",{className:"preview-video-wrap",style:{background:"#111",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",minHeight:"240px"},children:e?i.jsxs("video",{ref:t,controls:!0,autoPlay:!1,style:{width:"100%",maxHeight:"100%",display:"block"},children:[i.jsx("source",{src:e}),"Your browser does not support the video element."]}):i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No video available"})})}function Lo({src:e,type:t}){return i.jsx("div",{className:"preview-iframe-wrap",style:{height:"100%",display:"flex",flexDirection:"column"},children:t==="page"?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"preview-iframe-toolbar",style:{display:"flex",alignItems:"center",gap:"8px",padding:"6px 10px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0},children:[i.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.8rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:e}),i.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{fontSize:"0.8rem",color:"var(--accent)",textDecoration:"none",whiteSpace:"nowrap",fontFamily:"var(--sans)"},children:"Open in new tab ↗"})]}),i.jsx("iframe",{src:e,sandbox:"allow-same-origin allow-popups",allow:"autoplay 'none'",referrerPolicy:"no-referrer",style:{flex:1,border:"none",width:"100%"},title:"Page preview"})]}):i.jsxs(i.Fragment,{children:[i.jsx("div",{style:{padding:"8px 12px",borderBottom:"1px solid var(--line-soft)",background:"var(--paper-2)",flexShrink:0,fontSize:"0.85rem",color:"var(--muted)",fontFamily:"var(--sans)"},children:"PDF Document"}),i.jsx("iframe",{src:e,allow:"autoplay 'none'",style:{flex:1,border:"none",width:"100%"},title:"PDF preview"})]})})}function nm({src:e,alt:t}){return i.jsx("div",{className:"preview-image-wrap",style:{display:"flex",alignItems:"center",justifyContent:"center",width:"100%",height:"100%",background:"var(--paper-2)",overflow:"hidden"},children:i.jsx("a",{href:e,target:"_blank",rel:"noreferrer noopener",style:{display:"contents"},children:i.jsx("img",{src:e,alt:t||"",style:{objectFit:"contain",maxHeight:"100%",maxWidth:"100%",display:"block",cursor:"pointer"}})})})}function Gc(e){return e?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(new Date(e*1e3)):""}const B={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)"}};function rm(e,t,n){const r={};return n&&n.forEach((l,s)=>{l.relpath&&(r[l.relpath]=`/api/archives/${e}/entries/${t}/artifacts/${s}`)}),r}function wr(e,t,n){return e&&n[e]?n[e]:t||null}function qc(){return i.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",style:{flexShrink:0,color:"var(--ink)"},children:i.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 lm(e,t){if(!e)return null;const n=(t.urls||[]).filter(o=>o.fromIndex!=null&&o.toIndex!=null),r=(t.user_mentions||[]).filter(o=>o.fromIndex!=null&&o.toIndex!=null);if(n.length===0&&r.length===0)return e;const l=[...n.map(o=>({s:o.fromIndex,e:o.toIndex,kind:"url",href:o.expanded_url,display:o.display_url})),...r.map(o=>({s:o.fromIndex,e:o.toIndex,kind:"mention",screen_name:o.screen_name}))],s=new Set([0,e.length]);for(const o of l)o.s>=0&&o.s<=e.length&&s.add(o.s),o.e>=0&&o.e<=e.length&&s.add(o.e);const a=[...s].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1],g=e.slice(o,c),h=l.filter(y=>y.s<=o&&y.e>=c),f=h.find(y=>y.kind==="url");if(f)return i.jsx("a",{href:f.href,target:"_blank",rel:"noopener noreferrer",style:B.link,children:f.display||g},u);const x=h.find(y=>y.kind==="mention");return x?i.jsx("a",{href:`https://x.com/${x.screen_name}`,target:"_blank",rel:"noopener noreferrer",style:B.link,children:g},u):i.jsx("span",{children:g},u)})}function sm(e,t,n,r){if(!e)return null;t=t||[],n=n||[],r=r||[];const l=[];for(const o of t)o.length>0&&l.push({s:o.offset,e:o.offset+o.length,kind:"style",style:o.style});for(const o of n)l.push({s:o.fromIndex,e:o.toIndex,kind:"url",href:o.text});for(const o of r)l.push({s:o.fromIndex,e:o.toIndex,kind:"mention",name:o.text});if(l.length===0)return e;const s=new Set([0,e.length]);for(const o of l)o.s>=0&&o.s<=e.length&&s.add(o.s),o.e>=0&&o.e<=e.length&&s.add(o.e);const a=[...s].sort((o,u)=>o-u);return a.slice(0,-1).map((o,u)=>{const c=a[u+1],g=l.filter(w=>w.s<=o&&w.e>=c),h=e.slice(o,c);let f;if(h.includes(` `)){const w=h.split(` `);f=w.flatMap((D,m)=>mw.kind==="style"&&w.style==="Code")&&(f=i.jsx("code",{style:B.iCode,children:f})),g.some(w=>w.kind==="style"&&w.style==="Bold")&&(f=i.jsx("strong",{children:f})),g.some(w=>w.kind==="style"&&w.style==="Italic")&&(f=i.jsx("em",{children:f})),g.some(w=>w.kind==="style"&&w.style==="Underline")&&(f=i.jsx("u",{children:f})),g.some(w=>w.kind==="style"&&w.style==="Strikethrough")&&(f=i.jsx("s",{children:f}));const x=g.find(w=>w.kind==="url");x&&(f=i.jsx("a",{href:x.href,target:"_blank",rel:"noopener noreferrer",style:B.link,children:f}));const y=g.find(w=>w.kind==="mention");return y&&(f=i.jsx("a",{href:`https://x.com/${y.name}`,target:"_blank",rel:"noopener noreferrer",style:B.link,children:f})),i.jsx("span",{children:f},u)})}function im(e,t){const n=e.resolved_entities||[];return n.length===0?null:n.map((r,l)=>{var s;switch(r.type){case"divider":return i.jsx("hr",{style:B.bHr},l);case"media":{const a=wr(r.local_path,r.url,t);return a?i.jsx("img",{src:a,style:B.bImg,loading:"lazy",alt:""},l):null}case"tweet":return r.tweet_id?i.jsxs("a",{href:`https://x.com/i/status/${r.tweet_id}`,target:"_blank",rel:"noopener noreferrer",style:B.bTweet,children:[i.jsx(qc,{}),"View post on X"]},l):null;case"link":return r.url?i.jsx("p",{style:B.bP,children:i.jsx("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",style:B.link,children:r.url})},l):null;case"markdown":{const a=r.markdown??((s=r.data)==null?void 0:s.markdown)??"";return i.jsx("pre",{style:B.bMdPre,children:i.jsx("code",{style:B.bMdCode,children:a})},l)}case"emoji":return r.url?i.jsx("img",{src:r.url,alt:"",style:{height:"1.2em",verticalAlign:"middle",margin:"0 1px"}},l):null;default:return null}})}function xs(e,t,n){const r=e.type||"",l=e.text||"",s=e.inline_style_ranges||[],a=e.data||{},o=sm(l,s,a.urls||[],a.mentions||[]);switch(r){case"header-one":return i.jsx("h1",{style:B.bH1,children:o},t);case"header-two":{const u=l.match(/(?:x\.com|twitter\.com)\/i\/status\/(\d+)/);return u?i.jsxs("a",{href:`https://x.com/i/status/${u[1]}`,target:"_blank",rel:"noopener noreferrer",style:B.bTweet,children:[i.jsx(qc,{}),"View post on X"]},t):i.jsx("h2",{style:B.bH2,children:o},t)}case"unstyled":return l.trim()?i.jsx("p",{style:B.bP,children:o},t):i.jsx("span",{style:B.bSpacer},t);case"blockquote":return i.jsx("blockquote",{style:B.bQuote,children:o},t);case"unordered-list-item":case"ordered-list-item":return i.jsx("li",{style:B.bLi,children:o},t);case"atomic":return i.jsx("span",{children:im(e,n)},t);default:return l?i.jsx("p",{style:B.bP,children:o},t):null}}function am(e,t){const n=[];let r=0;for(;r0&&i.jsx("div",{style:B.mediaGrid,children:g.map((x,y)=>{if(x.type==="photo"){const w=wr(x.local_path,x.media_url_https,r);return w?i.jsx("img",{src:w,style:B.mediaImg,alt:x.alt_text||"",loading:"lazy"},y):null}if(x.type==="video"||x.type==="animated_gif"){const w=x.local_path&&r[x.local_path]||(()=>{var m,d;return(d=(((m=x.video_info)==null?void 0:m.variants)||[]).filter(v=>v.content_type==="video/mp4").sort((v,k)=>(k.bitrate||0)-(v.bitrate||0))[0])==null?void 0:d.url})();return w?i.jsx("video",{src:w,style:B.mediaVideo,controls:!0,loop:x.type==="animated_gif",muted:x.type==="animated_gif"},y):null}return null})}),(e.retweet_count>0||e.favorite_count>0)&&i.jsxs("div",{style:B.stats,children:[e.favorite_count>0&&i.jsxs("span",{children:["❤️ ",e.favorite_count.toLocaleString()]}),e.retweet_count>0&&i.jsxs("span",{children:["🔁 ",e.retweet_count.toLocaleString()]})]})]})]})}function um({archiveId:e,entryUid:t,artifacts:n,entityKind:r}){const[l,s]=p.useState(!0),[a,o]=p.useState(null),[u,c]=p.useState([]);if(p.useEffect(()=>{if(s(!0),o(null),c([]),!n||!e||!t){s(!1);return}const f=n.map((y,w)=>({...y,index:w})).filter(y=>y.artifact_role==="raw_tweet_json");if(f.length===0){o("No tweet data found."),s(!1);return}let x=!1;return Promise.all(f.map(y=>fetch(`/api/archives/${e}/entries/${t}/artifacts/${y.index}`).then(w=>{if(!w.ok)throw new Error(`HTTP ${w.status}`);return w.json()}))).then(y=>{x||c(y)}).catch(y=>{x||o(y.message||"Failed to load tweet.")}).finally(()=>{x||s(!1)}),()=>{x=!0}},[e,t,n]),l)return i.jsx("div",{style:B.loading,children:"Loading…"});if(a)return i.jsxs("div",{style:B.error,children:["Error: ",a]});if(u.length===0)return null;const g=rm(e,t,n);if(r==="tweet_thread")return i.jsx("div",{style:B.threadOuter,children:u.map((f,x)=>i.jsx(Ro,{tweet:f,isInThread:!0,isLast:x===u.length-1,artifactMap:g},f.id||x))});const h=u[0];return h.is_article&&h.article?i.jsx(om,{article:h.article,tweetAuthor:h.author,artifactMap:g}):i.jsx("div",{style:B.card,children:i.jsx(Ro,{tweet:h,isInThread:!1,isLast:!0,artifactMap:g})})}const cm=new Set(["mp4","webm","mov","mkv","avi","m4v","ogv"]),dm=new Set(["mp3","ogg","m4a","opus","wav","flac","aac"]),fm=new Set(["jpg","jpeg","png","gif","webp","avif","svg","bmp"]);function Zc({archiveId:e,entry:t,detail:n}){if(!t)return i.jsx("div",{className:"preview-panel preview-panel--empty",children:i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Select an entry to preview"})});if(!n)return i.jsx("div",{className:"preview-panel preview-panel--loading",children:i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"Loading…"})});const{summary:r,artifacts:l}=n,s=r.entry_uid,a=r.entity_kind;if(a==="tweet"||a==="tweet_thread")return i.jsx("div",{className:"preview-tweet-wrap",children:i.jsx(um,{archiveId:e,entryUid:s,artifacts:l,entityKind:a})});const o=l.findIndex(h=>h.artifact_role==="primary_media");if(o===-1)return i.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),l.length>0&&i.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:l.map((h,f)=>i.jsxs("li",{children:[h.artifact_role,": ",h.relpath]},f))})]});const u=l[o],c=`/api/archives/${e}/entries/${s}/artifacts/${o}`,g=u.relpath.split(".").pop().toLowerCase();return cm.has(g)?i.jsx("div",{className:"preview-panel",children:i.jsx(tm,{src:c})}):dm.has(g)?i.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:[i.jsx("span",{style:{fontSize:"2rem"},children:"🎵"}),i.jsx("span",{style:{color:"var(--ink)",fontSize:"0.95rem",fontWeight:600},children:r.title||s}),i.jsx("audio",{src:c,controls:!0,style:{marginTop:"8px",width:"100%",maxWidth:"400px"}})]}):g==="pdf"?i.jsx("div",{className:"preview-panel",style:{height:"100%"},children:i.jsx(Lo,{src:c,type:"pdf"})}):g==="html"||g==="htm"?i.jsx("div",{className:"preview-panel",style:{height:"100%"},children:i.jsx(Lo,{src:c,type:"page"})}):fm.has(g)?i.jsx("div",{className:"preview-panel",style:{height:"100%"},children:i.jsx(nm,{src:c,alt:r.title||"Image"})}):i.jsxs("div",{className:"preview-panel preview-panel--no-preview",children:[i.jsx("span",{style:{color:"var(--muted)",fontFamily:"var(--sans)",fontSize:"0.9rem"},children:"No preview available"}),i.jsx("ul",{style:{marginTop:"12px",paddingLeft:"20px",fontSize:"0.8rem",color:"var(--muted-2)",fontFamily:"var(--sans)"},children:l.map((h,f)=>i.jsxs("li",{children:[h.artifact_role,": ",h.relpath]},f))})]})}function pm({archiveId:e,entry:t,detail:n,onClose:r}){return p.useEffect(()=>{const l=s=>{s.key==="Escape"&&r()};return window.addEventListener("keydown",l),()=>window.removeEventListener("keydown",l)},[r]),i.jsx("div",{className:"preview-modal-backdrop",onClick:r,children:i.jsxs("div",{className:"preview-modal",onClick:l=>l.stopPropagation(),children:[i.jsxs("div",{className:"preview-modal-header",children:[i.jsx("span",{className:"preview-modal-title",children:(t==null?void 0:t.title)||(t==null?void 0:t.entry_uid)||"Preview"}),i.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:"↗"}),i.jsx("button",{className:"preview-modal-close",onClick:r,"aria-label":"Close preview",children:"×"})]}),i.jsx("div",{className:"preview-modal-body",children:i.jsx(Zc,{archiveId:e,entry:t,detail:n})})]})})}function zo(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 hm({entry:e,src:t,archiveId:n,onClose:r}){const l=p.useRef(null),[s,a]=p.useState(!1),[o,u]=p.useState(0),[c,g]=p.useState(NaN),[h,f]=p.useState(1);p.useEffect(()=>{!l.current||!t||(l.current.load(),u(0),g(NaN),a(!1))},[t]),p.useEffect(()=>{l.current&&(l.current.volume=h)},[h]);function x(){const d=l.current;d&&(s?d.pause():d.play().catch(()=>{}))}function y(d){const v=l.current;if(!v||!isFinite(c))return;const k=Number(d.target.value);v.currentTime=k,u(k)}function w(d){f(Number(d.target.value))}const D=(e==null?void 0:e.title)||(e==null?void 0:e.entry_uid)||"Unknown",m=(e==null?void 0:e.source_kind)||"other";return i.jsxs(i.Fragment,{children:[i.jsx("audio",{ref:l,src:t||void 0,preload:"auto",onPlay:()=>a(!0),onPause:()=>a(!1),onEnded:()=>a(!1),onTimeUpdate:()=>{var d;return u(((d=l.current)==null?void 0:d.currentTime)??0)},onLoadedMetadata:()=>{var d;return g(((d=l.current)==null?void 0:d.duration)??NaN)},onDurationChange:()=>{var d;return g(((d=l.current)==null?void 0:d.duration)??NaN)},style:{display:"none"}}),i.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:[i.jsxs("div",{className:"audio-bar-info",style:{display:"flex",alignItems:"center",gap:"8px",minWidth:0,flex:"0 1 220px",overflow:"hidden"},children:[i.jsx("span",{className:"source-icon",style:{flexShrink:0,width:"18px",height:"18px",display:"flex",alignItems:"center"},dangerouslySetInnerHTML:{__html:fa(m)}}),i.jsx("span",{style:{overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:"0.85rem",color:"var(--ink)"},title:D,children:D})]}),i.jsxs("div",{className:"audio-bar-controls",style:{display:"flex",alignItems:"center",gap:"10px",flex:"1 1 0",minWidth:0},children:[i.jsx("button",{onClick:x,"aria-label":s?"Pause":"Play",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"var(--ink)",flexShrink:0,fontSize:"1.2rem",lineHeight:1},children:s?"⏸":"▶"}),i.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:zo(o)}),i.jsx("input",{type:"range",min:0,max:isFinite(c)?c:0,step:.1,value:isFinite(o)?o:0,onChange:y,"aria-label":"Seek",style:{flex:1,minWidth:0,accentColor:"var(--accent)"}}),i.jsx("span",{style:{fontSize:"0.75rem",color:"var(--muted)",whiteSpace:"nowrap",flexShrink:0},children:zo(c)})]}),i.jsxs("div",{className:"audio-bar-right",style:{display:"flex",alignItems:"center",gap:"8px",flex:"0 1 160px"},children:[i.jsx("span",{style:{fontSize:"0.85rem",color:"var(--muted)",flexShrink:0},children:"🔊"}),i.jsx("input",{type:"range",min:0,max:1,step:.01,value:h,onChange:w,"aria-label":"Volume",style:{width:"80px",accentColor:"var(--accent)"}}),i.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 mm({archiveId:e,entryUid:t}){var g,h;const[n,r]=p.useState(null),[l,s]=p.useState(!0),[a,o]=p.useState(null);p.useEffect(()=>{pi(e,t).then(f=>{r(f),s(!1)}).catch(f=>{o((f==null?void 0:f.message)||"Failed to load entry"),s(!1)})},[e,t]);const u=((g=n==null?void 0:n.summary)==null?void 0:g.title)||t,c=(h=n==null?void 0:n.summary)==null?void 0:h.original_url;return i.jsxs("div",{style:{minHeight:"100vh",display:"flex",flexDirection:"column",background:"var(--paper)",fontFamily:"var(--sans)"},children:[i.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"10px",padding:"10px 16px",borderBottom:"1px solid var(--line)",flexShrink:0,background:"var(--paper-2)"},children:[i.jsx("a",{href:"/",style:{color:"var(--accent)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"← Archive"}),i.jsx("span",{style:{flex:1,fontSize:"14px",fontWeight:600,color:"var(--ink)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u}),c&&i.jsx("a",{href:c,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--muted)",textDecoration:"none",fontSize:"13px",flexShrink:0},children:"Original ↗"})]}),i.jsxs("div",{style:{flex:1,minHeight:0,overflow:"auto",display:"flex",flexDirection:"column"},children:[l&&i.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--muted)",fontSize:"14px"},children:"Loading…"}),a&&i.jsx("div",{style:{padding:"48px",textAlign:"center",color:"var(--alert)",fontSize:"14px"},children:a}),n&&i.jsx(Zc,{archiveId:e,entry:n.summary,detail:n})]})]})}const gm=7e3;function vm({toasts:e,onDismiss:t,onIgnoreUblock:n}){return e.length?i.jsx("div",{className:"toast-stack",role:"log","aria-live":"polite","aria-label":"Notifications",children:e.map(r=>i.jsx(xm,{toast:r,onDismiss:t,onIgnoreUblock:n},r.id))}):null}function ym(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),s=(l[l.length-1]??"")+r,a=s?`${t}/…/${s}`:t;return a.length<=56?a:a.slice(0,53)+"…"}catch{return"…"+e.slice(-51)}}function xm({toast:e,onDismiss:t,onIgnoreUblock:n}){const[r,l]=p.useState(!1),s=e.type==="warning",a=e.type==="success";p.useEffect(()=>{if(r)return;const u=setTimeout(()=>t(e.id),gm);return()=>clearTimeout(u)},[r,e.id,t]);const o=ym(e.locator);return a?i.jsx("div",{className:"toast toast--success",role:"alert","aria-atomic":"true",children:i.jsxs("div",{className:"toast-top",children:[i.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✓"}),i.jsxs("div",{className:"toast-body",children:[i.jsx("span",{className:"toast-headline",children:e.headline||"Archived"}),o&&i.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),i.jsx("div",{className:"toast-btns",children:i.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})})]})}):s?i.jsxs("div",{className:"toast toast--warning",role:"alert","aria-atomic":"true",children:[i.jsxs("div",{className:"toast-top",children:[i.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"⚠"}),i.jsxs("div",{className:"toast-body",children:[i.jsx("span",{className:"toast-headline",children:e.headline||"Archived with warnings"}),o&&i.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),i.jsxs("div",{className:"toast-btns",children:[e.text&&i.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),"aria-expanded":r,children:r?"Hide":"Details"}),e.locator&&i.jsx("button",{type:"button",className:"toast-view-btn toast-ignore-btn",onClick:()=>{n==null||n(),t(e.id)},children:"Ignore"}),i.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&i.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."})]}):i.jsxs("div",{className:"toast toast--error",role:"alert","aria-atomic":"true",children:[i.jsxs("div",{className:"toast-top",children:[i.jsx("span",{className:"toast-icon","aria-hidden":"true",children:"✕"}),i.jsxs("div",{className:"toast-body",children:[i.jsx("span",{className:"toast-headline",children:e.headline||"Capture failed"}),o&&i.jsx("span",{className:"toast-locator",title:e.locator,children:o})]}),i.jsxs("div",{className:"toast-btns",children:[e.text&&i.jsx("button",{type:"button",className:"toast-view-btn",onClick:()=>l(u=>!u),children:r?"Hide":"View error"}),i.jsx("button",{type:"button",className:"toast-dismiss",onClick:()=>t(e.id),"aria-label":"Dismiss",children:"×"})]})]}),r&&e.text&&i.jsx("pre",{className:"toast-error-detail",children:e.text})]})}const Hl=p.createContext(null),Wr=(()=>{const e=window.location.pathname.match(/^\/preview\/([^/]+)\/([^/]+)/);return e?{archiveId:e[1],entryUid:e[2]}:null})(),wm=["archive","tags","collections","runs","admin","settings"],km=["profile","tokens","instance","storage"];function ws(){const e=window.location.pathname.split("/").filter(Boolean),t=wm.includes(e[0])?e[0]:"archive",n=t==="settings"&&km.includes(e[1])?e[1]:"profile";return{view:t,settingsTab:n}}function jm(e,t){return e==="archive"?"/":e==="settings"?`/settings/${t}`:`/${e}`}function Sm(){const[e,t]=p.useState("loading"),[n,r]=p.useState(null);p.useEffect(()=>{(async()=>{if(await Yp()){t("setup");return}const W=await eh();if(!W){t("login");return}r(W),t("authenticated")})()},[]),p.useEffect(()=>{const I=()=>{r(null),t("login")};return window.addEventListener("auth:expired",I),()=>window.removeEventListener("auth:expired",I)},[]),p.useEffect(()=>{const I=()=>{const{view:W,settingsTab:le}=ws();m(W),v(le)};return window.addEventListener("popstate",I),()=>window.removeEventListener("popstate",I)},[]);const[l,s]=p.useState([]),[a,o]=p.useState(null),[u,c]=p.useState([]),[g,h]=p.useState(null),[f,x]=p.useState(null),[y,w]=p.useState(null),[D,m]=p.useState(()=>ws().view),[d,v]=p.useState(()=>ws().settingsTab),[k,S]=p.useState(""),[T,P]=p.useState(""),[N,M]=p.useState(!1),[O,V]=p.useState([]),[ce,re]=p.useState([]),[Z,je]=p.useState(()=>sessionStorage.getItem("captureDialogOpen")==="true"),[Ee,ye]=p.useState([]),R=p.useRef(0),[_,b]=p.useState(()=>sessionStorage.getItem("ublockWarningIgnored")==="true"),[j,C]=p.useState(null),F=p.useRef(0),A=(n==null?void 0:n.humanize_slugs)??!1;p.useEffect(()=>{const I=++F.current;C(null),!(!f||!a)&&pi(a,f.entry_uid).then(W=>{I===F.current&&C(W)}).catch(()=>{})},[f,a]),p.useEffect(()=>{sessionStorage.setItem("captureDialogOpen",Z)},[Z]);const U=p.useCallback(async(I,W,le)=>{if(I){M(!0);try{let Qe;W||le?Qe=await Bp(I,W,le):Qe=await bp(I),c(Qe),P(Qe.length===0?"No results":`${Qe.length} result${Qe.length===1?"":"s"}`)}catch{c([]),P("Search failed. Try again.")}finally{M(!1)}}},[]);p.useEffect(()=>{e==="authenticated"&&Mp().then(I=>{if(s(I),I.length>0){const W=I[0].id;o(W)}})},[e]),p.useEffect(()=>{a&&(w(null),x(null),h(null),Promise.all([U(a,"",null),_o(a).then(V),vs(a).then(re)]))},[a]),p.useEffect(()=>{if(a===null)return;const I=setTimeout(()=>{U(a,k,y)},300);return()=>clearTimeout(I)},[k,a]),p.useEffect(()=>{a!==null&&(y!==null&&m("archive"),U(a,k,y))},[y,a]);const G=p.useCallback(I=>{o(I)},[]),Q=p.useCallback(I=>{m(I),I==="tags"&&a&&vs(a).then(re)},[a]);p.useEffect(()=>{if(Wr)return;const I=jm(D,d);window.location.pathname!==I&&history.pushState(null,"",I)},[D,d]);const J=p.useCallback(I=>{h(I?I.entry_uid:null),x(I)},[]),L=p.useCallback(I=>{w(I)},[]),X=p.useCallback(()=>{w(null)},[]),We=p.useCallback(()=>{a&&vs(a).then(re)},[a]),Ve=p.useCallback((I,W)=>{y===I?w(W):y!=null&&y.startsWith(I+"/")&&w(W+y.slice(I.length))},[y]),z=p.useCallback(I=>{(y===I||y!=null&&y.startsWith(I+"/"))&&w(null)},[y]),H=p.useCallback((I,W)=>{c(le=>le.map(Qe=>Qe.entry_uid===I?{...Qe,title:W}:Qe)),x(le=>le&&le.entry_uid===I?{...le,title:W}:le),C(le=>le&&le.summary.entry_uid===I?{...le,summary:{...le.summary,title:W}}:le)},[]),Fe=p.useCallback(()=>{if(!a||!f)return;const I=++F.current;pi(a,f.entry_uid).then(W=>{I===F.current&&C(W)}).catch(()=>{})},[a,f]),dt=p.useCallback(I=>{c(W=>W.filter(le=>le.entry_uid!==I)),x(W=>(W==null?void 0:W.entry_uid)===I?null:W),h(W=>W===I?null:W)},[]),ed=p.useCallback(()=>{je(!0)},[]),td=p.useCallback(()=>{je(!1)},[]),nd=p.useCallback(()=>{a&&Promise.all([U(a,k,y),_o(a).then(V)])},[a,k,y,U]),rd=p.useCallback((I,W,le="error",Qe=null)=>{if(le==="warning"&&_&&W)return;const cd=++R.current;ye(dd=>[...dd,{id:cd,text:I,locator:W,type:le,headline:Qe}])},[_]),ld=p.useCallback(I=>{ye(W=>W.filter(le=>le.id!==I))},[]),sd=p.useCallback(()=>{sessionStorage.setItem("ublockWarningIgnored","true"),b(!0),ye(I=>I.filter(W=>!(W.type==="warning"&&W.locator)))},[]),[pa,Wl]=p.useState(null),[Dn,ha]=p.useState(null),id=p.useCallback(()=>{f&&Wl(f.entry_uid)},[f]),ad=p.useCallback(()=>Wl(null),[]),od=p.useCallback((I,W)=>{ha({src:I,entry:W})},[]),ud=p.useCallback(()=>ha(null),[]);return p.useEffect(()=>{Wl(null)},[f]),p.useEffect(()=>(document.body.classList.toggle("has-audio-bar",!!Dn),()=>document.body.classList.remove("has-audio-bar")),[Dn]),e==="loading"?i.jsx("div",{className:"auth-loading",children:"Loading\\u2026"}):e==="setup"?i.jsx(Ph,{onComplete:()=>t("login")}):e==="login"?i.jsx(Th,{onLogin:I=>{r(I),t("authenticated")}}):Wr?i.jsx(mm,{archiveId:Wr.archiveId,entryUid:Wr.entryUid}):i.jsx(Hl.Provider,{value:{currentUser:n,setCurrentUser:r},children:i.jsxs(i.Fragment,{children:[i.jsx(Lh,{archives:l,archiveId:a,onArchiveChange:G,view:D,onViewChange:Q,onCaptureClick:ed}),i.jsxs("main",{className:"app-shell",children:[i.jsxs("div",{className:"workspace",children:[D==="archive"&&i.jsxs("div",{className:"toolbar",children:[i.jsxs("div",{className:"search-field",children:[i.jsx("span",{className:"ico","aria-hidden":"true",children:i.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[i.jsx("circle",{cx:"11",cy:"11",r:"7"}),i.jsx("line",{x1:"16.5",y1:"16.5",x2:"21",y2:"21"})]})}),i.jsx("input",{className:"search-input",type:"search","aria-label":"Search archive","aria-busy":N,placeholder:"Search titles, URLs, types, tags…",value:k,onChange:I=>S(I.target.value)}),i.jsx("span",{className:"kbd",children:"⌘K"})]}),i.jsxs("span",{className:"result-count",children:[T&&i.jsxs(i.Fragment,{children:[i.jsx("b",{children:T.split(" ")[0]})," ",T.split(" ").slice(1).join(" ")]}),y&&i.jsxs("button",{className:"tag-filter-badge",onClick:X,children:["× ",A?Jc(y):y]})]})]}),D==="archive"&&i.jsx(Ih,{entries:u,selectedEntryUid:g,onSelectEntry:J,archiveId:a,tagFilter:y,onClearTagFilter:X,searchQuery:k,onSearchChange:S,resultCount:T,searchBusy:N}),D==="runs"&&i.jsx(Mh,{runs:O}),D==="admin"&&i.jsx(Bh,{archives:l}),D==="tags"&&i.jsx(Uh,{archiveId:a,tagNodes:ce,tagFilter:y,onTagFilterSet:L,onViewChange:Q,onTagRenamed:Ve,onTagDeleted:z,onTagsRefresh:We,humanizeTags:A}),D==="collections"&&i.jsx(Wh,{archiveId:a}),D==="settings"&&i.jsx(Qh,{tab:d,onTabChange:v,archiveId:a})]}),i.jsx(em,{archiveId:a,selectedEntry:f,detail:j,onTagFilterSet:L,tagNodes:ce,onTagsRefresh:We,onEntryTitleChange:H,onEntryDeleted:dt,humanizeTags:A,onDetailRefresh:Fe,onOpenPreview:id,onPlay:od})]}),pa&&f&&f.entry_uid===pa&&i.jsx(pm,{archiveId:a,entry:f,detail:j,onClose:ad}),Dn&&i.jsx(hm,{entry:Dn.entry,src:Dn.src,archiveId:a,onClose:ud}),i.jsx(Rh,{open:Z,archiveId:a,onClose:td,onCaptured:nd,onToast:rd}),i.jsx(vm,{toasts:Ee,onDismiss:ld,onIgnoreUblock:sd})]})})}Vc(document.getElementById("root")).render(i.jsx(p.StrictMode,{children:i.jsx(Sm,{})})); diff --git a/crates/archivr-server/static/index.html b/crates/archivr-server/static/index.html index c954ccc..aab0147 100644 --- a/crates/archivr-server/static/index.html +++ b/crates/archivr-server/static/index.html @@ -4,7 +4,7 @@ Archivr - + diff --git a/frontend/src/components/TweetPreview.jsx b/frontend/src/components/TweetPreview.jsx index 3b500e1..bcd2e3b 100644 --- a/frontend/src/components/TweetPreview.jsx +++ b/frontend/src/components/TweetPreview.jsx @@ -164,7 +164,7 @@ const S = { maxHeight: '280px', }, aMeta: { - padding: '14px 14px 0', + padding: '10px 14px 0', }, aTweetTitle: { fontSize: '20px', @@ -172,13 +172,13 @@ const S = { letterSpacing: '-0.3px', color: 'var(--ink)', lineHeight: '1.3', - marginBottom: '10px', + marginBottom: '8px', }, aAuthorRow: { display: 'flex', alignItems: 'center', gap: '8px', - marginBottom: '10px', + marginBottom: '8px', }, aAvatar: { width: '36px', @@ -221,7 +221,7 @@ const S = { letterSpacing: '-0.4px', color: 'var(--ink)', lineHeight: '1.25', - margin: '20px 0 8px', + margin: '16px 0 6px', }, bH2: { fontSize: '18px', @@ -229,7 +229,7 @@ const S = { letterSpacing: '-0.2px', color: 'var(--ink)', lineHeight: '1.3', - margin: '18px 0 6px', + margin: '14px 0 4px', }, bP: { fontSize: '15px', @@ -253,7 +253,7 @@ const S = { bHr: { border: 'none', borderTop: '1px solid var(--line)', - margin: '20px 0', + margin: '14px 0', }, bImg: { width: '100%',