1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/story-updates-surfaces.component-fW5MaEt7.js","assets/vendor-react-2mXWPygV.js","assets/vendor-ui-BInLtbYF.js","assets/index-Cp6Mk7n4.js","assets/vendor-app-Dz59apZY.js","assets/index-BqkYXXqC.css","assets/slide-over.component-CHomslcp.js","assets/use-overlay-focus-return-Ds4tDfMz.js","assets/story-update-context.component-BECkWl3i.js","assets/story-update-context-BbLd27cF.css","assets/story-updates-surfaces-BoSqp_lX.css"])))=>i.map(i=>d[i]); 2import{n as pl,q as je,u as pt,B as de,R as On,r as yt,w as Ve,c as L,L as ta,I as ct,a as Nn,b as dt,S as aa,d as hl,e as xl,i as bl,C as Br,f as gs,g as gl,M as Vr,h as Hr,j as fs,k as fl,F as Ur,l as Yr,m as Kr,o as Dn,p as zr,s as qr,t as vl,v as yl,x as wl,A as jl,y as Nl,z as vs,D as Sl,_ as Gr}from"./index-Cp6Mk7n4.js";import{r,j as e,u as Fn,R as Ze,h as kl,L as Cl,c as _l}from"./vendor-react-2mXWPygV.js";/* empty css */import{f as Va}from"./format-compact-number-CxZfytn2.js";import{w as na,x as da,y as Pt,z as Rl,E as Ll,F as Al}from"./vendor-app-Dz59apZY.js";import{N as $n,Z as Sn,_ as Qr,b as et,O as vt,z as wt,l as ut,$ as Tl,L as El,a0 as Xr,a1 as Ma,H as Pl,a2 as Ia,a3 as mt,a4 as Ml,a5 as Oa,a6 as ys,a7 as sa,Y as kn,a8 as Zr,a9 as Jr,aa as ws,p as Il,M as ei,d as ti,ab as Ol,f as ai,g as ni,h as si,ac as Zt,i as it,ad as Cn,e as Dl,k as Ha,ae as It,af as Fl,R as Wn,ag as Ua,ah as $l,ai as js,u as Wl,aj as Bl,q as Ns,ak as ri,al as ii,am as Vl,an as Ss,U as Hl,D as Ul,s as Yl,v as Kl,ao as zl,w as ql,x as ks,ap as Gl}from"./vendor-ui-BInLtbYF.js";import{L as Z,a as Oe,b as xe,c as Qe,d as Bn,e as Ft,f as Vn,g as Hn,h as Un,i as Ye,r as gt,j as Ql,k as Cs,R as _s,l as Xl,m as Zl,S as Jl,A as ec,u as tc,n as ac}from"./useLibraryStickyChromeHeight-wJENPMje.js";import{C as $t,M as _n,b as nc,i as oi,m as sc,a as rc,c as ic,d as oc,s as lc,e as cc,f as dc,g as uc,h as mc,j as pc,k as on,l as Qt,n as Rs,o as ln,p as hc,q as li,r as xc,t as ka,A as bc,u as Ls,v as gc,w as fc,x as vc}from"./useMinLg-BspfyuGX.js";import{A as yc}from"./archive-masthead.component-4Yfx0GZ5.js";import{M as wc,a as As}from"./mobile-primary-header.component-utDTvT7I.js";import{L as jc,A as Ts}from"./archive-state-frame.component-B86kijZd.js";import{d as ci,f as di,p as ui,u as mi,s as Nc,a as Sc,b as kc,t as Cc,h as _c,F as Rc,I as Lc,c as Ac,e as Tc}from"./setup-paths-CNuxu_dK.js";import{R as Ec}from"./rating.component-DPDKD9Os.js";import{S as ra}from"./story-update-context.component-BECkWl3i.js";import{S as pi,a as hi,b as xi}from"./slide-over.component-CHomslcp.js";import{l as bi,b as Pc,u as Mc,a as Ic,c as Oc,C as Dc,T as Fc}from"./useCollectionActionDialog-Dp02eJzH.js";import{u as $c}from"./use-overlay-focus-return-Ds4tDfMz.js";import"./select.component-f6V8CInH.js";import"./first-story-activation-BLMmSc5Z.js";const gi="trace:iphone-app-notice:dismissed-at",fi="trace:iphone-app-notice:dismissed-session",Wc=720*60*60*1e3;let vi=!1;const Rn=new Set;function Bc(){if(vi)return!0;try{if(sessionStorage.getItem(fi)==="1")return!0;const t=Number(localStorage.getItem(gi));return t>0&&Date.now()-t<Wc}catch{return!1}}function Vc(t){return Rn.add(t),window.addEventListener("storage",t),()=>{Rn.delete(t),window.removeEventListener("storage",t)}}function Hc(){return{dismissed:r.useSyncExternalStore(Vc,Bc,()=>!1),dismiss:()=>{vi=!0;try{localStorage.setItem(gi,String(Date.now()))}catch{}try{sessionStorage.setItem(fi,"1")}catch{}Rn.forEach(a=>a())}}}function Uc({dismissible:t=!1}){return Hc(),null}function Yc({enabled:t,libraryRevision:a,getActivityMarker:n}){const s=r.useRef(null),i=na({queryKey:je.accountAdvocacyActivityMarker(a),queryFn:n,enabled:t&&a>0,staleTime:0,gcTime:0,retry:1});r.useEffect(()=>{const o=i.data?.latest_activity_at??null;!o||o===s.current||pl(o)&&(s.current=o)},[i.data?.latest_activity_at])}function cn(t="api_limit"){window.dispatchEvent(new CustomEvent("trace:openUpgrade",{detail:{source:t}}))}const Wt=["No Archive Warnings Apply","Creator Chose Not To Use Archive Warnings","Graphic Depictions Of Violence","Major Character Death","Rape/Non-Con","Underage"],Kc="grid min-w-0 gap-5 sm:gap-4 sm:grid-cols-2 lg:grid-cols-3",Da=["F/F","F/M","Gen","M/M","Multi","Other"];function zc(t,a){return t.includes(a)?t.filter(n=>n!==a):[...t,a]}function qc(t){return t.split(/(?:\s*[/,&]\s*|\s+x\s+|\s+Ã\s+)/i).map(a=>
2a.trim()).filter(Boolean)}function Fa(t){const a=new Map;for(const n of t)for(const s of qc(n))a.set(s,(a.get(s)??0)+1);return Array.from(a.entries()).sort((n,s)=>n[1]!==s[1]?s[1]-n[1]:n[0].localeCompare(s[0],void 0,{sensitivity:"base"})).map(([n])=>n)}function dn(t){return t.toLocaleString("en-US")}function Gc(t){return gt(t)}function ze({id:t,title:a,count:n=0,children:s,open:i,onToggle:o,onReset:c}){const u=i,l=`filter-section-${t}`;return e.jsxs("section",{className:"df-section",children:[e.jsxs("button",{type:"button",className:"df-section-trigger focus-visible:outline-none focus-visible:shadow-ring","aria-expanded":u,"aria-controls":l,onClick:()=>o(t),children:[e.jsxs("span",{className:"df-section-label",children:[a,n>0?e.jsx("span",{className:"df-section-count",children:n}):null]}),e.jsxs("span",{className:"df-section-meta",children:[c&&n>0&&u?e.jsx("span",{className:"df-section-reset",onClick:m=>{m.stopPropagation(),c()},children:"reset"}):null,e.jsx($n,{className:L("df-section-chevron",u&&"is-open"),"aria-hidden":!0})]})]}),u?e.jsx("div",{id:l,className:"df-section-body",children:s}):null]})}function Qc({label:t,status:a,active:n,dotClassName:s,count:i,onClick:o}){return e.jsxs("button",{type:"button","aria-pressed":n,"data-status":a.toLowerCase(),className:L("df-reading-row focus-visible:outline-none focus-visible:shadow-ring",n&&"is-on"),onClick:o,children:[e.jsxs("span",{className:"df-reading-main",children:[e.jsx("span",{className:L("df-reading-dot",s),"aria-hidden":!0}),e.jsx("span",{className:"min-w-0 truncate",children:t})]}),typeof i<"u"?e.jsx("span",{className:"df-reading-count",children:i}):null]})}function Xc({storyUpdatesEnabled:t,filters:a,onChange:n,onReset:s,id:i,activeChips:o=[],resultCount:c,totalCount:u,suggestions:l}){const m=pt(),d=l??m,[x,y]=r.useState(()=>new Set(["reading-state","completion","ratings","tags-fandoms","archive-metadata"])),g=r.useCallback(v=>{y($=>{const f=new Set($);return f.has(v)?f.delete(v):f.add(v),f})},[]),N=r.useCallback(v=>x.has(v),[x]),S=a.statuses.length,C=a.platforms.length,_=a.completionStatus.length,p=a.ratings.length+(a.minRating?1:0)+(a.entryRating==="UNRATED"?1:0),b=(a.minWords||a.maxWords?1:0)+(a.minKudos||a.maxKudos?1:0),k=a.lastReadAfter||a.lastReadBefore?1:0,j=a.notes??(a.hasNotes?"WITH":"ANY"),O=j!=="ANY"?1:0,R=(a.tag?1:0)+(a.workTag?1:0)+a.fandoms.length,F=a.categoryFilter.length+a.pairMembers.length+(a.pairExact&&a.pairMembers.length?1:0)+a.characters.length+a.includeWarnings.length,A=(a.excludeTag?1:0)+(a.excludeWorkTag?1:0)+a.excludePairMembers.length+(a.excludePairExact&&a.excludePairMembers.length?1:0)+a.excludeCharacters.length+a.excludeFandoms.length+a.excludeCategoryFilter.length+a.excludeWarnings.length,z=typeof c=="number"&&typeof u=="number"?`${dn(c)} of ${dn(u)} matching · `:"",Q=v=>{const $=new Set(v);n({...a,includeWarnings:v,excludeWarnings:a.excludeWarnings.filter(f=>!$.has(f))})},te=v=>{const $=new Set(v);n({...a,excludeWarnings:v,includeWarnings:a.includeWarnings.filter(f=>!$.has(f))})};return e.jsxs("section",{id:i,"aria-label":"Advanced filters",className:"df-rail",children:[e.jsxs("div",{className:"df-head",children:[e.jsxs("div",{className:"df-title-row",children:[e.jsx("h2",{className:"df-title",children:"Filters"}),typeof c=="number"?e.jsxs("span",{className:"df-result-pill",children:[dn(c)," stories"]}):null]}),e.jsx("button",{type:"button",className:"df-reset",onClick:s,children:"Reset"})]}),e.jsxs("p",{className:"df-summary",children:[e.jsxs("span",{children:[e.jsx("strong",{children:o.length})," active"]}),z?e.jsxs("span",{children:[" · ",z.replace(/\s*·\s*$/,"")]}):null,e.jsx("span",{children:" · applies as you go"})]}),t?e.jsx(ze,{id:"story-updates",title:"Story updates",count:a.storyUpdates==="NEW"?1:0,open:N("story-updates"),onToggle:g,onReset:()=>n({...a,storyUpdates:"ANY"}),children:e.jsx(Oe,{title:"New updates",sub:"Saved stories with an unseen AO3 announcement.",checked:a.storyUpdates==="NEW",onChange:v=>n({...a,storyUpdates:v?"NEW":"ANY"})})}):null,e.jsx(ze,{id:"reading-state",title:"Reader status",count:S,open:N("reading-state"),onToggle:g,onReset:()=>n({...a,statuses:[]}),children:e.jsx("div",{className:"df-reading-list",children:On.map(v=>e.jsx(Qc,{label:yt(v),status:v,active:a.statuses.includes(v),dotClassName:Gc(v),onClick:()=>n({...a,statuses:zc(a.statuses,v)})},v))})}),e.jsx(ze,{id:"completion",title:"Work status",count:_,open:N("completion"),onToggle:g,onReset:()=>n({...a,completionStatus:[]}),children:e.jsx(Qe,{values:a.completionStatus,onChange:v=>n({...a,completionStatus:v}),options:[{value:"complete",label:Ve("complete")},{value:"wip",label:Ve("wip")},{value:"hiatus",label:Ve("hiatus")},{value:"abandoned",label:Ve("abandoned")}]})}),e.jsx(ze,{id:"source",title:"Source",count:C,open:N("source"),onToggle:g,onReset:()=>n({...a,platforms:[]}),children:e.jsx(Z,{label:"Platform",hint:"source",children:e.jsx(xe,{values:a.platforms,onChange:v=>n({...a,platforms:v}),getOptions:v=>d.suggestPlatforms(v),triggerPlaceholder:"Any platform",searchPlaceholder:"Search platforms...",maxChips:2})})}),e.jsxs(ze,{id:"ratings",title:"Ratings",count:p,open:N("ratings"),onToggle:g,onReset:()=>n({...a,ratings:[],minRating:void 0,entryRating:"ANY"}),children:[e.jsx(Z,{label:"Archive rating",hint:"from source",children:e.jsx(Vn,{values:a.ratings,onChange:v=>n({...a,ratings:v})})}),e.jsx(Z,{label:"Your rating",hint:"user-set",children:e.jsx(Hn,{value:a.minRating,entryRating:a.entryRating,onChange:v=>n({...a,minRating:v,entryRating:v?"ANY":a.entryRating}),onEntryRatingChange:v=>n({...a,entryRating:v,minRating:void 0})})})]}),e.jsxs(ze,{id:"length-popularity",title:"Length & Popularity",count:b,open:N("length-popularity"),onToggle:g,onReset:()=>n({...a,minWords:void 0,maxWords:void 0,minKudos:void 0,maxKudos:void 0}),children:[e.jsxs(Z,{label:"Word count",hint:"words",children:[e.jsx(Bn,{min:a.minWords,max:a.maxWords,onChange:({min:v,max:$})=>n({...a,minWords:v,maxWords:$})}),e.jsx(Ft,{min:a.minWords,max:a.maxWords,onChange:({min:v,max:$})=>n({...a,minWords:v,maxWords:$})})]}),e.jsx(Z,{label:"Kudos / favs",hint:"range",children:e.jsx(Ft,{min:a.minKudos,max:a.maxKudos,onChange:({min:v,max:$})=>n({...a,minKudos:v,maxKudos:$}),unit:"kudos"})})]}),e.jsx(ze,{id:"date",title:"Date",count:k,open:N("date"),onToggle:g,onReset:()=>n({...a,lastReadAfter:"",lastReadBefore:""}),children:e.jsx(Z,{label:"Read between",hint:"date range",children:e.jsx(Un,{start:a.lastReadAfter,end:a.lastReadBefore,onChange:({start:v,end:$})=>n({...a,lastReadAfter:v,lastReadBefore:$})})})}
2),e.jsxs(ze,{id:"tags-fandoms",title:"Tags & Fandoms",count:R,open:N("tags-fandoms"),onToggle:g,onReset:()=>n({...a,tag:"",workTag:"",fandoms:[]}),children:[e.jsx(Z,{label:"Fandom",hint:`${a.fandoms.length} selected`,children:e.jsx(xe,{values:a.fandoms,onChange:v=>n({...a,fandoms:v}),getOptions:v=>m.isReady?m.suggestFandoms(v,50):Promise.resolve([]),triggerPlaceholder:"Any fandom",searchPlaceholder:"Search all fandoms...",maxChips:2})}),e.jsx(Z,{label:"Library tag",hint:"yours",children:e.jsx(Ye,{value:a.tag,getOptions:v=>d.suggestLibraryTags(v),placeholder:"Any tag",searchPlaceholder:"Search your tags...",onChange:v=>n({...a,tag:v})})}),e.jsx(Z,{label:"AO3 tag",hint:"from source",children:e.jsx(Ye,{value:a.workTag,getOptions:v=>d.suggestWorkTags(v),placeholder:"Any AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:v=>n({...a,workTag:v})})})]}),e.jsxs(ze,{id:"archive-metadata",title:"Archive Metadata",count:F,open:N("archive-metadata"),onToggle:g,onReset:()=>n({...a,categoryFilter:[],pairMembers:[],pairExact:!1,characters:[],includeWarnings:[]}),children:[e.jsx(Z,{label:"Categories",hint:"from source",children:e.jsx(Qe,{values:a.categoryFilter,onChange:v=>n({...a,categoryFilter:v}),options:Da.map(v=>({value:v,label:v}))})}),e.jsx(Z,{label:"Must include relationships",hint:`${a.pairMembers.length} selected`,children:e.jsx(xe,{values:a.pairMembers,onChange:v=>n({...a,pairMembers:v}),getOptions:v=>m.isReady?m.suggestRelationships(v,50):Promise.resolve([]),transformOptions:Fa,triggerPlaceholder:"Any relationships",searchPlaceholder:"Type to search relationships..."})}),e.jsx(Oe,{title:"Exact relationships only",checked:a.pairExact,onChange:v=>n({...a,pairExact:v})}),e.jsx(Z,{label:"Must include characters",hint:`${a.characters.length} selected`,children:e.jsx(xe,{values:a.characters,onChange:v=>n({...a,characters:v}),getOptions:v=>m.isReady?m.suggestCharacters(v,50):Promise.resolve([]),triggerPlaceholder:"Any characters",searchPlaceholder:"Type to search characters..."})}),e.jsx(Z,{label:"Include warnings",hint:`${a.includeWarnings.length} selected`,children:e.jsx(xe,{values:a.includeWarnings,onChange:Q,options:[...Wt],triggerPlaceholder:"Any warnings",searchPlaceholder:"Search warnings...",maxChips:2})})]}),e.jsxs(ze,{id:"notes-flags",title:"Notes",count:O,open:N("notes-flags"),onToggle:g,onReset:()=>n({...a,hasNotes:!1,notes:"ANY"}),children:[e.jsx(Oe,{title:"Stories with notes",sub:"Your private notes.",checked:j==="WITH",onChange:v=>n({...a,hasNotes:!1,notes:v?"WITH":"ANY"})}),e.jsx(Oe,{title:"Stories without notes",sub:"Empty private notes.",checked:j==="WITHOUT",onChange:v=>n({...a,hasNotes:!1,notes:v?"WITHOUT":"ANY"})})]}),e.jsxs(ze,{id:"hide",title:"Hide From Results",count:A,open:N("hide"),onToggle:g,onReset:()=>n({...a,excludeTag:"",excludeWorkTag:"",excludePairMembers:[],excludePairExact:!1,excludeCharacters:[],excludeFandoms:[],excludeCategoryFilter:[],excludeWarnings:[]}),children:[e.jsx(Z,{label:"Hidden library tag",children:e.jsx(Ye,{value:a.excludeTag,getOptions:v=>d.suggestLibraryTags(v),placeholder:"Hide library tag",searchPlaceholder:"Search your tags...",onChange:v=>n({...a,excludeTag:v})})}),e.jsx(Z,{label:"Hidden AO3 tag",children:e.jsx(Ye,{value:a.excludeWorkTag,getOptions:v=>d.suggestWorkTags(v),placeholder:"Hide AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:v=>n({...a,excludeWorkTag:v})})}),e.jsx(Z,{label:"Hidden relationships",hint:`${a.excludePairMembers.length} selected`,children:e.jsx(xe,{values:a.excludePairMembers,onChange:v=>n({...a,excludePairMembers:v}),getOptions:v=>m.isReady?m.suggestRelationships(v,50):Promise.resolve([]),transformOptions:Fa,triggerPlaceholder:"Hide relationship",searchPlaceholder:"Type to search relationships..."})}),e.jsx(Oe,{title:"Exact hidden relationships only",checked:a.excludePairExact,onChange:v=>n({...a,excludePairExact:v})}),e.jsx(Z,{label:"Hidden characters",hint:`${a.excludeCharacters.length} selected`,children:e.jsx(xe,{values:a.excludeCharacters,onChange:v=>n({...a,excludeCharacters:v}),getOptions:v=>m.isReady?m.suggestCharacters(v,50):Promise.resolve([]),triggerPlaceholder:"Hide characters",searchPlaceholder:"Type to search characters..."})}),e.jsx(Z,{label:"Hidden fandoms",hint:`${a.excludeFandoms.length} selected`,children:e.jsx(xe,{values:a.excludeFandoms,onChange:v=>n({...a,excludeFandoms:v}),getOptions:v=>m.isReady?m.suggestFandoms(v,50):Promise.resolve([]),triggerPlaceholder:"Hide fandoms",searchPlaceholder:"Search all fandoms..."})}),e.jsx(Z,{label:"Hidden categories",children:e.jsx(Qe,{values:a.excludeCategoryFilter,onChange:v=>n({...a,excludeCategoryFilter:v}),options:Da.map(v=>({value:v,label:v}))})}),e.jsx(Z,{label:"Excluded warnings",hint:`${a.excludeWarnings.length} selected`,children:e.jsx(xe,{values:a.excludeWarnings,onChange:te,options:[...Wt],triggerPlaceholder:"No exclusions",searchPlaceholder:"Search warnings...",maxChips:2})})]})]})}function Es({storyUpdatesEnabled:t=!0,filters:a,onChange:n,onReset:s,id:i="filters-panel",activeChips:o,resultCount:c,totalCount:u,variant:l="default",suggestions:m}){const d=pt(),x=m??d,y=Kc,g="min-w-0",N="mb-1 text-xs font-medium text-content-muted",S=p=>{const b=new Set(p);n({...a,includeWarnings:p,excludeWarnings:a.excludeWarnings.filter(k=>!b.has(k))})},C=p=>{const b=new Set(p);n({...a,excludeWarnings:p,includeWarnings:a.includeWarnings.filter(k=>!b.has(k))})},_=a.notes??(a.hasNotes?"WITH":"ANY");return l==="rail"?e.jsx(Xc,{storyUpdatesEnabled:t,id:i,filters:a,onChange:n,onReset:s,activeChips:o,resultCount:c,totalCount:u,suggestions:m}):e.jsxs("section",{id:i,"aria-label":"Filters",className:l==="overlay"?"mt-0 w-full max-w-full overflow-x-hidden border-0 bg-transparent p-4 shadow-none":"mt-3 w-full max-w-full overflow-x-hidden rounded-2xl border border-border bg-surface-1 p-4 shadow-sm",children:[e.jsxs("div",{className:"mb-4 flex min-w-0 flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"min-w-0",children:e.jsx("div",{className:"text-sm font-semibold text-content-primary",children:"Filters"})}),e.jsx(de,{variant:"link",onClick:s,children:"Reset"})]}),e.jsxs("div",{className:y,children:[t?e.jsx(Z,{label:"Story updates",children:e.jsx(Oe,{title:"New updates",sub:"Unseen announcements for saved stories.",checked:a.storyUpdates==="NEW",onCh
2ange:p=>n({...a,storyUpdates:p?"NEW":"ANY"})})}):null,e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Platforms"}),e.jsx(xe,{values:a.platforms,onChange:p=>n({...a,platforms:p}),getOptions:p=>x.suggestPlatforms(p),triggerPlaceholder:"Any platform",searchPlaceholder:"Search platforms...",maxChips:2})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Reader status"}),e.jsx(Qe,{values:a.statuses,onChange:p=>n({...a,statuses:p}),options:On.map(p=>({value:p,label:yt(p)}))})]}),e.jsxs(Z,{label:"Word count",hint:"words",children:[e.jsx(Bn,{min:a.minWords,max:a.maxWords,onChange:({min:p,max:b})=>n({...a,minWords:p,maxWords:b})}),e.jsx(Ft,{min:a.minWords,max:a.maxWords,onChange:({min:p,max:b})=>n({...a,minWords:p,maxWords:b})})]}),e.jsx(Z,{label:"Kudos / favs",hint:"range",children:e.jsx(Ft,{min:a.minKudos,max:a.maxKudos,onChange:({min:p,max:b})=>n({...a,minKudos:p,maxKudos:b}),unit:"kudos"})}),e.jsx(Z,{label:"Archive rating",hint:"from source",children:e.jsx(Vn,{values:a.ratings,onChange:p=>n({...a,ratings:p})})}),e.jsx(Z,{label:"Your rating",hint:"user-set",children:e.jsx(Hn,{value:a.minRating,entryRating:a.entryRating,onChange:p=>n({...a,minRating:p,entryRating:p?"ANY":a.entryRating}),onEntryRatingChange:p=>n({...a,entryRating:p,minRating:void 0})})}),e.jsx(Z,{label:"Last read",hint:"date range",children:e.jsx(Un,{start:a.lastReadAfter,end:a.lastReadBefore,onChange:({start:p,end:b})=>n({...a,lastReadAfter:p,lastReadBefore:b})})}),e.jsxs(Z,{label:"Notes",children:[e.jsx(Oe,{title:"Stories with notes",sub:"Your private notes.",checked:_==="WITH",onChange:p=>n({...a,hasNotes:!1,notes:p?"WITH":"ANY"})}),e.jsx(Oe,{title:"Stories without notes",sub:"Empty private notes.",checked:_==="WITHOUT",onChange:p=>n({...a,hasNotes:!1,notes:p?"WITHOUT":"ANY"})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Work status"}),e.jsx(Qe,{values:a.completionStatus,onChange:p=>n({...a,completionStatus:p}),options:[{value:"complete",label:Ve("complete")},{value:"wip",label:Ve("wip")},{value:"hiatus",label:Ve("hiatus")},{value:"abandoned",label:Ve("abandoned")}]})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Your library tags (exact)"}),e.jsx(Ye,{value:a.tag,getOptions:p=>x.suggestLibraryTags(p),placeholder:"Any tag",searchPlaceholder:"Search your tags...",onChange:p=>n({...a,tag:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"AO3 tags"}),e.jsx(Ye,{value:a.workTag,getOptions:p=>x.suggestWorkTags(p),placeholder:"Any AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:p=>n({...a,workTag:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Romantic pairs"}),e.jsx(xe,{values:a.pairMembers,onChange:p=>n({...a,pairMembers:p}),getOptions:p=>d.isReady?d.suggestRelationships(p,50):Promise.resolve([]),transformOptions:Fa,triggerPlaceholder:"Any relationships",searchPlaceholder:"Type to search relationships..."}),e.jsx(Oe,{title:"Exact pairs only",checked:a.pairExact,onChange:p=>n({...a,pairExact:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Characters (all)"}),e.jsx(xe,{values:a.characters,onChange:p=>n({...a,characters:p}),getOptions:p=>d.isReady?d.suggestCharacters(p,50):Promise.resolve([]),triggerPlaceholder:"Any characters",searchPlaceholder:"Type to search characters..."})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Fandoms (any)"}),e.jsx(xe,{values:a.fandoms,onChange:p=>n({...a,fandoms:p}),getOptions:p=>d.isReady?d.suggestFandoms(p,50):Promise.resolve([]),triggerPlaceholder:"Any fandom",searchPlaceholder:"Search all fandoms..."})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Categories (any)"}),e.jsx(Qe,{values:a.categoryFilter,onChange:p=>n({...a,categoryFilter:p}),options:Da.map(p=>({value:p,label:p}))})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Archive warnings (any)"}),e.jsx(xe,{values:a.includeWarnings,onChange:S,options:[...Wt],triggerPlaceholder:"Any warnings",searchPlaceholder:"Search warningsâ¦",maxChips:2})]})]}),e.jsxs("div",{className:"col-span-full my-3 flex items-center gap-3",children:[e.jsx("div",{className:"h-px flex-1 bg-border"}),e.jsx("span",{className:"shrink-0 text-xs font-semibold uppercase tracking-wider text-content-muted",children:"Hide from results"}),e.jsx("div",{className:"h-px flex-1 bg-border"})]}),e.jsxs("div",{className:y,children:[e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Your library tags"}),e.jsx(Ye,{value:a.excludeTag,getOptions:p=>x.suggestLibraryTags(p),placeholder:"Hide library tag",searchPlaceholder:"Search your tags...",onChange:p=>n({...a,excludeTag:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"AO3 tags"}),e.jsx(Ye,{value:a.excludeWorkTag,getOptions:p=>x.suggestWorkTags(p),placeholder:"Hide AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:p=>n({...a,excludeWorkTag:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Romantic pairs"}),e.jsx(xe,{values:a.excludePairMembers,onChange:p=>n({...a,excludePairMembers:p}),getOptions:p=>d.isReady?d.suggestRelationships(p,50):Promise.resolve([]),transformOptions:Fa,triggerPlaceholder:"Hide relationship",searchPlaceholder:"Type to search relationships..."}),e.jsx(Oe,{title:"Exact pairs only",checked:a.excludePairExact,onChange:p=>n({...a,excludePairExact:p})})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Characters (any)"}),e.jsx(xe,{values:a.excludeCharacters,onChange:p=>n({...a,excludeCharacters:p}),getOptions:p=>d.isReady?d.suggestCharacters(p,50):Promise.resolve([]),triggerPlaceholder:"Hide characters",searchPlaceholder:"Type to search characters..."})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Fandoms (any)"}),e.jsx(xe,{values:a.excludeFandoms,onChange:p=>n({...a,excludeFandoms:p}),getOptions:p=>d.isReady?d.suggestFandoms(p,50):Promise.resolve([]),triggerPlaceholder:"Hide fandoms",searchPlaceholder:"Search all fandoms..."})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Categories (any)"}),e.jsx(Qe,{values:a.excludeCategoryFilter,onChange:p=>n({...a,excludeCategoryFilter:p}),options:Da.map(p=>({value:p,label:p}))})]}),e.jsxs("div",{className:g,children:[e.jsx("div",{className:N,children:"Archive warnings (any)"}),e.jsx(xe,{values:a.excludeWarnings,onChange:C,options:[...Wt],triggerPlaceholder:"No exclusions",searchPlaceholder:"Search warningsâ¦",maxChips:2})]})]})]})}const yi=["F/F","F/M","Gen","M/M","Multi","Other"],Zc={SAVED:gt("SAVED"),READING:gt("READING"),CAUGHT_UP:gt("CAUGHT_UP"),PAUSED:gt("PAUSED"),FINISHED:gt("FINISHED"),DROPPED:gt("DROPPED")};
2function Jc(t,a){return t.includes(a)?t.filter(n=>n!==a):[...t,a]}function ed(t){return t.split(/(?:\s*[/,&]\s*|\s+x\s+|\s+Ã\s+)/i).map(a=>a.trim()).filter(Boolean)}function wi(t){const a=new Map;for(const n of t)for(const s of ed(n))a.set(s,(a.get(s)??0)+1);return Array.from(a.entries()).sort((n,s)=>n[1]!==s[1]?s[1]-n[1]:n[0].localeCompare(s[0],void 0,{sensitivity:"base"})).map(([n])=>n)}function un(t){return t.toLocaleString("en-US")}function qe({title:t,children:a,className:n,defaultOpen:s=!0,count:i,onReset:o}){const[c,u]=r.useState(s),l=c?Qr:$n;return e.jsxs("section",{className:L("mf-section first:border-t-0",n),children:[e.jsxs("button",{type:"button",className:"mf-section-trigger focus-visible:outline-none focus-visible:shadow-ring","aria-expanded":c,onClick:()=>u(m=>!m),children:[e.jsxs("span",{className:"mf-section-label",children:[t,i&&i>0?e.jsx("span",{className:"mf-section-count",children:i}):null]}),e.jsxs("span",{className:"mf-section-meta",children:[o&&i&&i>0?e.jsx("span",{className:"mf-section-reset",onClick:m=>{m.stopPropagation(),o()},children:"reset"}):null,e.jsx(l,{className:L("mf-section-chevron",c&&"is-open"),"aria-hidden":!0})]})]}),c?e.jsx("div",{className:"mf-section-body",children:a}):null]})}function td({label:t,status:a,count:n,active:s,disabled:i,disabledReason:o,dotClass:c,onClick:u}){return e.jsxs("button",{type:"button","aria-pressed":s,"aria-label":t,"data-status":a?.toLowerCase(),disabled:i,onClick:u,className:L("mf-reading-row focus-visible:outline-none focus-visible:shadow-ring",s&&"is-on",i&&"cursor-not-allowed opacity-45 hover:bg-transparent"),children:[e.jsxs("span",{className:"inline-flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:L("h-1.5 w-1.5 rounded-full",c??"bg-border-strong"),"aria-hidden":!0}),e.jsx("span",{className:"truncate",children:t})]}),i&&o?e.jsx("span",{className:"mf-reading-reason",children:o}):n?e.jsx("span",{className:"mf-reading-count",children:n}):null]})}function ad({activeChips:t,onResetAll:a,resultCount:n,totalCount:s}){const i=n===0;return e.jsxs("div",{className:"mf-header-compact",children:[e.jsxs("div",{className:"mf-header-title-row",children:[e.jsx("h2",{className:"mf-header-title",children:"Filters"}),e.jsx("p",{className:L("mf-header-count",i&&"is-zero"),children:i?`0 of ${un(s)}`:`${un(n)} of ${un(s)}`})]}),a?e.jsx("button",{type:"button",className:"mf-header-reset",disabled:t.length===0,onClick:a,children:"Reset"}):null]})}function nd({filters:t,onChange:a}){const n=t.statuses.length;return e.jsx(qe,{title:"Reader status",count:n,children:e.jsx("div",{className:"mf-reading-list",role:"group","aria-label":"Reader status filters",children:On.map(s=>{const i=t.statuses.includes(s);return e.jsx(td,{label:yt(s),status:s,active:i,dotClass:Zc[s],onClick:()=>a({...t,statuses:Jc(t.statuses,s)})},s)})})})}function sd({filters:t,onChange:a}){return e.jsx(qe,{title:"Story updates",count:t.storyUpdates==="NEW"?1:0,onReset:()=>a({...t,storyUpdates:"ANY"}),children:e.jsx(Oe,{title:"New updates",sub:"Saved stories with an unseen AO3 announcement.",checked:t.storyUpdates==="NEW",onChange:n=>a({...t,storyUpdates:n?"NEW":"ANY"})})})}function rd({searchValue:t,onSearchChange:a}){return e.jsx("section",{className:"mf-search-section",children:e.jsx(Z,{label:"Search",children:e.jsx(Ql,{value:t,onChange:a,placeholder:"Title, author, fandom, notes, tags...",leadingIcon:e.jsx(Sn,{className:"h-4 w-4"}),clearable:!0})})})}function id({filters:t,onChange:a}){return e.jsx(qe,{title:"Work status",count:t.completionStatus.length,onReset:()=>a({...t,completionStatus:[]}),children:e.jsx(Qe,{values:t.completionStatus,onChange:n=>a({...t,completionStatus:n}),options:[{value:"complete",label:Ve("complete")},{value:"wip",label:Ve("wip")},{value:"hiatus",label:Ve("hiatus")},{value:"abandoned",label:Ve("abandoned")}]})})}function od({filters:t,onChange:a,suggestions:n}){return e.jsx(qe,{title:"Source",count:t.platforms.length,onReset:()=>a({...t,platforms:[]}),children:e.jsx(Z,{label:"Platform",hint:"source",children:e.jsx(xe,{values:t.platforms,onChange:s=>a({...t,platforms:s}),getOptions:s=>n.suggestPlatforms(s),triggerPlaceholder:"Any platform",searchPlaceholder:"Search platforms...",maxChips:2})})})}function ld({filters:t,onChange:a}){return e.jsxs(qe,{title:"Ratings",count:t.ratings.length+(t.minRating?1:0)+(t.entryRating==="UNRATED"?1:0),onReset:()=>a({...t,ratings:[],minRating:void 0,entryRating:"ANY"}),children:[e.jsx(Z,{label:"Archive rating",hint:"from source",children:e.jsx(Vn,{values:t.ratings,onChange:n=>a({...t,ratings:n})})}),e.jsx(Z,{label:"Your rating",hint:"user-set",children:e.jsx(Hn,{value:t.minRating,entryRating:t.entryRating,onChange:n=>a({...t,minRating:n,entryRating:n?"ANY":t.entryRating}),onEntryRatingChange:n=>a({...t,entryRating:n,minRating:void 0})})})]})}function cd({filters:t,onChange:a}){return e.jsxs(qe,{title:"Length & popularity",count:(t.minWords||t.maxWords?1:0)+(t.minKudos||t.maxKudos?1:0),onReset:()=>a({...t,minWords:void 0,maxWords:void 0,minKudos:void 0,maxKudos:void 0}),children:[e.jsxs(Z,{label:"Word count",hint:"words",children:[e.jsx(Bn,{min:t.minWords,max:t.maxWords,onChange:({min:n,max:s})=>a({...t,minWords:n,maxWords:s})}),e.jsx(Ft,{min:t.minWords,max:t.maxWords,onChange:({min:n,max:s})=>a({...t,minWords:n,maxWords:s})})]}),e.jsx(Z,{label:"Kudos / favs",hint:"range",children:e.jsx(Ft,{min:t.minKudos,max:t.maxKudos,onChange:({min:n,max:s})=>a({...t,minKudos:n,maxKudos:s}),unit:"kudos"})})]})}function dd({filters:t,onChange:a}){const n=t.notes??(t.hasNotes?"WITH":"ANY");return e.jsxs(qe,{title:"Notes",count:n!=="ANY"?1:0,onReset:()=>a({...t,hasNotes:!1,notes:"ANY"}),children:[e.jsx(Oe,{title:"Stories with your notes",sub:"Find stories you've left private notes on.",checked:n==="WITH",onChange:s=>a({...t,hasNotes:!1,notes:s?"WITH":"ANY"})}),e.jsx(Oe,{title:"Stories without your notes",sub:"Find stories where your private note is still empty.",checked:n==="WITHOUT",onChange:s=>a({...t,hasNotes:!1,notes:s?"WITHOUT":"ANY"})})]})}function ud({filters:t,onChange:a}){return e.jsx(qe,{title:"Date",count:t.lastReadAfter||t.lastReadBefore?1:0,onReset:()=>a({...t,lastReadAfter:"",lastReadBefore:""}),children:e.jsx(Z,{label:"Read between",hint:"date range",children:e.jsx(Un,{start:t.lastReadAfter,end:t.lastReadBefore,onChange:({start:n,end:s})=>a({...t,lastReadAfter:n,lastReadBefore:s})})})})}function md({filters:t,onChange:a,suggestions:n}){const s=pt();return e.jsxs(qe,{title:"Tags and fandoms",count:t.fandoms.length+(t.tag?1:0)+(t.
2workTag?1:0),onReset:()=>a({...t,fandoms:[],tag:"",workTag:""}),children:[e.jsx(Z,{label:"Fandom",hint:`${t.fandoms.length} selected`,children:e.jsx(xe,{values:t.fandoms,onChange:i=>a({...t,fandoms:i}),getOptions:i=>s.isReady?s.suggestFandoms(i,50):Promise.resolve([]),triggerPlaceholder:"Any fandom",searchPlaceholder:"Search all fandoms...",maxChips:2})}),e.jsxs("div",{className:"mf-tag-stack",children:[e.jsx(Z,{label:"Library tag",hint:"yours",children:e.jsx(Ye,{value:t.tag,onChange:i=>a({...t,tag:i}),getOptions:i=>n.suggestLibraryTags(i),placeholder:"Any tag",searchPlaceholder:"Search your tags..."})}),e.jsx(Z,{label:"AO3 tag",hint:"from source",children:e.jsx(Ye,{value:t.workTag,onChange:i=>a({...t,workTag:i}),getOptions:i=>n.suggestWorkTags(i),placeholder:"Any AO3 tag",searchPlaceholder:"Search AO3 tags..."})})]})]})}function pd({filters:t,onChange:a}){const n=pt(),s=i=>{const o=new Set(i);a({...t,includeWarnings:i,excludeWarnings:t.excludeWarnings.filter(c=>!o.has(c))})};return e.jsxs(qe,{title:"Archive metadata",count:t.categoryFilter.length+t.pairMembers.length+(t.pairExact&&t.pairMembers.length?1:0)+t.characters.length+t.includeWarnings.length,onReset:()=>a({...t,categoryFilter:[],pairMembers:[],pairExact:!1,characters:[],includeWarnings:[]}),children:[e.jsx(Z,{label:"Categories",hint:"from source",children:e.jsx(Qe,{values:t.categoryFilter,onChange:i=>a({...t,categoryFilter:i}),options:yi.map(i=>({value:i,label:i}))})}),e.jsx(Z,{label:"Must include relationships",hint:`${t.pairMembers.length} selected`,children:e.jsx(Cs,{values:t.pairMembers,onChange:i=>a({...t,pairMembers:i}),getOptions:i=>n.isReady?n.suggestRelationships(i,50):Promise.resolve([]),transformOptions:wi,searchPlaceholder:"Type to search relationships..."})}),e.jsx(Oe,{title:"Exact relationships only",checked:t.pairExact,onChange:i=>a({...t,pairExact:i})}),e.jsx(Z,{label:"Must include characters",hint:`${t.characters.length} selected`,children:e.jsx(Cs,{values:t.characters,onChange:i=>a({...t,characters:i}),getOptions:i=>n.isReady?n.suggestCharacters(i,50):Promise.resolve([]),searchPlaceholder:"Type to search characters..."})}),e.jsx(Z,{label:"Include warnings",hint:`${t.includeWarnings.length} selected`,children:e.jsx(xe,{values:t.includeWarnings,onChange:s,options:[...Wt],triggerPlaceholder:"Any warnings",searchPlaceholder:"Search warnings",maxChips:2})})]})}function hd({filters:t,onChange:a,suggestions:n}){const s=pt(),i=o=>{const c=new Set(o);a({...t,excludeWarnings:o,includeWarnings:t.includeWarnings.filter(u=>!c.has(u))})};return e.jsxs(qe,{title:"Hide from results",defaultOpen:!1,count:(t.excludeTag?1:0)+(t.excludeWorkTag?1:0)+t.excludePairMembers.length+(t.excludePairExact&&t.excludePairMembers.length?1:0)+t.excludeCharacters.length+t.excludeFandoms.length+t.excludeCategoryFilter.length+t.excludeWarnings.length,onReset:()=>a({...t,excludeTag:"",excludeWorkTag:"",excludePairMembers:[],excludePairExact:!1,excludeCharacters:[],excludeFandoms:[],excludeCategoryFilter:[],excludeWarnings:[]}),children:[e.jsxs("div",{className:"mf-tag-stack",children:[e.jsx(Z,{label:"Hidden library tag",children:e.jsx(Ye,{value:t.excludeTag,getOptions:o=>n.suggestLibraryTags(o),placeholder:"Hide library tag",searchPlaceholder:"Search your tags...",onChange:o=>a({...t,excludeTag:o})})}),e.jsx(Z,{label:"Hidden AO3 tag",children:e.jsx(Ye,{value:t.excludeWorkTag,getOptions:o=>n.suggestWorkTags(o),placeholder:"Hide AO3 tag",searchPlaceholder:"Search AO3 tags...",onChange:o=>a({...t,excludeWorkTag:o})})})]}),e.jsx(Z,{label:"Hidden relationships",hint:`${t.excludePairMembers.length} selected`,children:e.jsx(xe,{values:t.excludePairMembers,onChange:o=>a({...t,excludePairMembers:o}),getOptions:o=>s.isReady?s.suggestRelationships(o,50):Promise.resolve([]),transformOptions:wi,triggerPlaceholder:"Hide relationship",searchPlaceholder:"Type to search relationships..."})}),e.jsx(Oe,{title:"Exact hidden relationships only",checked:t.excludePairExact,onChange:o=>a({...t,excludePairExact:o})}),e.jsx(Z,{label:"Hidden characters",hint:`${t.excludeCharacters.length} selected`,children:e.jsx(xe,{values:t.excludeCharacters,onChange:o=>a({...t,excludeCharacters:o}),getOptions:o=>s.isReady?s.suggestCharacters(o,50):Promise.resolve([]),triggerPlaceholder:"Hide characters",searchPlaceholder:"Type to search characters..."})}),e.jsx(Z,{label:"Hidden fandoms",hint:`${t.excludeFandoms.length} selected`,children:e.jsx(xe,{values:t.excludeFandoms,onChange:o=>a({...t,excludeFandoms:o}),getOptions:o=>s.isReady?s.suggestFandoms(o,50):Promise.resolve([]),triggerPlaceholder:"Hide fandoms",searchPlaceholder:"Search all fandoms..."})}),e.jsx(Z,{label:"Hidden categories",children:e.jsx(Qe,{values:t.excludeCategoryFilter,onChange:o=>a({...t,excludeCategoryFilter:o}),options:yi.map(o=>({value:o,label:o}))})}),e.jsx(Z,{label:"Excluded warnings",hint:`${t.excludeWarnings.length} selected`,children:e.jsx(xe,{values:t.excludeWarnings,onChange:i,options:[...Wt],triggerPlaceholder:"No exclusions",searchPlaceholder:"Search warnings",maxChips:2})})]})}function xd({storyUpdatesEnabled:t=!0,filters:a,onChange:n,onSearchChange:s,searchValue:i,suggestions:o}){const c=pt(),u=o??c;return e.jsxs(e.Fragment,{children:[e.jsx(rd,{searchValue:i,onSearchChange:s}),t?e.jsx(sd,{filters:a,onChange:n}):null,e.jsx(nd,{filters:a,onChange:n}),e.jsx(id,{filters:a,onChange:n}),e.jsx(od,{filters:a,onChange:n,suggestions:u}),e.jsx(ld,{filters:a,onChange:n}),e.jsx(cd,{filters:a,onChange:n}),e.jsx(dd,{filters:a,onChange:n}),e.jsx(ud,{filters:a,onChange:n}),e.jsx(md,{filters:a,onChange:n,suggestions:u}),e.jsx(pd,{filters:a,onChange:n}),e.jsx(hd,{filters:a,onChange:n,suggestions:u})]})}const bd="relative z-30 hidden border-y border-[var(--line)] bg-[color-mix(in_oklab,var(--paper-2)_86%,transparent)] sm:block",gd="mx-auto flex w-full max-w-[96rem] items-center gap-4 px-[18px] py-3 sm:px-12 lg:px-16",ji="inline-flex shrink-0 items-center gap-2 font-mono text-[10px] font-medium uppercase leading-none text-[var(--ink-4)] [&_svg]:h-3.5 [&_svg]:w-3.5",fd="flex min-w-0 flex-1 items-center gap-2 overflow-x-auto pb-0.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",vd=et(["inline-flex min-h-9 max-w-[18rem] shrink-0 items-center gap-2 rounded-pill border px-3.5","font-sans text-[13px] font-medium leading-none outline-none transition-colors","focus-visible:shadow-ring [&_svg]:h-3.5 [&_svg]:w-3.5"].join(" "),{variants:{active:{true:"border-[var(--ink)] bg-[var(--archive-inverse-surface)] text-[var(--archive-inverse-text)]",false:"border-[var(--line-strong)] bg-transparent text-[var(--ink-2)] hover:border-[var(--ink-3)] hover:text-[var(--ink)]"},dirty:{true:"border-[var(--honey)] shadow-[0_0_0_2px_color-mix(in_oklab,var(--honey)_24%,transparent)]",false:""}},defaultVariants:{active:!1,dirty:!1}}
2),yd="min-w-0 truncate",ia="rounded-pill bg-[color-mix(in_oklab,var(--ink)_10%,transparent)] px-1.5 py-0.5 font-mono text-[10.5px] leading-none text-current opacity-70",Ps="inline-flex min-h-9 shrink-0 items-center rounded-pill border border-[var(--line)] px-3 font-mono text-[10px] font-medium uppercase leading-none text-[var(--ink-4)]",$a="h-1.5 w-1.5 shrink-0 rounded-pill bg-[var(--honey)]",wd="inline-flex min-h-9 shrink-0 items-center gap-1.5 rounded-pill border border-[var(--line-strong)] bg-transparent px-3 font-sans text-[13px] font-medium leading-none text-[var(--ink-3)] outline-none transition-colors hover:border-[var(--ink-3)] hover:text-[var(--ink)] focus-visible:shadow-ring [&_svg]:h-3.5 [&_svg]:w-3.5",jd="ml-auto flex shrink-0 items-center gap-2",Nd="inline-flex min-h-10 items-center gap-2 rounded-pill border border-[color-mix(in_oklab,var(--honey)_45%,var(--line))] bg-[color-mix(in_oklab,var(--honey)_12%,transparent)] py-1 pl-3 pr-1",Sd="inline-flex items-center gap-2 whitespace-nowrap text-[12.5px] font-medium text-[var(--ink)]",Ot="mx-auto w-full max-w-[96rem] px-[18px] pb-3 font-sans text-xs leading-snug text-[var(--ink-3)] sm:px-12 lg:px-16",Ms="mx-auto w-full max-w-[96rem] px-[18px] pb-4 sm:px-12 lg:px-16",kd="overflow-hidden rounded-sm border border-[var(--line-strong)] bg-[var(--paper-2)] shadow-[var(--shadow-popover)]",Cd="rounded-sm bg-[color-mix(in_oklab,var(--paper-2)_74%,transparent)]",_d="flex items-start justify-between gap-3 border-b border-[var(--line)] px-4 py-3",Rd="flex items-start justify-between gap-3 px-4 pb-2 pt-3",Ni="font-mono text-[10px] font-medium uppercase text-[var(--ink-4)]",Si="mt-1 font-landing-serif text-xl font-medium leading-tight text-[var(--ink)]",ki="mt-1 max-w-2xl text-sm leading-snug text-[var(--ink-3)]",Ld="p-4",Ad="px-4 pb-3 pt-1",Td="rounded-sm bg-[color-mix(in_oklab,var(--card)_70%,transparent)] p-3",Ed="font-mono text-[9.5px] font-medium uppercase text-[var(--ink-4)]",Pd="mt-2 flex flex-wrap items-center gap-2 text-sm text-[var(--ink-2)]",mn="inline-flex min-h-7 max-w-full items-center rounded-pill border border-[var(--line-strong)] bg-[var(--paper-2)] px-2.5 font-mono text-[10.5px] font-medium uppercase leading-none text-[var(--ink-3)]",Md="grid gap-3 md:grid-cols-[minmax(0,1fr)_12.5rem]",Id="max-h-[26rem] space-y-2 overflow-y-auto px-2 py-2 [scrollbar-width:thin]",Od="grid min-h-14 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-2 rounded-xs border border-[var(--line)] bg-[var(--card)] px-2 py-2",Dd="rounded-xs border border-[var(--line)] bg-[color-mix(in_oklab,var(--card)_72%,transparent)]",Fd="flex items-center justify-between gap-3 border-b border-[var(--line)] px-3 py-2 font-mono text-[9.5px] font-medium uppercase text-[var(--ink-4)]",$d="grid min-h-16 grid-cols-[2rem_2rem_minmax(0,1fr)_2rem_2rem] items-center gap-2 border-t border-[var(--line)] px-2 py-2 first:border-t-0",Wd="hidden shrink-0 text-[var(--ink-5)] sm:inline-flex [&_svg]:h-4 [&_svg]:w-4",Bd="grid w-8 shrink-0 grid-rows-2 gap-1",Is="inline-flex h-6 w-8 items-center justify-center rounded-2xs border border-[var(--line-strong)] text-[var(--ink-4)] outline-none transition-colors hover:border-[var(--ink-3)] hover:text-[var(--ink)] focus-visible:shadow-ring disabled:cursor-not-allowed disabled:opacity-35 [&_svg]:h-3.5 [&_svg]:w-3.5",Vd="inline-flex h-8 w-8 shrink-0 items-center justify-center rounded-xs border border-[var(--line-strong)] text-[var(--ink-4)] outline-none transition-colors hover:border-[var(--ink-3)] hover:text-[var(--ink)] focus-visible:shadow-ring aria-pressed:border-[color-mix(in_oklab,var(--honey)_55%,var(--line))] aria-pressed:bg-[color-mix(in_oklab,var(--honey)_13%,transparent)] aria-pressed:text-[var(--honey)] [&_svg]:h-4 [&_svg]:w-4",Os="flex min-w-0 flex-1 items-center gap-1.5 text-left outline-none focus-visible:shadow-ring",Ds="block min-w-0 truncate text-sm font-semibold leading-snug text-[var(--ink)]",Fs="mt-0.5 block min-w-0 truncate font-mono text-[10.5px] uppercase leading-none text-[var(--ink-4)]",Hd="min-w-0 space-y-1.5",Ud="h-9 w-full min-w-0 rounded-xs border border-[var(--line-strong)] bg-[var(--paper-2)] px-2.5 font-sans text-sm text-[var(--ink)] outline-none focus-visible:shadow-ring",Yd="flex flex-wrap items-center gap-2",Ci="mt-1 flex min-h-5 flex-wrap items-center gap-x-3 gap-y-1 text-xs leading-snug",_i="text-[var(--ink-3)]",Ri="font-medium text-[var(--rust)]",Li="text-[var(--ink-3)]",Ai="mt-1 rounded-xs border border-[color-mix(in_oklab,var(--rust)_35%,var(--line))] bg-[color-mix(in_oklab,var(--rust)_8%,transparent)] px-2.5 py-2 text-xs leading-snug text-[var(--rust)]",Kd="px-3 py-3 text-sm leading-snug text-[var(--ink-3)]",zd="rounded-sm border border-[var(--line-strong)] bg-[var(--card)] p-3",qd="mb-3 flex items-center justify-between gap-3",Gd="flex min-w-0 gap-2 overflow-x-auto pb-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",$s="inline-flex min-h-10 max-w-[17rem] shrink-0 items-center gap-2 rounded-sm border border-[var(--line-strong)] bg-[var(--paper-2)] px-3 text-sm font-medium leading-none text-[var(--ink-2)] outline-none transition-colors focus-visible:shadow-ring aria-pressed:border-[var(--ink)] aria-pressed:bg-[var(--ink)] aria-pressed:text-[var(--paper)] [&_svg]:h-4 [&_svg]:w-4",Qd="mt-3 rounded-sm border border-[color-mix(in_oklab,var(--honey)_42%,var(--line))] bg-[color-mix(in_oklab,var(--honey)_11%,transparent)] p-3",Xd="text-sm leading-snug text-[var(--ink-2)]",Zd="mt-3 grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_2.75rem] gap-2",Ln="mt-3 text-sm leading-snug text-[var(--ink-3)]",Ti="mt-3 rounded-sm border border-[color-mix(in_oklab,var(--rust)_32%,var(--line))] bg-[color-mix(in_oklab,var(--rust)_8%,transparent)] p-3 text-sm leading-snug text-[var(--ink-2)]",Je="all";
2function Be(t){return t.toLocaleString("en-US")}function pn(t){return t.trim().replace(/\s+/g," ").toLocaleLowerCase()}function An(t){const a=t.trim();return a?a.length>ta?`Use ${ta} characters or fewer.`:null:"Enter a view name."}function Ei({name:t,existingNames:a,currentName:n}){const s=pn(t);if(!s)return!1;const i=n?pn(n):null;return a.some(o=>{const c=pn(o);return c===s&&c!==i})}function Pi(t,a){const n=t==="all"?a:t.liveCount;return typeof n!="number"?null:t==="all"?`${Be(n)} stories in All Library`:`${Be(n)} matching stories`}function Mi(t,a){return r.useMemo(()=>t.find(n=>n.id===a)??null,[a,t])}function Ii({pinned:t,active:a}){return t?a?e.jsx(Xr,{"aria-hidden":!0}):e.jsx(Ma,{"aria-hidden":!0}):e.jsx(vt,{"aria-hidden":!0})}function Jd({item:t,allLibraryCount:a}){const n=t==="all"?a:t.liveCount;if(typeof n!="number")return null;const s=Pi(t,a);return e.jsx("span",{className:ia,"aria-label":s??void 0,children:Be(n)})}function hn({item:t,active:a,dirty:n,allLibraryCount:s,onSelect:i}){const o=t==="all",c=o?"All Library":t.name,u=Pi(t,s),l=[a?`Active Library View: ${c}`:`Select Library View: ${c}`,!o&&t.pinned?"pinned":null,u,a&&n?"unsaved edits":null].filter(m=>!!m);return e.jsxs("button",{type:"button",className:vd({active:a,dirty:a&&n}),"aria-pressed":a,"aria-label":l.join(", "),onClick:i,children:[o?e.jsx(vt,{"aria-hidden":!0}):e.jsx(Ii,{pinned:t.pinned,active:a}),e.jsx("span",{className:yd,children:c}),e.jsx(Jd,{item:t,allLibraryCount:s}),a&&n?e.jsx("span",{className:$a,"aria-hidden":!0}):null]})}function Oi({activeView:t,dirty:a,hasAdHocQuery:n,activeFilterCount:s,handlers:i,mutationState:o,onBeforeOpenPanel:c,compact:u=!1}){const l=!!t&&o?.updatingViewId===t?.id,m=o?.creating===!0;return t&&a?u?e.jsxs("div",{className:Qd,children:[e.jsxs("p",{className:Xd,children:[e.jsx("strong",{children:t.name})," has unsaved edits."]}),e.jsxs("div",{className:Zd,children:[e.jsx(de,{type:"button",size:"sm",variant:"solid",onClick:i.onUpdateView,loading:l,disabled:l,"aria-label":`Update ${t.name} with current filters`,leftIcon:e.jsx(ut,{}),children:"Update"}),e.jsx(de,{type:"button",size:"sm",variant:"outline",onClick:d=>{c?.(d.currentTarget),i.onOpenSave(!0)},disabled:m,"aria-label":"Save current edits as a new Library View",leftIcon:e.jsx(Pl,{}),children:"Save new"}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":"Revert to saved view",title:"Revert to saved view",onClick:i.onRevertView,className:"h-[var(--control-h)] w-full rounded-sm",children:e.jsx(Ia,{"aria-hidden":!0})})]})]}):e.jsxs("div",{className:Nd,children:[e.jsxs("span",{className:Sd,children:[e.jsx("span",{className:$a,"aria-hidden":!0}),"Unsaved edits"]}),e.jsx(de,{type:"button",size:"sm",variant:"solid",onClick:i.onUpdateView,loading:l,disabled:l,"aria-label":`Update ${t.name} with current filters`,leftIcon:e.jsx(ut,{}),children:"Update"}),e.jsx(de,{type:"button",size:"sm",variant:"outline",onClick:d=>{c?.(d.currentTarget),i.onOpenSave(!0)},disabled:m,"aria-label":"Save current edits as a new Library View",children:"Save as new"}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":"Revert to saved view",title:"Revert to saved view",onClick:i.onRevertView,children:e.jsx(Ia,{"aria-hidden":!0})})]}):!t&&n?u?e.jsxs("div",{className:"mt-3 flex items-center gap-3",children:[e.jsxs("p",{className:"min-w-0 flex-1 text-sm leading-snug text-[var(--ink-3)]",children:[e.jsx("strong",{className:"text-[var(--ink)]",children:s})," ","active refinements are not saved yet."]}),e.jsx(de,{type:"button",size:"sm",variant:"solid",onClick:d=>{c?.(d.currentTarget),i.onOpenSave(!1)},disabled:m,"aria-label":`Save ${s} active refinements as a Library View`,leftIcon:e.jsx(mt,{}),children:"Save"})]}):e.jsx(de,{type:"button",size:"sm",variant:"solid",onClick:d=>{c?.(d.currentTarget),i.onOpenSave(!1)},disabled:m,"aria-label":`Save ${s} active refinements as a Library View`,leftIcon:e.jsx(mt,{}),children:"Save current view"}):t&&u?e.jsxs("p",{className:Ln,children:["Showing ",e.jsx("strong",{className:"text-[var(--ink)]",children:t.name}),".",t.summary?` ${t.summary}.`:null]}):e.jsx(de,{type:"button",size:"sm",variant:"outline",disabled:!0,children:"Save current view"})}function Di({isError:t,isLoading:a,hasViews:n,compact:s=!1}){return t?e.jsx("p",{className:s?Ti:Ot,children:"Saved views could not load. All Library is still available."}):a?e.jsx("p",{className:s?Ln:Ot,children:"Loading saved views."}):n?null:e.jsx("p",{className:s?Ln:Ot,children:"No saved views yet. Refine All Library and save a private view to return later."})}function eu({views:t,activeViewId:a,dirty:n,hasAdHocQuery:s,isError:i=!1,isLoading:o=!1,allLibraryCount:c,visibleCount:u,activeFilterCount:l,capturedQuery:m,panelMode:d=null,
2saveAsNew:x=!1,zeroResultView:y=!1,overflowLabel:g,mutationState:N,handlers:S}){const C=r.useRef(null),_=Mi(t,a),p=a===null||a===Je,b=d==="manage",k=t.filter(A=>A.pinned),j=t.filter(A=>!A.pinned),O=_&&!_.pinned?[_]:j.slice(0,k.length>5?0:1),R=r.useCallback(A=>{C.current=A},[]),F=r.useCallback(()=>{S.onClosePanel(),window.setTimeout(()=>{C.current?.focus()},0)},[S]);return e.jsx("section",{"aria-label":"Library Views",children:e.jsxs("div",{className:bd,children:[e.jsxs("div",{className:gd,children:[e.jsxs("span",{className:ji,children:[e.jsx(vt,{"aria-hidden":!0}),"Library views"]}),e.jsxs("div",{className:fd,role:"list","aria-label":"Saved Library Views",children:[e.jsx(hn,{item:"all",active:p,dirty:n&&p,allLibraryCount:c,onSelect:()=>S.onSelectView(Je)}),k.map(A=>e.jsx(hn,{item:A,active:A.id===a,dirty:n,allLibraryCount:c,onSelect:()=>S.onSelectView(A.id)},A.id)),O.map(A=>e.jsx(hn,{item:A,active:A.id===a,dirty:n,allLibraryCount:c,onSelect:()=>S.onSelectView(A.id)},A.id)),e.jsxs("button",{type:"button",className:wd,"aria-label":b?"Close Manage Library Views":`Manage Library Views, ${t.length} saved views`,"aria-expanded":b,onClick:A=>{if(R(A.currentTarget),b){F();return}S.onOpenManage()},children:[b?e.jsx(wt,{"aria-hidden":!0}):e.jsx(El,{"aria-hidden":!0}),b?"Close":"Manage",b?null:e.jsx("span",{className:ia,children:t.length})]}),o?e.jsx("span",{className:Ps,children:"Loading"}):null,i?e.jsx("span",{className:Ps,children:"Unavailable"}):null]}),e.jsx("div",{className:jd,children:e.jsx(Oi,{activeView:_,dirty:n,hasAdHocQuery:s,activeFilterCount:l,handlers:S,mutationState:N,onBeforeOpenPanel:R})})]}),g?e.jsx("p",{className:Ot,children:g}):o||i||t.length===0?e.jsx(Di,{isError:i,isLoading:o,hasViews:t.length>0}):s&&!_?e.jsxs("p",{className:Ot,children:[l," active refinements on All Library. Save them to return to this exact slice later."]}):y?e.jsxs("p",{className:Ot,children:["This active view currently matches ",Be(u)," ","stories. The saved query stays available and will fill again as your Library changes."]}):null,d==="save"?e.jsx("div",{className:Ms,children:e.jsx(Fi,{capturedQuery:m,saveAsNew:x,activeView:_,existingNames:t.map(A=>A.name),isPending:N?.creating,errorMessage:N?.errorMessage,onClose:F,onSave:A=>{if(S.onSaveView){S.onSaveView(A);return}S.onSelectView(_?.id??Je)}})}):null,d==="manage"?e.jsx("div",{className:Ms,children:e.jsx($i,{views:t,activeViewId:a,allLibraryCount:c,mutationState:N,onClose:F,onSelectView:S.onSelectView,onTogglePin:S.onTogglePin,onRenameView:S.onRenameView,onDeleteView:S.onDeleteView,onMoveView:S.onMoveView})}):null]})})}function tu({activeView:t,dirty:a}){return t?{id:"library-view",label:a?"View edited":"View",value:t.name,ariaLabel:a?`Library View ${t.name}, unsaved edits`:`Library View ${t.name}`}:null}function Ws({title:t,eyebrow:a="Library views",description:n}){return e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"mf-header-eyebrow",children:[e.jsx(vt,{className:"h-4 w-4","aria-hidden":!0}),a]}),e.jsx("h2",{className:"mf-header-title",children:t}),n?e.jsx("p",{className:"mf-header-count",children:n}):null]})}function au({views:t,activeViewId:a,dirty:n,hasAdHocQuery:s,isError:i=!1,isLoading:o=!1,allLibraryCount:c,visibleCount:u,activeFilterCount:l,zeroResultView:m=!1,mutationState:d,handlers:x}){const y=Mi(t,a),g=a===null||a===Je,N=t.filter(C=>C.pinned),S=y&&!y.pinned?[y,...N.filter(C=>C.id!==y.id)]:N;return e.jsx(_n,{title:"Library Views",children:e.jsxs("div",{className:zd,children:[e.jsxs("div",{className:qd,children:[e.jsxs("span",{className:ji,children:[e.jsx(vt,{"aria-hidden":!0}),"Views"]}),e.jsx("button",{type:"button",className:"text-xs font-medium text-[var(--ink-3)] outline-none hover:text-[var(--ink)] focus-visible:shadow-ring","aria-label":`Manage Library Views, ${t.length} saved views`,onClick:x.onOpenManage,children:"Manage"})]}),e.jsxs("div",{className:Gd,"aria-label":"Saved Library Views",children:[e.jsxs("button",{type:"button",className:$s,"aria-pressed":g,"aria-label":`Select Library View: All Library, ${Be(c)} stories in All Library${g&&n?", unsaved edits":""}`,onClick:()=>x.onSelectView(Je),children:[e.jsx(vt,{"aria-hidden":!0}),e.jsx("span",{className:"min-w-0 truncate",children:"All Library"}),e.jsx("span",{className:ia,children:Be(c)}),g&&n?e.jsx("span",{className:$a}):null]}),S.map(C=>e.jsxs("button",{type:"button",className:$s,"aria-pressed":C.id===a,"aria-label":[C.id===a?`Active Library View: ${C.name}`:`Select Library View: ${C.name}`,C.pinned?"pinned":null,typeof C.liveCount=="number"?`${Be(C.liveCount)}
2 matching stories`:null,C.id===a&&n?"unsaved edits":null].filter(Boolean).join(", "),onClick:()=>x.onSelectView(C.id),children:[e.jsx(Ii,{pinned:C.pinned,active:C.id===a}),e.jsx("span",{className:"min-w-0 truncate",children:C.name}),typeof C.liveCount=="number"?e.jsx("span",{className:ia,children:Be(C.liveCount)}):null,C.id===a&&n?e.jsx("span",{className:$a}):null]},C.id))]}),e.jsx(Oi,{activeView:y,dirty:n,hasAdHocQuery:s,activeFilterCount:l,handlers:x,mutationState:d,compact:!0}),o||i||t.length===0?e.jsx(Di,{isError:i,isLoading:o,hasViews:t.length>0,compact:!0}):null,m?e.jsxs("div",{className:Ti,children:["This saved view matches ",e.jsx("strong",{children:Be(u)})," ","stories right now. It remains private and will update automatically when matching stories appear."]}):null]})})}function Fi({capturedQuery:t,saveAsNew:a,activeView:n,existingNames:s=[],isPending:i=!1,errorMessage:o,onClose:c,onSave:u,showHeader:l=!0}){const m=a&&n?`${n.name} copy`:"",[d,x]=r.useState(m),[y,g]=r.useState(!1),[N,S]=r.useState(!!m),[C,_]=r.useState(!1),p=r.useRef(null),b=r.useId(),k=r.useId(),j=r.useId(),O=a?"Save as a new view":"Save current view",R=d.trim(),F=An(d),z=!!(F&&(N||C||R.length>ta))?F:null,Q=Ei({name:d,existingNames:s,currentName:void 0}),te=!F&&!i,v=[j,z?b:null,Q?k:null].filter(f=>!!f).join(" ");r.useEffect(()=>{p.current?.focus(),p.current?.select()},[]);const $=r.useCallback(()=>{_(!0),te&&u({name:R,pinned:y})},[te,u,y,_,R]);return e.jsxs("section",{className:l?Cd:"rounded-sm border border-[var(--line-strong)] bg-[var(--card)]","aria-label":O,children:[l?e.jsxs("div",{className:Rd,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:Ni,children:"Private saved query"}),e.jsx("h3",{className:Si,children:O}),e.jsx("p",{className:ki,children:"Captures search, sort, and filters. Stories stay in your Library; the result set updates as metadata changes."})]}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":"Close save view panel",onClick:c,children:e.jsx(wt,{"aria-hidden":!0})})]}):null,e.jsxs("div",{className:L(l?Ad:Ld,Md),children:[e.jsxs("div",{className:"min-w-0 space-y-2.5",children:[e.jsxs("label",{className:"tf-row block",children:[e.jsxs("span",{className:"tf-label",children:[e.jsx("span",{children:"View name"}),e.jsx("span",{className:"tf-hint",children:"private to you"})]}),e.jsx("span",{className:"tf-field is-focus mt-1",children:e.jsx("input",{ref:p,value:d,onChange:f=>{S(!0),x(f.currentTarget.value)},onBlur:()=>S(!0),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),$())},placeholder:"Longfic in progress","aria-invalid":!!z,"aria-describedby":v})}),e.jsxs("span",{className:Ci,children:[e.jsxs("span",{id:j,className:_i,children:[R.length,"/",ta," characters"]}),z?e.jsx("span",{id:b,className:Ri,role:"alert",children:z}):Q?e.jsx("span",{id:k,className:Li,children:"Duplicate names are allowed."}):null]})]}),o?e.jsx("div",{className:Ai,role:"alert",children:o}):null,e.jsxs("div",{className:Td,children:[e.jsx("p",{className:Ed,children:"Captured query"}),e.jsxs("div",{className:Pd,children:[e.jsxs("span",{className:mn,children:["Sort: ",t.sortLabel]}),t.search?e.jsxs("span",{className:mn,children:["Search: ",t.search]}):null,t.chips.length?t.chips.map(f=>e.jsx("span",{className:mn,children:f},f)):e.jsx("span",{className:"text-sm italic text-[var(--ink-4)]",children:"No filters. This view saves the whole shelf with the selected sort."})]})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3 rounded-sm bg-[color-mix(in_oklab,var(--card)_70%,transparent)] p-3",children:[e.jsxs("button",{type:"button",className:"tf-toggle-row rounded-sm","aria-pressed":y,disabled:i,onClick:()=>g(f=>!f),children:[e.jsxs("span",{className:"tf-toggle-main",children:[e.jsx("span",{className:"tf-toggle-title",children:"Pin to views row"}),e.jsx("span",{className:"tf-toggle-sub",children:"Pinned views can show a live count."})]}),e.jsx("span",{className:L("tf-switch",y&&"is-on"),"aria-hidden":!0})]}),e.jsxs("div",{className:"mt-auto flex gap-2",children:[e.jsx(de,{type:"button",variant:"outline",onClick:c,disabled:i,children:"Cancel"}),e.jsx(de,{type:"button",variant:"solid",className:"flex-1",disabled:!te,loading:i,onClick:$,leftIcon:e.jsx(ut,{}),children:"Save view"})]})]})]})]})}function $i({views:t,activeViewId:a,allLibraryCount:n,mutationState:s,onClose:i,onSelectView:o,onTogglePin:c,onRenameView:u,onDeleteView:l,onMoveView:m,showHeader:d=!0}){const x=t.filter(f=>f.pinned),y=t.filter(f=>!f.pinned),g=x[0]?.id??y[0]?.id??null,N=r.useRef(null),S=r.useRef(null),C=r.useRef(null),[_,p]=r.useState(null),[b,k]=r.useState(""),[j,O]=r.useState(null),R=r.useMemo(()=>t.map(f=>f.name),[t]),F=!!(s?.creating||s?.updatingViewId||s?.deletingViewId||s?.reorderingViewId);r.useEffect(()=>{N.current?.focus()},[]),r.useEffect(()=>{_&&(S.current?.focus(),S.current?.select())},[_]),r.useEffect(()=>{j&&(t.some(f=>f.id===j.id)||O(null))},[j,t]);const A=r.useCallback(()=>{O(null),window.setTimeout(()=>{C.current?.focus()},0)},[O]),z=r.useCallback(f=>{p(f.id),k(f.name)},[]),Q=r.useCallback(()=>{p(null),k("")},[]),te=r.useCallback(f=>{const U=b.trim();if(!An(b)){if(U===f.name){Q();return}u(f.id,U),Q()}},[Q,b,u]),v=(f,U,oe,se)=>{const G=_===f.id,I=s?.updatingViewId===f.id,E=s?.deletingViewId===f.id,Y=s?.reorderingViewId===f.id,W=G?An(b):null,J=G&&Ei({name:b,existingNames:R,currentName:f.name}),X=G&&!W&&b.trim()!==f.name&&!I,ee=`library-view-rename-help-${f.id}`,le=`library-view-rename-error-${f.id}`,ae=`library-view-rename-duplicate-${f.id}`;return e.jsxs("div",{className:$d,children:[e.jsxs("div",{className:B
2d,"aria-label":`Reorder ${f.name}`,children:[e.jsx("button",{type:"button",className:Is,"aria-label":`Move ${f.name} up in ${se}`,title:`Move ${f.name} up`,disabled:oe===0||!!s?.reorderingViewId,onClick:()=>m(f.id,"up"),children:e.jsx(Qr,{"aria-hidden":!0})}),e.jsx("button",{type:"button",className:Is,"aria-label":`Move ${f.name} down in ${se}`,title:`Move ${f.name} down`,disabled:oe===U.length-1||!!s?.reorderingViewId,onClick:()=>m(f.id,"down"),children:e.jsx($n,{"aria-hidden":!0})})]}),e.jsx("button",{type:"button","aria-label":f.pinned?`Unpin ${f.name}`:`Pin ${f.name}`,"aria-pressed":f.pinned,className:Vd,disabled:F,onClick:()=>c(f.id),children:I?e.jsx("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent","aria-hidden":!0}):f.pinned?e.jsx(Xr,{"aria-hidden":!0}):e.jsx(Ma,{"aria-hidden":!0})}),G?e.jsxs("form",{className:Hd,onSubmit:P=>{P.preventDefault(),te(f)},children:[e.jsxs("label",{className:"sr-only",htmlFor:`library-view-rename-${f.id}`,children:["Rename ",f.name]}),e.jsx("input",{id:`library-view-rename-${f.id}`,ref:S,className:Ud,value:b,onChange:P=>k(P.currentTarget.value),onKeyDown:P=>{P.key==="Escape"&&(P.preventDefault(),Q())},"aria-invalid":!!W,"aria-describedby":[ee,W?le:null,J?ae:null].filter(Boolean).join(" ")}),e.jsxs("span",{className:Ci,children:[e.jsxs("span",{id:ee,className:_i,children:[b.trim().length,"/",ta," characters"]}),W?e.jsx("span",{id:le,className:Ri,role:"alert",children:W}):J?e.jsx("span",{id:ae,className:Li,children:"Duplicate names are allowed."}):null]}),e.jsxs("div",{className:Yd,children:[e.jsx(de,{type:"button",variant:"ghost",size:"sm",onClick:Q,disabled:I,children:"Cancel"}),e.jsx(de,{type:"submit",variant:"solid",size:"sm",loading:I,disabled:!X,children:"Rename"})]})]}):e.jsx("button",{type:"button",ref:f.id===g?N:void 0,className:Os,"aria-label":[f.id===a?`Active Library View: ${f.name}`:`Select Library View: ${f.name}`,f.pinned?"pinned":"unpinned",typeof f.liveCount=="number"?`${Be(f.liveCount)} matching stories`:"no live count"].join(", "),"aria-pressed":f.id===a,onClick:()=>o(f.id),children:e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:Ds,children:f.name}),e.jsxs("span",{className:Fs,children:[f.pinned&&typeof f.liveCount=="number"?`${Be(f.liveCount)} stories · `:"unpinned · no live count · ",f.summary]})]})}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":`Rename ${f.name}`,title:`Rename ${f.name}`,disabled:F||G,onClick:()=>z(f),children:e.jsx(Ml,{"aria-hidden":!0})}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":`Delete ${f.name}`,title:`Delete ${f.name}`,loading:E,disabled:F||G||Y,onClick:P=>{C.current=P.currentTarget,O(f)},className:"text-[var(--rust)] hover:text-[var(--rust)]",children:e.jsx(Oa,{"aria-hidden":!0})})]},f.id)},$=(f,U,oe)=>e.jsxs("div",{className:Dd,children:[e.jsxs("div",{className:Fd,children:[e.jsx("span",{children:f}),e.jsx("span",{"aria-label":`${U.length} ${f.toLowerCase()}`,children:U.length})]}),U.length?U.map((se,G)=>v(se,U,G,f)):e.jsx("p",{className:Kd,children:oe})]});return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:d?kd:"roun
2ded-sm border border-[var(--line-strong)] bg-[var(--card)]","aria-label":"Manage Library Views",children:[d?e.jsxs("div",{className:_d,children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:Ni,children:"Manage views"}),e.jsx("h3",{className:Si,children:"Reorder, pin, rename, or delete"}),e.jsx("p",{className:ki,children:"Deleting a view removes only the saved query. Stories and Collections stay in your Library."})]}),e.jsx(ct,{type:"button",variant:"ghost","aria-label":"Close manage views panel",onClick:i,children:e.jsx(wt,{"aria-hidden":!0})})]}):null,e.jsxs("div",{className:Id,children:[s?.errorMessage?e.jsx("div",{className:Ai,role:"alert",children:s.errorMessage}):null,e.jsxs("div",{className:Od,children:[e.jsx("span",{className:Wd,children:e.jsx(Tl,{"aria-hidden":!0})}),e.jsx("button",{type:"button",ref:g?void 0:N,className:Os,"aria-label":`Select Library View: All Library, ${Be(n)} stories in All Library`,"aria-pressed":!a,onClick:()=>o(Je),children:e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:Ds,children:"All Library"}),e.jsx("span",{className:Fs,children:"System view"})]})}),e.jsx("span",{className:ia,children:Be(n)})]}),$("Pinned views",x,"Pin saved views to keep them in the desktop row."),$("Unpinned views",y,"Unpinned views stay private and available from Manage.")]})]}),e.jsx($t,{open:!!j,surface:"archive",variant:"danger",title:j?`Delete "${j.name}" view?`:"Delete saved view?",description:"This deletes only the saved Library View. It does not delete stories, Collections, notes, tags, or reading progress.",confirmLabel:"Delete view",cancelLabel:"Cancel",loading:!!(j&&s?.deletingViewId===j.id),onCancel:A,onConfirm:()=>{j&&(l(j.id),O(null))}})]})}const nu=nc,su=`${oi} ${lc} hidden min-w-0 sm:flex`,ru=`${oi} ${sc}`,iu=`${cc} sm:min-w-[280px] sm:flex-[1_1_32rem]`,ou=dc,lu=uc,cu=mc,du="inline-flex h-10 shrink-0 items-center justify-center gap-2 rounded-[10px] border border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] px-3 font-sans text-[13px] font-medium leading-none text-[var(--ink-2)] outline-none transition hover:border-[var(--line-strong)] hover:bg-[var(--card)] hover:text-[var(--ink)] focus-visible:shadow-ring data-[popup-open]:border-[var(--line-strong)] data-[popup-open]:bg-[var(--card)] data-[popup-open]:text-[var(--ink)]",uu="h-3.5 w-3.5 shrink-0",mu="inline-flex shrink-0 items-center gap-0.5 rounded-[10px] border border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] p-[3px]",pu="inline-flex h-8 items-center gap-1.5 rounded-[7px] border border-transparent px-3 font-sans text-[12.5px] font-medium leading-none tracking-normal text-[var(--ink-3)] transition hover:text-[var(--ink)] [&_svg]:h-[14px] [&_svg]:w-[14px] [&_svg]:shrink-0",hu="border-[var(--line-strong)] bg-[var(--card)] text-[var(--ink)] hover:text-[var(--ink)] [&_svg]:text-[var(--rust)]",xu="flex items-stretch gap-2 border-b border-[var(--line)] bg-[var(--paper)] px-4 pb-3 sm:hidden",bu="grid min-h-10 min-w-0 flex-1 grid-cols-2 gap-0.5 rounded-[10px] border border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] p-[3px]",gu="inline-flex min-w-0 items-center justify-center gap-1.5 rounded-[7px] border border-transparent px-2 text-[12.5px] font-medium leading-none text-[var(--ink-3)] transition hover:text-[var(--ink)] [&_svg]:h-[15px] [&_svg]:w-[15px] [&_svg]:shrink-0",fu="border-[var(--line-strong)] bg-[var(--card)] text-[var(--ink)] [&_svg]:text-[var(--rust)]",Bs="inline-flex min-h-10 shrink-0 items-center justify-center gap-1.5 rounded-[10px] border border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] px-3 text-[12.5px] font-medium leading-none text-[var(--ink-2)] outline-none transition hover:border-[var(--line-strong)] hover:bg-[var(--card-2)] hover:text-[var(--ink)] focus-visible:shadow-ring aria-expanded:border-[var(--line-strong)] aria-expanded:bg-[var(--card-2)] [&_svg]:h-[14px] [&_svg]:w-[14px] [&_svg]:shrink-0",vu="absolute right-1 top-1 inline-flex h-4 min-w-4 items-center justify-center rounded-pill bg-[var(--rust)] px-1 font-mono text-[9px] font-semibold leading-none text-[var(--paper)]",yu="flex w-full max-w-full min-w-0 items-stretch gap-2",wu="max-h-64 overflow-hidden opacity-100 transition-[max-height,opacity,transform] duration-[260ms] ease-[cubic-bezier(.2,.7,.2,1)] motion-reduce:transition-opacity motion-reduce:duration-[80ms]",ju="max-h-0 -translate-y-1.5 opacity-0 motion-reduce:translate-y-0",Nu="space-y-3",Wi=oc,Su=rc,ku=ic,Cu="ml-auto shrink-0 font-mono text-[11px] uppercase leading-none tracking-[0.18em] text-[var(--ink-4)]",ua={value:"LAST_READ_DESC",label:"Recently read",shortLabel:"Recent"},oa=[{value:"BEST_MATCH",label:"Search relevance",shortLabel:"Relevance"},ua,{value:"STORY_UPDATE_DESC",label:"Recently updated",shortLabel:"Updates"},{value:"WORK_UPDATED_DESC",label:"Work updated",shortLabel:"Work updated"},{value:"UPDATED_DESC",label:"Recently edited",shortLabel:"Edited"},{value:"TITLE_ASC",label:"Title (AâZ)",shortLabel:"Title AâZ"},{value:"TITLE_DESC",label:"Title (ZâA)",shortLabel:"Title ZâA"},{value:"RATING_DESC",label:"Star rating (high â low)",shortLabel:"Stars high"},{value:"RATING_ASC",label:"Star rating (low â high)",shortLabel:"Stars low"}],ot="tf-opt outline-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-45 data-[highlighted]:bg-[var(--paper-2)] data-[highlighted]:text-[var(--ink)]",Jt="tf-label px-[14px] pb-1 pt-2",_u=[{value:"compact",label:"Compact",description:"Scan reading activity quickly",icon:Il},{value:"browse",label:"Detailed",description:"Show more story details and controls",icon:vt}];function Ru({sortOptions:t,bulkMode:a,canAdd:n,onAdd:s,shareCount:i,shareTitle:o,onShare:c,canCreateCollectionFromTags:u,canCreateCollectionFromCurrentFilter:l,onCreateCollectionFromTags:m,onCreateCollectionFromCurrentFilter:d,onToggleBulk:x,sort:y,onSortChange:g,showAdd:N=!0,showSelect:S=!0,showSort:C=!0,triggerAriaLabel:_="More library actions"}){return e.jsxs(ei,{children:[e.jsx(ti,{className:L(Wi,"data-[popup-open]:border-[var(--ink-3)] data-[popup-open]:text-[var(--ink)]"),"aria-label":_,children:e.jsx(Dl,{"aria-hidden":!0})}),e.jsx(ai,{children:e.jsx(ni,{side:"bottom",align:"end",sideOffset:6,children:e.jsxs(si,{className:"library-app archive-editorial-shell tf-pop !relative !left-auto !right-auto !top-auto !z-[1340] !min-w-[14rem] outline-none",children:[e.jsxs(Zt,{children:[e.jsx("div",{className:Jt,children:"Library"}),N&&n&&!a?e.jsx(it,{className:ot,onClick:()=>{s()},children:e.jsx("span",{className:"tf-opt-label",children:"Add manually"})}):null,e.jsxs(it,{className:ot,disabled:i===0,onClick:()=>{i>0&&c()},title:o,children:[e.jsx("span",{className:"tf-opt-label",children:"Share"}),i>0?e.jsx("span",{className:"tf-opt-meta",children:i}):null]}),S?e.jsx(it,{className:ot,onClick:()=>{x()},children:e.jsx("span",{className:"tf-opt-label",children:a?"Cancel selection":"Select stories"})}):null]}),a?null:e.jsxs(e.Fragment,{children:[e.jsx(Cn,{className:"my-1 h-px bg-[var(--line)]"}),e.jsxs(Zt,{children:[e.jsx("div",{className:Jt,children:"Collections"}),e.jsx(it,{className:ot,disabled:!l,onClick:()=>{l&&d?.()},children:e.jsx("span",{className:"tf-opt-label",children:"Create collection from current filters"})}),e.jsx(it,{className:ot,disabled:!u,onClick:()=>{u&&m?.()},children:e.jsx("span",{className:"tf-opt-label",children:"Create collection from private tags"})})]})]}),C?e.jsxs(e.Fragment,{children:[e.jsx(Cn,{className:"my-1 h-px bg-[var(--line)]"}),e.jsx("div",{className:Jt,children:"Sort by"}),e.jsx(Zt,{children:t.map(p=>e.jsxs(it,{className:L(ot,y===p.value&&"is-on"),onClick:()=>
2g(p.value),children:[e.jsx("span",{className:"tf-opt-label",children:p.label}),y===p.value?e.jsx("span",{className:"tf-opt-mark","aria-hidden":!0,children:e.jsx(sa,{})}):null]},p.value))})]}):null]})})})]})}function Bi(t,a=oa){return a.find(n=>n.value===t)??ua}function Lu({sortOptions:t,sort:a,onSortChange:n,groupingMode:s,onGroupingModeChange:i}){const o=Bi(a,t),c=s==="series"?" · Series":"";return e.jsxs(ei,{children:[e.jsxs(ti,{className:du,"aria-label":`Change sort, current sort ${o.label}${s==="series"?", grouped by series":""}`,children:[e.jsxs("span",{children:[o.shortLabel,c]}),e.jsx(Ol,{className:uu,"aria-hidden":!0})]}),e.jsx(ai,{children:e.jsx(ni,{side:"bottom",align:"end",sideOffset:6,children:e.jsxs(si,{className:"library-app archive-editorial-shell tf-pop !relative !left-auto !right-auto !top-auto !z-[1340] !min-w-[13rem] outline-none",children:[e.jsx("div",{className:Jt,children:"Sort by"}),e.jsx(Zt,{children:t.map(u=>e.jsxs(it,{className:L(ot,a===u.value&&"is-on"),onClick:()=>n(u.value),children:[e.jsx("span",{className:"tf-opt-label",children:u.label}),a===u.value?e.jsx("span",{className:"tf-opt-mark","aria-hidden":!0,children:e.jsx(sa,{})}):null]},u.value))}),e.jsx(Cn,{className:"my-1 h-px bg-[var(--line)]"}),e.jsx("div",{className:Jt,children:"Group by"}),e.jsx(Zt,{children:[{value:"none",label:"No grouping"},{value:"series",label:"Series"}].map(u=>e.jsxs(it,{className:L(ot,s===u.value&&"is-on"),onClick:()=>i?.(u.value),children:[e.jsx("span",{className:"tf-opt-label",children:u.label}),s===u.value?e.jsx("span",{className:"tf-opt-mark","aria-hidden":!0,children:e.jsx(sa,{})}):null]},u.value))})]})})})]})}function Au({sortOptions:t=oa,sort:a,onSortChange:n,groupingMode:s="none",onGroupingModeChange:i}){return e.jsxs(e.Fragment,{children:[e.jsx(_n,{title:"Sort by",children:e.jsx(Rs,{label:"Sort library stories",children:t.map(o=>e.jsx(ln,{active:a===o.value,onClick:()=>n(o.value),children:o.label},o.value))})}),e.jsx(_n,{title:"Group by",children:e.jsxs(Rs,{label:"Group library stories",children:[e.jsx(ln,{active:s==="none",onClick:()=>i?.("none"),children:"No grouping"}),e.jsx(ln,{active:s==="series",onClick:()=>i?.("series"),children:"Series"})]})})]})}function Tu({storyUpdatesEnabled:t=!0,totalCount:a,resultCount:n,bulkMode:s,onToggleBulk:i,canAdd:o,onAdd:c,selectedCount:u,visibleCount:l,onShare:m,canCreateCollectionFromTags:d=!1,canCreateCollectionFromCurrentFilter:x=!1,onCreateCollectionFromTags:y,onCreateCollectionFromCurrentFilter:g,searchValue:N,onSearchChange:S,onClearSearch:C,searchRef:_,sort:p,onSortChange:b,showFilters:k,onToggleFilters:j,activeFilterCount:O,filtersPanelId:R="filters-panel",mobileChips:F=[],mobilePresentation:A="default",mobileRuntime:z="browser",mobileChromeState:Q="full",mobileTitle:te="Library.",mobileTitleAriaLabel:v,mobileStats:$,mobileCollapsedStats:f,onMobileSearchActiveChange:U,densityMode:oe="compact",onDensityModeChange:se,groupingMode:G="none",onGroupingModeChange:I,variant:E="default"}){const[Y,W]=r.useState(!1),[J,X]=r.useState(!1),[ee,le]=r.useState(!1),[ae,P]=r.useState(!1),re=u||l,me=u?`Share selected stories (${u})`:`Share visible stories (${l})`,ce=n??l,We=typeof n=="number"?`Show ${n.toLocaleString()} ${n===1?"story":"stories"}`:"Show stories",pe=typeof a=="number"?`${ce.toLocaleString()} of ${a.toLocaleString()} matching`:null,De=E==="sticky",Se=t?oa:oa.filter(ke=>ke.value!=="STORY_UPDATE_DESC"),M=Bi(p,Se),T=G==="series"?`${M.shortLabel} · Series`:M.shortLabel,K=F,q=Q==="collapsed",fe=ee||ae;r.useEffect(()=>{U?.(fe)},[fe,U]);const be=()=>W(!1),we=ke=>{be(),ke()},ve=ke=>e.jsxs("div",{className:iu,children:[e.jsx(Sn,{className:ou,"aria-hidden":!0}),e.jsx(Nn,{placeholder:"Search title, author, fandom, tag...",value:N,onChange:ge=>S(ge.target.value),ref:ke,"data-library-toolbar-search":!0,className:lu}),N&&e.jsx(ct,{type:"button","aria-label":"Clear search",onClick:C,className:cu,variant:"ghost",children:"Ã"})]}),Re=(ke=!1)=>e.jsx("div",{className:ke?bu:mu,role:"group","aria-label":"Library density",children:_u.map(ge=>{const tt=ge.icon;return e.jsxs("button",{type:"button",className:L(ke?gu:pu,oe===ge.value&&(ke?fu:hu)),"aria-pressed":oe===ge.value,title:ge.description,onClick:()=>se?.(ge.value),children:[e.jsx(tt,{"aria-hidden":!0}),ge.label]},ge.value)})}),He=()=>e.jsx(wc,{title:te,titleAriaLabel:v,collapsedTitle:te,meta:$,collapsedMeta:f,collapsed:q,runtime:z,className:"relative",actions:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:As,"aria-label":"Search library","aria-haspopup":"dialog","aria-expanded":ee,"aria-controls":"library-mobile-search-sheet",onClick:()=>le(!0),children:e.jsx(Sn,{"aria-hidden":!0})}),e.jsxs("button",{type:"button",className:As,"aria-label":O?`Open filters, ${O} active`:"Open filters","aria-expanded":k,"aria-controls":R,onClick:j,children:[e.jsx(ws,{"aria-hidden":!0}),O?e.jsx("span",{className:vu,children:O}):null]})]}),controls:e.jsxs("div",{className:yu,children:[Re(!0),e.jsxs("button",{type:"button",className:Bs,"aria-label":`Sort library stories, current sort ${M.label}${G==="series"?", grouped by series":""}`,"aria-haspopup":"dialog","aria-expanded":J,"aria-controls":"library-mobile-sort-sheet",onClick:()=>X(!0),title:"Sort library stories",children:[e.jsx(ys,{"aria-hidden":!0}),e.jsx("span",{children:T})]})]})});return e.jsxs("div",{"data-archive-toolbar":!0,"data-library-toolbar":!0,"data-runtime":z,"data-chrome":Q,className:nu,children:[A==="nativeCompact"?He():e.jsxs("div",{className:L(wu,q&&ju),"data-library-mobile-browser-collapse-region":!0,"aria-hidden":q,children:[e.jsx(pc,{className:ru,searchLabel:"Search library",searchPlaceholder:"Search title, author, tag...",searchValue:N,onSearchChange:S,onClearSearch:C,searchRef:_,searchInputProps:{"data-library-toolbar-search":!0,onBlur:()=>P(!1),onFocus:()=>P(!0),tabIndex:q?-1:void 0},refineIconOnly:!0,refineActiveCount:O,refineExpanded:k,refineControlsId:R,onRefine:j,moreLabel:"More library actions",moreExpanded:Y,moreControlsId:"library-mobile-actions-sheet",onMore:()=>W(!0),chips:K,chipRailLabel:"Active library refinements",controlsTabIndex:q?-1:void 0}),e.jsxs("div",{className:xu,children:[Re(!0),e.jsxs("button",{type:"button",className:Bs,"aria-label":`Sort library stories, current sort ${M.label}${G==="series"?", grouped by series":""}`,"aria-haspopup":"dialog","aria-expanded":J,"aria-controls":"library-mobile-sort-sheet",tabIndex:q?-1:void 0,onClick:()=>X(!0),title:"Sort library stories",children:[e.jsx(ys,{"aria-hidden":!0}),e.jsx("span",{children:T})]})]})]}),e.jsx(on,{id:"library-mobile-sort-sheet",open:J,onOpenChange:X,title:"Sort library",eyebrow:"Sort",closeLabel:"Close library sort",footer:e.jsx("button",{type:"button",className:"a-btn is-primary w-full justify-center",onClick:()=>X(!1),children:We}),children:e.jsx(Au,{sortOptions:Se,sort:p,onSortChange:b,groupingMode:G,onGroupingModeChange:I})}),e.jsx(on,{id:"library-mobile-search-sheet",open:ee,onOpenChange:le,title:"Search library",eyebrow:"Search",closeLabel:"Close library search",footer
2:e.jsx("button",{type:"button",className:"a-btn is-primary w-full justify-center",onClick:()=>le(!1),children:"Done"}),children:e.jsx("div",{className:Nu,children:ve(_)})}),e.jsxs(on,{id:"library-mobile-actions-sheet",open:Y,onOpenChange:W,title:"Library actions",eyebrow:"More",closeLabel:"Close library actions",children:[o&&!s?e.jsx(Qt,{icon:e.jsx(mt,{}),label:"Add manually",description:"For SpaceBattles, Royal Road, Wattpad, and other unsupported sites",onClick:()=>we(c)}):null,e.jsx(Qt,{icon:e.jsx(sa,{}),label:s?"Done selecting":"Select stories",description:"Bulk status, tags, collections",onClick:()=>we(i)}),e.jsx(Qt,{icon:e.jsx(kn,{}),label:u?"Share selected stories":"Share visible stories",description:me,disabled:re===0,onClick:()=>{re>0&&we(m)}}),s?null:e.jsxs(e.Fragment,{children:[e.jsx(Qt,{icon:e.jsx(Zr,{}),label:"Create collection from current filters",description:"Use the matching Library result set",disabled:!x,onClick:()=>{x&&we(g??(()=>{}))}}),e.jsx(Qt,{icon:e.jsx(Jr,{}),label:"Create collection from private tags",description:"Seed a collection from your tag set",disabled:!d,onClick:()=>{d&&we(y??(()=>{}))}})]})]}),e.jsxs("div",{className:L(su,De&&"sm:py-3"),"data-archive-toolbar-surface":!0,children:[ve(_),Re(),e.jsx(Lu,{sortOptions:Se,sort:p,onSortChange:b,groupingMode:G,onGroupingModeChange:I}),e.jsxs("button",{type:"button",className:Su,onClick:i,"aria-pressed":s,"aria-label":s?"Done selecting stories":"Select stories",title:s?"Done":"Select stories",children:[e.jsx(sa,{"aria-hidden":!0}),e.jsx("span",{children:s?"Done":"Select"})]}),e.jsxs("button",{type:"button",className:L(Wi,k&&"border-[var(--ink-3)] text-[var(--ink)]"),onClick:j,title:"Filter your library","aria-label":O?`Open filters, ${O} active`:"Open filters","aria-expanded":k,"aria-controls":R,children:[e.jsx(ws,{"aria-hidden":!0}),O?e.jsx("span",{className:ku,children:O}):null]}),e.jsx(Ru,{sortOptions:Se,bulkMode:s,canAdd:o,onAdd:c,shareCount:re,shareTitle:me,onShare:m,canCreateCollectionFromTags:d,canCreateCollectionFromCurrentFilter:x,onCreateCollectionFromTags:y,onCreateCollectionFromCurrentFilter:g,onToggleBulk:i,sort:p,onSortChange:b,showAdd:!0,showSelect:!1,showSort:!1,triggerAriaLabel:"More desktop library actions"}),pe?e.jsx("p",{className:Cu,children:pe}):null]})]})}const Ca=et("relative z-0 mx-auto grid min-w-0 max-w-none grid-cols-1 items-start gap-0",{variants:{splitDetail:{false:"",true:"lg:mt-5"},densityMode:{compact:"gap-0 max-sm:-mx-4",browse:"gap-0 max-[899px]:pt-[13px] max-sm:gap-3"}},defaultVariants:{splitDetail:!1,densityMode:"compact"}}),Eu="",Pu="min-[900px]:overflow-hidden min-[900px]:rounded-[12px] min-[900px]:border min-[900px]:border-[var(--line)] min-[900px]:bg-[var(--card-sunk,var(--paper-2))]",Mu="hidden min-[900px]:grid min-[900px]:min-h-[34px] min-[900px]:grid-cols-[140px_minmax(0,1fr)_52px_124px_34px] min-[900px]:items-center min-[900px]:gap-[18px] min-[900px]:border-b min-[900px]:border-[var(--line)] min-[900px]:px-4 min-[900px]:pl-5",_a="font-mono text-[9.5px] font-medium uppercase leading-none tracking-[0.14em] text-[var(--ink-4)]",Iu="col-span-full min-w-0",Ou="grid min-h-13 grid-cols-[26px_minmax(0,1fr)_44px] items-stretch border-b border-[var(--line)] bg-[var(--card-sunk,var(--paper-2))] min-[900px]:min-h-8 min-[900px]:grid-cols-[30px_minmax(0,1fr)_32px]",Vs="flex min-w-0 items-center gap-2 px-2 py-2 text-left outline-none transition hover:bg-[color-mix(in_oklab,var(--card)_72%,transparent)] focus-visible:shadow-ring min-[900px]:px-3 min-[900px]:py-1",Du="size-3.5 shrink-0 text-[var(--ink-3)] transition-transform motion-reduce:transition-none",Hs="flex min-w-0 flex-1 flex-wrap items-baseline gap-x-2 gap-y-0.5",Us="font-mono text-[9px] font-semibold uppercase leading-none tracking-[0.16em] text-[var(--ink-4)]",Ys="max-w-full truncate font-mono text-[10.5px] font-medium uppercase leading-tight tracking-[0.14em] text-[var(--ink-2)]",Ks="min-w-0 font-sans text-[11.5px] leading-snug text-[var(--ink-4)]",Fu
2="inline-flex min-h-11 w-11 shrink-0 items-center justify-center self-stretch text-[var(--ink-3)] outline-none transition hover:bg-[var(--card)] hover:text-[var(--rust)] focus-visible:shadow-ring min-[900px]:min-h-8 min-[900px]:w-8 [&_svg]:size-3.5",$u="min-w-0",Wu="grid min-w-0 grid-cols-[26px_minmax(0,1fr)] min-[900px]:grid-cols-[30px_minmax(0,1fr)]",Bu="min-w-0",Vu="relative min-h-full text-[var(--ink-4)]",Hu="absolute bottom-0 right-2 top-0 w-px bg-[var(--line-strong,var(--line))]",Uu="absolute right-[5px] top-1/2 h-px w-[7px] -translate-y-1/2 bg-[var(--line-strong,var(--line))]",Yu="right-1 h-0.5 w-[9px] bg-[var(--rust)]",Ku="absolute right-[17px] top-1/2 -translate-y-1/2 font-mono text-[9px] leading-none text-[var(--ink-4)]",zu="text-[var(--rust)]";function qu({onAddManually:t}){const a=Fn(),n=r.useMemo(()=>ci(),[]),s=r.useMemo(()=>di(n),[n]),i=r.useMemo(()=>ui(n),[n]),o=r.useMemo(()=>null,[a.search]),c=mi({fixtureStatus:o});if(c.status.phase==="checking")return e.jsx(Vi,{});const u=c.status.phase==="detected";return e.jsxs("div",{className:"mx-auto flex min-h-[calc(100svh_-_13rem)] w-full max-w-3xl flex-col justify-center px-4 pb-8 pt-4 sm:min-h-0 sm:px-1 sm:pb-12 sm:pt-8",children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3 font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:[e.jsx(Ha,{className:"h-4 w-4 text-[var(--accent-editorial)]","aria-hidden":!0}),"My Library",e.jsx("span",{className:"h-px w-10 bg-border-strong","aria-hidden":!0}),"0 stories"]}),e.jsx("h2",{className:"font-landing-serif text-3xl font-semibold leading-tight text-content-primary sm:text-4xl",children:u?"Trace is installed.":"Add stories to your library."}),e.jsx("p",{className:"mt-3 max-w-[58ch] text-base leading-7 text-content-muted",children:u?"Open AO3 or FanFiction.net and use Trace as you browse to start adding stories.":"Add the Trace extension to save stories as you browse, or add one manually."}),e.jsxs("div",{className:"mt-6 flex flex-col gap-2 sm:flex-row sm:flex-wrap",children:[u?e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:"https://archiveofourown.org/works",target:"_blank",rel:"noopener noreferrer",className:L(dt({variant:"solid",size:"lg"}),"min-h-11 justify-center"),children:["Open AO3",e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]}),e.jsxs("a",{href:"https://www.fanfiction.net/",target:"_blank",rel:"noopener noreferrer",className:L(dt({variant:"outline",size:"lg"}),"min-h-11 justify-center bg-surface-1"),children:["Open FanFiction.net",e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]})]}):i?.href?e.jsxs("a",{href:i.href,target:"_blank",rel:"noopener noreferrer","aria-label":`Add Trace from ${i.label}`,className:L(dt({variant:"solid",size:"lg"}),"min-h-11 justify-center"),children:["Add Trace extension",e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]}):null,e.jsx(de,{type:"button",variant:"ghost",size:"lg",className:"min-h-11 justify-center",onClick:t,leftIcon:e.jsx(mt,{className:"h-4 w-4","aria-hidden":!0}),children:"Add manually"})]}),e.jsxs("p",{className:"mt-5 text-xs leading-5 text-content-muted",children:[u?"Extension not working? ":"Need help installing? ",e.jsx(aa,{to:s,className:"font-semibold text-content-primary underline decoration-border-strong underline-offset-4",children:"Open setup help"}),"."]})]})}function Gu(t){return new URLSearchParams(t).get("activation")==="extension-installed"}function Qu({setupHref:t,onAddManually:a,showManualFallback:n=!0}){return e.jsxs("div",{className:"relative rounded-xs border border-border bg-[color-mix(in_oklab,var(--library-surface-lowest)_62%,var(--library-bg))] p-5 pl-6 before:absolute before:bottom-4 before:left-0 before:top-4 before:w-1 before:bg-[var(--library-secondary)]",children:[e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsx("span",{className:"flex h-9 w-9 shrink-0 items-center justify-center rounded-xs border border-border bg-surface-2 text-content-muted",children:e.jsx(Wn,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:"Setup guide"}),e.jsx("p",{className:"font-landing-serif text-xl font-semibold leading-tight text-content-primary",children:"Want more setup help?"})]})]}),e.jsx("p",{className:"text-sm leading-relaxed text-content-muted",children:"Open the full guide for install links, screenshots, Safari permissions, recovery steps, and setup paths for other devices."}),e.jsxs(aa,{to:t,className:L(dt({variant:"solid",size:"lg"}),"mt-5 w-full justify-center sm:w-auto"),children:["Open setup guide",e.jsx(Ua,{className:"h-4 w-4","aria-hidden":!0})]}),n?e.jsxs("div",{className:"mt-5 border-t border-border-subtle pt-5",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:"Fallback"}),e.jsx("p",{className:"mt-1 text-sm leading-relaxed text-content-muted",children:"Use manual add for unsupported browsers, archives, or reading formats the Trace extension cannot save yet."}),e.jsx(de,{variant:"outline",size:"lg",onClick:a,className:"mt-4 w-full justify-center sm:w-auto",leftIcon:e.jsx(mt,{className:"h-4 w-4","aria-hidden":!0}),children:"Add manually"})]}):null]})}function Xu({installTarget:t,setupHref:a,onAddManually:n,setupPath:s}){const i=r.useId(),o=s==="ios-safari";return e.jsxs("section",{className:"relative min-h-[25rem] max-w-3xl overflow-hidden rounded-xs border border-border bg-surface-1 p-5 pl-6 shadow-sm before:absolute before:bottom-0 before:left-0 before:top-0 before:w-1 before:bg-[var(--forest)] sm:min-h-80 sm:p-6 sm:pl-7","aria-labelledby":i,children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-sm border border-[color-mix(in_oklab,var(--forest)_22%,var(--border))] bg-[var(--forest-soft)] text-[var(--forest)]","aria-hidden":!0,
2children:e.jsx(Wn,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-[var(--forest)]",children:o?"Trace app needed":"Extension not detected"}),e.jsx("h3",{id:i,className:"mt-1 font-landing-serif text-2xl font-semibold leading-tight text-content-primary",children:o?"Install the Trace app.":"Install the Trace extension."})]})]}),e.jsx("p",{className:"mt-4 max-w-[56ch] text-sm leading-relaxed text-content-muted",children:o?"Install the app, sign in, then enable the Safari extension.":"Trace is not installed in this browser yet. Install it once, then Trace can connect automatically."}),e.jsx("div",{className:"mt-6 flex flex-col gap-2 sm:flex-row sm:items-center",children:t?.href?e.jsxs("a",{href:t.href,target:"_blank",rel:"noopener noreferrer","aria-label":`Install Trace from ${t.label}`,className:L(dt({variant:"solid",size:"lg"}),"min-h-11 justify-center"),children:[o?"Install app":"Install extension",e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]}):e.jsxs(aa,{to:a,className:L(dt({variant:"solid",size:"lg"}),"min-h-11 justify-center"),children:["Open setup guide",e.jsx(Ua,{className:"h-4 w-4","aria-hidden":!0})]})}),e.jsxs("p",{className:"mt-5 border-t border-border-subtle pt-4 text-sm leading-6 text-content-muted",children:["Not using AO3 or FanFiction.net?"," ",e.jsx("button",{type:"button",className:"font-semibold text-content-primary underline decoration-border-strong underline-offset-4 hover:text-[var(--forest)]",onClick:n,children:"Add manually"}),"."]}),e.jsxs("p",{className:"mt-4 text-xs leading-5 text-content-muted",children:["Need help?"," ",e.jsx(aa,{to:a,className:"font-semibold text-content-primary underline decoration-border-strong underline-offset-4",children:"Open setup guide"}),"."]})]})}function Vi(){return e.jsxs("div",{role:"status","aria-label":"Checking Trace extension",className:"mt-6 max-w-3xl",children:[e.jsx("span",{className:"sr-only",children:"Checking Trace extension"}),e.jsx("div",{className:"h-10 w-64 max-w-full animate-pulse rounded-xs bg-surface-2"}),e.jsx("div",{className:"mt-3 h-5 w-80 max-w-full animate-pulse rounded-xs bg-surface-2"}),e.jsxs("div",{className:"relative mt-6 min-h-[20rem] overflow-hidden rounded-xs border border-border bg-surface-1 p-5 pl-6 shadow-sm before:absolute before:bottom-0 before:left-0 before:top-0 before:w-1 before:bg-border-strong sm:min-h-72 sm:p-6 sm:pl-7","aria-hidden":!0,children:[e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-sm border border-border-subtle bg-surface-2 text-content-muted",children:e.jsx(Ia,{className:"h-5 w-5 animate-spin"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"h-3 w-24 animate-pulse rounded-xs bg-surface-2"}),e.jsx("div",{className:"mt-3 h-7 w-56 max-w-full animate-pulse rounded-xs bg-surface-2"})]})]}),e.jsx("div",{className:"mt-6 h-4 w-full max-w-[32rem] animate-pulse rounded-xs bg-surface-2"}),e.jsx("div",{className:"mt-3 h-4 w-3/4 max-w-[26rem] animate-pulse rounded-xs bg-surface-2"}),e.jsx("div",{className:"mt-8 h-11 w-full max-w-[38rem] animate-pulse rounded-xs bg-surface-2"})]})]})}function Zu(t){return t==="ios-safari"?"Install app":"Install extension"}function Ju(t){return t==="ios-app"}function em(t){return t.connected?!0:t.phase==="detected"&&t.authState==="unknown"}function tm({onAddManually:t}){const a=Fn(),n=r.useMemo(()=>null,[a.search]),s=r.useMemo(()=>n??ci(),[n]),i=r.useMemo(()=>di(s),[s]),o=r.useMemo(()=>ui(s),[s]),c=r.useMemo(()=>null,[a.search]),u=r.useMemo(()=>null,[a.search]),l=r.useMemo(()=>null,[a.search]),m=Ju(s),d=r.useMemo(()=>Gu(a.search),[a.search]),x=mi({enabled:!m,fixtureStatus:m?null:c}),y=Tc(s)?"extension":"fallback",g=r.useMemo(()=>Nc(s),[s]),N=r.useMemo(()=>Sc(s),[s]),S=r.useCallback(z=>{hl(z,{surface:"library_empty"})},[]),C=da(),_=pt(),p=r.useCallback(async({handoffAt:z,baselineLibraryCount:Q})=>{if(u!=null)return!0;if(!_.isReady)return!1;const te=await C.fetchQuery({queryKey:je.me,queryFn:()=>_.me(),staleTime:0});return kc({libraryCount:te.library_count,firstStoryCompletedAt:te.first_story_completed_at,handoffAt:z,baselineLibraryCount:Q})},[_,u,C]),b=r.useCallback(()=>{C.invalidateQueries({queryKey:je.me}),C.invalidateQueries({queryKey:je.library.all})},[C]),k=Cc(x.status),j=r.useCallback(z=>{S({...z,extensionPhase:x.status.phase,extensionConnected:x.status.connected,extensionAuthState:x.status.authState,extensionBrowser
2Kind:x.status.browserKind,archiveHostKind:x.status.lastArchiveHostKind,archiveActionKind:x.status.lastArchiveActionKind,archiveErrorKind:x.status.lastArchiveErrorKind,firstSaveSeen:x.status.firstSaveSeen,extensionFirstStoryAddSupported:k,recentArchiveActivity:_c(x.status),libraryCountState:"empty"})},[k,x.status,S]),O=y==="extension"&&em(x.status),R=y==="extension"&&d&&x.status.phase==="checking",F=y==="extension"&&!R&&(x.status.phase==="checking"||x.status.phase==="not_detected"),A=O||m||R||F;return e.jsxs("div",{"data-testid":"library-empty-state",className:L("mx-auto w-full max-w-5xl px-4 sm:px-1 sm:pb-12 sm:pt-8",A?"flex min-h-[calc(100svh_-_13rem)] flex-col justify-center pb-6 pt-3 sm:block sm:min-h-0":"pb-28 pt-4"),children:[e.jsxs("div",{className:"mb-4 flex flex-wrap items-center gap-3 font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:[e.jsx(Ha,{className:"h-4 w-4 text-[var(--accent-editorial)]","aria-hidden":!0}),"My Library",e.jsx("span",{className:"h-px w-10 bg-border-strong","aria-hidden":!0}),"0 stories"]}),R?e.jsx(Vi,{}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"max-w-3xl font-landing-serif text-3xl font-semibold leading-tight text-content-primary sm:text-4xl",children:O?e.jsxs(e.Fragment,{children:["Add your"," ",e.jsx("em",{className:"font-normal italic text-[var(--rust)]",children:"first story."})]}):m?"Trace for Safari.":F?"Install Trace to start.":"Add your first story."}),e.jsx("p",{className:L("mt-3 max-w-2xl text-base leading-7 text-content-muted",A?"min-h-14":"min-h-20 sm:min-h-14"),children:O?e.jsx(e.Fragment,{children:"Paste a story URL below."}):m?e.jsx(e.Fragment,{children:"Finish the step below."}):F?e.jsx(e.Fragment,{children:"Trace did not find the extension in this browser yet."}):e.jsx(e.Fragment,{children:"Set up Trace once, then it can track stories and keep your place as you read. It only takes a few minutes. Start with the live step below, or open the full guide for screenshots and extra context."})}),e.jsxs("div",{className:L("mt-5 text-left sm:mt-6",A?"max-w-3xl":"grid gap-4 lg:grid-cols-[minmax(0,1.08fr)_minmax(0,0.92fr)]"),children:[O?e.jsx(Rc,{setupHref:i,extensionFirstStoryAddSupported:k,analyticsVariant:"compact",pathSupport:y,onAnalyticsEvent:j,manualAddAction:{onClick:t}}):m?e.jsx(Lc,{setupHref:i,isAuthenticated:!0,serverLibraryCount:0,confirmFirstStorySaved:p,onFirstStorySuccess:b,onAnalyticsEvent:S,analyticsVariant:"compact",manualAddAction:{onClick:t},fixtureState:u,fixtureVerificationState:l??"idle"}):F?e.jsx(Xu,{installTarget:o,setupHref:i,onAddManually:t,setupPath:s}):e.jsx(Ac,{status:x.status,libraryCount:0,pathSupport:y,stepLabels:g,stateCopy:N,onCheckAgain:x.checkAgain,onAnalyticsEvent:S,variant:"compact",completeAction:null,setupHref:i,installAction:o?.href?e.jsxs("a",{href:o.href,target:"_blank",rel:"noopener noreferrer","aria-label":`Install Trace from ${o.label}`,className:L(dt({variant:"solid",size:"sm"}),"min-h-10"),children:[Zu(s),e.jsx(It,{className:"h-4 w-4","aria-hidden":!0})]}):void 0,authAction:e.jsx(aa,{to:i,className:L(dt({variant:"solid",size:"sm"}),"min-h-10"),children:"Open setup guide"}),manualAddAction:e.jsx(de,{variant:"outline",size:"sm",onClick:t,className:"min-h-10",leftIcon:e.jsx(mt,{className:"h-4 w-4","aria-hidden":!0}),children:"Add manually"})}),!O&&!R&&!F&&!m?e.jsx(Qu,{setupHref:i,onAddManually:t,showManualFallback:y!=="fallback"&&!x.status.firstSaveSeen}):null]}),!O&&!R&&!F&&!m?e.jsxs("details",{className:"mt-8 rounded-xs border border-border-subtle bg-surface-1 px-4 py-4 text-sm leading-relaxed text-content-muted",children:[e.jsxs("summary",{className:"cursor-pointer font-semibold text-content-primary",children:[e.jsx(Fl,{className:"mr-2 inline h-5 w-5 shrink-0 text-content-muted","aria-hidden":!0}),"What Trace can see"]}),e.jsx("p",{className:"mt-3 max-w-3xl",children:"The extension reads supported archive pages you open. It does not ask for AO3 or FFN credentials, read story text, or inspect unrelated browsing. If AO3 or FFN shows nothing after Trace connects, allow the extension on that site, refresh, and try a story, listing, or bookmarks page."})]}):null]})]})}function am({onAddManually:t,firstStoryCompleted:a}){return a?e.jsx(qu,{onAddManually:t}):e.jsx(tm,{onAddManually:t})}function nm(t,a){return t||a?"No results. Try clearing filters or changing your search.":"No stories yet. Add one by URL to get started."}const sm=et(["@container group relative min-w-0 cursor-pointer overflow-visible text-left","bg-transparent","shadow-none outline-none","transition-[border-color,box-shadow] duration-100 ease-out","hover:bg-[color-mix(in_oklab,var(--paper-2)_35%,transparent)]","focus-visible:outline-none focus-visible:shadow-ring"].join(" "),{variants:{selected:{true:["bg-[color-mix(in_oklab,var(--rust-soft)_22%,transparent)]","shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--rust)_38%,transparent)]"].join(" ")},bulkMode:{true:""},isBehind:{true:""},densityMode:{compact:["border-b border-[var(--line)]","min-[900px]:before:bottom-0 min-[900px]:before:top-0 min-[900px]:before:rounded-none","max-[899px]:mb-0 max-[899px]:rounded-none max-[899px]:border-x-0 max-[899px]:border-t-0 max-[899px]:bg-transparent max-[899px]:shadow-none","max-[899px]:before:bottom-[11px] max-[899px]:before:top-[11px] max-[899px]:before:w-1 max-[899px]:before:rounded-r-[4px]"].join(" "),browse:["border-b border-[var(--line)]","max-[899px]:mb-[11px] max-[899px]:overflow-hidden max-[899px]:rounded-[5px] max-[899px]:border max-[899px]:border-[var(--line)] max-[899px]:bg-[var(--card)]","max-[899px]:shadow-none max-[899px]:before:hidden"].join(" ")},isEvaluating:{true:["z-[30] rounded-sm border border-[color-mix(in_oklab,var(--honey)_35%,var(--line))]","bg-[color-mix(in_oklab,var(--honey)_8%,var(--paper))]","shadow-[0_12px_28px_color-mix(in_oklab,var(--ink)_10%,transparent)]","max-[899px]:rounded-[5px] max-[899px]:border-0 max-[899px]:bg-[var(--card-2)] max-[899px]:shadow-[inset_0_0_0_1px_var(--line-strong)]"].join(" ")},celebrate:{true:"animate-card-pop"},statusChrome:{none:"",current:["trace-row-wash--current","bg-[color-mix(in_oklab,var(--status-reading)_15%,var(--paper))]","hover:bg-[color-mix(in_oklab,var(--status-reading)_19%,var(--paper))]","max-[899px]:!bg-[color-mix(in_oklab,var(--status-reading)_20%,var(--paper))]","max-[899px]:h
2over:!bg-[color-mix(in_oklab,var(--status-reading)_23%,var(--paper))]"].join(" ")}},defaultVariants:{statusChrome:"none",densityMode:"browse"}}),rm="max-[899px]:select-none max-[899px]:touch-pan-y max-[899px]:overscroll-x-contain max-[899px]:overflow-hidden",im=et(["absolute bottom-0 right-0 top-0 z-[30] hidden overflow-hidden border-0","rounded-r-[5px] bg-danger-600 text-[var(--solid-button-fg)]","font-mono text-micro font-semibold uppercase leading-none tracking-[0.08em]","shadow-[inset_1px_0_0_color-mix(in_oklab,var(--danger-700)_52%,transparent)] max-[899px]:inline-flex","disabled:cursor-not-allowed disabled:opacity-55"].join(" "),{variants:{open:{true:"pointer-events-auto opacity-100",false:"pointer-events-none opacity-0"}},defaultVariants:{open:!1}}),om="absolute inset-y-0 right-0 flex w-[88px] flex-col items-center justify-center gap-1 px-2",lm="grid h-6 w-6 shrink-0 place-items-center text-white",cm="h-5 w-5 shrink-0",dm="relative z-[30] min-w-0 will-change-transform [backface-visibility:hidden]",um="max-[899px]:shadow-[6px_0_18px_-14px_color-mix(in_oklab,var(--ink)_70%,transparent)]",mm="cursor-grabbing",pm=["hidden min-w-0 grid-cols-[minmax(0,1fr)_190px] gap-x-6","px-[26px] py-[22px] text-[var(--ink)] @min-[900px]:grid"].join(" "),hm="min-w-0",xm="mt-[9px] flex min-w-0 flex-wrap items-baseline gap-x-[11px] gap-y-1",bm="inline-flex h-[18px] w-[18px] shrink-0 translate-y-[2px] items-center justify-center",gm="min-w-0 max-w-[min(100%,42rem)] font-landing-serif text-[23px] font-medium leading-[1.12] tracking-normal text-[var(--ink)]",Tn="font-medium text-[var(--ink-2)]",fm="inline-flex shrink-0 items-center gap-0.5 font-mono text-[10px] font-medium uppercase leading-none tracking-[0.06em] text-[var(--rust)] underline-offset-2 hover:underline",vm="mt-1.5 flex min-w-0 flex-wrap items-center gap-x-[9px] gap-y-1 font-sans text-[13.5px] leading-snug text-[var(--ink-3)]",ym="inline-flex max-w-full items-center truncate rounded-2xs border border-[var(--line)] px-1.5 py-0.5 font-mono text-[9px] font-medium uppercase leading-none tracking-[0.08em] text-[var(--ink-4)]",wm=et(["inline-flex min-h-5 items-center rounded-pill border px-2","font-mono text-micro font-semibold uppercase leading-none tracking-[0.1em]"].join(" "),{variants:{tone:{neutral:"border-[color-mix(in_oklab,var(--library-outline)_18%,transparent)] bg-[color-mix(in_oklab,var(--paper-2)_62%,transparent)] text-[var(--ink-3)]",wip:"border-[color-mix(in_oklab,var(--honey)_42%,transparent)] bg-[color-mix(in_oklab,var(--honey)_13%,var(--library-surface-lowest))] text-[color-mix(in_oklab,var(--honey)_82%,var(--ink))]",complete:"border-[color-mix(in_oklab,var(--status-completed)_36%,transparent)] bg-[color-mix(in_oklab,var(--status-completed)_12%,var(--library-surface-lowest))] text-[var(--status-completed)]",hiatus:"border-[color-mix(in_oklab,var(--status-paused)_38%,transparent)] bg-[color-mix(in_oklab,var(--status-paused)_12%,var(--library-surface-lowest))] text-[var(--status-paused)]",abandoned:"border-[color-mix(in_oklab,var(--rust)_38%,transparent)] bg-[color-mix(in_oklab,var(--rust)_11%,var(--library-surface-lowest))] text-[var(--rust)]",catchup:"border-[color-mix(in_oklab,var(--status-caught-up)_34%,transparent)] bg-[color-mix(in_oklab,var(--status-caught-up)_12%,var(--library-surface-lowest))] text-[var(--status-caught-up)]"}},defaultVariants:{tone:"neutral"}}),jm="mt-3.5",Nm="mt-[11px] max-w-[600px] font-sans text-sm leading-[1.55] text-[var(--ink-2)]",Hi="text-[var(--ink-3)]",Sm="mt-2.5 flex min-w-0 flex-wrap gap-x-2 gap-y-1.5",Dt="inline-block min-w-0 max-w-[12.5rem] shrink-0 overflow-hidden text-ellipsis whitespace-nowrap rounded-pill border border-[var(--line)] bg-transparent px-2.5 py-1 text-xs leading-none text-[var(--ink-3)] @max-[899px]:max-w-[9.75rem]",Ui="border-[var(--line-strong)] bg-[var(--card-2)] font-medium text-[var(--ink)]",km="border-dashed border-[color-mix(in_oklab,var(--honey)_30%,transparent)] text-[var(--honey)]",Cm="flex min-w-[190px] flex-col items-end gap-2 pt-0.5 text-right text-xs text-[var(--ink-3)]",_m="flex w-full min-w-0 items-center gap-[9px]",Rm="shrink-0 whitespace-nowrap font-mono text-[11px] leading-none text-[var(--ink-4)]",zs=["relative grid min-w-0 grid-cols-1 px-4 pb-4 pt-[14px] text-[var(--ink)]","@min-[900px]:hidden"].join(" "),qs="flex min-w-0 items-start gap-2",Gs="min-w-0 flex-1 font-landing-serif text-[19px] font-medium leading-[1.16] tracking-normal text-[var(--ink)]",Qs="mt-1 min-w-0 text-[12.5px] leading-snug text-[var(--ink-3)]",Xs="mt-[9px] max-w-none text-[13.5px] leading-[1.5] text-[var(--ink-2)]",Zs="mb-2 flex min-w-0 items-center gap-2",Yi=et(["trace-mobile-browse-status-chip inline-flex min-w-0 shrink-0 items-center gap-1.5 rounded-[5px] border px-[9px] py-1","font-mono text-[9.5px] font-medium uppercase leading-none tracking-[0.13em]"].join(" "),{variants:{tone
2:{neutral:"border-[var(--status-planning-border)] bg-[var(--status-planning-container)] text-[var(--status-planning-on-container)]",reading:"border-[var(--status-reading-border)] bg-[var(--status-reading-container)] text-[var(--status-reading-on-container)]",catchup:"border-[var(--status-caught-up-border)] bg-[var(--status-caught-up-container)] text-[var(--status-caught-up-on-container)]",completed:"border-[var(--status-completed-border)] bg-[var(--status-completed-container)] text-[var(--status-completed-on-container)]",paused:"border-[var(--status-paused-border)] bg-[var(--status-paused-container)] text-[var(--status-paused-on-container)]",planning:"border-[var(--status-planning-border)] bg-[var(--status-planning-container)] text-[var(--status-planning-on-container)]",dropped:"border-[var(--status-dropped-border)] bg-[var(--status-dropped-container)] text-[var(--status-dropped-on-container)]"}},defaultVariants:{tone:"neutral"}}),Lm="h-1.5 w-1.5 shrink-0 rounded-pill bg-current",Js="ml-auto shrink-0 font-mono text-[10px] font-medium uppercase leading-none tracking-normal",Am="hidden max-[899px]:flex min-w-0 items-center gap-2 border-b border-[color-mix(in_oklab,var(--honey)_22%,transparent)] bg-[color-mix(in_oklab,var(--honey)_10%,var(--card-2))] px-4 py-2",Tm="font-mono text-[9px] font-medium uppercase leading-none tracking-[0.16em] text-[var(--honey)]",Em="ml-auto min-w-0 truncate font-mono text-[9px] uppercase leading-none tracking-[0.12em] text-[var(--ink-4)]",Pm="mt-[7px] flex min-w-0 items-center gap-[7px]",Mm=et("h-1.5 w-1.5 shrink-0 rounded-[2px]",{variants:{tone:{neutral:"bg-[var(--ink-3)]",wip:"bg-[var(--ink-3)]",complete:"bg-[var(--status-completed)]",hiatus:"bg-[var(--status-paused)]",abandoned:"bg-[var(--rust)]",catchup:"bg-[var(--status-caught-up)]"}},defaultVariants:{tone:"neutral"}}),Im=et("min-w-0 truncate font-mono text-[10px] font-medium uppercase leading-none tracking-[0.1em]",{variants:{tone:{neutral:"text-[var(--ink-3)]",wip:"text-[var(--ink-3)]",complete:"text-[var(--status-completed)]",hiatus:"text-[var(--status-paused)]",abandoned:"text-[var(--rust)]",catchup:"text-[var(--status-caught-up)]"}},defaultVariants:{tone:"neutral"}}),Om="mt-2 flex min-w-0 flex-nowrap gap-1.5 overflow-hidden",Dm=["relative","before:content-['']","before:absolute before:left-0 before:top-0 before:bottom-0","before:w-[3px]","before:rounded-none","before:opacity-100 before:transition-[opacity,filter] before:duration-100 before:ease-out","group-hover:before:brightness-[1.06]","before:pointer-events-none"].join(" ");function Fm(t){switch(t){case"reading":return"before:bg-[var(--status-reading)]";case"catchup":return"before:bg-[var(--status-caught-up)]";case"completed":return"before:bg-[var(--status-completed)]";case"paused":return"before:bg-[var(--status-paused)]";case"dropped":return"before:bg-[var(--status-dropped)]";case"planning":return"before:bg-[var(--status-planning)]";default:return"before:bg-[var(--status-planning)]"}}const $m="before:bg-[var(--status-reading)]";function Ki(t){switch(t){case"reading":return"bg-[var(--status-reading)]";case"catchup":return"bg-[var(--status-caught-up)]";case"completed":return"bg-[var(--status-completed)]";case"paused":return"bg-[var(--status-paused)]";case"dropped":return"bg-[var(--status-dropped)]";case"planning":return"bg-[var(--status-planning)]";default:return"bg-[var(--status-planning)]"}}function Wm(t){switch(t){case"reading":return"var(--status-reading-progress)";case"catchup":return"var(--status-caught-up-progress)";case"completed":return"var(--status-completed-progress)";case"paused":return"var(--status-paused-progress)";case"dropped":return"var(--status-dropped-progress)";case"planning":return"var(--status-planning-progress)";default:return"var(--status-planning-progress)"}}const Bm="inline-flex items-center h-[20px] px-2 rounded-pill border border-border text-xs leading-none text-content-muted",Vm="trace-mobile-readonly-stars mt-[13px] hidden min-w-0 items-center gap-[3px] text-[15px] @max-[899px]:flex",Hm="text-[var(--honey)]",Um="text-[var(--ink-5)]",Ym="inline-flex min-w-0",er="mt-[13px] flex min-w-0 items-center gap-[11px]",tr="h-[3px] min-w-0 flex-1 overflow-hidden rounded-pill bg-[var(--ink-5)]",ar="block h-full min-w-[2px] rounded-pill bg-[color:var(--mobile-browse-progress-color)]",nr="shrink-0 whitespace-nowrap font-mono text-xs leading-none text-[var(--ink-2)]",sr=["trace-mobile-progress-control inline-flex min-h-11 w-full shrink-0 items-center justify-between gap-2 rounded-[18px] border border-border-subtle","bg-[color-mix(in_oklab,var(--library-surface-low)_82%,var(--library-surface-lowest))] px-3","font-mono text-[13px] font-bold tabular-nums text-content-primary shadow-[0_1px_3px_color-mix(in_oklab,var(--library-primary)_7%,transparent)]"].join(" "),rr=["inline-flex h-8 w-8 items-center justify-center rounded-full","text-base font-bold leading-none text-[var(--library-primary)]","transition hover:bg-[color-mix(in_oklab,var(--library-primary)_10%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),Km="min-w-[6.3rem] text-center leading-none",la=et(["mt-[2px] shrink-0","inline-grid place-items-center","h-[18px] w-[18px] rounded-full","bg-[var(--success-600)] text-[var(--bg-app)]","text-[12px] font-extrabold","pointer-events-none select-none","transition-all duration-300","opacity-0 scale-[0.75]"].join(" "),{variants:{show:{true:"opacity-100 scale-100"}}}),zm="",qm=["inline-flex shrink-0 items-center gap-0 rounded-pill border border-[var(--line)]","bg-[var(--paper-2)] p-0.5","font-mono text-xs tabular-nums text-[var(--ink)]"].join(" "),ir=["inline-flex h-[22px] w-[22px] items-center justify-center rounded-full border-0 bg-transparent","text-sm leading-none text-[var(--ink-3)] transition","hover:bg-[var(--paper-3)] hover:text-[var(--ink)]","disabled:cursor-not-allowed disabled:opacity-35"].join(" "),Gm="min-w-[46px] px-1 text-center leading-none",Qm=["h-[3px] w-[120px] overflow-hidden rounded-pill border border-[color-mix(in_oklab,var(--library-outline)_12%,transparent)]","bg-[color-mix(in_oklab,var(--library-outline)_16%,var(--paper-3))]"].join(" "),Xm="block h-full min-w-[2px] rounded-pill bg-[color:var(--desktop-progress-color)] opacity-[0.85] transition-[width,background-color] duration-300",Zm=["grid min-h-[54px] min-w-0 grid-cols-[140px_minmax(0,1fr)_52px_124px_34px] items-center gap-[18px]","px-4 py-0 pl-5 text-[var(--ink)]","@max-[899px]:gri
2d-cols-1 @max-[899px]:gap-2 @max-[899px]:px-4 @max-[899px]:py-3.5 @max-[899px]:pl-[20px]"].join(" "),Jm="trace-compact-desktop-row hidden min-[900px]:grid",ep=["trace-mobile-compact-row relative block min-w-0 px-4 py-[13px] pl-[18px] text-[var(--ink)]","min-[900px]:hidden"].join(" "),tp="flex min-w-0 items-baseline gap-3",ap="min-w-0 flex-1 truncate font-landing-serif text-[16.5px] font-medium leading-[1.2] tracking-normal text-[var(--ink)]",np="shrink-0 whitespace-nowrap font-mono text-xs leading-none text-[var(--ink-2)]",Wa="text-[var(--ink-4)]",sp="mt-[5px] flex min-w-0 items-center gap-2",rp="h-[7px] w-[7px] shrink-0 rounded-pill",ip="shrink-0 whitespace-nowrap text-[12.5px] leading-none text-[var(--ink-3)]",op="font-semibold text-[var(--status-reading)]",lp="min-w-0 flex-1 truncate whitespace-nowrap text-[12.5px] leading-none text-[var(--ink-4)]",cp="pointer-events-none mt-[13px] mb-px h-[3px] overflow-hidden rounded-pill bg-[color-mix(in_oklab,var(--ink)_10%,transparent)]",dp="block h-full rounded-pill bg-[var(--mobile-compact-progress-color)]",up="min-w-0",mp="flex min-w-0 items-center gap-2",pp="h-[7px] w-[7px] shrink-0 rounded-pill",hp="min-w-0 truncate font-sans text-[13px] font-medium leading-none text-[var(--ink-3)]",xp="font-semibold text-[var(--status-reading)]",bp="flex min-w-0 items-center gap-2",gp="min-w-0 flex-1 truncate font-landing-serif text-[16.5px] font-medium leading-[1.16] tracking-normal text-[var(--ink)] @max-[899px]:text-[15.5px]",fp="mt-1 flex min-w-0 items-center gap-x-2 overflow-hidden whitespace-nowrap text-[12.5px] leading-none text-[var(--ink-4)] @max-[899px]:gap-x-2",vp="min-w-0 truncate font-semibold text-[var(--ink-3)]",yp="justify-self-start text-[9.5px]",wp="flex min-w-0 shrink-0 flex-col items-end gap-1.5 text-right @max-[899px]:min-w-0 @max-[899px]:items-stretch @max-[899px]:text-left",jp="whitespace-nowrap font-mono text-[12.5px] font-medium leading-none tabular-nums text-[var(--ink-2)]",Np="font-mono text-[10.5px] leading-none text-[var(--honey)]",or="flex h-[30px] w-[30px] items-center justify-center",Sp="inline-flex h-[30px] w-[30px] items-center justify-center rounded-[8px] border border-[var(--line)] bg-transparent font-mono text-[15px] leading-none text-[var(--ink-3)] opacity-0 outline-none transition hover:border-[var(--line-strong)] hover:bg-[var(--card)] hover:text-[var(--ink)] focus-visible:opacity-100 focus-visible:shadow-ring group-hover:opacity-100 disabled:cursor-not-allowed disabled:opacity-0 group-hover:disabled:opacity-35",kp=["flex min-w-0 items-center justify-between gap-3","border-b border-[color-mix(in_oklab,var(--honey)_24%,var(--line))]","px-[22px] py-3 @max-[899px]:hidden"].join(" "),Cp="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-1",_p="font-mono text-[10px] font-semibold uppercase leading-none tracking-[0.18em] text-[var(--honey)]",Rp="text-xs leading-none text-[var(--ink-3)]",Lp="flex shrink-0 items-center gap-2",lr="inline-flex min-h-10 w-full items-center justify-center gap-1.5 rounded-[9px] border border-[var(--line)] bg-transparent px-2 text-xs font-medium leading-none text-[var(--ink-2)] transition hover:border-[var(--ink-3)] hover:text-[var(--ink)] disabled:cursor-not-allowed disabled:opacity-45 @min-[900px]:min-h-8 @min-[900px]:w-auto @min-[900px]:rounded-[5px] @min-[900px]:px-3",Ap="inline-flex min-h-10 w-full items-center justify-center gap-1.5 rounded-[9px] border border-[var(--line)] bg-transparent px-2 text-xs font-medium leading-none text-[var(--rust)] transition hover:border-[color-mix(in_oklab,var(--rust)_42%,var(--line))] hover:text-[var(--rust)] @min-[900px]:ml-auto @min-[900px]:min-h-8 @min-[900px]:w-auto @min-[900px]:rounded-[5px] @min-[900px]:border-transparent @min-[900px]:px-0",ea="h-3.5 w-3.5 shrink-0",Tp="@min-[900px]:hidden",Ep="hidden @min-[900px]:inline",Pp="inline-flex min-h-8 items-center justify-center gap-1.5 rounded-[5px] border border-transparent bg-transparent px-1 text-xs font-medium leading-none text-[var(--ink-3)] transition hover:text-[var(--ink)]",Mp="mb-2 block font-mono text-[10px] font-semibold uppercase leading-none tracking-[0.16em] text-[var(--ink-4)]",zi="mt-3 inline-flex min-w-0 items-center gap-2 rounded-[5px] border border-[color-mix(in_oklab,var(--honey)_24%,transparent)] bg-[
2color-mix(in_oklab,var(--honey)_8%,var(--paper))] px-2 py-1",qi="font-mono text-[11px] leading-none text-[var(--ink-4)]",Gi="text-[var(--honey)]",Ip="font-mono text-[11px] leading-none text-[var(--ink-3)]",Op="min-h-[96px] w-full resize-y rounded-[5px] border border-[var(--line-strong)] bg-[color-mix(in_oklab,var(--paper-2)_72%,var(--paper))] px-3 py-2 text-sm leading-relaxed text-[var(--ink)] outline-none transition placeholder:text-[var(--ink-4)] focus:border-[var(--honey)] focus:shadow-[0_0_0_2px_color-mix(in_oklab,var(--honey)_18%,transparent)]",Dp="ml-auto text-right font-mono text-[10px] leading-none text-[var(--ink-4)]",cr="min-w-0",dr="mb-3 flex min-w-0 flex-wrap gap-1.5",Fp="inline-flex items-center gap-1.5 border-[color-mix(in_oklab,var(--forest)_32%,transparent)] bg-[var(--forest-soft)] text-[var(--forest)]",$p="h-1 w-1 shrink-0 rounded-pill bg-[var(--forest)]",Wp="inline-flex min-h-6 items-center gap-1 rounded-pill border border-dashed border-[var(--line-strong)] bg-transparent px-2.5 text-xs leading-none text-[var(--ink-4)] transition hover:border-[var(--ink-4)] hover:text-[var(--ink-2)] disabled:cursor-not-allowed disabled:opacity-50",Bp="inline-flex min-h-6 max-w-full items-center gap-1 rounded-pill border border-dashed border-[var(--line-strong)] bg-transparent px-2 py-0.5",Vp="min-w-0 w-28 bg-transparent text-xs leading-none text-[var(--ink)] outline-none placeholder:text-[var(--ink-4)]",Hp="rounded-pill px-1.5 text-[11px] font-medium leading-none text-[var(--rust)] disabled:text-[var(--ink-4)]",Up="text-xs leading-none text-[var(--ink-4)]",Yp="mt-3 grid min-w-0 grid-cols-3 gap-2 @min-[900px]:flex @min-[900px]:items-center",Kp="mt-[13px] min-w-0",zp="mt-3 min-w-0",qp="mt-3 min-w-0",Gp="block w-full min-w-0 rounded-[5px] border border-[var(--line)] bg-[color-mix(in_oklab,var(--paper-2)_64%,var(--paper))] px-3 py-2 text-left font-landing-serif text-sm italic leading-relaxed text-[var(--ink-2)] transition hover:border-[var(--ink-4)]",Qp="block w-full min-w-0 rounded-[5px] border border-dashed border-[var(--line-strong)] bg-transparent px-3 py-2 text-left text-sm leading-relaxed text-[var(--ink-4)] transition hover:border-[var(--ink-4)] hover:text-[var(--ink-2)]",Xp="min-w-0",Zp="mt-2 flex min-w-0 items-center gap-2",Jp="inline-flex min-h-8 items-center justify-center rounded-[5px] border border-[color-mix(in_oklab,var(--honey)_45%,var(--line))] bg-[var(--honey)] px-3 text-xs font-semibold leading-none text-[var(--ink)] transition hover:bg-[color-mix(in_oklab,var(--honey)_90%,var(--paper))]",eh="inline-flex min-h-8 items-center justify-center rounded-[5px] border border-[var(--line)] bg-transparent px-3 text-xs font-semibold leading-none text-[var(--ink-3)] transition hover:border-[var(--ink-3)] hover:text-[var(--ink)]",th="flex min-w-0 items-center",ah="mt-4 flex min-w-0 flex-wrap gap-x-8 gap-y-4",nh="min-w-0 flex-[1_1_18rem]",sh="min-w-0 flex-[2_1_22rem]",rh="flex w-full min-w-0 flex-col items-end gap-2 text-right",ih=t=>bl(t)?xl[t]:"neutral",oh=new Set(["DebugAuthor","debugauthor","DEBUGAUTHOR"].map(t=>t.toLowerCase()));function lh(t){return t.filter(a=>!oh.has(a.trim().toLowerCase()))}const En='button,a,input,textarea,select,[role="combobox"],[role="listbox"],[role="radiogroup"],[role="menuitem"],[data-card-interactive]',ch=260,dh=220,uh="(max-width: 899px)",mh=470,Mt=88,ur=14,xn=6,ph=16,hh=-.42,xh=.36;function bh(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia(uh).matches}function gh(t){return t instanceof Element&&!!t.closest(En)}function mr(){return typeof performance<"u"?performance.now():Date.now()}function pr(t){if(t<-Mt){const a=Math.abs(t)-Mt,n=ur*(1-Math.exp(-a/64));return-Mt-Math.min(ur,n)}return Math.max(-Mt,Math.min(0,t))}function fh(t,a){return a?"text-[var(--ink-4)]":"text-[var(--rust)]"}function Qi(t){return typeof t.chapters_published=="number"&&t.chapters_published>0?Math.floor(t.chapters_published):null}function vh(t){return typeof t.chapters_planned=="number"&&t.chapters_planned>0?Math.floor(t.chapters_planned):null}function yh(t){return t!=="unknown"}function Xi(t){const a=t.workStatusOverride?.trim();if(a){const s=gs({workStatusOverride:a,completionStatus:t.completionStatus,chaptersPublished:t.chapters_published,chaptersPlanned:t.chapters_planned});return{workStatus:s.work_status,provenance:s.work_status_provenance}}if(t.work_status!=null){const s=gl(t.work_status);return{workStatus:s,provenance:t.work_status_provenance??(s==="unknown"?"unknown":"source")}}const n=gs({completionStatus:t.completionStatus,chaptersPublished:t.chapters_published,chaptersPlanned:t.chapters_planned});return{workStatus:n.work_status,provenance:n.work_status_provenance}}function wh(t){return yh(t.workStatus)?t.provenance==="override"?!0:t.provenance==="source"&&t.workStatus!=="wip":!1}function jh(t){return t==="wip"?"ONGOING":t==="complete"?"COMPLETE":t==="hiatus"?"HIATUS":"ABANDONED"}function Nh(t){const a=[];if(wh(t)){const{workStatus:n}=t;a.push({label:jh(n),tone:n})}return a}function Sh(t){const a=t.sourceHost?.toLowerCase()??"";return(t.source?.toUpperCase()??"")==="AO3"||a.includes("archiveofourown")}function kh(t){try{const a=new Date(t);return Number.isNaN(a.getTime())?"":a.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}catch{return""}}function Ch(t,a){const n=Xl(a,t),s=Math.max(0,Math.floor(Number(t.progress.value??0))),i=Number.isFinite(n)&&n>0?Math.floor(n):void 0,o=i?Math.min(s,i):s,m=(t.progress.unit==="CHAPTER"?Qi(a):null)??i,d=Xi(a),x=null,y=void 0,g=ih(t.status),N=a.source||"Open",S=lh(a.authors||[]).join(", "),C=(a.canonicalFandoms?.length?a.canonicalFandoms:a.fandoms||[]).filter(
2Boolean).join(" / "),_=typeof a.words=="number"&&a.words>0?`${a.words.toLocaleString()} words`:null,p=typeof a.words=="number"&&a.words>0?a.words.toLocaleString():null,b=Zl(a,t),k=t.progress.unit==="CHAPTER"?b==="?"?`Chapter ${o}`:`Chapter ${o} / ${b}`:i?`Chapter ${o} / ${i}`:`Chapter ${o}`,j=Number(t.progress.value||0),O=t.progress.unit==="PERCENT"?Math.max(0,Math.min(100,j)):t.progress.unit==="WORD"?Number(t.progress.total||0)>0?Math.max(0,Math.min(100,j/Number(t.progress.total||0)*100)):0:typeof i=="number"&&i>0?Math.max(0,Math.min(100,o/i*100)):0,R=kh(a.updatedDate??""),F=x,A=R?`Work updated ${R}`:null,z=null,Q=void 0,te=[F,A].filter(Boolean).join(" · ")||null;return{progressValue:s,progressTotal:i,editableChapterMax:m,shownNow:o,behindCount:null,badgeLabel:x,badgeTitle:y,verified:a.verified!==!1,isBehind:!1,tone:g,site:N,authorLine:S,fandomLine:C,externalOpenHref:li(a,t),externalOpenNotice:hc(a,t),hasTags:(t.tags||[]).some(Boolean),updatedLabel:R,isDropped:t.status==="DROPPED",wordCountLabel:_,mobileWordCountLabel:p,denomLabel:b,progressChapterLine:k,desktopActivityLabel:te,desktopCatchupLabel:F,desktopUpdatedLabel:A,stateSignals:Nh(d),cardUpdateLabel:z,cardUpdateTitle:Q,visualProgressPercent:O,visualProgressColor:Wm(g)}}function Zi(t){return t.status!=="SAVED"}function _h({filled:t}){return e.jsx("svg",{viewBox:"0 0 24 24",className:"h-[1em] w-[1em]","aria-hidden":"true",children:e.jsx("path",{d:"M12 3.5l2.6 5.3 5.9.9-4.2 4.1 1 5.8L12 17l-5.3 2.6 1-5.8L3.5 9.7l5.9-.9L12 3.5Z",fill:t?"currentColor":"none",stroke:"currentColor",strokeWidth:"1.35",strokeLinejoin:"round"})})}function Rh({value:t}){const a=Math.max(0,Math.min(5,Math.floor(Number(t)||0)));return e.jsx("div",{className:Vm,"aria-label":a?`${a} star rating`:"Not rated",children:[1,2,3,4,5].map(n=>e.jsx("span",{className:n<=a?Hm:Um,children:e.jsx(_h,{filled:n<=a})},n))})}function ca({series:t}){return t?e.jsxs("span",{className:ym,title:t.name,children:[t.name,t.position!=null?` · Part ${t.position}`:""]}):null}function Ta({children:t,className:a}){return e.jsx("div",{className:a,"data-card-interactive":"",onClick:n=>n.stopPropagation(),children:t})}function Ji({status:t,tone:a,isCurrent:n}){return e.jsxs("span",{className:Yi({tone:a}),children:[e.jsx("span",{className:Lm,"aria-hidden":!0}),e.jsxs("span",{children:[yt(t),n?" · last read":""]})]})}function Ya(t,a){return t.progress.unit==="CHAPTER"?t.status==="SAVED"?"â":String(a.shownNow):t.progress.unit==="WORD"?`${Number(t.progress.value||0).toLocaleString()}w`:`${Math.round(Number(t.progress.value||0))}%`}function Ka(t,a){return t.progress.unit==="CHAPTER"?String(a.denomLabel):null}function Lh({entry:t,vm:a}){const n=Ya(t,a),s=Ka(t,a);return e.jsxs("div",{className:_m,children:[e.jsx(ro,{vm:a}),e.jsxs("span",{className:Rm,children:[n,s?e.jsxs("span",{className:Wa,children:[" / ",s]}):null]})]})}function Ah(t,a){return t==null?null:a!=null&&a>t?`${t} of ${a} posted`:null}function Th(t){const{workStatus:a,provenance:n}=Xi(t),s=Qi(t),i=vh(t);if(a==="complete")return{label:"Complete",tone:"complete"};if(a==="hiatus")return{label:"Hiatus",tone:"hiatus"};if(a==="abandoned")return{label:"Abandoned",tone:"abandoned"};if(a==="wip"&&n==="override")return{label:"Ongoing",tone:"wip"};const o=Ah(s,i);return o?{label:o,tone:"neutral"}:s!=null?{label:"Status unknown",tone:"neutral"}:null}function Pn({story:t}){const a=Th(t);return a?e.jsxs("div",{className:Pm,children:[e.jsx("span",{className:Mm({tone:a.tone}),"aria-hidden":!0}),e.jsx("span",{className:Im({tone:a.tone}),children:a.label})]}):null}const Eh=r.memo(function({showStoryUpdates:a=!0,entry:n,story:s,onOpen:i,onEnterEvaluate:o,onExitEvaluate:c,onOpenDetails:u,onAddToCollection:l,onShare:m,onChangeStatus:d,onIncrementChapter:x,onDecrementChapter:y,onSetChapterValue:g,onChangeRating:N,onChangeNotes:S,onChangeTags:C,bulkMode:_=!1,selected:p=!1,onToggleSelect:b,onStartBulkSelect:k,onRemoveFromLibrary:j,removing:O=!1,onLayoutPointerLockChange:R,desktopVariant:F="metadata",isMostRecentReading:A=!1,densityMode:z="browse",isEvaluating:Q=!1,seriesContext:te=null,className:v}){const $=Ch(n,s),{progressTotal:f,shownNow:U,denomLabel:oe,progressChapterLine:se,site:G,isDropped:I,externalOpenHref:E,externalOpenNotice:Y}=$,[W,J]=r.useState(!1),X=n.status==="FINISHED"||typeof f=="number"&&f>0&&$.progressValue>=f,ee=r.useRef(X);r.useEffect(()=>{let D=null;return!ee.current&&X&&(J(!0),D=setTimeout(()=>J(!1),600)),ee.current=X,()=>{D&&clearTimeout(D)}},[X]),r.useEffect(()=>{ee.current=X},[n.id,X]);const le=r.useRef(null),ae=r.useRef(null),P=r.useRef(null),re=r.useRef(null),me=r.useRef(!1),[ce,We]=r.useState(!1),[pe,De]=r.useState(!1),Se=$l(0),M=js(Se,D=>`translate3d(${D}px, 0, 0)`),T=js(Se,D=>Math.max(0,Math.min(Mt,-D))),K=Wl(),q=()=>{P.current&&(clearTimeout(P.current),P.current=null)},fe=r.useCallback(()=>{re.current?.stop(),re.current=null},[]),be=r.useCallback((D,H={})=>{fe();const Ne=D?-Mt:0;
2if(We(D),De(!1),K||H.immediate){Se.set(Ne);return}re.current=Bl(Se,Ne,{type:"spring",stiffness:680,damping:46,mass:.72,velocity:(H.velocity??0)*1e3,restDelta:.2,restSpeed:1.6})},[Se,K,fe]);r.useEffect(()=>()=>{q(),fe()},[fe]),r.useEffect(()=>{_&&(q(),ae.current=null,be(!1,{immediate:!0}))},[_,be]),r.useEffect(()=>{q(),ae.current=null,be(!1,{immediate:!0})},[n.id,be]);const we=!_&&!Q,ve=we&&!!j,Re=we&&!!k,He=pe||ce,ke=pe?"dragging":ce?"open":"closed",ge=D=>{if(D.pointerType!=="touch"||!bh()||gh(D.target)||!ve&&!Re&&!ce)return;const H=D.pointerId,Ne=mr(),Ge=pr(Se.get());fe(),ae.current={pointerId:H,startX:D.clientX,startY:D.clientY,baseOffset:Ge,dragging:!1,lastOffset:Ge,lastClientX:D.clientX,lastMoveAt:Ne,velocityX:0,wasOpen:ce,longPressFired:!1},q(),Re&&!ce&&(P.current=setTimeout(()=>{const Ie=ae.current;!Ie||Ie.pointerId!==H||Ie.dragging||(Ie.longPressFired=!0,me.current=!0,be(!1,{immediate:!0}),k?.())},mh))},tt=D=>{const H=ae.current;if(!H||H.pointerId!==D.pointerId||H.longPressFired)return;const Ne=D.clientX-H.startX,Ge=D.clientY-H.startY,Ie=Math.abs(Ne),Fe=Math.abs(Ge);if(!H.dragging&&Fe>ph&&Fe>Ie){q(),ae.current=null;return}if(!ve){(Ie>xn||Fe>xn)&&q();return}if(!H.dragging){if(Ie<xn||Ie<=Fe)return;if(!H.wasOpen&&Ne>0){q(),ae.current=null;return}H.dragging=!0,q(),De(!0);try{D.currentTarget.setPointerCapture(D.pointerId)}catch{}}const ha=pr(H.baseOffset+Ne),Ee=mr(),Te=Math.max(1,Ee-H.lastMoveAt);H.velocityX=(D.clientX-H.lastClientX)/Te,H.lastClientX=D.clientX,H.lastMoveAt=Ee,H.lastOffset=ha,Se.set(ha),D.preventDefault()},ht=D=>{const H=ae.current;if(!(!H||H.pointerId!==D.pointerId)){q(),ae.current=null;try{D.currentTarget.releasePointerCapture(D.pointerId)}catch{}if(H.longPressFired){me.current=!0;return}if(H.dragging){const Ne=H.velocityX<hh?H.lastOffset<=-40:H.velocityX>xh?!1:H.lastOffset<=-46;be(Ne,{velocity:H.velocityX}),me.current=!0;return}ce&&(be(!1),me.current=!0)}},ye=D=>{const H=ae.current;if(!(!H||H.pointerId!==D.pointerId)){q(),ae.current=null;try{D.currentTarget.releasePointerCapture(D.pointerId)}catch{}H.dragging&&be(H.wasOpen)}},Le=D=>{D.stopPropagation(),!(O||!j)&&(be(!1,{immediate:!0}),j())},Ke=n.progress.unit==="CHAPTER"?e.jsx($h,{value:n.progress.value,shownNow:U,denomLabel:oe,max:$.editableChapterMax,onCommit:g,onIncrement:x,onDecrement:y}):e.jsx("button",{type:"button",className:L(Bm,"min-h-10 bg-transparent sm:min-h-[20px]"),onClick:()=>i(),children:n.progress.unit==="WORD"?`${Number(n.progress.value||0).toLocaleString()} w`:`${Math.round(Number(n.progress.value||0))}%`}),jt=n.progress.unit==="CHAPTER"?e.jsxs("div",{className:sr,"data-card-interactive":"",onClick:D=>D.stopPropagation(),children:[e.jsx("button",{type:"button",className:rr,onClick:y,disabled:U<=0,"aria-label":"Decrease chapter",children:"â"}),e.jsxs("span",{className:Km,"aria-label":se,children:[e.jsx("span",{className:"text-content-muted",children:"Ch."})," ",U,e.jsx("span",{className:"px-1 text-content-muted",children:"/"}),oe]}),e.jsx("button",{type:"button",className:rr,onClick:x,disabled:typeof $.editableChapterMax=="number"&&U>=$.editableChapterMax,"aria-label":"Increase chapter",children:"+"})]}):e.jsx("button",{type:"button",className:sr,"data-card-interactive":"",onClick:D=>{D.stopPropagation(),i()},children:n.progress.unit==="WORD"?`${Number(n.progress.value||0).toLocaleString()} w`:`${Math.round(Number(n.progress.value||0))}%`}),Ae=e.jsx(Ta,{children:e.jsx(_s,{value:n.status??"",onChange:D=>d(D),ariaLabel:`Reading status for ${s.title}`})}),Pe=e.jsx(Ta,{children:e.jsx(_s,{value:n.status??"",onChange:D=>d(D),ariaLabel:`Reading status for ${s.title}`,className:L("trace-state-select--mobile-chip",Yi({tone:$.tone}))})}),Me=()=>Zi(n)?e.jsx(Ta,{className:Ym,children:e.jsx(Ec,{value:n.rating??0,onChange:N,size:"card",className:"trace-row-stars"})}):null,xt=D=>{const H=L(fm,fh(G,I),D);return E&&!_?e.jsxs("a",{href:E,target:"_blank",rel:"noopener noreferrer",className:H,title:Y??`Open on ${G}`,"aria-label":Y?`Open on ${G} in new tab. ${Y}`:`Open on ${G} in new tab`,onClick:Ne=>Ne.stopPropagation(),children:[G,e.jsx("span",{"aria-hidden":!0,
2children:" â"})]}):e.jsx("span",{className:H,children:G})},at=_?e.jsx("span",{className:bm,"data-card-interactive":"",onClick:D=>D.stopPropagation(),children:e.jsx(Br,{checked:p,onCheckedChange:()=>b?.(),"aria-label":`Select ${s.title}`})}):void 0,ma=p?"none":A&&z==="compact"?"current":"none",Nt=()=>{if(_){b?.();return}if(z==="browse"){if(!Q&&o){o();return}if(Q&&c){c();return}}i()},pa=_?`Select ${s.title}`:z==="browse"&&Q&&c?`Collapse evaluation for ${s.title}`:z==="browse"&&!Q&&o?`Evaluate ${s.title}`:`Open ${s.title}`,St=D=>{if(me.current){me.current=!1,D.preventDefault(),D.stopPropagation();return}if(ce){be(!1),D.preventDefault(),D.stopPropagation();return}if(_){D.stopPropagation(),b?.();return}const H=D.target;H&&H.closest(En)||Nt()};return e.jsxs("article",{ref:le,className:L(zm,Dm,A&&z==="compact"?$m:Fm($.tone),sm({selected:p,bulkMode:_,isBehind:$.isBehind,celebrate:W,statusChrome:ma,densityMode:z,isEvaluating:Q}),(ve||Re)&&rm,v),"data-mobile-swipe":ke,tabIndex:_?0:-1,role:"button","aria-label":pa,onPointerEnter:()=>R?.(1),onPointerLeave:()=>R?.(-1),onPointerDown:ge,onPointerMove:tt,onPointerUp:ht,onPointerCancel:ye,onClick:St,onKeyDown:D=>{if(D.key==="Enter"||D.key===" "){const H=D.target;if(H&&H.closest(En))return;D.preventDefault(),_?b?.():Nt()}},children:[j?e.jsx(Ns.button,{type:"button",className:im({open:He}),style:{width:T},"data-card-interactive":"","data-state":ke,"aria-hidden":!He,tabIndex:ce?0:-1,disabled:O,"aria-label":`Remove ${s.title} from library`,onClick:Le,children:e.jsxs("span",{className:om,children:[e.jsx("span",{className:lm,"aria-hidden":!0,children:e.jsx(Oa,{className:cm})}),e.jsx("span",{children:O?"Removing":"Remove"})]})}):null,e.jsx(Ns.div,{className:L(dm,He&&um,pe&&mm),style:{transform:M},children:z==="compact"?e.jsx(Ph,{showStoryUpdates:a,entry:n,story:s,vm:$,bulkMode:_,celebrate:W,selectControl:at,renderRatingControl:Me,renderSource:xt,isMostRecentReading:A,isEvaluating:Q,onChangeNotes:S,onChangeTags:C,onAddToCollection:l,onShare:m,onOpenDetails:u??i,seriesContext:te,onIncrementChapter:x,canIncrementChapter:!(typeof $.editableChapterMax=="number"&&U>=$.editableChapterMax)}):e.jsxs(e.Fragment,{children:[Q?e.jsx(Ih,{onDone:c}):null,e.jsx(Vh,{showStoryUpdates:a,entry:n,story:s,vm:$,bulkMode:_,celebrate:W,selectControl:at,mobileProgressControl:jt,mobileStatusChipSelect:Pe,onExitEvaluate:c,renderRatingControl:Me,renderSource:xt,isMostRecentReading:A,isEvaluating:Q,onChangeNotes:S,onChangeTags:C,onAddToCollection:l,onShare:m,onOpenDetails:u??i,seriesContext:te}),e.jsx(Hh,{showStoryUpdates:a,entry:n,story:s,vm:$,bulkMode:_,celebrate:W,selectControl:at,actionProgressControl:Ke,statusSelect:Ae,desktopVariant:F,renderRatingControl:Me,renderSource:xt,isMostRecentReading:A,isEvaluating:Q,onChangeNotes:S,onChangeTags:C,onAddToCollection:l,onShare:m,onOpenDetails:u??i,seriesContext:te})]})})]})});function Ph({showStoryUpdates:t,entry:a,story:n,vm:s,bulkMode:i,celebrate:o,selectControl:c,renderSource:u,isMostRecentReading:l,seriesContext:m,onIncrementChapter:d,canIncrementChapter:x}){const y=Ya(a,s),g=Ka(a,s),N=l?"Last read":yt(a.status),S=s.cardUpdateLabel;return e.jsxs(e.Fragment,{children:[e.jsx(Mh,{showStoryUpdates:t,entry:a,story:n,vm:s,
2celebrate:o,selectControl:c,isMostRecentReading:l,seriesContext:m}),e.jsxs("div",{className:L(Zm,Jm),children:[e.jsxs("div",{className:mp,children:[c,e.jsx("span",{className:L(pp,Ki(s.tone)),"aria-hidden":!0}),e.jsx("span",{className:L(hp,l&&xp),children:N})]}),e.jsxs("div",{className:up,children:[e.jsxs("div",{className:bp,children:[e.jsx("h3",{className:gp,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,o?e.jsx("span",{className:la({show:o}),"aria-hidden":!0,children:"â"}):null]}),e.jsxs("div",{className:fp,children:[s.authorLine?e.jsx("span",{className:vp,children:s.authorLine}):null,s.authorLine&&s.fandomLine?e.jsx("span",{"aria-hidden":!0,children:"·"}):null,s.fandomLine?e.jsx("span",{className:"truncate",children:s.fandomLine}):null,m?e.jsx(ca,{series:m}):null]})]}),i?e.jsx("span",{}):u(yp),e.jsxs("div",{className:wp,children:[e.jsxs("span",{className:jp,children:[y,g?e.jsxs("span",{className:"text-[var(--ink-4)]",children:[" / ",g]}):null]}),S?e.jsx("span",{className:Np,title:s.cardUpdateTitle??void 0,children:S}):null]}),a.progress.unit==="CHAPTER"?e.jsx(Ta,{className:or,children:e.jsx("button",{type:"button",className:Sp,onClick:d,disabled:!x,"aria-label":"Increase chapter on compact row",children:"+"})}):e.jsx("span",{className:or,"aria-hidden":!0})]})]})}
2function Mh({showStoryUpdates:t,entry:a,story:n,vm:s,celebrate:i,selectControl:o,isMostRecentReading:c,seriesContext:u}){const l=Ya(a,s),m=Ka(a,s),d=c?"Last read":yt(a.status),x=a.status==="READING";return e.jsxs("div",{className:ep,children:[e.jsxs("div",{className:tp,children:[o,e.jsx("h3",{className:ap,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,i?e.jsx("span",{className:la({show:i}),"aria-hidden":!0,children:"â"}):null,e.jsxs("span",{className:np,children:[l,m?e.jsxs("span",{className:Wa,children:[" ","/ ",m]}):null]})]}),e.jsxs("div",{className:sp,children:[e.jsx("span",{className:L(rp,Ki(s.tone)),"aria-hidden":!0}),e.jsx("span",{className:L(ip,c&&op),children:d}),s.fandomLine?e.jsxs("span",{className:lp,children:["· ",s.fandomLine]}):null,u?e.jsx(ca,{series:u}):null]}),x?e.jsx("div",{className:cp,"aria-hidden":!0,children:e.jsx("span",{className:dp,style:{width:`${s.visualProgressPercent}%`,"--mobile-compact-progress-color":s.visualProgressColor}})}):null]})}function Ih({onDone:t}){return e.jsxs("div",{className:kp,"data-card-interactive":"",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:Cp,children:[e.jsx("span",{className:_p,children:"Evaluating"}),e.jsx("span",{className:Rp,children:"Changes save as you go"})]}),e.jsx("div",{className:Lp,children:e.jsxs("button",{type:"button",className:Pp,onClick:t,children:["Done",e.jsx(wt,{className:ea,"aria-hidden":!0})]})})]})}function Bt({children:t}){return e.jsx("div",{className:Mp,children:t})}function Oh(t){return t.trim().replace(/\s+/g," ")}function Dh(t,a){const n=Oh(a);return n?t.some(i=>i.trim().toLowerCase()===n.toLowerCase())?t:[...t,n]:t}function Fh({tags:t,onChangeTags:a}){const[n,s]=r.useState(!1),[i,o]=r.useState(""),c=()=>{o(""),s(!1)},u=l=>{l.preventDefault();const m=Dh(t,i);m!==t&&a?.(m),c()};return n?e.jsxs("form",{className:Bp,"data-card-interactive":"",onClick:l=>l.stopPropagation(),onSubmit:u,children:[e.jsx("input",{"aria-label":"New private tag",autoFocus:!0,className:Vp,value:i,maxLength:48,onChange:l=>o(l.target.value),onKeyDown:l=>{l.key==="Escape"&&(l.preventDefault(),c())}}),e.jsx("button",{type:"submit",className:Hp,disabled:!i.trim(),children:"Add"})]}):e.jsxs("button",{type:"button",className:Wp,"data-card-interactive":"",disabled:!a,"aria-label":"Add private tag",onClick:l=>{l.stopPropagation(),a&&s(!0)},children:[e.jsx(mt,{className:ea,"aria-hidden":!0}),"tag"]})}function eo({entry:t,story:a,onChangeTags:n}){const{publicTags:s,privateTags:i}=no(a,t),o=i.slice(0,5),c=s.slice(0,5),u=Math.max(0,s.length-c.length);return e.jsxs("div",{className:zp,children:[e.jsxs("div",{className:cr,children:[e.jsx(Bt,{children:"Your tags"}),e.jsxs("div",{className:dr,children:[o.map(l=>e.jsxs("span",{className:L(Dt,Fp),children:[e.jsx("span",{className:$p,"aria-hidden":!0}),l]},`private:${l}`)),e.jsx(Fh,{tags:i,onChangeTags:n})]})]}),e.jsxs("div",{className:cr,children:[e.jsx(Bt,{children:"Source tags"}),e.jsxs("div",{className:dr,children:[c.length?c.map(l=>e.jsx("span",{className:L(Dt,l.tone==="relationship"&&Ui),title:l.value,children:l.value},`source:${l.tone}:${l.value}`)):e.jsx("span",{className:Up,children:"No source tags"}),u>0?e.jsxs("span",{className:L(Dt,"trace-row-chip--muted"),children:["+",u]}):null]})]})]})}function to({entryId:t,note:a,onChangeNotes:n}){const[s,i]=r.useState(!1),[o,c]=r.useState(a??"");if(r.useEffect(()=>{c(a??""),i(!1)},[t,a]),s)return e.jsxs("div",{className:Xp,"data-card-interactive":"",onClick:l=>l.stopPropagation(),children:[e.jsx("textarea",{"aria-label":"Private note",className:Op,value:o,maxLength:1200,readOnly:!n,placeholder:"What did you think? Where did you leave off?",onChange:l=>c(l.target.value)}),e.jsxs("div",{className:Zp,children:[e.jsx("button",{type:"button",className:Jp,onClick:()=>{n?.(o),i(!1)},children:"Save note"}),e.jsx("button",{type:"button",className:eh,onClick:()=>{c(a??""),i(!1)},children:"Cancel"}),e.jsxs("span",{className:Dp,children:[o.length.toLocaleString()," chars"]})]})]});const u=o.trim();return e.jsx("button",{type:"button",className:u?Gp:Qp,"data-card-interactive":"",onClick:l=>{l.stopPropagation(),i(!0)},children:u||"Add a note"})}function ao({onAddToCollection:t,onShare:a,onOpenDetails:n}){return e.jsxs("div",{className:Yp,"data-card-interactive":"",children:[e.jsxs("button",{type:"button",className:lr,disabled:!t,onClick:s=>{s.stopPropagation(),t?.()},children:[e.jsx(Zr,{className:ea,"aria-hidden":!0}),"Collection"]}),e.jsxs("button",{type:"button",className:lr,disabled:!a,onClick:s=>{s.stopPropagation(),a?.()},children:[e.jsx(ri,{className:ea,"aria-hidden":!0}),"Copy link"]}),e.jsxs("button",{type:"button",className:Ap,onClick:s=>{s.stopPropagation(),n()},children:[e.jsx("span",{className:Tp,children:"Details"}),e.jsx("span",{className:Ep,children:"View full details"}),e.jsx(ii,{className:ea,"aria-hidden":!0})]})]})}function $h({value:t,shownNow:a,denomLabel:n,max:s,onCommit:i,onIncrement:o,onDecrement:c}){const[u,l]=r.useState(String(t));r.useEffect(()=>{l(String(t))},[t]);const m=d=>{const x=Number(d.replace(/[^\d]/g,"")),y=Number.isFinite(x)?x:0,g=Math.max(0,Math.min(s??y,y));i(g),l(String(g))};return e.jsxs("div",{className:qm,onClick:d=>d.stopPropagation(),children:[e.jsx("button",{type:"button",className:ir,onClick:c,disabled:a<=0,"aria-label":"Decrease chapter on desktop",children:"â"}),e.jsxs("span",{className:Gm,children:[e.jsx("input",{"aria-label":"Chapter",type:"text",inputMode:"numeric",pattern:"[0-9]*",value:u,size:Math.min(4,Math.max(2,u.length||1)),onChange:d=>l(d.target.value),onBlur:d=>m(d.target.value),onKeyDown:d=>{d.key==="Enter"&&m(d.currentTarget.value)},className:"h-5 min-w-0 rounded-none border-0 bg-transparent p-0 text-center font-mono text-[13px] leading-none text-content-primary outline-none focus-visible:shadow-[0_1px_0_var(--library-secondary)]"}),e.jsx("span",{className:"px-1 text-content-muted",children:"/"}),e.jsx("span",{children:n})]}),e.jsx("button",{type:"button",className:ir,onClick:o,disabled:typeof s=="number"&&a>=s,"aria-label":"Increase chapter on desktop",children:"+"})]})}function Wh(t){const a=t.contentRating?.trim();return a?`Rated ${a}`:null}function Bh(t,a){return[a.fandomLine,a.wordCountLabel,Wh(t)].filter(n=>!!n)}function no(t,a){const{chips:n,hiddenPrimaryCount:s}=Yh(t,{relationshipLimit:1}
2),i=(a.tags??[]).filter(Boolean);return{publicTags:n,hiddenPublicCount:s,privateTags:i}}function so({story:t,entry:a,maxPublic:n=4,maxPrivate:s=3,mobile:i=!1}){const{publicTags:o,hiddenPublicCount:c,privateTags:u}=no(t,a),l=o.slice(0,n),m=u.slice(0,s),d=c+Math.max(0,o.length-l.length)+Math.max(0,u.length-m.length);return!l.length&&!m.length&&d===0?null:e.jsxs("div",{className:L(i?L(Om,"trace-row-tags--mobile"):Sm),children:[l.map(x=>e.jsx("span",{className:L(Dt,x.tone==="relationship"&&Ui,"trace-row-chip"),title:x.value,children:x.value},`public:${x.tone}:${x.value}`)),m.map(x=>e.jsxs("span",{className:L(Dt,km,"trace-row-chip trace-row-chip--private"),title:x,children:["#",x]},`private:${x}`)),d>0?e.jsxs("span",{className:L(Dt,"trace-row-chip trace-row-chip--muted"),children:["+",d]}):null]})}function Vh({showStoryUpdates:t,entry:a,story:n,vm:s,bulkMode:i,celebrate:o,selectControl:c,mobileProgressControl:u,mobileStatusChipSelect:l,renderRatingControl:m,renderSource:d,isMostRecentReading:x,isEvaluating:y,onChangeNotes:g,onChangeTags:N,onAddToCollection:S,onShare:C,onOpenDetails:_,seriesContext:p}){const b=!!a.notes?.trim()&&!i,k=a.status==="SAVED"||!a.notes?.trim()||b,j=[s.fandomLine,s.wordCountLabel].filter(F=>!!F),O=Ya(a,s),R=Ka(a,s);return y?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:Am,"data-card-interactive":"",onClick:F=>F.stopPropagation(),children:[e.jsx("span",{className:Tm,children:"Evaluating"}),e.jsx("span",{className:Em,children:"Tap card to close"})]}),e.jsxs("div",{className:zs,children:[e.jsxs("div",{className:Zs,children:[l,i?null:d(Js)]}),e.jsxs("div",{className:qs,children:[c,e.jsx("h3",{className:Gs,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,e.jsx("span",{className:la({show:o}),"aria-hidden":!0,children:"â"})]}),s.authorLine||j.length||p?e.jsxs("div",{className:Qs,title:s.authorLine,children:[s.authorLine?e.jsxs(e.Fragment,{children:["by ",e.jsx("span",{className:Tn,children:s.authorLine})]}
2):null,s.authorLine&&j.length?" · ":null,j.map((F,A)=>e.jsxs(Ze.Fragment,{children:[A>0?" · ":null,F]},F)),p?e.jsxs(e.Fragment,{children:[s.authorLine||j.length?" · ":null,e.jsx(ca,{series:p})]}):null]}):null,k?e.jsx(Mn,{story:n,className:L(Xs,b&&Hi),lines:"line-clamp-5",maxChars:260}):null,Zi(a)?e.jsxs("div",{className:zi,children:[m(),e.jsx("span",{className:L(qi,(a.rating??0)>0&&Gi),children:(a.rating??0)>0?`${a.rating}.0`:"rate"})]}):null,i?null:e.jsx(eo,{story:n,entry:a,onChangeTags:N}),e.jsxs("div",{className:Kp,children:[e.jsx(Bt,{children:"Status & progress"}),u,e.jsxs("div",{className:er,children:[e.jsx("div",{className:tr,role:"meter","aria-label":s.progressChapterLine,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(s.visualProgressPercent),children:e.jsx("span",{className:ar,style:{width:`${s.visualProgressPercent}%`,"--mobile-browse-progress-color":s.visualProgressColor}})}),e.jsxs("span",{className:nr,children:[O,R?e.jsxs("span",{className:Wa,children:[" ","/ ",R]}):null]})]}),e.jsx(Pn,{story:n})]}),i?null:e.jsxs("div",{className:qp,children:[e.jsx(Bt,{children:"Your note"}),e.jsx(to,{entryId:a.id,note:a.notes,onChangeNotes:g}),e.jsx(ao,{onAddToCollection:S,onShare:C,onOpenDetails:_})]})]})]}):e.jsxs("div",{className:zs,children:[e.jsxs("div",{className:Zs,children:[e.jsx(Ji,{status:a.status,tone:s.tone,isCurrent:x}),i?null:d(Js)]}),e.jsxs("div",{className:qs,children:[c,e.jsx("h3",{className:Gs,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,e.jsx("span",{className:la({show:o}),"aria-hidden":!0,children:"â"})]}),s.authorLine||j.length||p?e.jsxs("div",{className:Qs,title:s.authorLine,children:[s.authorLine?e.jsxs(e.Fragment,{children:["by ",e.jsx("span",{className:Tn,children:s.authorLine})]}
2):null,s.authorLine&&j.length?" · ":null,j.map((F,A)=>e.jsxs(Ze.Fragment,{children:[A>0?" · ":null,F]},F)),p?e.jsxs(e.Fragment,{children:[s.authorLine||j.length?" · ":null,e.jsx(ca,{series:p})]}):null]}):null,e.jsx(Mn,{story:n,className:Xs,lines:"line-clamp-2",maxChars:165}),e.jsx(Rh,{value:a.rating}),i?null:e.jsx(so,{story:n,entry:a,maxPublic:2,maxPrivate:0,mobile:!0}),e.jsxs("div",{className:er,children:[e.jsx("div",{className:tr,role:"meter","aria-label":s.progressChapterLine,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(s.visualProgressPercent),children:e.jsx("span",{className:ar,style:{width:`${s.visualProgressPercent}%`,"--mobile-browse-progress-color":s.visualProgressColor}})}),e.jsxs("span",{className:nr,children:[O,R?e.jsxs("span",{className:Wa,children:[" ","/ ",R]}):null]})]}),e.jsx(Pn,{story:n})]})}function Hh({showStoryUpdates:t,...a}){return e.jsx(Uh,{showStoryUpdates:t,...a})}function Uh({showStoryUpdates:t,entry:a,story:n,vm:s,bulkMode:i,celebrate:o,selectControl:c,actionProgressControl:u,statusSelect:l,renderRatingControl:m,renderSource:d,isMostRecentReading:x,isEvaluating:y,onChangeNotes:g,onChangeTags:N,onAddToCollection:S,onShare:C,onOpenDetails:_,seriesContext:p}){const b=Bh(n,s),k=m(),j=!!a.notes?.trim()&&!i,O=a.status==="SAVED"||!a.notes?.trim()||j;return e.jsxs("div",{className:pm,children:[e.jsxs("div",{className:hm,children:[y?e.jsx("div",{className:th,children:l}):e.jsx(Ji,{status:a.status,tone:s.tone,isCurrent:x}),e.jsxs("div",{className:xm,children:[c,e.jsx("h3",{className:gm,children:n.title}),t&&a.storyUpdate?.is_unseen?e.jsx(ra,{compact:!0}):null,d(),e.jsx("span",{className:la({show:o}),"aria-hidden":!0,children:"â"})]}),e.jsxs("div",{className:vm,children:[s.authorLine?e.jsxs("span",{children:["by ",e.jsx("span",{className:Tn,children:s.authorLine})]}):null,b.map(R=>e.jsx("span",{children:R},R)),e.jsx(ca,{series:p}),typeof n.kudos=="number"&&n.kudos>0?e.jsxs("span",{children:[n.kudos.toLocaleString()," kudos"]}):null,a.reReadCount>0?e.jsxs("span",{children:[a.reReadCount+1,"à read"]}):null,s.verified?null:e.jsx("span",{children:"unverified"}),s.stateSignals.map(R=>e.jsx("span",{className:wm({tone:R.tone}),children:R.label},`state:${R.label}`))]}),O?e.jsx(Mn,{story:n,className:L(Nm,j&&Hi),lines:y?"line-clamp-5":"line-clamp-2",maxChars:y?520:j?dh:ch}):null,k?e.jsxs("div",{className:y?zi:jm,children:[k,y?e.jsx("span",{className:L(qi,(a.rating??0)>0&&Gi),children:(a.rating??0)>0?`${a.rating}.0`:"rate it"}):null]}):null,!i&&!y?e.jsx(so,{story:n,entry:a,maxPublic:6,maxPrivate:3}):null,!i&&y?e.jsxs("div",{className:ah,children:[e.jsx("div",{className:nh,children:e.jsx(eo,{story:n,entry:a,onChangeTags:N})}),e.jsxs("div",{className:sh,children:[e.jsx(Bt,{children:"Your note"}),e.jsx(to,{entryId:a.id,note:a.notes,onChangeNotes:g}),e.jsx(ao,{onAddToCollection:S,onShare:C,onOpenDetails:_})]})]}):null]}),e.jsx("aside",{className:Cm,"aria-label":`Tracking for ${n.title}`,children:y?e.jsxs("div",{className:rh,children:[e.jsx(Bt,{children:"Progress"}),u,e.jsx(ro,{vm:s}),e.jsxs("span",{className:Ip,children:[s.progressChapterLine," · ",Math.round(s.visualProgressPercent),"%"]}),e.jsx(Pn,{story:n})]}):e.jsx(Lh,{entry:a,vm:s})})]})}function ro({vm:t}){return e.jsx("div",{className:Qm,role:"meter","aria-label":t.progressChapterLine,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(t.visualProgressPercent),children:e.jsx("span",{className:Xm,style:{width:`${t.visualProgressPercent}%`,"--desktop-progress-color":t.visualProgressColor}})})}function Mn({story:t,className:a,lines:n="line-clamp-2",maxChars:s}){const i=t.summary?.trim();if(!i)return null;const o=typeof s=="number"&&i.length>s?`${i.slice(0,Math.max(0,s-3)).trimEnd().replace(/[.,;:!?-]+$/,"")}...`:i;return e.jsx("p",{className:L(n,"text-sm leading-snug text-content-muted",a),children:o})}function bn(t){return Array.from(new Set(t.filter(Boolean)))}function Yh(t,a={}){const n=bn(t.relationships??[]),s=bn(t.canonicalCharacters?.length?t.canonicalCharacters:t.characters),i=Math.max(0,Math.floor(a.relationshipLimit??1)),o=n.length?n.slice(0,i):s,c=n.length?"relationship":"character",u=n.length?Math.max(0,n.length-o.length):0,l=Sh(t)?bn(t.workTags??[]):[],m=new Set,d=[];for(const x of o){const y=x.toLowerCase();m.has(y)||(m.add(y),d.push({value:x,tone:c}))}if(n.length)for(const x of n.slice(o.length))m.add(x.toLowerCase());for(const x of l){const y=x.toLowerCase();m.has(y)||(m.add(y),d.push({value:x,tone:"tag"}))}return{chips:d,hiddenPrimaryCount:u}}function hr({position:t,cap:a,active:n=!1}){return e.jsxs("span",{className:Vu,"aria-hidden":"true",children:[e.jsx("span",{className:L(Hu,a==="header"&&"top-1/2",a==="end"&&"bottom-1/2",a==="solo"&&"bottom-1/2 top-1/2")}),a!=="header"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:L(Uu,n&&Yu)}),t!=null?e.jsx("span",{className:L(Ku,n&&zu),children:t}):null]}):null]})}function Kh(t){const a=Array.from(new Set(t)).sort((s,i)=>s-i);return a.length?a.length===1?`Part ${a[0]}`:a.every((s,i)=>i===0||s===a[i-1]+1)?`Parts ${a[0]}â${a[a.length-1]}`:`Parts ${a.join(", ")}`:null}const zh=({storyUpdatesEnabled:t=!0,gridRef:a,isLoading:n,isFetching:s=!1,isError:i,visible:o,storiesMap:c,activeFilterCount:u,debouncedSearch:l,bulkMode:m,isSelected:d,onToggleSelect:x,onStartBulkSelect:y,onRemoveEntry:g,removingEntryId:N=null,onOpenDetails:S,onChangeStatus:C,onIncrementChapter:_,onDecrementChapter:p,onSetChapterValue:b,onChangeRating:k,onChangeNotes:j,onChangeTags:O,onAddToCollection:R,onShareStory:F,onLayoutPointerLockChange:A,deferredRecencyReorderIds:z=[],onDeferredRecencyEntryExit:Q,mostRecentReadingEntryId:te,loadMoreRef:v,hasNextPage:$,isFetchingNextPage:f,onFetchNextPage:U,onAddManually:oe,firstStoryCompleted:se=!1,onRetry:G,splitDetailOpen:I=!1,densityMode:E="compact",groupingMode:Y="none",evaluatingEntryId:W=null,onStartEvaluate:J,onCloseEvaluate:X,getDesktopCardVariant:ee,getDesktopCardVariantLabel:le})=>{const[ae,P]=r.useState(()=>new Set),re=!u&&!l,me=n,ce=!n&&!i&&o.length>0,We=r.useMemo(()=>Y==="series"?xc(o,c):o.map(M=>({kind:"entry",entry:M}
2)),[Y,c,o]),pe=m||u>0||l.trim().length>0,De=r.useCallback(M=>{P(T=>{const K=new Set(T);return K.has(M)?K.delete(M):K.add(M),K})},[]),Se=r.useCallback((M,T,K)=>{const q=c[M.storyId];if(!q)return null;const fe=Y==="series"&&!K?ka(q):null,be=ee?.(M,T),we=le?.(M,T);return e.jsxs(qh,{className:K?Wu:void 0,active:z.includes(M.id),onExit:()=>Q?.(M.id),children:[K?e.jsx(hr,{position:K.position,cap:K.cap,active:K.active}):null,e.jsxs("div",{className:K?Bu:void 0,children:[we?e.jsxs("div",{className:"mb-2 flex flex-wrap items-baseline justify-between gap-2 px-1",children:[e.jsx("div",{className:"text-2xs font-bold uppercase tracking-[0.18em] text-content-muted",children:we.label}),we.note?e.jsx("div",{className:"text-xs text-content-subtle",children:we.note}):null]}):null,e.jsx(Eh,{showStoryUpdates:t,entry:M,story:q,seriesContext:fe,onOpen:()=>S(M.id),onEnterEvaluate:()=>J?.(M.id),onExitEvaluate:X,onOpenDetails:()=>S(M.id),onAddToCollection:()=>R?.(M.id),onShare:F?()=>F(M.id):void 0,onChangeStatus:ve=>C(M.id,ve),onIncrementChapter:()=>_(M.id),onDecrementChapter:()=>p(M.id),onSetChapterValue:ve=>b(M.id,ve),onChangeRating:ve=>k(M.id,ve),onChangeNotes:j?ve=>j(M.id,ve):void 0,onChangeTags:O?ve=>O(M.id,ve):void 0,bulkMode:m,selected:d(M.id),onToggleSelect:()=>x(M.id),onStartBulkSelect:y?()=>y(M.id):void 0,onRemoveFromLibrary:g?()=>g(M.id):void 0,removing:N===M.id,onLayoutPointerLockChange:A,desktopVariant:be,isMostRecentReading:M.id===te,densityMode:E,isEvaluating:W===M.id})]})]},M.id)},[m,t,z,E,W,ee,le,Y,d,te,R,j,k,C,O,X,p,Q,_,A,S,g,b,F,y,J,x,N,c]);return e.jsxs("div",{ref:a,className:L("mt-0",I&&"lg:mt-0"),"aria-busy":n||s,children:[me&&e.jsxs("div",{className:L(Ca({splitDetail:I,densityMode:E})),"aria-busy":"true","aria-label":"Loading library stories",children:[e.jsx("p",{className:"col-span-full px-4 text-xs font-medium text-content-muted sm:px-0",children:"Loading library stories"}),Array.from({length:4}).map((M,T)=>e.jsx(jc,{},T))]}),!n&&i&&e.jsx("div",{className:L(Ca({splitDetail:I,densityMode:E})),children:e.jsx(Ts,{chrome:"bare",variant:"error",title:"We couldn't reach your library.",description:"A sync hiccup, almost certainly on our side. Your stories are safe; nothing has been lost.",detail:"Trace · err · LIB.503",actions:G?e.jsx(de,{variant:"solid",size:"lg",onClick:G,children:"Try again"}):null,className:"col-span-full"})}),!n&&!i&&o.length===0&&re&&oe&&e.jsx(am,{onAddManually:oe,firstStoryCompleted:se}),!n&&!i&&o.length===0&&!re&&e.jsx("div",{className:L(Ca({splitDetail:I,densityMode:E})),children:e.jsx(Ts,{chrome:"bare",variant:"no-results",title:nm(u,l),description:"Loosen a filter, or clear them all to see your full library.",className:"col-span-full"})}),ce&&e.jsxs("div",{className:L(Ca({splitDetail:I,densityMode:E}),E==="compact"&&Pu),children:[E==="compact"?e.jsxs("div",{className:Mu,"aria-hidden":"true",children:[e.jsx("span",{className:_a,children:"Status"}),e.jsx("span",{className:_a,children:"Story"}),e.jsx("span",{className:_a,children:"Src"}),e.jsx("span",{className:L(_a,"text-right"),children:"Chapter"}),e.jsx("span",{})]}):null,We.map((M,T)=>{if(M.kind==="entry")return Se(M.entry,T);const K=pe||!ae.has(M.key),q=`library-series-${T}`,fe=M.entries.map(Le=>ka(c[Le.storyId])?.position).filter(Le=>Le!=null),be=Kh(fe),we=u>0||l.trim().length>0,ve=`${M.entries.length}${we?" matching":""} in library`,Re=M.entries.find(Le=>Le.id===M.anchorEntryId)??M.entries[0],He=Re?ka(c[Re.storyId])?.position??null:null,ke=M.entries.filter(Le=>d(Le.id)).length,ge=ke===M.entries.length,tt=K?M.entries:Re?[Re]:[],ht=K?`${ve}${be?` · ${be}`:""}`:`${ve}${He!=null?` · showing part ${He}`:""} · ${Math.max(0,M.entries.length-1)} hidden`,ye=()=>{M.entries.forEach(Le=>{(ge?d(Le.id):!d(Le.id))&&x(Le.id)})};return e.jsxs("section",{className:Iu,"aria-label":`${M.name} series`,children:[e.jsxs("div",{className:Ou,children:[e.jsx(hr,{cap:"header"}),m?e.jsxs("div",{className:Vs,children:[e.jsx(Br,{checked:ge,indeterminate:ke>0&&!ge,onCheckedChange:ye,"aria-label":`Select ${M.entries.length} loaded stories from ${M.name}`}),e.jsxs("span",{className:Hs,children:[e.jsx("span",{className:Us,children:"Series"}),e.jsx("span",{className:Ys,children:M.name}),e.jsx("span",{className:Ks,children:ke>0?`${ke} of ${M.entries.length} selected`:ht})]})]}):e.jsxs("button",{type:"button",className:Vs,"aria-expanded":K,"aria-controls":q,disabled:pe,title:pe?u>0?"Series stay expanded while filters are active":"Series stay expanded while searching":void 0,onClick:()=>
2De(M.key),children:[e.jsx(ii,{"aria-hidden":!0,className:L(Du,K&&"rotate-90")}),e.jsxs("span",{className:Hs,children:[e.jsx("span",{className:Us,children:"Series"}),e.jsx("span",{className:Ys,children:M.name}),e.jsx("span",{className:Ks,children:ht})]})]}),M.url?e.jsx("a",{className:Fu,href:M.url,target:"_blank",rel:"noreferrer","aria-label":`Open ${M.name} series on source`,children:e.jsx(It,{"aria-hidden":!0})}):e.jsx("span",{"aria-hidden":!0})]}),e.jsx("div",{className:$u,id:q,role:"group","aria-label":`${M.name}, ${M.entries.length} stories in your library`,children:tt.map((Le,Ke)=>{const jt=ka(c[Le.storyId])?.position??null,Ae=K?Ke===0?"start":Ke===tt.length-1?"end":"middle":"solo";return Se(Le,T+Ke,{position:jt,cap:Ae,active:Le.id===M.anchorEntryId})})})]},M.key)})]}),e.jsx("div",{ref:v,className:"h-px","aria-hidden":"true"}),$&&e.jsx("div",{className:"flex flex-col items-center gap-4 pt-10",children:e.jsx(de,{className:"library-load-more",variant:f?"ghost":"outline",disabled:f,loading:f,onClick:U,children:f?"Loadingâ¦":"Load more"})})]})};function qh({active:t,onExit:a,className:n,children:s}){const i=r.useRef(null);return r.useEffect(()=>{if(!t||typeof IntersectionObserver>"u")return;const o=i.current;if(!o)return;let c=!1;const u=new IntersectionObserver(l=>{const m=l[0];!m||c||m.isIntersecting||(c=!0,a())},{root:null,threshold:0});return u.observe(o),()=>u.disconnect()},[t,a]),e.jsx("div",{ref:i,className:L(Eu,n),children:s})}const Gh=t=>{if(!Number.isFinite(t)||t<=0)return"";const a=Math.max(0,Math.min(5,Math.round(t)));return"â ".repeat(a)+"â".repeat(5-a)},Qh=t=>typeof t=="number"?Va(t):"",xr=(t="",a=300)=>t.length>a?t.slice(0,a-1)+"â¦":t,lt=(t="")=>t.replace(/\s+/g," ").trim(),gn=(t,a=" ⢠")=>t.filter(Boolean).join(a),Xh=new Set(["\\","`","*","_","{","}","[","]"]),Vt=(t="")=>Array.from(t,a=>Xh.has(a)?`\\${a}`:a).join(""),Zh=t=>{const a=Vt(lt(t.title));return t.canonicalUrl?`**[${a}](${t.canonicalUrl})**`:`**${a}**`},Jh=t=>{const a=t.map(n=>lt(n)).filter(Boolean).join(", ");return a?` by ${Vt(a)}`:""},ex=t=>t.split(/\n+/).map(lt).filter(Boolean).map(a=>`> ${Vt(a)}`).join(` 3`),tx=t=>t.split(/\n+/).map(lt).filter(Boolean).map(a=>`> Private note: ${Vt(a)}`).join(` 4`),ax=t=>Array.isArray(t)?t.map(a=>typeof a=="string"?a.trim():String(a??"").trim()).filter(Boolean):typeof t=="string"&&t.trim()?[t.trim()]:[],nx=t=>{const a=(()=>{try{return t.canonicalUrl?new URL(t.canonicalUrl).hostname.replace(/^www\./,""):""}catch{return""}})(),n=a.toLowerCase();return t.source||(n.includes("archiveofourown")?"AO3":n.includes("fanfiction")?"FFN":a)},sx=(t,a,n,s)=>{const i=[],o=s?.trim();return o&&i.push(`## ${o}`,""),t.forEach((c,u)=>{const l=a[c.storyId];if(!l)return;const m=n.includeSummary,d=n.includeRelationships,x=n.includeNotes,y=nx(l),g=Zh(l),N=Jh(l.authors||[]),S=l.words?`${Qh(l.words)} words`:"",C=n.includeRating?Gh(c.rating):"",_=n.includeRating&&C?C:"",p=l.fandoms?.length?lt(l.fandoms.join(" / ")):"",b=ax(l.relationships),k=d&&b.length?Vt(lt(b.join(", "))):"",j=m&&l.summary?xr(lt(l.summary),420):"",O=x&&c.notes?xr(lt(c.notes),420):"";i.push(`${g}${N}`);const R=gn([y||"",S,_]),F=gn([p?Vt(p):"",k]," · "),A=gn([R,F]," · ");A&&i.push("",A),j&&i.push("",ex(j)),O&&i.push("",tx(O)),u!==t.length-1&&i.push("")}),i.join(` 5`)},rx=t=>{if(!Number.isFinite(t)||t<=0)return"";const a=Math.max(0,Math.min(5,Math.round(t)));return"â ".repeat(a)+"â".repeat(5-a)},ix=t=>typeof t=="number"?Va(t):"",br=(t="",a=300)=>t.length>a?t.slice(0,a-1)+"â¦":t,Ra=(t="")=>t.replace(/\s+/g," ").trim(),fn=(t,a=" · ")=>t.filter(Boolean).join(a),ox=t=>Array.isArray(t)?t.map(a=>typeof a=="string"?a.trim():String(a??"").trim()).filter(Boolean):typeof t=="string"&&t.trim()?[t.trim()]:[],lx=t=>{const a=(()=>{try{return t.canonicalUrl?new URL(t.canonicalUrl).hostname.replace(/^www\./,""):""}catch{return""}})(),n=a.toLowerCase();return t.source||(n.includes("archiveofourown")?"AO3":n.includes("fanfiction")?"FFN":a)},cx=(t,a,n,s)=>{const i=[],o=s?.trim();return o&&i.push(o,""),t.forEach((c,u)=>{const l=a[c.storyId];if(!l)return;const m=n.includeSummary,d=n.includeRelationships,x=n.includeNotes,y=lx(l),g=(l.authors||[]).join(", "),N=l.words?`${ix(l.words)} words`:"",S=n.includeRating?rx(c.rating):"",C=n.includeRating&&S?S:"",_=l.fandoms?.length?Ra(l.fandoms.join(" / ")):"",p=ox(l.relationships),b=d&&p.length?Ra(p.join(", ")):"",k=m&&l.summary?br(Ra(l.summary),420):"",j=x&&c.notes?br(Ra(c.notes),420):"";i.push(`${l.title}${g?` - ${g}`:""}`),l.canonicalUrl&&i.push(l.canonicalUrl);const O=fn([y||"",N,C]),R=fn([_,b]," · "),F=fn([O,R]," · ");F&&i.push(F),k&&i.push("",k),j&&i.push("",`Private note: ${j}`),u!==t.length-1&&i.push("")}),i.join(` 6`)};function dx({selected:t,options:a=[],getOptions:n,onChange:s,id:i,placeholder:o="Select tagsâ¦",multi:c=!0,allowCreate:u=!0,triggerClassName:l,panelClassName:m}){return e.jsx(Jl,{id:i,value:t,onChange:s,getOptions:n,options:a,placeholder:o,searchPlaceholder:"Search tagsâ¦",ariaLabel:o,multi:c,allowCreate:u,showClear:!0,showDone:!0,maxChips:3,transformOptions:d=>Array.from(new Set(d.map(x=>
6x.trim()).filter(Boolean))).sort((x,y)=>x.localeCompare(y,void 0,{sensitivity:"base"})),className:"w-full",triggerClassName:l,panelClassName:m})}const ux="library-app archive-editorial-shell flex h-full min-h-0 w-full flex-col overflow-hidden bg-[var(--paper)] bg-none text-[var(--ink)]",mx="min-h-0 flex-1 overflow-y-auto overscroll-contain px-[22px] py-[18px] [-webkit-overflow-scrolling:touch]",vn="space-y-3 border-t border-[var(--line)] py-4 first:border-t-0 first:pt-0",px="flex items-start gap-3",hx=["mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-[6px]","bg-[var(--forest)] font-[var(--landing-font-mono)]","text-[10.5px] font-bold text-[var(--paper)]"].join(" "),xx="text-[14px] font-semibold leading-tight text-[var(--ink)]",bx="space-y-3",gx="flex flex-col gap-1.5",fx=t=>["flex w-full cursor-pointer items-start gap-3 rounded-[10px] border px-[14px] py-3 text-left","font-[var(--landing-font-sans)] transition","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]",t?"border-[var(--ink-3)] bg-[var(--card-2)]":"border-[var(--line)] bg-[var(--card)] hover:border-[var(--line-strong)]","disabled:cursor-not-allowed disabled:opacity-50"].join(" "),vx=t=>["mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded-full border-[1.5px]",t?"border-[var(--forest-deep)] bg-[var(--forest-deep)]":"border-[var(--ink-4)] bg-transparent"].join(" "),yx="h-1.5 w-1.5 rounded-full bg-[var(--paper)]",wx="min-w-0 flex-1",jx="block text-[14px] font-medium leading-snug text-[var(--ink)]",Nx="mt-0.5 block font-[var(--landing-font-mono)] text-[11.5px] leading-snug text-[var(--ink-3)]",Sx="shrink-0 font-[var(--landing-font-mono)] text-[11.5px] text-[var(--ink-4)]",kx="min-w-0 space-y-3",Cx="grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-start",_x=["!min-h-[42px] !rounded-[10px] !border !border-[var(--line)]","!bg-[var(--card)] !px-3 !py-2","!font-[var(--landing-font-sans)] !text-[14px] !text-[var(--ink)]","hover:!border-[var(--line-strong)] hover:!bg-[var(--card)]","aria-expanded:!border-[var(--honey)] aria-expanded:!bg-[var(--paper)]","aria-expanded:!shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]"].join(" "),Rx=["library-app archive-editorial-shell","!rounded-[12px] !border-[var(--line-strong)] !bg-[var(--card)] !shadow-[var(--shadow-modal)]","[&>div:first-child]:!border-[var(--line)] [&>div:first-child]:!bg-[var(--card)]","[&>div:last-child]:!border-[var(--line)] [&>div:last-child]:!bg-[var(--paper-2)]"].join(" "),Lx="tf-segmented tf-segmented--sm",gr=t=>["tf-seg",t?"is-on":""].filter(Boolean).join(" "),Ax="flex flex-wrap items-baseline gap-x-1.5",Tx="text-[14px] font-medium text-[var(--ink)]",Ex="font-[var(--landing-font-mono)] text-[11.5px] leading-relaxed text-[var(--ink-3)]",Px="space-y-1.5",Mx="border-l-[3px] border-[var(--honey)] bg-[var(--card)] px-3 py-2",Ix="truncate font-[var(--landing-font-serif)] text-[15px] font-medium leading-tight text-[var(--ink)]",Ox="mt-0.5 truncate font-[var(--landing-font-mono)] text-[11.5px] leading-snug text-[var(--ink-3)]",Dx="px-3 font-[var(--landing-font-mono)] text-[11.5px] text-[var(--ink-4)]",Fx="border-l-[3px] border-[var(--rust)] bg-[color-mix(in_oklab,var(--rust)_8%,transparent)] px-3 py-2 text-[13px] text-[var(--rust)]",$x="space-y-2",La="a-form-label",Wx="tf-field",Bx="a-form-hint",Vx="grid gap-4 sm:grid-cols-[minmax(0,0.75fr)_minmax(0,1.25fr)]",Hx="tf-segmented",fr=t=>["tf-seg",t?"is-on":""].filter(Boolean).join(" "),Ux="flex flex-col gap-1",Yx="tf-toggle-row",Kx=t=>["tf-switch",t?"is-on":""].filter(Boolean).join(" "),zx="tf-toggle-main",qx="tf-toggle-title",Gx="tf-toggle-sub",Qx="space-y-3",Xx="text-[14px] font-medium leading-tight text-[var(--ink)]",Zx="mt-0.5 font-[var(--landing-font-mono)] text-[11.5px] leading-snug text-[var(--ink-3)]",Jx="flex items-start gap-2 text-[12px] leading-relaxed text-[var(--ink-3)]",eb="text-[var(--rust)]",tb="flex flex-wrap items-center gap-2",vr="a-btn is-secondary is-sm",ab="tf-field tf-field--textarea",nb="min-h-40 w-full resize-y font-[var(--landing-font-mono)] text-[12px] leading-[1.65]",sb="a-panelfoot shrink-0",rb="flex-1",ib="a-btn is-ghost",ob="a-btn is-secondary max-sm:hidden",lb="a-btn is-primary",Xt=50,cb=3,io={selected:"Selected stories",visible:"Visible view",tag:"Tagged stories"},db={selected:"Checked in the library",visible:"Matches the current filters",tag:"Matches selected library tags"};function oo(t){return`${t} ${t===1?"story":"stories"}`}function ub(t){if(!t)return"Story unavailable";
6const a=t.authors.filter(Boolean).join(", ")||"Unknown author",n=t.fandoms.filter(Boolean)[0]??"Unknown fandom";return`${a} - ${n}`}function mb(t,a){switch(t){case"copied":return"Copied to clipboard.";case"error":return"Copy failed. The preview remains selectable.";case"unavailable":return"No shareable stories for this scope.";case"idle":return`Ready to copy ${oo(a)}.`}}function yn({step:t,title:a}){return e.jsxs("div",{className:px,children:[e.jsx("span",{className:hx,children:t}),e.jsx("h3",{className:xx,children:a})]})}function pb({selectedCount:t,visibleCount:a,tagShareCount:n,shareSource:s,onChangeShareSource:i}){const o=[{value:"visible",count:a},{value:"selected",count:t},{value:"tag",count:n}];return e.jsx("div",{className:gx,role:"group","aria-label":"Share scope",children:o.map(c=>{const u=s===c.value,l=c.value==="selected"&&t===0;return e.jsxs("button",{type:"button",disabled:l,"aria-pressed":u,className:fx(u),onClick:()=>i(c.value),children:[e.jsx("span",{className:vx(u),"aria-hidden":!0,children:u?e.jsx("span",{className:yx}):null}),e.jsxs("span",{className:wx,children:[e.jsx("span",{className:jx,children:io[c.value]}),e.jsx("span",{className:Nx,children:l?"Select stories first":db[c.value]})]}),e.jsx("span",{className:Sx,children:c.count})]},c.value)})})}function hb({clipboardFormat:t,onChange:a}){return e.jsxs("div",{className:Hx,role:"group","aria-label":"Clipboard format",children:[e.jsx("button",{type:"button","aria-pressed":t==="markdown",className:fr(t==="markdown"),onClick:()=>a("markdown"),children:"Markdown"}),e.jsx("button",{type:"button","aria-pressed":t==="plaintext",className:fr(t==="plaintext"),onClick:()=>a("plaintext"),children:"Plain text"})]})}function xb({shareOpts:t,onChangeShareOpts:a}){const n=[{key:"includeRating",label:"Rating",sub:"Five-star rating you set."},{key:"includeRelationships",label:"Relationships",sub:"AO3 ship tags from source."},{key:"includeSummary",label:"Summary",sub:"First 280 characters of the source blurb."},{key:"includeNotes",label:"Private notes",sub:"Stay off by default. Toggle on with care."}];return e.jsx("div",{className:Ux,children:n.map(s=>{const i=t[s.key];return e.jsxs("button",{type:"button","aria-pressed":i,"aria-label":s.label,className:Yx,onClick:()=>a(o=>({...o,[s.key]:!o[s.key]})),children:[e.jsx("span",{className:Kx(i),"aria-hidden":!0}),e.jsxs("span",{className:zx,children:[e.jsx("span",{className:qx,children:s.label}),e.jsx("span",{className:Gx,children:s.sub})]})]},s.key)})})}function bb({open:t,onClose:a,selectedCount:n,visibleCount:s,tagShareCount:i,shareTotalCount:o,getEntriesForShareBatch:c,storiesMap:u,shareSource:l,onChangeShareSource:m,allTags:d,shareTags:x,onChangeShareTags:y,shareTagMatchMode:g,onChangeShareTagMatchMode:N,shareTitle:S,onChangeShareTitle:C,shareOpts:_,onChangeShareOpts:p,onToast:b}){const[k,j]=r.useState("markdown"),[O,R]=r.useState(!1),[F,A]=r.useState(!1),[z,Q]=r.useState(0),te=r.useMemo(()=>({..._,format:"Detailed"}),[_]),v=o,$=Math.max(1,Math.ceil(v/Xt)),f=Math.min(z,$-1),U=f*Xt,oe=Math.min(U+Xt,v),se=r.useMemo(()=>c(U,Xt),[c,U]),G=$>1;r.useEffect(()=>{R(!1),A(!1),Q(0)},[l,x,g]),r.useEffect(()=>{z>=$&&Q($-1)},[$,z]);const I=r.useMemo(()=>sx(se,u,te,S),[se,u,te,S]),E=r.useMemo(()=>cx(se,u,te,S),[se,u,te,S]),Y=k==="markdown"?I:E,W=se.length>0,J=se.slice(0,cb).map(P=>({entry:P,story:u[P.storyId]})),X=Math.max(0,v-J.length),ee=F?"error":W?O?"copied":"idle":"unavailable",le=async()=>{if(W)try{await navigator.clipboard.writeText(Y),R(!0),A(!1),window.setTimeout(()=>R(!1),1400),b?.(G?`Batch ${f+1} copied`:k==="markdown"?"Markdown copied":"Plain text copied")}catch{A(!0),b?.("Copy failed")}},ae=()=>{if(!W)return;const P=(S.trim()||"trace-stories").toLocaleLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48),re=new Blob([I],{type:"text/markdown;charset=utf-8"}),me=URL.createObjectURL(re),ce=document.createElement("a");ce.href=me,ce.download=`${P||"trace-stories"}.md`,document.body.append(ce),ce.click(),ce.remove(),URL.revokeObjectURL(me),b?.("Markdown downloaded")};return e.jsx(pi,{open:t,title:"Share",onClose:a,variant:"library",size:"lg",desktopPresentation:"sheet",desktopBackdrop:"transparent",hideHeader:!0,hideHeaderClose:!0,hideFooter:!0,panelClassName:xi.share,bodyClassName:hi,children:e.jsxs(bc,{eyebrow:"Share",title:"Share stories",onClose:a,closeLabel:"Close share drawer",className:ux,bodyClassName:mx,footerClassName:sb,footer
6:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:ib,onClick:a,children:"Cancel"}),e.jsx("span",{className:rb}),e.jsx("button",{type:"button",className:ob,onClick:ae,disabled:!W,children:"Download .md"}),e.jsxs("button",{type:"button",className:lb,onClick:le,disabled:!W,children:[O?e.jsx(ut,{"aria-hidden":!0}):e.jsx(ri,{"aria-hidden":!0}),O?"Copied":k==="markdown"?"Copy Markdown":"Copy plain text"]})]}),children:[e.jsxs("section",{className:vn,children:[e.jsx(yn,{step:1,title:"Select what stories to share"}),e.jsxs("div",{className:bx,children:[e.jsx(pb,{selectedCount:n,visibleCount:s,tagShareCount:i,shareSource:l,onChangeShareSource:m}),e.jsxs("div",{className:kx,children:[l==="tag"?e.jsxs("div",{className:Cx,children:[e.jsx(dx,{selected:x,options:d,multi:!0,allowCreate:!1,placeholder:"Pick tags...",triggerClassName:_x,panelClassName:Rx,onChange:y}),e.jsxs("div",{className:Lx,role:"group","aria-label":"Tag match",children:[e.jsx("button",{type:"button","aria-pressed":g==="any",className:gr(g==="any"),onClick:()=>N("any"),children:"Any tag"}),e.jsx("button",{type:"button","aria-pressed":g==="all",className:gr(g==="all"),onClick:()=>N("all"),children:"Every tag"})]})]}):null,e.jsxs("div",{className:Ax,children:[e.jsx("span",{className:Tx,children:oo(v)}),e.jsxs("span",{className:Ex,children:["from ",io[l].toLowerCase()]})]}),e.jsxs("div",{className:Px,children:[J.map(({entry:P,story:re})=>e.jsxs("div",{className:Mx,children:[e.jsx("div",{className:Ix,children:re?.title??"Story unavailable"}),e.jsx("div",{className:Ox,children:ub(re)})]},P.id)),X>0?e.jsxs("div",{className:Dx,children:["+",X," more in this share"]}):null,J.length?null:e.jsx("div",{className:Fx,children:"No stories match this scope."})]})]})]})]}),e.jsxs("section",{className:vn,children:[e.jsx(yn,{step:2,title:"Choose format and included details"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:$x,children:[e.jsx("label",{className:La,htmlFor:"share-title",children:"List title"}),e.jsx("div",{className:Wx,children:e.jsx("input",{id:"share-title",placeholder:"Optional heading",value:S,onChange:P=>C(P.target.value),"aria-describedby":"share-title-help"})}),e.jsx("p",{id:"share-title-help",className:Bx,children:"Included as the heading at the top of the copied Markdown or plain-text list."})]}),e.jsxs("div",{className:Vx,children:[e.jsxs("div",{children:[e.jsx("div",{className:La,children:"Format"}),e.jsx(hb,{clipboardFormat:k,onChange:j})]}),e.jsxs("div",{children:[e.jsx("div",{className:La,children:"Details included"}),e.jsx(xb,{shareOpts:_,onChangeShareOpts:p})]})]})]})]}),e.jsxs("section",{className:vn,children:[e.jsx(yn,{step:3,title:"Copy"}),e.jsxs("div",{className:Qx,children:[e.jsxs("div",{children:[e.jsx("div",{className:Xx,children:v===0?"No stories ready to copy":G?`Batch ${f+1} of ${$}`:`${v} ${v===1?"story":"stories"} ready to copy`}),v>0?e.jsxs("div",{className:Zx,children:["Copying ",U+1,"-",oe," of ",v,G?`, ${Xt} at a time.`:"."]}):null]}),e.jsxs("div",{className:L(Jx,(ee==="error"||ee==="unavailable")&&eb),children:[ee==="error"||ee==="unavailable"?e.jsx(Vl,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}):O?e.jsx(ut,{className:"mt-0.5 h-3.5 w-3.5 shrink-0","aria-hidden":!0}):null,e.jsx("span",{children:mb(ee,v)})]}),G?e.jsxs("div",{className:tb,"aria-label":"Share batch",children:[e.jsx("button",{type:"button",className:vr,disabled:f===0,onClick:()=>Q(P=>Math.max(0,P-1)),children:"Previous batch"}),e.jsx("button",{type:"button",className:vr,disabled:f>=$-1,onClick:()=>Q(P=>Math.min($-1,P+1)),children:"Next batch"})]}):null,e.jsxs("div",{children:[e.jsx("div",{className:La,children:"Output preview"}),e.jsx("div",{className:ab,children:e.jsx("textarea",{className:nb,rows:8,readOnly:!0,value:Y,"aria-label":k==="markdown"?"Markdown preview":"Plain text preview"})})]})]})]})]})})}const gb=["hidden sm:flex","sticky top-0 z-[1300]","items-center gap-2 overflow-x-auto","border-b border-[color-mix(in_oklab,var(--honey)_34%,var(--line-strong))]","bg-[color-mix(in_oklab,var(--honey)_18%,var(--paper))] px-8 py-3 text-[var(--ink)] shadow-[0_14px_28px_color-mix(in_oklab,var(--honey)_10%,transparent)]","max-w-full min-w-0 [-webkit-overflow-scrolling:touch]"].join(" "),fb="shrink-0",vb="font-mono text-xs tracking-[0.04em] text-[var(--ink)]",yr="mx-1 h-4 w-px shrink-0 bg-[color-mix(in_oklab,var(--ink)_14%,transparent)]",yb="min-w-3 flex-1",wr=["inline-flex min-h-8 shrink-0 items-center justify-center rounded-sm border-0 bg-transparent px-2","text-[12.5px] text-[var(--ink-3)] transition","hover:text-[var(--ink)] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),wb=["inline-flex min-h-8 shrink-0 items-center justify-center rounded-[8px] border border-[var(--ink)]","bg-[var(--ink)] px-3 font-mono text-[11px] font-semibold uppercase leading-none tracking-[0.08em] text-[var(--paper)] transition","hover:bg-[color-mix(in_oklab,var(--ink)_88%,var(--rust))] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--ink)_18%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),ft=["inline-flex min-h-8 shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-[8px]","border border-[var(--line-strong)]","bg-[color-mix(in_oklab,var(--paper)_78%,transparent)] px-2.5","text-[12.5px] text-[var(--ink)] transition","hover:border-[color-mix(in_oklab,var(--honey)_34%,var(--line-strong))] hover:bg-[color-mix(in_oklab,var(--honey)_10%,var(--paper))]","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-45","[&_svg]:h-[13px] [&_svg]:w-[13px]"].join(" "),jb="!text-[var(--rust)] hover:!text-[var(--rust)]",Nb=["inline-flex min-h-8 shrink-0 items-center justify-center rounded-sm border-0 bg-transparent px-2","text-[12.5px] text-[var(--archive-inverse-muted)] transition","hover:text-[var(--archive-inverse-text)] focu
6s-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),Sb=["inline-flex min-h-9 shrink-0 items-center justify-center rounded-[9px] border border-[color-mix(in_oklab,var(--honey)_52%,transparent)]","bg-[var(--honey)] px-3 font-mono text-[11px] font-semibold uppercase leading-none tracking-[0.08em] text-[var(--ink)]","shadow-[0_8px_18px_-12px_var(--honey)] transition hover:bg-[color-mix(in_oklab,var(--honey)_90%,var(--paper))]","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_28%,transparent)]","disabled:cursor-not-allowed disabled:opacity-40"].join(" "),kb=["inline-flex min-h-8 shrink-0 items-center justify-center rounded-[8px] border border-[color-mix(in_oklab,var(--honey)_45%,transparent)]","bg-[color-mix(in_oklab,var(--honey)_18%,transparent)] px-3 font-mono text-[10.5px] font-semibold uppercase leading-none tracking-[0.08em] text-[var(--archive-inverse-text)] transition","hover:bg-[color-mix(in_oklab,var(--honey)_26%,transparent)] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]"].join(" "),Cb="!text-[var(--rust)] hover:!text-[var(--rust)]",_b=["fixed inset-x-0 z-[45]","grid gap-2 sm:hidden","rounded-t-[16px] bg-[var(--archive-inverse-surface)] px-4 py-3 text-[var(--archive-inverse-text)] shadow-[0_-18px_32px_-16px_rgba(0,0,0,0.45)]"].join(" "),Rb="bottom-0 pb-[calc(0.75rem+env(safe-area-inset-bottom))]",Lb="flex min-w-0 items-center justify-between gap-2",Ab="flex min-w-0 items-center gap-1.5",Tb="font-mono text-xs tracking-[0.04em] text-[var(--archive-inverse-text)]",Eb="flex shrink-0 items-center gap-1",Pb="grid grid-cols-3 gap-1.5",Lt=["inline-flex min-h-10 min-w-0 items-center justify-center gap-1.5 rounded-[8px]","border border-[var(--archive-inverse-line)]","bg-[var(--archive-inverse-control)] px-2","text-[12px] text-[var(--archive-inverse-text)] transition","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-45","[&_svg]:h-[13px] [&_svg]:w-[13px]"].join(" "),Mb=["fixed inset-x-0 top-0 z-[44]","sm:hidden","cursor-default border-0 bg-[color-mix(in_oklab,var(--content-primary)_10%,transparent)] p-0"].join(" "),Ib="bottom-[calc(8.75rem+env(safe-area-inset-bottom))]",Ob=["fixed inset-x-0 z-[46]","sm:hidden","mx-2","overflow-y-auto overscroll-contain","rounded-t-xl rounded-b-lg border border-[var(--archive-inverse-line)] bg-[var(--archive-inverse-surface)] p-3 text-[var(--archive-inverse-text)] shadow-overlay [-webkit-overflow-scrolling:touch]"].join(" "),Db=["bottom-[calc(8.75rem+env(safe-area-inset-bottom))]","max-h-[min(68dvh,calc(100dvh-9.5rem-env(safe-area-inset-top)-env(safe-area-inset-bottom)))]"].join(" "),Fb="mb-3",$b="h-1 w-10 rounded-full bg-[var(--archive-inverse-line)]",Wb="flex items-start justify-between gap-3 pb-2",Bb="text-sm font-semibold leading-tight text-[var(--archive-inverse-text)]",Vb="mt-0.5 text-xs text-[var(--archive-inverse-subtle)]",Hb="mt-2 overflow-hidden rounded-sm border border-[var(--archive-inverse-line)] bg-[var(--archive-inverse-control)]",Ub=["flex w-full items-center justify-between gap-3 px-3 py-3 text-left","border-b border-[var(--archive-inverse-line)] last:border-b-0","transition-colors hover:bg-[var(--archive-inverse-control-hover)] focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]","disabled:cursor-not-allowed disabled:opacity-45"].join(" "),Yb="min-w-0",Kb="block text-sm font-medium leading-tight text-[var(--archive-inverse-text)]",zb="mt-2 grid gap-2",qb="grid grid-cols-2 gap-2",Gb="flex flex-wrap gap-1.5",Qb=["inline-flex min-h-7 max-w-full items-center rounded-pill border border-[var(--archive-inverse-line)]","bg-[var(--archive-inverse-control)] px-2.5 text-xs text-[var(--archive-inverse-muted)]","transition-colors hover:border-[var(--archive-inverse-line)] hover:text-[var(--archive-inverse-text)]","focus-visible:outline-none focus-visible:shadow-[0_0_0_3px_color-mix(in_oklab,var(--honey)_22%,transparent)]"].join(" "),Xb=["hidden sm:block fixed inset-x-8 bottom-[calc(4.75rem+env(safe-area-inset-bottom))] z-[1300]","mx-auto max-w-7xl rounded-[12px] border border-[var(--line-strong)] bg-[var(--paper)] p-3 text-[var(--ink)] shadow-[var(--shadow-md)]"].join(" "),Zb="flex flex-wrap gap-2",Jb=ft,eg="grid grid-cols-[minmax(14rem,22rem)_auto_auto_minmax(0,1fr)] items-center gap-2",jr="text-xs text-[var(--ink-3)]",Nr=t=>t.trim().toLowerCase();function tg(t,a){const n=Nr(a);return n?(t.tags??[]).map(Nr).includes(n):!1}const Sr=[{value:"SAVED",label:"Saved"},{value:"READING",label:"Reading"},{value:"CAUGHT_UP",label:"Caught up"},{value:"PAUSED",label:"Paused"},{value:"FINISHED",label:"Finished"},{value:"DROPPED",label:"Dropped"}];function ag({selectedCount:t,visibleCount:a,totalCount:n,loadedCount:s,onSelectAllVisible:i,onSelectAllLibrary:o,onBulkSetStatus:c,onBulkCatchUp:u,bulkTag:l,onBulkTagChange:m,allTags:d,onBulkAddTag:x,onBulkRemoveTag:y,selectedEntries:g,onExitBulkMode:N,onAddToCollection:S,onShare:C,onBulkRemove:_,bulk
6Removing:p=!1}){const b=t===0,[k,j]=r.useState(!1),[O,R]=r.useState(!1),[F,A]=r.useState(null),[z,Q]=r.useState(!1),te=r.useRef(null),[v,$]=r.useState("status");r.useEffect(()=>{t===0&&(A(null),Q(!1))},[t]),r.useEffect(()=>{z||$("status")},[z]);const f=l.trim(),U=a.toLocaleString(),oe=typeof n=="number"?n.toLocaleString():null,se=typeof s=="number"?s.toLocaleString():null,G=!!o&&typeof n=="number"&&typeof s=="number"&&s>=n&&n>a&&n>0,I=oe?`Select all ${oe}`:se?`Select all ${se}`:"Select all",{haveCount:E,missingCount:Y}=r.useMemo(()=>{const P=f.trim();if(!P)return{haveCount:0,missingCount:0};let re=0;for(const me of g)tg(me,P)&&re++;return{haveCount:re,missingCount:g.length-re}},[g,f]),W=g.length>0&&f&&Y>0,J=g.length>0&&f&&E>0,X=r.useMemo(()=>{const P=f.toLowerCase();return d.filter(re=>{const me=re.trim();return!me||me===f?!1:P?me.toLowerCase().includes(P):!0}).slice(0,6)},[d,f]),ee=()=>{Q(!1),$("status")},le=P=>{c(P),ee()},ae=()=>{u(),ee(),R(!1)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:L(_b,Rb),role:"region","aria-label":"Bulk selection",children:[e.jsxs("div",{className:Lb,children:[e.jsx("div",{className:Ab,children:e.jsxs("span",{className:Tb,"aria-live":"polite",children:[e.jsx("strong",{children:t})," selected"]})}),e.jsxs("div",{className:Eb,children:[e.jsxs("button",{type:"button",className:Nb,onClick:i,children:["Select ",U]}),e.jsx("button",{type:"button",className:Sb,onClick:N,children:"Done selecting"})]})]}),e.jsxs("div",{className:Pb,children:[S?e.jsxs("button",{type:"button",className:Lt,onClick:S,disabled:b,children:[e.jsx(Ss,{"aria-hidden":!0}),"Collect"]}):null,e.jsxs("button",{type:"button",className:Lt,onClick:()=>{$("status"),Q(!0)},disabled:b,children:[e.jsx(Ma,{"aria-hidden":!0}),"State"]}),e.jsxs("button",{type:"button",className:Lt,onClick:()=>R(!0),disabled:b,children:[e.jsx(ut,{"aria-hidden":!0}),"Caught up"]}),C?e.jsxs("button",{type:"button",className:Lt,onClick:C,disabled:b,children:[e.jsx(kn,{"aria-hidden":!0}),"Share"]}):null,e.jsxs("button",{type:"button",className:Lt,onClick:()=>{$("tags"),Q(!0)},disabled:b,children:[e.jsx(Jr,{"aria-hidden":!0}),"Tag"]}),_?e.jsxs("button",{type:"button",className:L(Lt,Cb),onClick:()=>j(!0),disabled:b||p,children:[e.jsx(Oa,{"aria-hidden":!0}),"Remove"]}):null]})]}),z?e.jsx("button",{type:"button",className:L(Mb,Ib),"aria-label":"Close bulk actions",onClick:ee}):null,z?e.jsxs("div",{ref:te,"data-mobile-sheet-drag-target":"",className:L(Ob,Db),role:"dialog","aria-label":v==="status"?"Set bulk status":"Edit bulk tags",children:[e.jsx(Vr,{className:Fb,indicatorClassName:$b,targetRef:te,onDismiss:ee}),e.jsxs("div",{className:Wb,children:[e.jsxs("div",{children:[e.jsx("div",{className:Bb,children:v==="status"?"Set reader status":"Edit tags"}),e.jsxs("div",{className:Vb,children:[t," selected"]})]}),e.jsx("button",{type:"button",className:kb,onClick:ee,children:"Done"})]}),v==="status"?e.jsx("div",{className:Hb,children:Sr.map(P=>e.jsx("button",{type:"button",className:Ub,disabled:b,onClick:()=>le(P.value),children:e.jsx("span",{className:Yb,children:e.jsx("span",{className:Kb,children:P.label})})},P.value))}):e.jsxs("div",{className:zb,children:[e.jsx(Nn,{size:"sm",fullWidth:!0,placeholder:"Tag...",disabled:b,value:l,onChange:P=>m(P.target.value),"aria-label":"Bulk tag"}),X.length?e.jsx("div",{className:Gb,"aria-label":"Tag suggestions",children:X.map(P=>e.jsx("button",{type:"button",className:Qb,onClick:()=>m(P),children:P},P))}):null,e.jsxs("div",{className:qb,children:[e.jsxs(de,{variant:"outline",size:"sm",onClick:()=>x(f),disabled:!W,children:["Add",f?` to ${Y}`:""]}),e.jsxs(de,{variant:"outline",size:"sm",onClick:()=>y(f),disabled:!J,children:["Remove",f?` from ${E}`:""]})]}),f&&g.length>0?e.jsxs("span",{className:jr,children:["On selected: ",E," have it, ",Y," don't"]}):null]})]}):null,e.jsxs("div",{className:gb,role:"region","aria-label":"Bulk actions",children:[e.jsx("div",{className:fb,children:e.jsxs("span",{className:vb,"aria-live":"polite",children:[e.jsx("strong",{children:t})," selected",e.jsxs("span",{children:[" · of ",U," visible"]})]})}),e.jsx("span",{className:yr,"aria-hidden":!0}),e.jsxs("button",{type:"button",className:wr,onClick:i,children:["Select all ",U]}),oe&&G?e.jsx("button",{type:"button",className:wr,onClick:o,children:I}):null,e.jsx("span",{className:yb}),S?e.jsxs("button",{type:"button",className:ft,onClick:S,disabled:b,children:[e.jsx(Ss,{"aria-hidden":!0}),"Add to collection"]}):null,e.jsxs("button",{type:"button",className:ft,onClick:()=>A(P=>P==="status"?null:"status"),disabled:b,children:[e.jsx(Ma,{"aria-hidden":!0}),"Change status"]}),e.jsxs("button",{type:"button",className:ft,onClick:()=>R(!0),disabled:b,children:[e.jsx(ut,{"aria-hidden":!0}),"Mark caught up"]}),C?e.jsxs("button",{type:"button",className:ft,onClick:C,disabled:b,children:[e.jsx(kn,{"aria-hidden":!0}),"Share"]}):null,e.jsxs("button",{type:"button",className:ft,onClick:()=>A(P=>P==="tags"?null:"tags"),disabled:b,children:[e.jsx(mt,{"aria-hidden":!0}),"Tag"]}),_?e.jsxs("button",{type:"button",className:L(ft,jb),onClick:()=>j(!0),disabled:b||p,children:[e.jsx(Oa,{"aria-hidden":!0}),"Remove"]}):null,e.jsx("span",{className:yr,"aria-hidden":!0}),e.jsx("button",{type:"button",className:wb,onClick:N,children:"Done selecting"})]}),F?e.jsx("div",{className:Xb,role:"region","aria-label":"Bulk subactions",children:F==="status"?e.jsx("div",{className:Zb,children:Sr.map(P=>e.jsx("button",{type:"button",className:Jb,disabled:b,onClick:()=>{c(P.value),A(null)},children:P.label},P.value))}):e.jsxs("div",{className:eg,children:[e.jsx(Nn,{size:"sm",fullWidth:!0,placeholder:"Tag...",disabled:b,value:l,onCh
6ange:P=>m(P.target.value),"aria-label":"Bulk tag"}),e.jsxs(de,{variant:"outline",size:"sm",onClick:()=>x(f),disabled:!W,children:["Add",f?` to ${Y}`:""]}),e.jsxs(de,{variant:"outline",size:"sm",onClick:()=>y(f),disabled:!J,children:["Remove",f?` from ${E}`:""]}),f&&g.length>0?e.jsxs("span",{className:jr,children:["On selected: ",E," have it, ",Y," don't"]}):null]})}):null,_&&e.jsx($t,{open:k,title:"Remove from library",description:`Remove ${t} stor${t===1?"y":"ies"} from your library? This can't be undone.`,confirmLabel:"Remove",variant:"danger",loading:p,onConfirm:()=>{j(!1),_()},onCancel:()=>j(!1)}),e.jsx($t,{open:O,title:"Catch up selected stories?",description:`Update progress to the latest known chapter for ${t} selected stor${t===1?"y":"ies"}?`,confirmLabel:"Catch up",onConfirm:ae,onCancel:()=>R(!1)})]})}function ng({onCancel:t,onConfirm:a,open:n}){const[s,i]=r.useState(null),[o,c]=r.useState("");r.useEffect(()=>{n||(i(null),c(""))},[n]);const u=s==="today"?Ls():s==="date"?o:null,l=s==="unknown"||s==="today"||!!u;return e.jsx($t,{confirmDisabled:!l,confirmLabel:"Mark finished",description:"Choose the finish date to apply to every selected story.",onCancel:t,onConfirm:()=>a(gc(u)),open:n,surface:"archive",title:"Finish selected stories",children:e.jsxs("div",{className:"mt-4 grid gap-3",role:"radiogroup","aria-label":"Bulk finish date",children:[[["today","Today"],["date","Choose a date"],["unknown","Date unknown"]].map(([m,d])=>e.jsxs("label",{className:"flex items-center gap-3 text-sm",children:[e.jsx("input",{checked:s===m,name:"bulk-finish-date",onCh
6ange:()=>i(m),type:"radio",value:m}),e.jsx("span",{children:d})]},m)),s==="date"?e.jsx("input",{"aria-label":"Shared finish date",className:"tf-field",max:Ls(),onChange:m=>c(m.target.value),type:"date",value:o}):null]})})}const sg="https://archiveofourown.org/works",rg="https://www.fanfiction.net/",ig={1:{eyebrow:"Your first story is saved",title:"Keep reading as usual.",body:"On AO3 or FanFiction.net, use Add to Trace or simply open a story and let auto-track save it. Reading on another site? Use Add manually and keep reading as usual.",icon:Ha},2:{eyebrow:"Build your library",title:"Add a whole page at once.",body:"You can also add a whole supported listing or bookmarks page: open the Trace extension and choose Import this page.",icon:Wn},3:{eyebrow:"As your library grows",title:"Make it yours.",body:"Use filters and collections to organize your library. Add private notes, ratings, and tags to remember what mattered.",icon:Hl}};function og({step:t,pending:a=!1,error:n=null,onAdvance:s,onDismiss:i,onComplete:o,onOpenArchive:c}){const u=ig[t],l=u.icon,m=r.useRef(null),d=r.useRef(t),[x,y]=r.useState(null),g=a||x!==null;r.useEffect(()=>{d.current!==t&&(d.current=t,m.current?.focus())},[t]);const N=r.useCallback(async(S,C)=>{if(!g){y(S);try{if(!await o()||!C)return;c?c(C):window.location.assign(C)}finally{y(null)}}},[g,o,c]);return e.jsxs("section",{"aria-label":"Getting started with your library",className:"relative mb-5 overflow-hidden rounded-lg border border-[color-mix(in_oklab,var(--forest)_24%,var(--border))] bg-surface-1 p-5 pl-6 shadow-sm before:absolute before:bottom-0 before:left-0 before:top-0 before:w-1 before:bg-[var(--forest)] sm:p-6 sm:pl-7",children:[e.jsx("button",{type:"button","aria-label":"Skip getting started guide",onClick:i,disabled:g,className:"absolute right-3 top-3 inline-flex h-11 w-11 items-center justify-center rounded-lg text-content-muted transition hover:bg-surface-2 hover:text-content-primary focus-visible:shadow-ring disabled:cursor-wait disabled:opacity-50",children:e.jsx(wt,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"flex items-start gap-4 pr-10",children:[e.jsx("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-sm border border-[color-mix(in_oklab,var(--forest)_22%,var(--border))] bg-[var(--forest-soft)] text-[var(--forest)]","aria-hidden":!0,children:e.jsx(l,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-[var(--forest)]",children:u.eyebrow}),e.jsx("h2",{ref:m,tabIndex:-1,className:"mt-1 font-landing-serif text-2xl font-semibold leading-tight text-content-primary outline-none",children:u.title})]})]}),e.jsx("p",{className:"mt-4 max-w-[58ch] text-sm leading-6 text-content-muted",children:u.body}),e.jsxs("div",{className:"mt-5 flex items-center gap-2","aria-label":`Step ${t} of 3`,children:[[1,2,3].map(S=>e.jsx("span",{className:L("h-1.5 rounded-pill transition-[width,background-color]",S===t?"w-8 bg-[var(--forest)]":S<t?"w-4 bg-[color-mix(in_oklab,var(--forest)_55%,var(--border))]":"w-4 bg-border"),"aria-hidden":!0},S)),e.jsxs("span",{className:"ml-1 font-mono text-micro font-semibold uppercase tracking-widest text-content-muted",children:[t," of 3"]})]}),n?e.jsx("p",{className:"mt-4 text-sm text-[var(--rust)]",role:"alert",children:n}):null,t<3?e.jsx(de,{type:"button",variant:"solid",size:"lg",className:"mt-5 min-h-11 justify-center",onClick:s,disabled:g,loading:g,rightIcon:e.jsx(Ua,{className:"h-4 w-4","aria-hidden":!0}),children:"Next"}):e.jsxs("div",{className:"mt-5 flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center",children:[e.jsx(de,{type:"button",variant:"solid",size:"lg",className:"min-h-11 justify-center",onClick:()=>{N("ao3",sg)},disabled:g,loading:x==="ao3",children:"Open AO3"}),e.jsx(de,{type:"button",variant:"outline",size:"lg",className:"min-h-11 justify-center bg-surface-1",onClick:()=>{N("ffn",rg)},disabled:g,loading:x==="ffn",children:"Open FanFiction.net"}),e.jsx(de,{type:"button",variant:"ghost",size:"lg",className:"min-h-11 justify-center",onClick:()=>{N("library")},disabled:g,loading:x==="library",children:"Stay in My Library"})]})]})}function lg({chips:t,onClear:a,onClearAll:n}){return t.length?e.jsxs("div",{className:"flex min-w-0 items-center gap-2 overflow-x-auto border-b border-[var(--line)] px-4 pb-3 pt-0 sm:flex-wrap sm:overflow-visible sm:px-8 sm:pt-2","aria-label":"Active library filters",children:[t.map(s=>e.jsx(ec,{label:s.label,value:s.value,removeLabel:`Remove ${s.ariaLabel} filter`,onRemove:()=>
6a(s.id),className:"max-w-64 shrink-0 sm:max-w-72"},s.id)),t.length>1?e.jsx("button",{type:"button",onClick:n,className:"inline-flex min-h-8 shrink-0 items-center rounded-pill px-3 font-mono text-[10.5px] font-medium uppercase leading-none tracking-[0.18em] text-[var(--rust)] transition hover:bg-[var(--paper-2)] focus-visible:outline-none focus-visible:shadow-ring",children:"Clear"}):null]}):null}function cg(){const[t,a]=kl(),n=r.useCallback(b=>{const k=t.toString(),j=new URLSearchParams(t);b(j),j.toString()!==k&&a(j,{replace:!0})},[a,t]),s=t.get("q")??"",i=t.get("libraryViewId")||null,o=t.get("view");r.useEffect(()=>{o!==null&&n(b=>{b.delete("view")})},[n,o]);const c=t.get("catchup"),u=c==="UP"||c==="BEHIND"||c==="ANY"?c:"ANY",l=t.get("panel"),m=l==="add"||l==="share"||l==="details"?l:null,d=t.get("sort"),x=d&&Hr(d)?d:"LAST_READ_DESC",y=m==="details"?t.get("entryId")??void 0:void 0,g=r.useCallback(b=>{n(k=>{const j=b??"";j.trim()?k.set("q",j):k.delete("q")})},[n]),N=r.useCallback(b=>{n(k=>{k.set("sort",b)})},[n]),S=r.useCallback(b=>{n(k=>{b==="ANY"?k.delete("catchup"):k.set("catchup",b)})},[n]),C=r.useCallback(b=>{n(k=>{const j=b?.trim();j?k.set("libraryViewId",j):k.delete("libraryViewId")})},[n]),_=r.useCallback((b,k)=>{n(j=>{j.set("panel",b),b==="details"&&k?.entryId?j.set("entryId",k.entryId):j.delete("entryId")})},[n]),p=r.useCallback(()=>{n(b=>{b.delete("panel"),b.delete("entryId")})},[n]);return{q:s,sort:x,panel:m,entryId:y,catchup:u,libraryViewId:i,setQ:g,setSort:N,setCatchup:S,setLibraryViewId:C,openPanel:_,closePanel:p}}function dg(t){return(t??[]).map(a=>a.trim()).filter(a=>a.length>0)}function $e(t){const a=dg(t);return a.length?a.length<=2?a.join(", "):`${a.slice(0,2).join(", ")} +${a.length-2}`:null}const ug={general:"General / K-K+",teen:"Teen / T",mature:"Mature / M",explicit:"Explicit",not_rated:"Not rated"},mg=t=>ug[t]??fl(t);function Aa(t){return t.toLocaleString("en-US")}function kr(t){return t.trim().slice(0,10)}function ie(t,a,n,s){const i=s?.trim();i&&t.push({id:a,label:n,value:i,ariaLabel:`${n}: ${i}`})}function lo(t,a){const n=[];return ie(n,"search","Search",a),ie(n,"ratings","Content rating",$e(t.ratings.map(mg))),ie(n,"platforms","Platforms",$e(t.platforms)),ie(n,"statuses","Reader status",$e(t.statuses.map(s=>yt(s)))),t.catchup==="UP"?ie(n,"catchup","Catch-up",fs("UP")):t.catchup==="BEHIND"&&ie(n,"catchup","Catch-up",fs("BEHIND")),t.storyUpdates==="NEW"&&ie(n,"storyUpdates","Story updates","New updates"),typeof t.minWords=="number"&&ie(n,"minWords","Words",`${Aa(t.minWords)}+`),typeof t.maxWords=="number"&&ie(n,"maxWords","Words",`⤠${Aa(t.maxWords)}`),typeof t.minKudos=="number"&&ie(n,"minKudos","Favs/kudos",`${Aa(t.minKudos)}+`),typeof t.maxKudos=="number"&&ie(n,"maxKudos","Favs/kudos",`⤠${Aa(t.maxKudos)}`),typeof t.minRating=="number"?ie(n,"minRating","Rating",`${t.minRating}+ stars`):t.entryRating==="UNRATED"&&ie(n,"entryRating","Rating","Unrated only"),t.lastReadAfter.trim()&&ie(n,"lastReadAfter","Read after",kr(t.lastReadAfter)),t.lastReadBefore.trim()&&ie(n,"lastReadBefore","Read before",kr(t.lastReadBefore)),t.notes==="WITH"||t.hasNotes?ie(n,"hasNotes","Notes","With notes"):t.notes==="WITHOUT"&&ie(n,"hasNotes","Notes","Without notes"),ie(n,"completionStatus","Work status",$e(t.completionStatus.map(s=>Ve(s)))),ie(n,"tag","Library tag",t.tag),ie(n,"workTag","AO3 tag",t.workTag),ie(n,"pairMembers","Pairs",$e(t.pairMembers)),t.pairExact&&t.pairMembers.length&&ie(n,"pairExact","Pairs","Exact only"),ie(n,"characters","Characters",$e(t.characters)),ie(n,"fandoms","Fandoms",$e(t.fandoms)),ie(n,"categoryFilter","Categories",$e(t.categoryFilter)),ie(n,"includeWarnings","Warnings",$e(t.includeWarnings)),ie(n,"excludeTag","Hide tag",t.excludeTag),ie(n,"excludeWorkTag","Hide AO3 tag",t.excludeWorkTag),ie(n,"excludePairMembers","Hide pairs",$e(t.excludePairMembers)),t.excludePairExact&&t.excludePairMembers.length&&ie(n,"excludePairExact","Hide pairs","Exact only"),ie(n,"excludeCharacters","Hide characters",$e(t.excludeCharacters)),ie(n,"excludeFandoms","Hide fandoms",$e(t.excludeFandoms)),ie(n,"excludeCategoryFilter","Hide categories",$e(t.excludeCategoryFilter)),ie(n,"excludeWarnings","Hide warnings",$e(t.excludeWarnings)),n}
6function Et(t){return t.toLocaleString("en-US")}function pg(t){return t>=1e4?Va(t):Et(t)}function hg({entries:t,storiesMap:a,totalCount:n,visibleCount:s,activeFilterCount:i,hasQuery:o=!1}){const c=t.filter(x=>x.status==="READING").length,u=t.filter(x=>x.status==="CAUGHT_UP").length,l=t.filter(x=>x.status==="FINISHED").length,m=t.reduce((x,y)=>{const g=a[y.storyId]?.words;return x+(typeof g=="number"?g:0)},0),d=[{value:Et(n),label:n===1?"story saved":"saved"}];return(i>0||o)&&d.push({value:Et(s),label:"matching now"}),c>0&&d.push({value:Et(c),label:"reading"}),u>0&&d.push({value:Et(u),label:"caught up"}),l>0&&d.push({value:Et(l),label:"finished"}),m>0&&d.push({value:pg(m),label:"words tracked"}),d.slice(0,5)}function xg(t){const a=t.lastReadAt??t.updatedAt,n=a?Date.parse(a):Number.NaN;return Number.isFinite(n)?n:null}function bg(t){if(t.status==="SAVED")return null;const a=t.lastReadAt?Date.parse(t.lastReadAt):Number.NaN;return Number.isFinite(a)?a:t.status!=="READING"&&t.status!=="CAUGHT_UP"?null:xg(t)}function gg(t){let a=null,n=Number.NEGATIVE_INFINITY;for(const s of t){const i=bg(s);i==null||i<=n||(a=s.id,n=i)}return a}const wn=Ur,fg=({overCap:t,atCap:a,totalCount:n})=>e.jsxs("div",{className:"mb-3 flex flex-wrap items-center justify-between gap-3 rounded-xl border border-border bg-surface-2/60 p-3",children:[e.jsx("span",{className:"text-sm text-content-subtle",children:t?`You're over the free limit (${wn}). Trace Unlimited lets you keep adding stories.`:a?`Youâve hit the free limit (${wn}).`:`Almost at the free limit (${n}/${wn}).`}),e.jsx(de,{variant:"cta",onClick:()=>window.dispatchEvent(new CustomEvent("trace:openUpgrade",{detail:{source:"library_cap"}})),children:"See Trace Unlimited"})]});function vg({pending:t=!1,error:a=null,onDismiss:n}){return e.jsxs("aside",{"aria-labelledby":"reader-launch-note-heading",className:"relative my-5 overflow-hidden border-y border-[color-mix(in_oklab,var(--rust)_24%,var(--border))] bg-[color-mix(in_oklab,var(--surface-1)_92%,var(--rust-soft))] py-4 pl-5 pr-12 sm:border sm:py-5 sm:pl-6 sm:pr-14",children:[e.jsx("span",{"aria-hidden":!0,className:"absolute bottom-0 left-0 top-0 w-1 bg-[var(--rust)]"}),e.jsx(ct,{type:"button",variant:"ghost",size:"lg","aria-label":"Hide Trace Reader note",onClick:()=>{n()},disabled:t,loading:t,className:"absolute right-1.5 top-1.5 text-content-muted sm:right-2 sm:top-2",children:e.jsx(wt,{className:"h-5 w-5","aria-hidden":!0})}),e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:gap-5",children:[e.jsx("span",{"aria-hidden":!0,className:"hidden h-11 w-11 shrink-0 items-center justify-center border border-[color-mix(in_oklab,var(--rust)_28%,var(--border))] bg-[var(--rust-soft)] text-[var(--rust)] sm:flex",children:e.jsx(Ha,{className:"h-5 w-5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-mono text-micro font-semibold uppercase tracking-widest text-[var(--rust)]",children:"New app"}),e.jsx("h2",{id:"reader-launch-note-heading",className:"mt-1 font-landing-serif text-xl font-semibold leading-tight text-content-primary sm:text-2xl",children:"Trace now tracks the AO3 stories you read offline."}),e.jsx("p",{className:"mt-2 max-w-[72ch] text-sm leading-6 text-content-muted",children:"The extension automatically tracks stories you read on AO3. Trace Reader now does the same for downloaded EPUBs, with statuses, ratings and notes you can update as you read. It's built for fanfiction and accessibility, and your EPUB files and story text stay on your device."}),a?e.jsx("p",{className:"mt-2 text-sm text-[var(--rust)]",role:"alert",children:a}):null]}),e.jsx(de,{nativeButton:!1,render:e.jsx(Cl,{to:"/reader"}),variant:"outline",size:"lg",className:"min-h-11 shrink-0 self-start bg-surface-1 sm:self-center",rightIcon:e.jsx(Ua,{"aria-hidden":!0}),children:"See Trace Reader"})]})]})}function yg({accountLoading:t,isPro:a,nearCap:n,atCap:s}){return!t&&!a&&(n||s)}const co="(max-width: 639px)";function wg(t){if(typeof window>"u"||!window.matchMedia)return()=>{};const a=window.matchMedia(co);return a.addEventListener?(a.addEventListener("change",t),()=>a.removeEventListener("change",t)):(a.addListener(t),()=>a.removeListener(t))}function jg(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia(co).matches}function Ng(){return!1}function Sg(){return r.useSyncExternalStore(wg,jg,Ng)}function kg({showFilters:t,children:a,filtersPanel:n,mobileFiltersHeader:s,mobileFiltersBody:i,mobileFiltersFooter:o,stickyTopClass:c="top-16",
6sticky:u=!0,runtime:l="browser",chromeState:m="full",stickyChromeRef:d,visibleCount:x,onCloseFilters:y}){const g=Sg(),N=!!i,C=t&&!!(i??n)&&g,_=$c(C),p=r.useRef(null),b=o?.applyLabel??(typeof x=="number"?`Show ${x.toLocaleString()} results`:"Apply filters"),k=!!o?.applyDisabled,j=o?.onApply??y,O=e.jsx(Ul,{open:C,modal:!0,onOpenChange:R=>{R||y?.()},children:e.jsxs(Yl,{children:[e.jsx(Kl,{className:L("library-app archive-editorial-shell library-filter-mobile-backdrop fixed inset-0 z-[1300] sm:hidden",N&&"!bg-[rgba(8,10,7,0.55)]")}),e.jsx(zl,{className:L("fixed inset-0 z-[1310] flex w-screen max-w-full overflow-hidden overscroll-none sm:hidden",N&&"items-end pointer-events-none"),children:e.jsx(ql,{ref:p,"data-mobile-sheet-drag-target":"",finalFocus:_,className:L("library-app archive-editorial-shell library-filter-mobile-shell flex w-full max-w-full flex-col overflow-x-hidden outline-none",N?"pointer-events-auto max-h-[min(88dvh,calc(100dvh_-_env(safe-area-inset-top)_-_0.75rem))] overflow-hidden rounded-t-lg border border-[var(--line-strong)] shadow-[0_-20px_50px_-24px_rgba(0,0,0,0.6)]":"h-full","motion-reduce:transition-none"),children:N?e.jsxs(e.Fragment,{children:[e.jsx(ks,{className:"sr-only",children:"Filter and sort"}),y?e.jsx(Vr,{className:"library-filter-mobile-handle",targetRef:p,onDismiss:y}):null,e.jsxs("div",{className:"library-filter-mobile-header flex w-full max-w-full shrink-0 items-start justify-between gap-3",children:[e.jsx("div",{className:"min-w-0 flex-1",children:s}),e.jsx("button",{type:"button",className:"library-filter-mobile-close flex shrink-0 items-center justify-center focus-visible:outline-none","aria-label":"Close filters",onClick:y,children:e.jsx(wt,{className:"h-5 w-5","aria-hidden":!0})})]}),e.jsx("div",{className:"library-filter-mobile-body min-h-0 w-full max-w-full flex-1 overflow-x-hidden overflow-y-auto overscroll-contain [-webkit-overflow-scrolling:touch]",children:i}),o?e.jsx("div",{className:"library-filter-mobile-footer w-full max-w-full shrink-0",children:e.jsxs("div",{className:L("grid gap-2","grid-cols-[7rem_minmax(0,1fr)]"),children:[e.jsx(de,{type:"button",variant:"outline",onClick:o.onReset,leftIcon:e.jsx(Ia,{}),children:"Reset"}),e.jsx(de,{type:"button",variant:k?"outline":"solid",disabled:k,onClick:j,leftIcon:k?void 0:e.jsx(ut,{}),className:L(k&&"cursor-not-allowed"),children:b})]})}):null]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex w-full max-w-full shrink-0 items-center justify-between border-b border-border px-4 pb-3 pt-[calc(env(safe-area-inset-top)+0.75rem)]",children:[e.jsx(ks,{className:"text-lg font-semibold text-content-primary",children:"Filters"}),e.jsx(Gl,{type:"button",className:"flex h-10 w-10 items-center justify-center rounded-lg text-content-muted transition-colors hover:bg-surface-2 hover:text-content-primary","aria-label":"Close filters",children:e.jsx("svg",{viewBox:"0 0 24 24",className:"h-5 w-5","aria-hidden":!0,children:e.jsx("path",{d:"M18 6L6 18M6 6l12 12",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round"})})})]}),e.jsx("div",{className:"min-h-0 w-full max-w-full flex-1 overflow-x-hidden overflow-y-auto overscroll-contain [-webkit-overflow-scrolling:touch]",children:n}),e.jsx("div",{className:"w-full max-w-full shrink-0 border-t border-border bg-surface-1 px-4 pt-3 pb-[calc(env(safe-area-inset-bottom)+4.5rem)]",children:e.jsx(de,{variant:"solid",size:"lg",className:"w-full",onClick:y,children:typeof x=="number"?`Show ${x.toLocaleString()} results`:"Apply filters"})})]})})})]})});return e.jsxs("div",{ref:d,"data-library-sticky-chrome":!0,"data-runtime":l,"data-chrome":m,className:L(fc,"z-[40]",u===!0?["sticky","bg-[color-mix(in_oklab,var(--library-bg)_88%,transparent)] backdrop-blur-sm",c]:u==="mobile"?["relative bg-transparent","max-sm:sticky max-sm:bg-[color-mix(in_oklab,var(--library-bg)_88%,transparent)] max-sm:backdrop-blur-sm",c]:"relative bg-transparent"),children:[a,t&&n&&!g?e.jsx("div",{className:L("absolute left-0 right-0 top-full z-[50] mt-1","overflow-x-hidden overflow-y-auto rounded-2xl border border-border-subtle bg-surface-1 shadow-lg","max-h-[min(70vh,calc(100dvh-8rem))]","hidden sm:block xl:hidden"),role:"region","aria-label":"Library filters",children:n}):null,O]})}function uo(t){return t==="LAST_READ_DESC"||t==="UPDATED_DESC"||t==="WORK_UPDATED_DESC"}function Ea(t,a){const n=new Map(a.map(o=>[o.id,o])),s=new Set,i=[];for(const o of t){const c=n.get(o);c&&(i.push(c),s.add(o))}for(const o of a)s.has(o.id)||i.push(o);return i}const Cg=(t,a,n,s)=>{const i=m=>(a[m]?.title??"").toLowerCase(),o=m=>{const d=m?Date.parse(m):Number.NaN;return Number.isFinite(d)?d:0},c=s?.priorOrder,u=uo(n)&&s?.freezeUpdatedOrder&&c&&c.length>0;let l;return n==="BEST_MATCH"||n==="STORY_UPDATE_DESC"?l=[...t]:n==="LAST_READ_DESC"?u?l=Ea(c,t):l=[...t].sort((m,d)=>o(d.lastReadAt??d.updatedAt)-o(m.lastReadAt??m.updatedAt)):n==="WORK_UPDATED_DESC"?u?l=Ea(c,t):l=[...t].sort((m,d)=>{const x=o(a[d.storyId]?.updatedDate)-o(a[m.storyId]?.updatedDate);return x!==0?x:o(d.lastReadAt??d.updatedAt)-o(m.lastReadAt??m.updatedAt)}):n==="TITLE_ASC"?l=[...t].sort((m,d)=>i(m.storyId).localeCompare(i(d.storyId),void 0,{sensitivity:"base"})):n==="TITLE_DESC"?l=[...t].sort((m,d)=>i(d.storyId).localeCompare(i(m.storyId),void 0,{sensitivity:"base"})):n==="RATING_DESC"?l=[...t].sort((m,d)=>{const x=Number.isFinite(m.rating)?m.rating:0,g=(Number.isFinite(d.rating)?d.rating:0)-x;return g!==0?g:i(m.storyId).localeCompare(i(d.storyId),void 0,{sensitivity:"base"})}):n==="RATING_ASC"?l=[...t].sort((m,d)=>{const x=Number.isFinite(m.rating)?m.rating:0,y=Number.isFinite(d.rating)?d.rating:0,g=x-y;return g!==0?g:i(m.storyId).localeCompare(i(d.storyId),void 0,{sensitivity:"base"})}):u?l=Ea(c,t):l=[...t].sort((m,d)=>o(d.updatedAt)-o(m.updatedAt)),l};function _g({entries:t,storiesMap:a,sort:n,listIdentityKey:s}){const i=r.useRef(0),o=r.useRef([]),c=r.useRef([]),u=r.useRef(new Set),l=r.useRef(s),[m,d]=r.useState(0),[x,y]=r.useState(0),g=r.useCallback(b=>{const k=i.current;b===1?(k===0&&(o.current=[...c.current]),i.current=k+1):(i.current=Math.max(0,k-1),i.current===0&&(o.current=[])),d(j=>j+1)},[]),N=r.useCallback(()=>{i.current!==0&&(i.current=0,o.current=[],d(b=>b+1))},[]),S=r.useCallback(b=>{uo(n)&&(u.current.has(b)||(u.current.add(b),y(k=>k+1)))},[n]),C=r.useCallback(b=>{u.current.delete(b)&&(N(),y(k=>k+1))},[N]);r.useEffect(()=>{l.current!==s&&(l.current=s,i.current=0,o.current=[],u.current.clear(),d(b=>b+1),y(b=>b+1))},[s]),r.useEffect(()=>{if(!u.current.size)return;const b=new Set(t.map(j=>j.id));let k=!1;for(const j of u.current)b.has(j)||(u.current.delete(j),k=!0);k&&y(j=>j+1)},[t]);const _=r.useMemo(()=>{const b=i.current>0,k=b&&o.current.length>0?{freezeUpdatedOrder:!0,priorOrder:o.current}:void 0,j=Cg(t,a,n,k),R=!b&&u.current.size>
60&&c.current.length>0?Ea(c.current,j):j;return b||(c.current=R.map(F=>F.id)),R},[t,a,n,m,x]),p=r.useMemo(()=>Array.from(u.current),[x]);return{visible:_,onLayoutPointerLockChange:g,markEntryForDeferredRecencyReorder:S,deferredRecencyReorderIds:p,onDeferredRecencyEntryExit:C}}function Rg({visible:t,entries:a,storiesMap:n,queuePatch:s,deleteEntry:i,pushToast:o,invalidateLibrary:c,resetKey:u}){const[l,m]=r.useState(!1),[d,x]=r.useState(new Set),[y,g]=r.useState(!1),[N,S]=r.useState(""),[C,_]=r.useState(!1),p=r.useCallback(()=>{g(!1),x(new Set)},[]);r.useEffect(()=>{!l||!y||x(I=>{const E=new Set(I);return t.forEach(Y=>E.add(Y.id)),E})},[t,l,y]),r.useEffect(()=>{g(!1),p()},[u,p]),r.useEffect(()=>{l||p()},[l,p]);const b=r.useCallback(I=>d.has(I),[d]),k=r.useCallback(I=>{g(!1),x(E=>{const Y=new Set(E);return Y.has(I)?Y.delete(I):Y.add(I),Y})},[]),j=r.useCallback(()=>{x(new Set(t.map(I=>I.id))),g(!0)},[t]),O=r.useCallback(()=>{x(new Set(a.map(I=>I.id))),g(!1)},[a]),R=r.useMemo(()=>{const I={};return a.forEach(E=>I[E.id]=E),I},[a]),F=r.useCallback(I=>{const E=R[I];return E?n[E.storyId]:void 0},[R,n]),A=r.useCallback(I=>typeof I?.chapters_published=="number"?I.chapters_published:void 0,[]),z=r.useCallback((I,E)=>{d.forEach(Y=>{const W=R[Y];if(!W){s(Y,{status:I,completion:E});return}const J=n[W.storyId],X=bi(W,J,I);s(Y,E?{...X,completion:E}:X)}),o(`Set reader status on ${d.size} stor${d.size===1?"y":"ies"}`)},[d,R,n,s,o]),Q=r.useCallback(I=>{if(I==="FINISHED"){_(!0);return}z(I)},[z]),te=r.useCallback(I=>{z("FINISHED",I),_(!1)},[z]),v=r.useCallback(I=>{const E=(I||"").trim();if(!E)return;let Y=0;d.forEach(W=>{const J=R[W];if(!J)return;const X=J.tags||[];X.includes(E)||(s(W,{tags:[...X,E]}),Y++)}),Y&&o(`Added â${E}â to ${Y} stor${Y===1?"y":"ies"}`)},[d,R,s,o]),$=r.useCallback(I=>{const E=(I||"").trim();if(!E)return;let Y=0;d.forEach(W=>{const J=R[W];if(!J)return;const X=J.tags||[];X.includes(E)&&(s(W,{tags:X.filter(ee=>ee!==E)}),Y++)}),Y&&o(`Removed â${E}â from ${Y} stor${Y===1?"y":"ies"}`)},[d,R,s,o]),f=r.useCallback(()=>{let I=0;d.forEach(E=>{const Y=R[E],W=F(E);if(!Y||Y.progress.unit!=="CHAPTER")return;const J=A(W);if(typeof J!="number")return;const X=typeof Y.progress.total=="number"?Math.min(Y.progress.total,J):J;Y.progress.value!==X&&(s(E,{progress:{...Y.progress,value:X}}),I++)}),I&&o(`Caught up ${I} stor${I===1?"y":"ies"}`)},[d,R,F,A,s,o]),U=r.useMemo(()=>Array.from(d).map(I=>R[I]).filter(Boolean),[d,R]),[oe,se]=r.useState(!1),G=r.useCallback(async()=>{const I=Array.from(d);if(!I.length)return;se(!0);let E=0;const W=(await Promise.allSettled(I.map(async J=>{await i(J),E++}))).filter(J=>J.status==="rejected").length;se(!1),E>0?o(W?`Removed ${E} stor${E===1?"y":"ies"} (${W} failed)`:`Removed ${E} stor${E===1?"y":"ies"} from library`):W&&o("Failed to remove stories"),p(),c()},[d,i,o,p,c]);return{bulkMode:l,setBulkMode:m,selected:d,selectedCount:d.size,bulkTag:N,setBulkTag:S,selectAllActive:y,isSelected:b,toggleOne:k,selectAllVisible:j,selectAllLoaded:O,clearSelection:p,bulkSetStatus:Q,bulkAddTag:v,bulkRemoveTag:$,bulkCatchUp:f,bulkRemove:G,bulkRemoving:oe,bulkFinishPending:C,cancelBulkFinished:()=>_(!1),confirmBulkFinished:te,selectedEntries:U}}const Lg="trace:library-scroll-position:",In="[data-app-shell-scroll]",Ag="window";function mo(){return document.querySelector(In)}function Tg(t){const a=window.getComputedStyle(t).overflowY;return a!=="visible"&&a!=="hidden"&&t.scrollHeight>t.clientHeight+2}function Yn(){const t=mo();return t&&Tg(t)?t:null}function za(){const t=Yn();return t?Math.max(0,t.scrollTop):Math.max(0,window.scrollY||document.documentElement.scrollTop||document.body.scrollTop||0)}function Eg(t){const a=Yn();return a?(typeof a.scrollTo=="function"?a.scrollTo({top:t,behavior:"auto"}):a.scrollTop=t,Math.max(0,a.scrollTop)):(typeof window.scrollTo=="function"&&window.scrollTo({top:t,behavior:"auto"}),document.documentElement.scrollTop=t,document.body.scrollTop=t,za())}function Pg(){const t=Yn();return t?Math.max(0,t.scrollHeight-t.clientHeight):Math.max(0,document.documentElement.scrollHeight-window.innerHeight,document.body.scrollHeight-window.innerHeight)}function po(t){try{const a=window.sessionStorage.getItem(t),n=a?Number.parseInt(a,10):Number.NaN;return Number.isFinite(n)&&n>0?n:0}catch{return 0}}function Cr(t,a=za()){try{window.sessionStorage.setItem(t,String(Math.round(Math.max(0,a))))}catch{}}function ho(t){return typeof window.requestAnimationFrame=="function"?window.requestAnimationFrame(t):window.setTimeout(()=>t(Date.now()),0)}function xo(t){if(typeof window.cancelAnimationFrame=="function"){window.cancelAnimationFrame(t);return}window.clearTimeout(t)}function Mg(t){return t.currentTarget instanceof HTMLElement?Math.max(0,t.currentTarget.scrollTop):za()}function Ig(t){const a=r.useRef(0);r.useEffect(()=>{a.current=po(t)},[t]);const n=r.useCallback(()=>{const i=za();a.current=i,Cr(t,i)},[t]),s=r.useCallback(()=>{Cr(t,a.current)},[t]);return r.useEffect(()=>{let i=0;const o=()=>n(),c=m=>{a.current=Mg(m),!i&&(i=ho(()=>{i=0,s()}))},u=()=>{document.visibilityState==="hidden"&&o()},l=mo();return window.addEventListener("scroll",c,{passive:!0}),l?.addEventListener("scroll",c,{passive:!0}),window.addEventListener("pagehide",o),document.addEventListener("visibilitychange",u),()=>{i&&xo(i),s(),window.removeEventListener("scroll",c),l?.removeEventListener("scroll",c),window.removeEventListener("pagehide",o),document.removeEventListener("visibilitychange",u)}},[s,n,t]),n}function Og(t){const a=t?.post_first_story_onboarding;return!!(t?.first_story_completed_at&&!t.library_discovery_dismissed&&a&&a.status!=="completed"&&a.status!=="dism
6issed")}function Dg({account:t,patchUiSettings:a}){const n=da(),[s,i]=r.useState(null),c=t?.post_first_story_onboarding?.step??1,u=Pt({mutationFn:y=>a({post_first_story_onboarding:y}),onSuccess:y=>{n.setQueryData(je.me,g=>g&&{...g,library_discovery_dismissed:y.library_discovery_dismissed,post_first_story_onboarding:y.post_first_story_onboarding})}}),l=r.useCallback(async y=>{i(null);try{return await u.mutateAsync(y),!0}catch{return i("We couldn't save your progress. Try again."),!1}},[u]),m=r.useCallback(()=>{const y=Math.min(3,c+1);return l({version:1,status:"in_progress",step:y})},[l,c]),d=r.useCallback(()=>l({version:1,status:"dismissed",step:c}),[l,c]),x=r.useCallback(()=>l({version:1,status:"completed",step:3}),[l]);return{show:Og(t),step:c,pending:u.isPending,error:s,advance:m,dismiss:d,complete:x}}const jn="reader-1.0.0";function Fg({enabled:t,getNotice:a,dismissNotice:n}){const s=da(),[i,o]=r.useState(null),c=je.accountReleaseNotice(jn),u=na({queryKey:c,queryFn:()=>a(jn),enabled:t,staleTime:1/0}),l=Pt({mutationFn:()=>n(jn),onSuccess:d=>{s.setQueryData(c,{notice_id:d.notice_id,dismissed:d.dismissed})}}),m=r.useCallback(async()=>{o(null);try{return await l.mutateAsync(),!0}catch{return o("We couldn't hide this note. Try again."),!1}},[l]);return{show:u.data?.dismissed===!1,pending:l.isPending,error:i,dismiss:m}}const _r="trace:story-updates-education-v1:dismissed";function $g(){const[t,a]=r.useState(()=>{try{return window.localStorage.getItem(_r)==="true"}catch{return!1}}),n=r.useCallback(()=>{a(!0);try{window.localStorage.setItem(_r,"true")}catch{}},[]);return{dismissed:t,dismiss:n}}function Wg(t,a){if(!Yr())return;const n=window.webkit?.messageHandlers?.traceWidget;if(!n)return;const s=t.find(o=>o.status==="READING");if(!s){n.postMessage({title:"",author:"",fandom:"",progressCurrent:0,progressTotal:null,status:""});return}const i=a[s.storyId];n.postMessage({title:i?.title??"",author:(i?.authors??[])[0]??"",fandom:(i?.fandoms??[])[0]??"",progressCurrent:s.progress?.value??0,progressTotal:s.progress?.total??null,status:s.status})}const bo="(max-width: 639px)",Bg="window",Vg=8,Rr=64;function Hg(t){if(typeof window>"u"||!window.matchMedia)return()=>{};const a=window.matchMedia(bo);return a.addEventListener?(a.addEventListener("change",t),()=>a.removeEventListener("change",t)):(a.addListener(t),()=>a.removeListener(t))}function Ug(){return typeof window>"u"||!window.matchMedia?!1:window.matchMedia(bo).matches}function Yg(){return!1}function Kg(){return r.useSyncExternalStore(Hg,Ug,Yg)}function zg(t){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(t):window.setTimeout(()=>t(Date.now()),0)}function qg(t){if(typeof window<"u"&&window.cancelAnimationFrame){window.cancelAnimationFrame(t);return}window.clearTimeout(t)}function Gg(t){return typeof window>"u"||typeof document>"u"?null:t===Bg?window:document.querySelector(t)}function Lr(t){return t===window?Math.max(0,window.scrollY||document.documentElement.scrollTop||document.body.scrollTop||0):Math.max(0,t.scrollTop)}function Qg({enabled:t,freezeFull:a=!1,resetKey:n,scrollContainerSelector:s}){const i=Kg(),[o,c]=r.useState("full");return r.useEffect(()=>{c("full")},[n]),r.useEffect(()=>{if(!t||!i||a){c("full");return}const u=Gg(s);if(!u){c("full");return}let l=Lr(u),m=0;l>Rr&&c("collapsed");const d=()=>{m=0;const y=Lr(u),g=y-l;if(l=y,y<=Vg){c("full");return}if(g>0&&y>Rr){c("collapsed");return}g<-6&&c("full")},x=()=>{m||(m=zg(d))};return u.addEventListener("scroll",x,{passive:!0}),()=>{m&&qg(m),u.removeEventListener("scroll",x)}},[t,a,i,s]),!t||!i||a?"full":o}function Ar(t){const a=t?document.querySelector(t):null;return a?Math.max(0,a.scrollTop):window.scrollY||document.documentElement.scrollTop||document.body.scrollTop||0}function Xg(t){return t instanceof Element?!!t.closest('a,button,input,textarea,select,[role="slider"],[role="combobox"],[role="listbox"],[role="radiogroup"],[role="progressbar"]'):!1}function Zg({enabled:t,blocked:a=!1,scrollContainerSelector:n,onRefresh:s}){const[i,o]=r.useState(0),[c,u]=r.useState(!1),l=r.useRef(0),m=r.useRef(!1),d=r.useRef(0),x=r.useRef(!1),y=r.useRef(s);return r.useEffect(()=>{y.current=s},[s]),r.useEffect(()=>{if(!t||a){o(0),m.current=!1,d.current=0;return}const g=52,N=88,S=k=>{x.current||Xg(k.target)||Ar(n)>2||(m.current=!0,l.current=k.touches[0].clientY,d.current=0)},C=k=>{if(!m.current||x.current)return;if(Ar(n)>2){m.current=!1,d.current=0,o(0);return}const j=k.touches[0].clientY-l.current;if(j<=0){d.current=0,o(0);return}const O=Math.min(j*.42,N);d.current=O,o(O)},_=()=>{if(!m.current)return;m.current=!1;const k=d.current;d.current=0,o(0),!(k<g||x.current)&&(x.current=!0,u(!0),Promise.resolve(y.current()).c
6atch(()=>{}).finally(()=>{x.current=!1,u(!1)}))},p=()=>_(),b=()=>{m.current=!1,d.current=0,o(0)};return window.addEventListener("touchstart",S,{passive:!0}),window.addEventListener("touchmove",C,{passive:!0}),window.addEventListener("touchend",p,{passive:!0}),window.addEventListener("touchcancel",b,{passive:!0}),()=>{window.removeEventListener("touchstart",S),window.removeEventListener("touchmove",C),window.removeEventListener("touchend",p),window.removeEventListener("touchcancel",b)}},[t,a,n]),{pullPx:i,refreshing:c}}function Jg({pullPx:t,refreshing:a,className:n}){const s=t>6||a,i=a?1:Math.min(1,Math.max(0,t/56));return e.jsx("div",{className:L("pointer-events-none fixed left-0 right-0 top-0 z-[45] flex justify-center","pt-[max(0.5rem,calc(env(safe-area-inset-top)+4px))]",n),"aria-hidden":!0,children:e.jsx("div",{className:L("flex h-9 w-9 items-center justify-center rounded-full border border-border","bg-surface-1/95 shadow-md backdrop-blur-[2px]","transition-[opacity,transform] duration-150"),style:{opacity:s?i:0,transform:`translateY(${Math.min(10,t*.12)}px)`},children:s&&e.jsx("span",{className:L("inline-block h-4 w-4 rounded-full border-2 border-accent border-t-transparent",a&&"animate-spin")})})})}function ef(){const[t,a]=r.useState(!1);return r.useEffect(()=>{const n=window.matchMedia("(hover: none) and (pointer: coarse)"),s=()=>a(n.matches);return s(),n.addEventListener("change",s),()=>n.removeEventListener("change",s)},[]),t}function Tr(t,a=500){const n=r.useRef(null),s=r.useRef(t);return r.useEffect(()=>{s.current=t},[t]),r.useEffect(()=>()=>{n.current&&clearTimeout(n.current)},[]),r.useCallback((...i)=>{n.current&&clearTimeout(n.current),n.current=setTimeout(()=>s.current(...i),a)},[a])}function tf({addOpen:t,shareOpen:a,detailsOpen:n,showFilters:s,onClosePanel:i,onCloseFilters:o,onFocusSearch:c}){const u=r.useCallback(l=>{if((l.ctrlKey||l.metaKey)&&l.key.toLowerCase()==="k"){l.preventDefault(),c();return}if(l.key==="Escape"){if(s){o();return}(t||a||n)&&i()}},[t,a,n,s,i,o,c]);r.useEffect(()=>(window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)),[u])}function af(t){return r.useMemo(()=>{let a=0;const n=t.notes??(t.hasNotes?"WITH":"ANY");return t.ratings?.length&&a++,t.platforms?.length&&a++,typeof t.minWords=="number"&&a++,typeof t.maxWords=="number"&&a++,typeof t.minKudos=="number"&&a++,typeof t.maxKudos=="number"&&a++,typeof t.minRating=="number"&&a++,t.entryRating==="UNRATED"&&a++,n!=="ANY"&&a++,t.tag?.trim()&&a++,t.workTag?.trim()&&a++,t.statuses?.length&&a++,t.pairMembers?.length&&a++,t.pairExact&&t.pairMembers?.length&&a++,t.characters?.length&&a++,t.fandoms?.length&&a++,t.catchup!=="ANY"&&a++,t.storyUpdates==="NEW"&&a++,t.completionStatus?.length&&a++,t.excludeWarnings?.length&&a++,t.includeWarnings?.length&&a++,t.categoryFilter?.length&&a++,t.excludeTag?.trim()&&a++,t.excludeWorkTag?.trim()&&a++,t.excludePairMembers?.length&&a++,t.excludePairExact&&t.excludePairMembers?.length&&a++,t.excludeCharacters?.length&&a++,t.excludeFandoms?.length&&a++,t.excludeCategoryFilter?.length&&a++,t.lastReadAfter?.trim()&&a++,t.lastReadBefore?.trim()&&a++,a},[t])}function nf(t,a){return{sort:t.sort==="STORY_UPDATE_DESC"?"LAST_READ_DESC":t.sort,filters:t.filters.storyUpdates==="NEW"?{...t.filters,storyUpdates:"ANY"}:t.filters}}const Er=["page","limit"],Pr=t=>typeof t=="object"&&t!==null,Mr=(t,a)=>Object.prototype.hasOwnProperty.call(t,a);function Ba(t){if(!Pr(t))return;const a=[];for(const s of Er)Mr(t,s)&&t[s]!==void 0&&a.push(s);const n=t.filters;if(Pr(n))for(const s of Er)Mr(n,s)&&n[s]!==void 0&&a.push(`filters.${s}`);if(a.length)throw new Error(`Saved Library View queries cannot include pagination fields: ${a.join(", ")}`)}function Ht(t={}){return{ratings:Kr(t.ratings),platforms:[...t.platforms??[]],minWords:t.minWords,maxWords:t.maxWords,minKudos:t.minKudos,maxKudos:t.maxKudos,minRating:t.minRating,entryRating:t.entryRating??"ANY",notes:t.notes??"ANY",hasNotes:t.hasNotes??!1,tag:t.tag??"",workTag:t.workTag??"",statuses:[...t.statuses??[]],pairMembers:[...t.pairMembers??[]],pairExact:t.pairExact??!1,characters:[...t.characters??[]],fandoms:[...t.fandoms??[]],catchup:t.catchup??"ANY",storyUpdates:t.storyUpdates??"ANY",completionStatus:[...t.completionStatus??[]],excludeWarnings:[...t.excludeWarnings??[]],includeWarnings:[...t.includeWarnings??[]],categoryFilter:[...t.categoryFilter??[]],excludeTag:t.excludeTag??"",excludeWorkTag:t.excludeWorkTag??"",excludePairMembers:[...t.excludePairMembers??[]],excludePairExact:t.excludePairExact??!1,excludeCharacters:[...t.excludeCharacters??[]],excludeFandoms:[...t.excludeFandoms??[]],excludeCategoryFilter:[...t.excludeCategoryFilter??[]],lastReadAfter:t.lastReadAfter??"",lastReadBefore:t.lastReadBefore??""}}function Kn(t){return Ba(t),Ba(t.filters),Dn.parse(zr({search:t.search,sort:t.sort,filters:t.filters}))}const Ue=t=>{const a=Array.from(new Set((t??[]).map(n=>
6n.trim()).filter(Boolean))).sort((n,s)=>n.localeCompare(s));return a.length?a:void 0},sf=t=>{const a=Array.from(new Set((t??[]).map(qr).filter(Boolean))).sort((n,s)=>n.localeCompare(s));return a.length?a:void 0},rf=t=>{const a=Array.from(new Set(t??[])).sort((n,s)=>n.localeCompare(s));return a.length?a:void 0},of=t=>{const a=Kr(t);return a.length?a:void 0},At=t=>t?.trim()||void 0,lf=t=>Object.fromEntries(Object.entries(t).filter(([,a])=>a!==void 0));function cf(t){const a=Ue(t.pairMembers),n=Ue(t.excludePairMembers),s=t.notes==="ANY"?void 0:t.notes??(t.hasNotes?"WITH":void 0);return lf({ratings:of(t.ratings),platforms:sf(t.platforms),minWords:t.minWords,maxWords:t.maxWords,minKudos:t.minKudos,maxKudos:t.maxKudos,notes:s,tag:At(t.tag),workTag:At(t.workTag),statuses:rf(t.statuses),pairMembers:a,pairExact:a&&t.pairExact?!0:void 0,characters:Ue(t.characters),relationships:Ue(t.relationships),fandoms:Ue(t.fandoms),completionStatus:Ue(t.completionStatus),excludeWarnings:Ue(t.excludeWarnings),includeWarnings:Ue(t.includeWarnings),categoryFilter:Ue(t.categoryFilter),excludeTag:At(t.excludeTag),excludeWorkTag:At(t.excludeWorkTag),excludePairMembers:n,excludePairExact:n&&t.excludePairExact?!0:void 0,excludeCharacters:Ue(t.excludeCharacters),excludeFandoms:Ue(t.excludeFandoms),excludeCategoryFilter:Ue(t.excludeCategoryFilter),lastReadAfter:At(t.lastReadAfter),lastReadBefore:At(t.lastReadBefore),minEntryRating:t.minEntryRating,entryRating:t.entryRating==="UNRATED"?"UNRATED":void 0,catchup:t.catchup==="ANY"?void 0:t.catchup,storyUpdates:t.storyUpdates==="NEW"?"NEW":void 0})}function go(t){Ba(t);const a=Dn.parse(t);return{search:a.search,sort:a.sort,filters:cf(a.filters)}}const Ir=t=>JSON.stringify(go(t));function Or(t,a){return t?Ir(t)!==Ir(Kn(a)):!1}function Pa(t){Ba(t);const a=Dn.parse(t),n=a.filters,s=n.notes??(n.hasNotes?"WITH":"ANY");return{search:a.search,sort:a.sort,filters:Ht({ratings:n.ratings,platforms:n.platforms?.map(qr),minWords:n.minWords,maxWords:n.maxWords,minKudos:n.minKudos,maxKudos:n.maxKudos,minRating:n.minEntryRating,entryRating:n.entryRating??"ANY",notes:s,hasNotes:s==="WITH",tag:n.tag,workTag:n.workTag,statuses:n.statuses,pairMembers:n.pairMembers,pairExact:n.pairExact,characters:n.characters,fandoms:n.fandoms,catchup:n.catchup??"ANY",storyUpdates:n.storyUpdates??"ANY",completionStatus:n.completionStatus,excludeWarnings:n.excludeWarnings,includeWarnings:n.includeWarnings,categoryFilter:n.categoryFilter,excludeTag:n.excludeTag,excludeWorkTag:n.excludeWorkTag,excludePairMembers:n.excludePairMembers,excludePairExact:n.excludePairExact,excludeCharacters:n.excludeCharacters,excludeFandoms:n.excludeFandoms,excludeCategoryFilter:n.excludeCategoryFilter,lastReadAfter:n.lastReadAfter,lastReadBefore:n.lastReadBefore})}}const df={search:"",sort:ua.value,filters:Ht()},uf=go(Kn(df));function mf(t){return oa.find(a=>a.value===t)?.label??t}function fo(t){const a=lo(t.filters,t.search).filter(n=>n.id!=="search").map(n=>`${n.label}: ${n.value}`);return{sortLabel:mf(t.sort),search:t.search.trim(),chips:a}}function pf(t){const a=Pa(t),n=fo(a),s=[n.search?`Search: ${n.search}`:null,a.sort!==ua.value?`Sort: ${n.sortLabel}`:null,...n.chips.slice(0,2)].filter(o=>!!o);if(!s.length)return"Whole Library";const i=n.chips.length-Math.min(n.chips.length,2);return i>0?`${s.join(" · ")} · +${i}`:s.join(" · ")}function Dr(t){return{id:t.view_id,name:t.name,summary:pf(t.query),query:t.query,pinned:t.pinned,liveCount:t.pinned?t.live_count:void 0}}function hf(t){return[...t].sort((a,n)=>a.position!==n.position?a.position-n.position:a.created_at.localeCompare(n.created_at))}function Fr(t,a){const n=t?.views??[],i=n.some(o=>o.view_id===a.view_id)?n.map(o=>o.view_id===a.view_id?a:o):[...n,a];return{views:hf(i)}}function xf(t,a){return t&&{views:t.views.filter(n=>n.view_id!==a)}}function bf(t,a,n){const s=t.find(l=>l.view_id===a);if(!s)return null;const i=t.filter(l=>l.pinned===s.pinned),o=i.findIndex(l=>l.view_id===a),c=n==="up"?o-1:o+1,u=i[c];return u?t.map(l=>l.view_id===s.view_id?u:l.view_id===u.view_id?s:l):null}function gf({api:t,libraryViewId:a,setLibraryViewId:n,searchInput:s,sort:i,filters:o,setSearchInput:c,setDebouncedSearch:u,setSort:l,setFilters:m,setShowFilters:d,onToast:x}){const y=da(),g=r.useRef(null),N=r.useRef(!1),S=r.useRef(!1),C=r.useRef(!1),_=r.useRef(!1),[p,b]=r.useState("refine"),[k,j]=r.useState(!1),[O,R]=r.useState(null),[F,A]=r.useState(!1),z=a&&a!==Je?a:null,[Q,te]=r.useState(z);r.useEffect(()=>{te(z)},[z]);const v=na({queryKey:je.libraryViews.list(),queryFn:()=>t.listLibraryViews(),enabled:t.isReady,staleTime:6e4}),$=Q,f=r.useMemo(()=>v.data?.views??[],[v.data?.views]),U=$?f.find(T=>T.view_id===$)??null:null,oe=r.useMemo(()=>f.map(Dr),[f]),se=r.useMemo(()=>U?Dr(U):null,[U]),G=r.useMemo(()=>({search:s,sort:i,filters:o}),[o,s,i]),I=r.useMemo(()=>Kn(G),[G]),E=r.useMemo(()=>fo(G),[G]),Y=r.useMemo(()=>Or(U?.query,G),[U?.query,G]),W=r.useMemo(()=>Or(uf,G),[G]),J=r.useCallback(T=>{c(T.search),u(T.search),l(T.sort),m(T.filters)},[u,m,c,l]),X=r.useCallback(()=>{g.current=null,te(null),n(null),J({search:"",sort:ua.value,filters:Ht()}),b("refine"),j(!1),R(null),A(!1)},[J,n]),ee=r.useCallback(()=>{y.invalidateQueries({queryKey:je.libraryViews.list()})},[y]),le=Pt({mutationFn:T=>t.createLibraryView({name:T.name,pinned:T.pinned,query:I}),onSuccess:T=>{y.setQueryData(je.libraryViews.list(),K=>Fr(K,T.view)),g.current=T.view.view_id,te(T.view.view_id),n(T.view.view_id),b("refine"),j(!1),R(null),A(!1),ee(),x?.("Library View saved")},onError:()=>x?.("Failed to save Library View"),onSettled:()=>{N.current=!1}}),ae=Pt({mutationFn:({viewId:T,payload:K})=>t.updateLibraryView(T,K),onSuccess:T=>{y.setQueryData(je.libraryViews.list(),K=>Fr(K,T.view)),T.view.view_id===a&&(g.current=T.view.view_id),ee(),x?.("Library View updated")},onError:()=>x?.("Failed to update Library View"),onSettled:()=>{S.current=!1}}),P=Pt({mutationFn:T=>t.deleteLibraryView(T),onSuccess:(T,K)=>{y.setQueryData(je.libraryViews.list(),q=>xf(q,K)),a===K&&X(),ee(),x?.("Library View deleted")},onError:()=>x?.("Failed to delete Library View"),onSettled:()=>{C.current=!1}}),re=Pt({mutationFn:({orderedViewIds:T})=>t.reorderLibraryViews({view_ids:T}),onSuccess:T=>{y.setQueryData(je.libraryViews.list(),T),ee(),x?.("Library Views reordered")},onError:()=>x?.("Failed to reorder Library Views"),onSettled:()=>{_.current=!1}}),me=r.useMemo(()=>{const T=le.error?"Failed to save Library View.":ae.error?"Failed to update Library View.":P.error?"Failed to delete Library View.":re.error?"Failed to reorder Library Views.":null;return{creating:le.isPending,updatingViewId:ae.isPending?ae.variables?.viewId??null:null,deletingViewId:P.isPending?P.variables??null:null,reorderingViewId:re.isPending?re.variables?.viewId??null:null,errorMessage:T}},[le.error,le.isPending,P.error,P.isPending,P.variables,re.error,re.isPending,re.variables?.viewId,ae.error,ae.isPending,ae.variables?.viewId]),ce=r.useCallback(T=>{if(T===Je){X();return}const K=f.find(fe=>fe.view_id===T);if(!K)return;const q=Pa(K.query);te(K.view_id),J(q),g.current=K.view_id,n(K.view_id),b("refine"),j(!1)},[J,f,X,n]);r.useEffect(()=>{if(!$){g.current=null,a===Je&&X();return}if(!v.isSuccess)return;const T=f.find(K=>K.view_id===$);if(!T){X(),x?.("Library View unavailable; showing All Library");return}g.current!==$&&(J(Pa(T.query)),g.current=T.view_id)},[J,a,f,x,$,X,v.isSuccess]);const We=r.useMemo(()=>({onSelectView:ce,onOpenSave:(T=!1)=>{j(T),b("save"),d(!0)},onOpenManage:()=>{j(!1),b("manage"),d(!0)},onSaveView:T=>{N.current||le.isPending||(N.current=!0,le.mutate(T))},onUpdateView:()=>{U&&(S.current||ae.isPending||(S.current=!0,ae.mutate({viewId:U.view_id,payload:{query:I},kind:"query"})))},onRevertView:()=>{U&&(J(Pa(U.query)),g.current=U.view_id,b("refine"))},onClosePanel:()=>{b("refine"),j(!1)},onTogglePin:T=>{if(S.current||ae.isPending)return;const K=f.find(q=>q.view_id===T);K&&(S.current=!0,ae.mutate({viewId:T,payload:{pinned:!K.pinned},kind:"pin"}))},onRenameView:(T,K)=>{if(S.current||ae.isPending)return;const q=f.find(be=>be.view_id===T);if(!q)return;const fe=K.trim();
6!fe||fe===q.name||(S.current=!0,ae.mutate({viewId:T,payload:{name:fe},kind:"rename"}))},onDeleteView:T=>{C.current||P.isPending||(C.current=!0,P.mutate(T))},onMoveView:(T,K)=>{if(_.current||re.isPending)return;const q=bf(f,T,K);q&&(_.current=!0,re.mutate({viewId:T,orderedViewIds:q.map(fe=>fe.view_id)}))}}),[U,J,le,I,P,f,re,ce,d,ae]),pe=r.useMemo(()=>({...We,onSelectView:T=>{ce(T),R(null),A(!1)},onOpenSave:(T=!1)=>{A(T),R("save")},onOpenManage:()=>{A(!1),R("manage")},onClosePanel:()=>{R(null),A(!1)},onRevertView:()=>{We.onRevertView(),R(null),A(!1)}}),[We,ce]),De=se?tu({activeView:se,dirty:Y}):null,Se=r.useCallback(()=>{b("refine"),j(!1),d(!0)},[d]),M=r.useCallback(()=>{d(!1),b("refine"),j(!1)},[d]);return{activeLibraryView:U,activeViewId:$,activeViewItem:se,capturedQuery:E,closeSheet:M,createLibraryView:le,currentSavedQuery:I,desktopHandlers:pe,desktopPanelMode:O,desktopSaveAsNew:F,dirty:Y,handlers:We,hasAdHocQuery:W,mutationState:me,openRefineSheet:Se,reorderLibraryViews:re,saveAsNew:k,sheetMode:p,toolbarChip:De,updateLibraryView:ae,viewItems:oe,viewsQuery:v}}const vo="trace:library-view-state-v1";function $r(t){return typeof t=="object"&&t!==null}function ff(t){return typeof t=="string"?t:""}function vf(){try{const t=window.sessionStorage.getItem(vo);if(!t)return null;const a=JSON.parse(t);if(!$r(a))return null;const n=Hr(a.sort)?a.sort:"LAST_READ_DESC",s=Ht($r(a.filters)?a.filters:{});return{search:ff(a.search),sort:n,filters:s}}catch{return null}}function yf(t){try{window.sessionStorage.setItem(vo,JSON.stringify({search:t.search,sort:t.sort,filters:Ht(t.filters)}))}catch{}}const Wr=Ur,wf=300,jf=500,Tt=!1;Ze.lazy(async()=>({default:(await Gr(()=>import("./story-updates-surfaces.component-fW5MaEt7.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]))).StoryUpdatesEducation}));Ze.lazy(async()=>({default:(await Gr(()=>import("./story-updates-surfaces.component-fW5MaEt7.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]))).StoryUpdatesLibraryShortcut}));function Nf(t){return t instanceof Error?t.message:String(t)}function Sf(t,a){return typeof t=="object"&&t!==null&&"status"in t&&t.status===a}const yo="trace.libraryDensityMode",wo="trace.libraryGroupingMode",kf={statuses:"Status",completionStatus:"Work",tag:"Tag",workTag:"AO3",excludeTag:"Hide tag",excludeWorkTag:"Hide AO3",minWords:"Words",maxWords:"Words",minKudos:"Kudos",maxKudos:"Kudos",entryRating:"Rating",hasNotes:"Notes",storyUpdates:"Updates"};function Cf(t){return t.replace(/^(â¤\s*)?([\d,]+)(\+)?$/,(a,n,s,i)=>{const o=Number(s.replace(/,/g,""));return!Number.isFinite(o)||o<1e4?a:`${n??""}${Va(o)}${i??""}`})}function _f(t,a){return kf[t]??a}function Rf(t,a){return t==="minWords"||t==="maxWords"||t==="minKudos"||t==="maxKudos"?Cf(a):a}function Lf(){try{const t=window.localStorage.getItem(yo);return t==="browse"||t==="compact"?t:"compact"}catch{return"compact"}}function Af(t){try{window.localStorage.setItem(yo,t)}catch{}}function Tf(){try{return window.localStorage.getItem(wo)==="series"?"series":"none"}catch{return"none"}}function Ef(t){try{window.localStorage.setItem(wo,t)}catch{}}function iv(){const t=pt(),a=Yr(),s=vl()==="app",i=da(),o=_l(),c=Fn(),u=r.useRef(vf()),l=r.useMemo(()=>new URLSearchParams(c.search),[c.search]),m=l.has("q"),d=l.has("sort"),x=l.has("catchup"),y=r.useCallback((h=!0)=>{i.invalidateQueries({queryKey:je.library.all}),i.invalidateQueries({queryKey:je.suggestions}),i.invalidateQueries({queryKey:je.stats.all}),h&&i.invalidateQueries({queryKey:je.me})},[i]),g=r.useCallback(()=>{i.invalidateQueries({queryKey:je.suggestions}),i.invalidateQueries({queryKey:je.stats.all})},[i]),{q:N,sort:S,panel:C,entryId:_,catchup:p,setQ:b,setSort:k,setCatchup:j,libraryViewId:O,setLibraryViewId:R,openPanel:F,closePanel:A}=cg(),[z,Q]=r.useState(!1),[te,v]=r.useState(""),[$,f]=r.useState(!1),[U,oe]=r.useState(m?N:u.current?.search??N),[se,G]=r.useState(m?N:u.current?.search??N),I=nf({sort:d?S:u.current?.sort??S,filters:Ht({...u.current?.filters??{},catchup:x?p:u.current?.filters.catchup??p})}),[E,Y]=r.useState(I.sort),[W,J]=r.useState(I.filters),X=r.useCallback(h=>{Y(w=>{const B=typeof h=="function"?h(w):h;return B==="STORY_UPDATE_DESC"?"LAST_READ_DESC":B})},[]),ee=r.useCallback(h=>{J(w=>{const B=typeof h=="function"?h(w):h;return B.storyUpdates==="NEW"?{...B,storyUpdates:"ANY"}:B})},[]),[le,ae]=r.useState(Lf),[P,re]=r.useState(Tf),[me,ce]=r.useState(null);r.useEffect(()=>{m&&oe(N)},[m,N]),r.useEffect(()=>{d&&X(S)},[d,X,S]),r.useEffect(()=>Af(le),[le]),r.useEffect(()=>Ef(P),[P]),r.useEffect(()=>{le==="compact"&&ce(null)},[le]);const We=Tr(h=>G(h),wf);r.useEffect(()=>{We(U)},[U,We]),r.useEffect(()=>{b(se)},[se,b]),r.useEffect(()=>{E!==S&&k(E)},[E,S,k]);const{data:pe,isLoading:De,refetch:Se}=na({queryKey:je.me,queryFn:()=>t.me(),enabled:t.isReady,staleTime:6e4}),M=!!pe?.pro,T=Dg({account:pe,patchUiSettings:t.patchAccountUiSettings}),K=Fg({enabled:!!pe,getNotice:t.getAccountReleaseNotice,dismissNotice:t.dismissAccountReleaseNotice});$g(),na({queryKey:je.library.storyUpdatesCount,queryFn:()=>t.listLibrary({search:"",sort:"STORY_UPDATE_DESC",page:1,limit:1,filters:{storyUpdates:"NEW"}}),select:h=>h.total??0,enabled:Tt,staleTime:6e4});const[q,fe]=r.useState(!1);r.useEffect(()=>{x&&ee(h=>h.catchup===p?h:{...h,catchup:p})},[p,x,ee]),r.useEffect(()=>{W.catchup!==p&&j(W.catchup)},[W.catchup,p,j]),r.useEffect(()=>{yf({search:U,sort:E,filters:W})},[W,U,E]);const be=r.useMemo(()=>JSON.stringify({q:se,sort:E,filters:W}),[se,E,W]),we=r.useMemo(()=>`${Lg}${be}`,[be]),ve=Ig(we);r.useEffect(()=>yl(h=>{`${c.pathname}
6${c.search}`===h.returnTo&&(ve(),o(`/library/${h.entryId}`,{state:{libraryReturnTo:h.returnTo}}))}),[c.pathname,c.search,o,ve]);const Re=C==="add",He=C==="share",ke=C==="details",ge=!1;r.useEffect(()=>{if(ke){if(_){o(`/library/${_}`,{replace:!0});return}A()}},[A,_,ke,o]);const tt=async h=>{Q(!0),v("");try{await t.manualEntry(h),A(),y(),Ce("Added to your library"),vs()}catch(w){const B=Nf(w);throw(B.includes("FREE_LIMIT_REACHED")||Sf(w,402))&&cn("library_cap"),v(B||"Failed to add story"),w}finally{Q(!1)}},ht=50,ye=Rl({queryKey:je.library.list({search:se,sort:E,filters:W,limit:ht}),queryFn:({pageParam:h})=>t.listLibrary({search:se,sort:E,page:1,limit:ht,cursor:typeof h=="string"?h:void 0,pagination:"cursor",filters:W}),getNextPageParam:h=>h?.hasMore&&h.nextCursor?h.nextCursor:void 0,enabled:t.isReady,retry:2,retryDelay:h=>Math.min(1e3*2**h,8e3),initialPageParam:null,placeholderData:Al,staleTime:5*6e4,gcTime:10*6e4,refetchOnWindowFocus:!1,refetchOnMount:"always"});Yc({enabled:a&&t.isReady&&ye.isSuccess,libraryRevision:ye.dataUpdatedAt,getActivityMarker:t.getAdvocacyActivityMarker});const Le=ef(),Ke=r.useCallback(()=>ye.refetch(),[ye]);r.useEffect(()=>{let h=0;const w=()=>{h&&window.clearTimeout(h),h=window.setTimeout(()=>{h=0,Ke()},350)},B=()=>{w()},ue=()=>{document.visibilityState==="visible"&&w()},_e=()=>{w()};return window.addEventListener("focus",B),window.addEventListener("pageshow",_e),document.addEventListener("visibilitychange",ue),()=>{window.removeEventListener("focus",B),window.removeEventListener("pageshow",_e),document.removeEventListener("visibilitychange",ue),h&&window.clearTimeout(h)}},[Ke]),r.useEffect(()=>{const h=w=>{w.source===window&&w.origin===window.location.origin&&w.data?.type==="TRACE_LIBRARY_INVALIDATED"&&(y(),Ke())};return window.addEventListener("message",h),()=>{window.removeEventListener("message",h)}},[y,Ke]);const jt=Zg({enabled:(Le||a)&&!q,scrollContainerSelector:a?In:void 0,onRefresh:Ke}),Ae=ye.data?.pages?.[0]?.total??0,Pe=typeof pe?.library_count=="number"?pe.library_count:Ae,Me=Ae,xt=typeof pe?.cap?.limit=="number"?pe.cap.limit:Wr,at=!De&&!M&&(pe?.cap?.over===!0||Pe>=xt),ma=r.useCallback(()=>{if(at){cn("library_cap");return}v(""),F("add")},[at,F]),Nt=r.useRef(!1);r.useEffect(()=>{if(!Re){Nt.current=!1;return}!at||Nt.current||(Nt.current=!0,A(),cn("library_cap"))},[Re,A,at]);const pa=r.useMemo(()=>{const h=(ye.data?.pages??[]).flatMap(ue=>ue?.data??[]),w=new Set,B=[];for(const ue of h){const _e=String(ue.entry.entry_id);w.has(_e)||(w.add(_e),B.push(ue))}return B},[ye.data]),St=!!ye.data?.pages?.length,D=ye.isLoading&&!St,H=ye.isError&&!St,{hasNextPage:Ne,fetchNextPage:Ge,isFetchingNextPage:Ie}=ye,Fe=r.useRef(null),ha=Ze.useCallback(h=>{if(Fe.current&&(Fe.current.disconnect(),Fe.current=null),!h||!Ne)return;const w=new IntersectionObserver(B=>{B[0].isIntersecting&&Ne&&!Ie&&Ge()},{rootMargin:"1200px 0px 1200px 0px"});w.observe(h),Fe.current=w},[Ne,Ie,Ge]);r.useEffect(()=>(!Ne&&Fe.current&&(Fe.current.disconnect(),Fe.current=null),()=>{Fe.current?.disconnect(),Fe.current=null}),[Ne]);const{storiesMap:Ee,entries:Te}=r.useMemo(()=>Pc(pa),[pa]);r.useEffect(()=>{Wg(Te,Ee)},[Te,Ee]);const[jo,zn]=r.useState(null),[No,qn]=r.useState(null),Ut=r.useRef(null),Ce=Ze.useCallback((h,w=3e3,B=null)=>{zn(h),qn(B),Ut.current&&clearTimeout(Ut.current),Ut.current=setTimeout(()=>{zn(null),qn(null)},w)},[]);r.useEffect(()=>()=>{Ut.current&&clearTimeout(Ut.current)},[ee]);const V=gf({api:t,libraryViewId:O,setLibraryViewId:R,searchInput:U,sort:E,filters:W,setSearchInput:oe,setDebouncedSearch:G,setSort:X,setFilters:ee,setShowFilters:fe,onToast:Ce}),Gn=r.useRef(0),{updateEntry:Qn,queuePatch:Xn,flushNow:xa}=Mc({patchEntry:t.patchEntry,bulkPatchEntries:t.bulkPatchEntries,queryKeyPrefix:je.library.all,onPatchSettled:g,onPatchSuccess:({entryId:h,patch:w})=>{Sl(h,w),vs()},flushMs:200,onPatchError:h=>{if(h.status!==429)return;const w=Date.now();if(w-Gn.current<4e3)return;Gn.current=w;const B=h.retryAfterSec,ue=typeof B=="number"&&B>0?` Try again in ~${B}s.`:"";Ce(`Too many updates too quickly.${ue} Saving will resume in a moment.`,5e3)}}),Zn=r.useMemo(()=>{const h=new Set;return Te.forEach(w=>
6(w.tags||[]).forEach(B=>h.add(B))),Array.from(h).sort((w,B)=>w.localeCompare(B))},[Te]),{visible:he,onLayoutPointerLockChange:So,markEntryForDeferredRecencyReorder:ba,deferredRecencyReorderIds:ko,onDeferredRecencyEntryExit:Co}=_g({entries:Te,storiesMap:Ee,sort:E,listIdentityKey:be}),Jn=r.useRef(!1);r.useEffect(()=>{Jn.current||!pe||pe.first_story_completed_at!==null||he.length===0||(Jn.current=!0,Se())},[pe,Se,he.length]);const qa=r.useRef(null);r.useEffect(()=>{if(!ye.isSuccess||qa.current===we)return;const h=po(we);if(h<=0){qa.current=we;return}let w=!1,B=0,ue=0,_e=0,Gt=!1;const Sa=()=>{if(w)return;const ml=Eg(h);if(Math.abs(ml-h)<=4||B>=48){qa.current=we;return}Pg()+4<h&&Ne&&!Ie&&!Gt&&(Gt=!0,Ge().finally(()=>{Gt=!1})),B+=1,ue=window.setTimeout(Sa,50)};return _e=ho(Sa),()=>{w=!0,_e&&xo(_e),ue&&window.clearTimeout(ue)}},[Ge,Ne,Ie,ye.isSuccess,we,he.length]);const _o=r.useMemo(()=>gg(Te),[Te]);r.useEffect(()=>{me&&(he.some(h=>h.id===me)||ce(null))},[me,he]);const Yt=r.useCallback((h,w)=>(ba(h),Qn(h,w)),[ba,Qn]),bt=r.useCallback((h,w)=>{ba(h),Xn(h,w)},[ba,Xn]),Ro=r.useRef(null),es=r.useRef(null);tc(es);const nt=r.useMemo(()=>_?Te.find(h=>h.id===_):void 0,[Te,_]);nt&&Ee[nt.storyId],vc();const ga=!1,ts=ge,[as,ns]=r.useState(!1),[Lo,ss]=r.useState(!1),[Ga,rs]=r.useState(null),Ao=async()=>{if(nt){ss(!0);try{await t.deleteEntry(nt.id),Ce("Removed from library"),ns(!1),A(),y()}catch(h){console.error(h),Ce("Failed to remove")}finally{ss(!1)}}},To=Ze.useCallback(async h=>{if(!Ga){rs(h);try{await t.deleteEntry(h),Ce("Removed from library"),nt?.id===h&&A(),y()}catch{Ce("Failed to remove")}finally{rs(null)}}},[t,A,y,nt?.id,Ce,Ga]),[Pf,Mf]=r.useState(0),[If,Of]=r.useState(""),[Df,Ff]=r.useState([]);r.useEffect(()=>{},[ge,nt]),Tr((h,w)=>{bt(h,w)},jf);const[Xe,Qa]=r.useState("visible"),[Xa,Eo]=r.useState([]),[Za,Po]=r.useState("any"),[Mo,Io]=r.useState(""),[Oo,Do]=r.useState({includeSummary:!0,includeRating:!1,includeRelationships:!0,includeNotes:!1,format:"Detailed"}),ne=Rg({visible:he,entries:Te,storiesMap:Ee,queuePatch:bt,deleteEntry:t.deleteEntry,pushToast:Ce,invalidateLibrary:()=>y(),resetKey:be}),st=Ic(),fa=r.useMemo(()=>Xa.map(h=>h.trim()).filter(Boolean),[Xa]),va=r.useCallback(h=>{if(!fa.length)return!1;const w=h.tags||[];return Za==="all"?fa.every(B=>w.includes(B)):w.some(B=>fa.includes(B))},[fa,Za]),Ja=r.useMemo(()=>{let h=0;for(const w of he)va(w)&&(h+=1);return h},[he,va]),Fo=r.useMemo(()=>Xe==="selected"?ne.selectedEntries.length:Xe==="visible"?he.length:Xe==="tag"?Ja:0,[Xe,ne.selectedEntries.length,he.length,Ja]),$o=r.useCallback((h,w)=>{if(w<=0)return[];if(Xe==="selected")return ne.selectedEntries.slice(h,h+w);if(Xe==="visible")return he.slice(h,h+w);if(Xe!=="tag")return[];const B=[];let ue=0;for(const _e of he)if(va(_e)&&(ue>=h&&B.length<w&&B.push(_e),ue+=1,B.length>=w))break;return B},[Xe,ne.selectedEntries,he,va]),is=r.useRef(null),kt=r.useCallback(()=>{for(const h of document.querySelectorAll("[data-library-toolbar-search]"))if(h.offsetParent!==null){h.focus();return}is.current?.focus()},[]);tf({addOpen:Re,shareOpen:He,detailsOpen:ge,showFilters:q,onClosePanel:A,onCloseFilters:V.closeSheet,onFocusSearch:kt});const Ct=af(W),en=U.trim().length>0||se.trim().length>0,Wo=!!O||V.viewItems.length>0||V.viewsQuery.isError,ya=Ct>0||en||Wo||q,Bo=!De&&typeof pe?.library_count=="number"&&pe.library_count===0,Vo=St&&Ae===0&&he.length===0,Ho=!t.isReady||De||!St&&!H&&(ye.isPending||ye.isLoading||ye.fetchStatus==="fetching"),Uo=!H&&!ya&&he.length===0&&ye.fetchStatus==="fetching",tn=!H&&!ya&&he.length===0&&!Uo&&(Bo||Vo),an=!H&&!tn&&!ya&&he.length===0&&Ho,Kt=D&&!tn&&!an,_t=!tn&&!an&&(Kt||H||Ae>0||ya),Yo=_t||Ae>0||he.length>0||wl(),Ko=r.useMemo(()=>hg({entries:Te,storiesMap:Ee,totalCount:Ae,visibleCount:he.length,activeFilterCount:Ct,hasQuery:en}),[Ct,Te,en,Ee,Ae,he.length]),wa=r.useMemo(()=>Te.filter(h=>h.status==="READING").length,[Te]),zo=r.useMemo(()=>{const h=Pe.toLocaleString(),w=wa.toLocaleString();return`${h} saved · ${w} reading`},[Pe,wa]),qo=r.useMemo(()=>`${Pe.toLocaleString()} · ${wa.toLocaleString()}`,[Pe,wa]),nn=s?"standalone":"browser",Go=s?In:Ag,Qo=Qg({enabled:s&&_t,freezeFull:$||q,resetKey:c.pathname,scrollC
6ontainerSelector:Go}),os=nn==="standalone"?Qo:"full",Xo=r.useCallback(()=>{if(q){V.closeSheet();return}V.openRefineSheet()},[V,q]),Rt=r.useCallback(()=>{ee({ratings:[],platforms:[],hasNotes:!1,notes:"ANY",tag:"",workTag:"",statuses:[],minWords:void 0,maxWords:void 0,minKudos:void 0,maxKudos:void 0,minRating:void 0,entryRating:"ANY",pairMembers:[],pairExact:!1,characters:[],fandoms:[],catchup:"ANY",storyUpdates:"ANY",completionStatus:[],excludeWarnings:[],includeWarnings:[],categoryFilter:[],excludeTag:"",excludeWorkTag:"",excludePairMembers:[],excludePairExact:!1,excludeCharacters:[],excludeFandoms:[],excludeCategoryFilter:[],lastReadAfter:"",lastReadBefore:""})},[ee]);r.useCallback(()=>{R(null),ee(h=>({...h,storyUpdates:"NEW"})),X("STORY_UPDATE_DESC"),fe(!1)},[ee,R,X]);const zt=r.useCallback(h=>{if(h==="search"){oe(""),G(""),kt();return}ee(w=>{switch(h){case"ratings":return{...w,ratings:[]};case"platforms":return{...w,platforms:[]};case"minWords":return{...w,minWords:void 0};case"maxWords":return{...w,maxWords:void 0};case"minKudos":return{...w,minKudos:void 0};case"maxKudos":return{...w,maxKudos:void 0};case"minRating":return{...w,minRating:void 0,entryRating:"ANY"};case"entryRating":return{...w,entryRating:"ANY"};case"hasNotes":return{...w,hasNotes:!1,notes:"ANY"};case"tag":return{...w,tag:""};case"workTag":return{...w,workTag:""};case"statuses":return{...w,statuses:[]};case"pairMembers":return{...w,pairMembers:[],pairExact:!1};case"pairExact":return{...w,pairExact:!1};case"characters":return{...w,characters:[]};case"fandoms":return{...w,fandoms:[]};case"catchup":return{...w,catchup:"ANY"};case"storyUpdates":return{...w,storyUpdates:"ANY"};case"completionStatus":return{...w,completionStatus:[]};case"includeWarnings":return{...w,includeWarnings:[]};case"categoryFilter":return{...w,categoryFilter:[]};case"excludeTag":return{...w,excludeTag:""};case"excludeWorkTag":return{...w,excludeWorkTag:""};case"excludePairMembers":return{...w,excludePairMembers:[],excludePairExact:!1};case"excludePairExact":return{...w,excludePairExact:!1};case"excludeCharacters":return{...w,excludeCharacters:[]};case"excludeFandoms":return{...w,excludeFandoms:[]};case"excludeCategoryFilter":return{...w,excludeCategoryFilter:[]};case"excludeWarnings":return{...w,excludeWarnings:[]};case"lastReadAfter":return{...w,lastReadAfter:""};case"lastReadBefore":return{...w,lastReadBefore:""};default:return w}})},[kt,ee]),ls=r.useCallback(()=>{oe(""),G(""),Rt(),kt()},[kt,Rt]),sn=r.useCallback(()=>{oe(""),G(""),Rt()},[Rt]),rt=r.useMemo(()=>lo(W,U),[W,U]),Zo=V.activeViewItem?[]:rt,cs=r.useMemo(()=>rt.map(h=>({id:h.id,label:_f(h.id,h.label),value:Rf(h.id,h.value),ariaLabel:`${h.ariaLabel} filter`,onRemove:()=>zt(h.id)})),[rt,zt]),Jo=r.useMemo(()=>[...V.toolbarChip?[V.toolbarChip]:[],...V.activeViewItem?[]:cs],[V.activeViewItem,V.toolbarChip,cs]),ds=r.useMemo(()=>zr({search:se,sort:E,filters:W}),[se,E,W]),rn=Pe>=xt,el=Pe>xt,tl=typeof Ae=="number"&&Ae>=Wr-2&&!rn,us=yg({accountLoading:De,isPro:M,nearCap:tl,atCap:rn}),ms=K.show&&Ae>0&&!De&&!D&&!H&&!T.show&&!ne.bulkMode&&!us,qt=r.useMemo(()=>{const h={};return Te.forEach(w=>h[w.id]=w),h},[Te]),ja=h=>qt[h],ps=h=>{const w=Ee[h.storyId];return typeof w?.chapters_published=="number"?w.chapters_published:void 0},al=Ze.useCallback(async h=>{const w=qt[h],B=w?Ee[w.storyId]:void 0,ue=w&&B?li(B,w):null;if(!ue){Ce("No source URL to copy");return}try{await navigator.clipboard.writeText(ue),Ce("Story link copied")}catch{Ce("Could not copy story link")}},[qt,Ee,Ce]),nl=Ze.useCallback((h,w)=>{const B=qt[h];if(!B){Yt(h,{status:w});return}const ue=Ee[B.storyId],_e=bi(B,ue,w),Gt=Yt(h,_e);if(_e.progress?.value,w==="FINISHED"&&B.status!=="FINISHED"){const Sa=Oc(B);Ce("Finished today",5e3,{label:"Undo",onClick:async()=>{await Gt.catch(()=>{}),await Yt(h,Sa).catch(()=>{}),Ce("Completion undone")}})}},[qt,Ee,Yt,ge,nt?.id,Ce]),sl=h=>{const w=ja(h);if(!w||w.progress.unit!=="CHAPTER")return;const B=w.progress.total??ps(w)??1/0,ue=Math.min((w.progress.value||0)+1,typeof B=="number"?B:1/0);ue!==(w.progress.value||0)&&bt(h,{progress:{...w.progress,value:ue}})},rl=h=>{const w=ja(h);if(!w||w.progress.unit!=="CHAPTER")return;const B=Math.max((w.progress.value||0)-1,0);B!==(w.progress.value||0)&&bt(h,{progress:{...w.progress,value:B}})},[Na,hs]=r.useState(null),il=async h=>{try{await t.startReread(h),Ce("Starting re-read!"),y(!1)}catch(w){Ce("Failed to start re-read"),console.error(w)}hs(null)}
6,ol=(h,w)=>{const B=ja(h);if(!B||B.progress.unit!=="CHAPTER")return;const ue=B.progress.total??ps(B)??void 0;let _e=Math.max(0,Number(w)||0);typeof ue=="number"&&(_e=Math.min(_e,ue)),_e!==(B.progress.value||0)&&bt(h,{progress:{...B.progress,value:_e}})},xs=r.useRef(!1);r.useEffect(()=>{xs.current&&!ge&&xa(),xs.current=ge},[ge,xa]),r.useEffect(()=>()=>xa(),[xa]);const ll=q?V.sheetMode==="save"?e.jsx(Ws,{title:V.saveAsNew?"Save as new":"Save current view",description:"Private saved query"}):V.sheetMode==="manage"?e.jsx(Ws,{title:"Manage views",description:"Pin, rename, and remove saved queries"}):e.jsx(ad,{activeChips:rt,onResetAll:sn,resultCount:Me,totalCount:Pe}):null,cl=q?V.sheetMode==="save"?e.jsx(Fi,{capturedQuery:V.capturedQuery,saveAsNew:V.saveAsNew,activeView:V.activeViewItem,existingNames:V.viewItems.map(h=>h.name),isPending:V.createLibraryView.isPending,errorMessage:V.mutationState.errorMessage,showHeader:!1,onClose:V.handlers.onClosePanel,onSave:h=>V.handlers.onSaveView?.(h)}):V.sheetMode==="manage"?e.jsx($i,{views:V.viewItems,activeViewId:V.activeViewItem?.id??null,allLibraryCount:Pe,mutationState:V.mutationState,showHeader:!1,onClose:V.handlers.onClosePanel,onSelectView:V.handlers.onSelectView,onTogglePin:V.handlers.onTogglePin,onRenameView:V.handlers.onRenameView,onDeleteView:V.handlers.onDeleteView,onMoveView:V.handlers.onMoveView}):e.jsxs(e.Fragment,{children:[e.jsx(au,{views:V.viewItems,activeViewId:V.activeViewId,dirty:V.dirty,hasAdHocQuery:V.hasAdHocQuery,isError:V.viewsQuery.isError,isLoading:V.viewsQuery.isLoading,allLibraryCount:Pe,visibleCount:Me,activeFilterCount:rt.length,zeroResultView:!!(V.activeViewItem&&!Kt&&!H&&Me===0),mutationState:V.mutationState,handlers:V.handlers}),e.jsx(xd,{storyUpdatesEnabled:Tt,filters:W,onChange:ee,searchValue:U,onSearchChange:oe,activeChips:rt,onClearActiveFilter:zt,onClearAllActiveFilters:sn,visibleCount:Me})]}):null,bs=Me===0,dl=q&&V.sheetMode==="refine"?{onReset:sn,applyLabel:bs?"Show 0 results":`Show ${Me.toLocaleString()}`,applyDisabled:bs}:null,ul=ne.bulkMode||Re&&!0||He||q||st.open||as||!!Na||ts;return e.jsxs(e.Fragment,{children:[e.jsxs(Ll,{children:[e.jsx("title",{children:"trace â My Library"}),e.jsx("meta",{name:"robots",content:"noindex, nofollow"})]}),e.jsxs(jl,{className:"archive-editorial-shell",mobileDockHidden:ul,children:[ne.bulkMode&&e.jsx(ag,{selectedCount:ne.selectedCount,visibleCount:he.length,loadedCount:Te.length,totalCount:Ae,onSelectAllVisible:ne.selectAllVisible,onSelectAllLibrary:ne.selectAllLoaded,onClearSelection:ne.clearSelection,onBulkSetStatus:ne.bulkSetStatus,onBulkCatchUp:ne.bulkCatchUp,bulkTag:ne.bulkTag,onBulkTagChange:ne.setBulkTag,allTags:Zn,onBulkAddTag:ne.bulkAddTag,onBulkRemoveTag:ne.bulkRemoveTag,selectedEntries:ne.selectedEntries,onExitBulkMode:()=>ne.setBulkMode(!1),onAddToCollection:()=>st.openForEntries(ne.selectedEntries),onShare:()=>{Qa("selected"),F("share")},onBulkRemove:ne.bulkRemove,bulkRemoving:ne.bulkRemoving}),e.jsxs("div",{className:"library-main-canvas","data-advocacy-prompt-blocker":D||H||T.show||ms?"":void 0,children:[e.jsx(Jg,{pullPx:jt.pullPx,refreshing:jt.refreshing}),Yo?e.jsx("div",{className:"relative z-0",children:e.jsx(yc,{eyebrow:"Reading archive",className:L("relative z-[1]",s&&"max-sm:hidden"),title:"Library.",titleId:"library-page-heading",stats:Ko,mobileStatLimit:2,density:"compact",spacing:"ledger"})}):null,e.jsx(Uc,{dismissible:!Re}),_t?e.jsx(eu,{views:V.viewItems,activeViewId:V.activeViewId,dirty:V.activeViewItem?V.dirty:V.hasAdHocQuery,hasAdHocQuery:V.hasAdHocQuery,isError:V.viewsQuery.isError,isLoading:V.viewsQuery.isLoading,allLibraryCount:Pe,visibleCount:Me,activeFilterCount:rt.length,zeroResultView:!!(V.activeViewItem&&!Kt&&!H&&Me===0),capturedQuery:V.capturedQuery,panelMode:V.desktopPanelMode,saveAsNew:V.desktopSaveAsNew,mutationState:V.mutationState,handlers:V.desktopHandlers}):null,e.jsxs("div",{className:L("relative mx-auto w-full max-w-7xl px-4 sm:px-6 sm:pb-10 lg:px-8 xl:max-w-[96rem]","pb-10",ne.bulkMode&&"pb-56 sm:pb-44"),children:[e.jsx("div",{className:"relative",children:us&&e.jsx(fg,{atCap:rn,overCap:el,totalCount:Pe})}),ms?e.jsx(vg,{pending:K.pending,error:K.error,onDismiss:K.dismiss}):null,null,null,_t?e.jsxs(kg,{stickyChromeRef:es,sticky:s,stickyTopClass:s?"top-0":"top-[54px]",runtime:nn,chromeState:os,show
6Filters:q,visibleCount:Me,onCloseFilters:V.closeSheet,mobileFiltersHeader:ll,mobileFiltersBody:cl,mobileFiltersFooter:dl,filtersPanel:q?e.jsx(Es,{storyUpdatesEnabled:Tt,id:"filters-panel-overlay",variant:"overlay",filters:W,onChange:ee,onReset:Rt}):null,children:[e.jsx(Tu,{storyUpdatesEnabled:Tt,variant:"sticky",totalCount:Pe,resultCount:Me,bulkMode:ne.bulkMode,onToggleBulk:()=>ne.setBulkMode(h=>!h),canAdd:!ne.bulkMode,onAdd:ma,selectedCount:ne.selectedCount,visibleCount:he.length,onShare:()=>{Qa(ne.selectedCount?"selected":"visible"),F("share")},canCreateCollectionFromTags:Ae>0,canCreateCollectionFromCurrentFilter:Ae>0,onCreateCollectionFromTags:()=>st.openForTags({query:ds,totalCount:Ae}),onCreateCollectionFromCurrentFilter:()=>st.openForCurrentFilter({query:ds,totalCount:Ae,activeFilterCount:Ct}),searchValue:U,onSearchChange:oe,onClearSearch:()=>{oe(""),G(""),kt()},searchRef:is,sort:E,onSortChange:X,showFilters:q,onToggleFilters:Xo,activeFilterCount:Ct,filtersPanelId:"filters-panel-overlay",mobileChips:Jo,mobileRuntime:nn,mobileChromeState:os,mobilePresentation:s?"nativeCompact":"default",mobileTitle:e.jsxs(e.Fragment,{children:["Library",e.jsx("span",{className:"text-[var(--rust)]",children:"."})]}),mobileTitleAriaLabel:"Library.",mobileStats:zo,mobileCollapsedStats:qo,onMobileSearchActiveChange:f,densityMode:le,onDensityModeChange:h=>{ae(h),h==="compact"&&ce(null)},groupingMode:P,onGroupingModeChange:re}),e.jsx("div",{className:L("max-sm:hidden","xl:hidden"),children:e.jsx(lg,{chips:Zo,onClear:zt,onClearAll:ls})})]}):null,e.jsxs("div",{className:L("relative",_t&&"xl:grid xl:grid-cols-[minmax(0,1fr)_20.375rem] xl:items-start xl:gap-8 xl:pt-6"),children:[e.jsxs("div",{className:L("min-w-0",ga),children:[!Kt&&!H&&he.length>0&&T.show&&!0&&e.jsx(og,{step:T.step,pending:T.pending,error:T.error,onAdvance:T.advance,onDismiss:T.dismiss,onComplete:T.complete}),e.jsxs("div",{className:"relative min-w-0",children:[q&&e.jsx("button",{type:"button",className:"absolute inset-0 z-[38] hidden cursor-default border-0 bg-[color-mix(in_oklab,var(--content-primary)_6%,transparent)] p-0 sm:block xl:hidden","aria-label":"Close filters",onClick:V.closeSheet}),e.jsx("div",{className:"relative",children:an?e.jsx("div",{className:"mx-auto w-full max-w-5xl px-4 pb-28 pt-4 sm:px-1 sm:pb-12 sm:pt-8","aria-busy":"true","aria-label":"Loading library",children:e.jsx("div",{className:"min-h-[32rem] sm:min-h-[28rem]","aria-hidden":"true"})}):e.jsx(zh,{storyUpdatesEnabled:Tt,gridRef:Ro,isLoading:Kt,isFetching:ye.fetchStatus==="fetching",isError:H,visible:he,storiesMap:Ee,activeFilterCount:Ct,debouncedSearch:se,bulkMode:ne.bulkMode,isSelected:ne.isSelected,onToggleSelect:ne.toggleOne,onStartBulkSelect:h=>{ce(null),ne.bulkMode||ne.setBulkMode(!0),ne.isSelected(h)||ne.toggleOne(h)},onRemoveEntry:To,removingEntryId:Ga,onOpenDetails:async h=>{ce(null),ve();const w=`${c.pathname}${c.search}`;await Nl({entryId:h,source:"library",returnTo:w})||`${window.location.pathname}${window.location.search}`===w&&o(`/library/${h}`,{state:{libraryReturnTo:w}})},onChangeStatus:nl,onIncrementChapter:sl,onDecrementChapter:rl,onSetChapterValue:ol,onChangeRating:(h,w)=>Yt(h,{rating:w}),onChangeNotes:(h,w)=>bt(h,{notes:w}),onChangeTags:(h,w)=>bt(h,{tags:w}),onAddToCollection:h=>{const w=ja(h);w&&st.openForEntry(w,Ee[w.storyId])},onShareStory:al,onLayoutPointerLockChange:So,deferredRecencyReorderIds:ko,onDeferredRecencyEntryExit:Co,mostRecentReadingEntryId:_o,densityMode:le,groupingMode:P,evaluatingEntryId:me,onStartEvaluate:ce,onCloseEvaluate:()=>ce(null),loadMoreRef:ha,hasNextPage:!!Ne,isFetchingNextPage:Ie,onFetchNextPage:Ge,onAddManually:ma,firstStoryCompleted:!!pe?.first_story_completed_at,onRetry:()=>ye.refetch(),splitDetailOpen:ga})})]})]}),ga,_t&&!ga&&e.jsx("aside",{className:L("hidden xl:block xl:self-start",a&&"pt-2"),"aria-label":"Library filters",children:e.jsx(Es,{storyUpdatesEnabled:Tt,id:"filters-panel-rail",variant:"rail",filters:W,onChange:ee,onReset:Rt,resultCount:Me,totalCount:Pe,activeChips:rt,onClearActiveFilter:zt,onClearAllActiveFilters:ls})})]})]})]}),e.jsx(pi,{open:Re,title:"Add a story manually",onClose:A,variant:"library",size:"lg",desktopPresentation:"sheet",desktopBackdrop:"transparent",hideHeader:!0,hideHeaderClose:!0,hideFooter:!0,panelClassName:xi.addStory,bodyClassName:hi,children:e.jsx(ac,{onManualAdd:tt,adding:z,addError:te,onClose:A})}),e.jsx(bb,{open:He,onClose:A,selectedCount:ne.selectedCount,visibleCount:he.length,tagShareCount:Ja,shareTotalCount:Fo,getEntriesForShareBatch:$o,storiesMap:Ee,shareSource:Xe,onChangeShareSource:Qa,allTags:Zn,shareTags:Xa,onChangeShareTags:Eo,shareTagMatchMode:Za,onChangeShareTagMatchMode:Po,shareTitle:Mo,onChangeShareTitle:Io,shareOpts:Oo,onChangeShareOpts:Do,onToast:h=>Ce(h)}),ts,e.jsx(Dc,{open:st.open,target:st.target,onClose:st.close,onSuccess:h=>Ce(h,4500)}),e.jsx($t,{open:as,title:"Remove from library",description:"Remove this story from your library? This can't be und
6one.",confirmLabel:"Remove",variant:"danger",loading:Lo,onConfirm:Ao,onCancel:()=>ns(!1)}),e.jsx($t,{open:!!Na,title:"Starting a re-read?",description:"This will reset your progress and start a new read-through. Your previous reading history will be saved.",confirmLabel:"Start re-read",onConfirm:()=>{Na&&il(Na)},onCancel:()=>hs(null)}),e.jsx(ng,{onCancel:ne.cancelBulkFinished,onConfirm:ne.confirmBulkFinished,open:ne.bulkFinishPending}),e.jsx(Fc,{message:jo,action:No})]})]})}export{iv as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.