1import{r as l,j as e,i as Je,c as Xe,u as es}from"./vendor-react-2mXWPygV.js";import{x as ss,w as ts,y as as,E as ns}from"./vendor-app-BYWHQm7D.js";import{r as ne,f as xe,g as rs,T as is,R as os,W as ls,u as cs,q as D,A as ds,D as us,z as hs,y as ps}from"./index-Bc0LLRT4.js";import{u as J,x as ms,k as Ne,v as fs,q as Ce,y as de,z as xs,B as js,D as bs,E as ys,C as je}from"./useMinLg-k9XJBU-I.js";import{A as be}from"./archive-state-frame.component-DQO0Rx0D.js";import{B as S,aq as De,ar as _e,as as Me,at as Le,au as Re,av as Ee,aw as ks,N as vs,O as gs,Q as ws,R as Ss,S as Ns,ac as Cs,U as Ds}from"./vendor-ui-CZXIQ_Np.js";import{a as _s}from"./story-update-context.component-DzwcKtA4.js";import{a as Ms,b as Ls,u as Rs,l as ye,c as Es,C as Ts,T as As}from"./useCollectionActionDialog-DpqwS7vO.js";import"./use-overlay-focus-return-Ds4tDfMz.js";const Ps=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function ce(s){const[t,o,n]=s.split("-").map(Number);return new Date(t,o-1,n,12)}function K(s,t){const o=new Date(s);return o.setDate(o.getDate()+t),o}function Y(s,t){const o=s.getDate(),n=new Date(s.getFullYear(),s.getMonth()+t,1,12),r=new Date(n.getFullYear(),n.getMonth()+1,0,12).getDate();return n.setDate(Math.min(o,r)),n}function B(s){return new Date(s.getFullYear(),s.getMonth(),1,12)}function Fs(s,t){return s.getFullYear()===t.getFullYear()&&s.getMonth()===t.getMonth()}function Os({label:s,max:t=J(),onValueChange:o,value:n}){const r=l.useMemo(()=>ce(t),[t]),d=l.useMemo(()=>n&&n<=t?ce(n):r,[t,r,n]),[c,b]=l.useState(()=>B(d)),[x,u]=l.useState(d),k=l.useRef(new Map),N=l.useRef(!1);l.useEffect(()=>{if(!n||n>t)return;const h=ce(n);u(h),b(B(h))},[t,n]),l.useEffect(()=>{N.current&&(N.current=!1,k.current.get(J(x))?.focus())},[x,c]);const j=l.useMemo(()=>{const h=B(c);return K(h,-h.getDay())},[c]),M=l.useMemo(()=>Array.from({length:42},(h,f)=>K(j,f)),[j]),C=c.toLocaleDateString("en-GB",{month:"long",year:"numeric"}),i=h=>{const f=h>r?r:h;N.current=!0,u(f),b(B(f))},m=(h,f)=>{let w;switch(h.key){case"ArrowLeft":w=K(f,-1);break;case"ArrowRight":w=K(f,1);break;case"ArrowUp":w=K(f,-7);break;case"ArrowDown":w=K(f,7);break;case"Home":w=K(f,-f.getDay());break;case"End":w=K(f,6-f.getDay());break;case"PageUp":w=Y(f,-1);break;case"PageDown":w=Y(f,1);break;default:return}h.preventDefault(),i(w)},L=Y(B(c),1)<=B(r);return e.jsxs("div",{className:"date-only-calendar","aria-label":s,role:"group",children:[e.jsxs("div",{className:"date-only-calendar-head",children:[e.jsx("button",{"aria-label":"Previous month",onClick:()=>b(h=>Y(h,-1)),type:"button",children:"â¹"}),e.jsx("strong",{"aria-live":"polite",children:C}),e.jsx("button",{"aria-label":"Next month",disabled:!L,onClick:()=>b(h=>Y(h,1)),type:"button",children:"âº"})]}),e.jsxs("div",{className:"date-only-calendar-grid",role:"grid","aria-label":C,children:[Ps.map(h=>e.jsx("span",{"aria-hidden":"true",className:"date-only-calendar-weekday",children:h.slice(0,1)},h)),M.map(h=>{const f=J(h),w=f>t,P=f===n,F=!Fs(h,c);return e.jsx("button",{"aria-label":h.toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"}),"aria-selected":P,className:[F?"is-outside":"",P?"is-selected":"",f===t?"is-today":""].filter(Boolean).join(" "),disabled:w,onClick:()=>{u(h),o(f)},onKeyDown:E=>m(E,h),ref:E=>{E?k.current.set(f,E):k.current.delete(f)},role:"gridcell",tabIndex:J(x)===f?0:-1,type:"button",children:h.getDate()},f)})]})]})}function Us({draft:s,label:t,onCancel:o,onDraftChange:n,onSave:r,saveError:d,saving:c}){const b=J(),x=s!=null&&s>b;return e.jsxs("div",{className:"sd37-date-editor-form",children:[e.jsxs("div",{className:"sd37-date-editor-value",children:[e.jsx("span",{children:"Finished on"}),e.jsx("b",{children:s??"Date unknown"})]}),e.jsx(Os,{label:`Finish date for ${t}`,max:b,onValueChange:n,value:s}),x||d?e.jsx("p",{className:"sd37-date-editor-error",role:"alert",children:x?"Finish date cannot be in the future.":d}):null,e.jsxs("div",{className:"sd37-date-editor-choices",children:[e.jsx(S,{onClick:()=>n(b),type:"button",children:"Today"}),e.jsx(S,{onClick:()=>n(null),type:"button",children:"Date unknown"})]}),e.jsxs("div",{className:"sd37-date-editor-actions",children:[e.jsx(S,{disabled:c,onClick:o,type:"button",children:"Cancel"}),e.jsx(S,{className:"is-primary",disabled:x||c,onClick:r,type:"button",children:c?"Savingâ¦":"Save"})]})]})}function $s({initiallyOpen:s=!1,label:t,onSave:o,value:n}){const r=ms(),[d,c]=l.useState(s),[b,x]=l.useState(n),[u,k]=l.useState(null),[N,j]=l.useState(!1),M=()=>{x(n),k(null),c(!0)},C=()=>{x(n),k(null),c(!1)},i=async()=>{j(!0),k(null);try{await o(fs(b)),c(!1)}catch(L){k(L instanceof Error?L.message:"Could not save finish date.")}finally{j(!1)}},m=e.jsx(Us,{draft:b,label:t,onCancel:C,onDraftChange:x,onSave:i,saveError:u,saving:N});return r?e.jsxs(De,{onOpenChange:c,open:d,children:[e.jsx(_e,{render:e.jsx(S,{"aria-label":`Edit finish date for ${t}`,className:"sd37-history-edit",onClick:()=>{x(n),k(null)},type:"button"}),children:"Edit"}),e.jsx(Me,{children:e.jsx(Le,{align:"end",sideOffset:8,children:e.jsxs(Re,{className:"library-app archive-editorial-shell sd37-date-editor-popover",children:[e.jsx(Ee,{className:"sd37-date-editor-title",children:"Finish date"}),m]})})})]}):e.jsxs(e.Fragment,{children:[e.jsx(S,{"aria-label":`Edit finish date for ${t}`,className:"sd37-history-edit",onClick:M,type:"button",children:"Edit"}),e.jsx(Ne,{closeLabel:"Close finish date",onOpenChange:c,open:d,title:"Finish date",children:m})]})}const Is=2e3,Ks={book:e.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6",children:[e.jsx("path",{d:"M4 5.5A2.5 2.5 0 0 1 6.5 3H20v15H6.5A2.5 2.5 0 0 0 4 20.5z"}),e.jsx("path",{d:"M4 5.5v15"})]}),chevron:e.jsx("path",{d:"m9 6 6 6-6 6",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.9"}),collection:e.jsx("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6",children:e.jsx("path",{d:"M3 7a2 2 0 0 1 2-2h4l2 2h6a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"})}),external:e.jsx("path",{d:"M7 17 17 7M9 7h8v8",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6"}),minus:e.jsx("path",{d:"M5 12h14",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2"}),more:e.jsxs("g",{fill:"currentColor",children:[e.jsx("circle",{cx:"12",cy:"5",r:"1.7"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.7"}),e.jsx("circle",{cx:"12",cy:"19",r:"1.7"})]}),plus:e.jsx("path",{d:"M12 5v14M5 12h14",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeWidth:"2"}),share:e.jsxs("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.6",children:[e.jsx("circle",{cx:"6",cy:"12",r:"2.4"}),e.jsx("circle",{cx:"17",cy:"6",r:"2.4"}),e.jsx("circle",{cx:"17",cy:"18",r:"2.4"}),e.jsx("path",{d:"m8.2 10.8 6.6-3.6M8.2 13.2l6.6 3.6"})]}),star: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:"currentColor",stroke:"currentColor",strokeWidth:"1.2"}),trash:e.jsx("g",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"1.7",children:e.jsx("path",{d:"M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13M10 11v6M14 11v6"})})},G=[{value:"complete",label:"Complete",detail:"The work is finished."}
1,{value:"abandoned",label:"Abandoned",detail:"The work is unlikely to continue."},{value:"hiatus",label:"On hiatus",detail:"The work is paused."},{value:"wip",label:"Still ongoing",detail:"More chapters are expected."},{value:"source",label:"Use detected status",detail:"Clear your manual status."}];function _({name:s,size:t=16}){return e.jsx("svg",{"aria-hidden":"true",height:t,viewBox:"0 0 24 24",width:t,children:Ks[s]})}function U({children:s}){return e.jsx("div",{className:"sd37-sec",children:s})}function Z(s){return typeof s=="number"&&Number.isFinite(s)?s.toLocaleString():"Unknown"}function re(s){if(!s)return"Unknown";const t=new Date(s);return Number.isNaN(t.getTime())?"Unknown":t.toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})}function Te(s){return`sd37-status-${s.toLowerCase()}`}function qs(s){return s.canonicalFandoms?.find(Boolean)??s.fandoms?.find(Boolean)??"Unknown fandom"}function Bs(s){return s.source||s.sourceHost||"source"}function Hs(s){const t=s.source?.toUpperCase()??"",o=s.sourceHost?.toLowerCase()??"",n=s.canonicalUrl?.toLowerCase()??"";return t==="FFN"||t.includes("FANFICTION")||o.includes("fanfiction")||n.includes("fanfiction.net")}function zs(s){return Hs(s)?"FFN story pages do not expose descriptions, so Trace can only save this if it saw the story on a listing page. Open the author page and Trace will try to capture it from the author's story list.":"No archive summary available."}function Ws(s){const t=s.workStatusOverride?.trim();if(t){const n=xe({workStatusOverride:t,completionStatus:s.completionStatus,chaptersPublished:s.chapters_published,chaptersPlanned:s.chapters_planned});return{provenance:n.work_status_provenance,workStatus:n.work_status}}if(s.work_status!=null){const n=rs(s.work_status),r=s.work_status_provenance??(n==="unknown"?"unknown":"source"),d=typeof s.chapters_planned=="number"&&s.chapters_planned>0?Math.floor(s.chapters_planned):null,c=typeof s.chapters_published=="number"&&s.chapters_published>=0?Math.floor(s.chapters_published):null;return n==="wip"&&r!=="override"&&(d==null||c==null||c>=d)?{provenance:"unknown",workStatus:"unknown"}:{provenance:r,workStatus:n}}const o=xe({workStatusOverride:s.workStatusOverride,completionStatus:s.completionStatus,chaptersPublished:s.chapters_published,chaptersPlanned:s.chapters_planned});return{provenance:o.work_status_provenance,workStatus:o.work_status}}function Qs(s){return s==="unknown"?"Unknown":ls[s]}function Vs(s,t,o,n){const r=Math.max(0,Math.floor(Number(o)||0)),d=typeof s.chapters_published=="number"&&s.chapters_published>0?Math.floor(s.chapters_published):typeof t.progress.total=="number"&&t.progress.total>0?Math.floor(t.progress.total):Math.max(r,0),c=typeof s.chapters_planned=="number"&&s.chapters_planned>0?Math.floor(s.chapters_planned):null,b=n==="complete"||(s.completionStatus||"").toLowerCase().trim()==="complete"||c!=null&&d>=c,x=b?"complete":c!=null?"known":"unknown",u=t.status==="SAVED"?"â":String(r);return{complete:b,kind:x,planned:c,plannedText:b?String(d):c!=null?String(c):"Not stated (?)",read:r,readText:u,released:d}}function Ys({release:s,story:t}){const o=[["Words",Z(t.words)],["Read chapters",`${s.readText} / ${s.released||"?"}`],["Posted chapters",s.released?String(s.released):"Unknown"],["Expected total",s.plannedText],["Posting status",s.complete?"Complete":s.kind==="known"?"Ongoing":"Unknown"],["Kudos",Z(t.kudos??t.favorites)],["Comments",Z(t.commentsCount??t.reviews)],["Bookmarks",Z(t.bookmarks)],["Hits",Z(t.hits)],["Rating",t.contentRating||"Not rated"],["Category",t.categories?.find(Boolean)||"Unknown"],["Language",t.language?.trim()||"Unknown"],["Published",re(t.publishedDate)],["Updated",re(t.updatedDate)]],n=(t.series??[]).filter(r=>r.name?.trim());return n.length&&o.splice(2,0,["Series",e.jsx("span",{className:"sd37-series-list",children:n.map((r,d)=>{const c=r.name.trim(),b=xs(r),x=js(r.url);return e.jsxs("span",{children:[x?e.jsx("a",{href:x,target:"_blank",rel:"noreferrer",children:c}):c,b?e.jsxs("small",{children:[" · ",b]}):null]},`${c}-${d}`)}
1)})]),o}function Gs(){return e.jsxs(De,{children:[e.jsx(_e,{"aria-label":"About series in Trace",className:"inline-flex size-5 items-center justify-center rounded-full border border-[var(--line-strong)] font-sans text-xs font-semibold leading-none text-[var(--ink-4)] outline-none transition hover:border-[var(--rust)] hover:text-[var(--rust)] focus-visible:shadow-ring data-[popup-open]:border-[var(--rust)] data-[popup-open]:text-[var(--rust)]",children:"?"}),e.jsx(Me,{children:e.jsx(Le,{align:"start",side:"top",sideOffset:8,children:e.jsxs(Re,{className:"library-app archive-editorial-shell z-[1350] w-64 max-w-[calc(100vw-var(--space-8))] rounded-sm border border-[var(--line-strong)] bg-[var(--paper)] p-3 text-left shadow-lg outline-none",children:[e.jsx(Ee,{className:"font-sans text-sm font-semibold leading-snug text-[var(--ink)]",children:"About series in Trace"}),e.jsx(ks,{className:"mt-1 font-sans text-xs leading-relaxed text-[var(--ink-3)]",children:"Trace groups only stories currently loaded in your Library. The source series may contain more works."})]})})})]})}function ke({label:s}){return s!=="Series"?s:e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx("span",{children:s}),e.jsx(Gs,{})]})}function Zs({onChange:s,value:t}){const[o,n]=l.useState(0),r=o||t||0;return e.jsx("span",{className:"sd37-stars",onMouseLeave:()=>n(0),children:[1,2,3,4,5].map(d=>e.jsx(S,{"aria-label":`${d} star${d===1?"":"s"}`,"aria-pressed":t===d,className:d<=r?"is-on":void 0,disabled:!s,onClick:()=>s?.(t===d?0:d),onMouseEnter:()=>n(d),type:"button",children:e.jsx(_,{name:"star",size:20})},d))})}function Js({onChangeStatus:s,value:t}){return e.jsxs("span",{className:"sd37-status-select",children:[e.jsx(_,{name:t==="SAVED"?"collection":"book",size:14}),e.jsx("span",{children:ne(t)}),e.jsx(_,{name:"chevron",size:13}),s?e.jsx("select",{"aria-label":"Reader status",onChange:o=>s(o.target.value),value:t,children:os.map(o=>e.jsx("option",{value:o,children:ne(o)},o))}):null]})}function Xs({onChange:s,released:t,value:o}){const n=t>0?t:void 0,r=()=>s(Math.max(0,o-1)),d=()=>s(n==null?o+1:Math.min(n,o+1));return e.jsxs("span",{className:"sd37-stepper",children:[e.jsx(S,{"aria-label":"Decrease chapter",onClick:r,type:"button",children:e.jsx(_,{name:"minus",size:14})}),e.jsxs("span",{children:[o," / ",t||"?"]}),e.jsx(S,{"aria-label":"Increase chapter",onClick:d,type:"button",children:e.jsx(_,{name:"plus",size:14})})]})}function et({children:s}){return e.jsx("span",{className:"sd37-chip sd37-chip-source",children:s})}function st({children:s}){return e.jsx("span",{className:"sd37-chip sd37-chip-ship",children:s})}function tt({children:s}){return e.jsxs("span",{className:"sd37-chip sd37-chip-private",children:[e.jsx("span",{"aria-hidden":"true"}),s]})}function at({label:s,onClick:t}){const o=e.jsxs(e.Fragment,{children:[e.jsx(_,{name:"plus",size:11}),s]});return t?e.jsx(S,{"aria-label":`Add ${s}`,className:"sd37-chip sd37-chip-add",onClick:t,type:"button",children:o}):e.jsx("span",{className:"sd37-chip sd37-chip-add",children:o})}function ve({emptyLabel:s="none",kind:t,values:o}){return o.length?e.jsx("div",{className:"sd37-chip-list",children:o.map(n=>t==="private"?e.jsx(tt,{children:n},n):t==="ship"?e.jsx(st,{children:n},n):e.jsx(et,{children:n},n))}):e.jsx("span",{className:"sd37-empty",children:s})}function nt({emptyLabel:s="none",values:t}){return t.length?e.jsx("p",{className:"sd37-source-tag-text",children:t.join(", ")}):e.jsx("span",{className:"sd37-empty",children:s})}function ge({entry:s,onChangeStatus:t,onOpenSource:o,onProgressChange:n,onStartReading:r,onStartReread:d,release:c,sourceHref:b,startReadingPending:x,startSourceHref:u,story:k}){const N=c.released?Math.max(0,Math.min(100,c.read/c.released*100)):0,j=Math.max(0,c.released-c.read),M=c.complete?"Complete · all chapters released":c.kind==="known"?`${c.released} of ${c.planned} planned chapters posted`:"Planned length not stated",C=Te(s.status),i=s.status==="SAVED",m=s.status==="FINISHED",L=i?r:m?d:void 0,h=i?"Start reading":"Start reread";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"sd37-track-card",children:[e.jsxs("div",{className:"sd37-track-top",children:[e.jsxs("span",{children:["Chapter ",c.readText," ",e.jsxs("span",{children:["/ ",c.released||"?"]})]}),e.jsxs("span",{children:[Math.round(N),"%"]})]}),e.jsx("div",{className:`sd37-progress ${C}`,"aria-label":"Reading progress",children:e.jsx("span",{style:{width:`${N}%`}})}),e.jsxs("div",{className:"sd37-release-line",children:[e.jsx("span",{"aria-hidden":"true",className:c.complete?"is-complete":void 0}),e.jsx("span",{children:M})]}),e.jsxs("div",{className:"sd37-track-controls",children:[e.jsx(Js,{onChangeStatus:t,value:s.status}),e.jsx(Xs,{onChange:n,released:c.released,value:c.read})]})]}),L?e.jsxs(S,{"aria-busy":i&&x?!0:void 0,className:"sd37-primary-cta",disabled:i&&x,onClick:L,type:"button",children:[e.jsx(_,{name:"book",size:16}),i&&x?"Startingâ¦":h]}):b?e.jsxs("a",{className:"sd37-primary-cta",href:b,onClick:o,rel:"noreferrer",target:"_blank",children:[e.jsx(_,{name:"book",size:16}),"Continue reading"]}):null,(i||m)&&u?e.jsxs("a",{className:"sd37-source-cta",href:u,rel:"noreferrer",target:"_blank",children:[e.jsx(_,{name:"external",size:14}),"Open in source"]}):null,k.catchup_state==="BEHIND"&&j===0?e.jsx("p",{className:"sd37-track-note",children:"Unread chapters are available from the last synced source state."}):null]})}function we({draftNotes:s,draftTags:t,includeActions:o=!1,includeCollections:n=!1,collections:r=[],onAddToCollection:d,onChangeRating:c,onOpenCollection:b,onNotesChange:x,notesDirt
1y:u,notesSavePending:k=!1,onRemove:N,onSaveNotes:j,onShare:M,onTagsChange:C,value:i}){const[m,L]=l.useState(""),[h,f]=l.useState(!1),[w,P]=l.useState(!1),F=l.useRef(null),E=l.useRef(k);l.useEffect(()=>{h&&F.current?.focus()},[h]),l.useEffect(()=>{let v=null;const y=E.current&&!k&&!u;return u?P(!1):y&&(P(!0),v=setTimeout(()=>P(!1),Is)),E.current=k,()=>{v&&clearTimeout(v)}},[u,k]);const $=()=>{const v=m.trim();!v||t.includes(v)||(C([...t,v]),L(""),f(!1))};return e.jsxs("div",{className:"sd37-eval-card",children:[e.jsx(U,{children:"Your rating"}),e.jsx(Zs,{value:i,onChange:c}),e.jsxs("div",{className:"sd37-eval-section",children:[e.jsx(U,{children:"Your tags"}),e.jsxs("div",{className:"sd37-chip-list",children:[t.map(v=>e.jsxs(S,{className:"sd37-chip sd37-chip-private",onClick:()=>C(t.filter(y=>y!==v)),type:"button",children:[e.jsx("span",{"aria-hidden":"true"}),v]},v)),e.jsx(at,{label:"tag",onClick:()=>f(!0)})]}),h?e.jsxs("div",{className:"sd37-tag-entry",children:[e.jsx("input",{"aria-label":"Add private tag",onChange:v=>L(v.target.value),onKeyDown:v=>{if(v.key==="Escape"){v.preventDefault(),L(""),f(!1);return}v.key==="Enter"&&(v.preventDefault(),$())},placeholder:"Add private tag",ref:F,value:m}),e.jsx(S,{disabled:!m.trim(),onClick:$,type:"button",children:"Add"})]}):null]}),e.jsxs("div",{className:"sd37-eval-section",children:[e.jsx(U,{children:"Your note"}),e.jsx(is,{"aria-label":"Private notes",className:"sd37-note-block",onChange:v=>x(v.target.value),placeholder:"Anything you want to remember about this story.",rows:3,value:s}),e.jsxs("div",{className:"sd37-note-save-row",children:[e.jsx("span",{"aria-live":"polite",children:k?"Saving noteâ¦":u?"Unsaved changes":w?"Note saved":null}),e.jsx(S,{disabled:!u||k,onClick:j,type:"button",children:k?"Savingâ¦":"Save note"})]})]}),n?e.jsx(Ae,{collections:r,onAddToCollection:d,onOpenCollection:b}):null,o?e.jsxs("div",{className:"sd37-actions",children:[M?e.jsxs(S,{onClick:M,type:"button",children:[e.jsx(_,{name:"share",size:14}),"Share"]}):null,e.jsxs(S,{className:"is-danger",onClick:N,type:"button",children:[e.jsx(_,{name:"trash",size:14}),"Remove"]})]}):null]})}function Ae({collections:s=[],onAddToCollection:t,onOpenCollection:o}){return e.jsxs("div",{className:"sd37-eval-section sd37-collections-line",children:[e.jsx(U,{children:"In collections"}),e.jsxs("div",{className:"sd37-chip-list",children:[s.map(n=>e.jsxs("a",{className:"sd37-chip sd37-chip-collection",href:n.href??`/collections/${n.collectionId}`,onClick:r=>{!o||r.defaultPrevented||r.button!==0||r.metaKey||r.altKey||r.ctrlKey||r.shiftKey||(r.preventDefault(),o(n.collectionId))},children:[e.jsx(_,{name:"collection",size:12}),n.title]},n.collectionId)),t?e.jsxs(S,{className:"sd37-chip sd37-chip-add",onClick:t,type:"button",children:[e.jsx(_,{name:"collection",size:12}),"add"]}):s.length===0?e.jsx("span",{className:"sd37-empty",children:"none"}):null]})]})}function rt(s){if(!s)return"Date unknown";const t=new Date(`${s}T12:00:00.000Z`);return Number.isNaN(t.getTime())?"Date unknown":t.toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric",timeZone:"UTC"})}function it(s,t,o){return t&&!o?s===1?"Current read":"Current reread":s===1?"First read":`Reread ${s-1}`}function ot({entry:s,history:t,initiallyOpenReadNumber:o,onUpdate:n}){return e.jsxs("section",{className:"sd37-main-section sd37-reading-history",children:[e.jsx(U,{children:"Reading history"}),e.jsxs("div",{className:"sd37-history-list",children:[t.map(r=>{const d=it(r.read_number,r.is_current,r.completed);return e.jsxs("div",{className:"sd37-history-row",children:[e.jsxs("div",{children:[e.jsx("span",{children:d}),e.jsx("b",{children:r.completed?`Finished · ${rt(r.completed_on)}`:`${ne(s.status)}${s.lastReadAt?` · Last read ${re(s.lastReadAt)}`:""}`})]}),r.completed&&n?e.jsx($s,{initiallyOpen:o===r.read_number,label:d,onSave:c=>n(r.read_number,c),value:r.completed_on}):null]},r.read_number)}),e.jsx("div",{className:"sd37-history-row",children:e.jsxs("div",{children:[e.jsx("span",{children:"Added"}),e.jsx("b",{children:re(s.createdAt??s.updatedAt)})]})})]})]})}function Se({onSetWorkStatusOverride:s,sourceName:t,state:o,story:n}){return e.jsxs("div",{className:"sd37-work-line",children:[e.jsxs("div",{className:"sd37-work-line-main",children:[e.jsx("span",{children:"Work"}),e.jsx("b",{children:Qs(o.workStatus)}),o.provenance!=="unknown"?e.jsx("em",{children:bs(o.provenance)}):null]}),s?e.jsx(lt,{onSetWorkStatusOverride:s,story:n}):null,e.jsx("small",{children:ys(o.workStatus,t,o.provenance)})]})}function lt({disabled:s=!1,onSetWorkStatusOverride:t,story:o}){const n=o.workStatusOverride?.trim()||"source",r=n==="wip"||n==="complete"||n==="hiatus"||n==="abandoned"?n:"source",[d,c]=l.useState(!1),b=G.find(u=>u.value===r)??G[G.length-1],x=u=>{s||(t(u==="source"?null:u),c(!1))};return e.jsxs(e.Fragment,{children:[e.jsxs(vs,{children:[e.jsx(gs,{className:"sd37-work-edit sd37-work-edit-desktop",disabled:s,type:"button",children:"Edit"}),e.jsx(ws,{children:e.jsx(Ss,{side:"bottom",align:"end",sideOffset:8,children:e.jsx(Ns,{className:"library-app archive-editorial-shell tf-pop sd-work-status-menu outline-none",children:e.jsx(Cs,{children:G.map(u=>e.jsxs(Ds,{className:`sd-work-status-menu-item${u.value===r?" is-selected":""}`,onClick:()=>x(u.value),children:[e.jsx("span",{className:`sd-work-status-dot sd-work-status-dot--${u.value}`,"aria-hidden":!0}),e.jsxs("span",{className:"sd-work-status-menu-copy",children:[e.jsx("span",{children:u.label}),e.jsx("small",{children:u.detail})]}),u.value===r?e.jsx("span",{className:"sd-work-status-menu-selected",children:"Selected"}):null]},u.value))})})})})]}),e.jsx(S,{"aria-label":`Edit work status, current ${b.label}`,className:"sd37-work-edit sd37-work-edit-mobile",disabled:s,onClick:()=>c(!0),type:"button",children:"Edit"}),e.jsx(Ne,{open:d,onOpenChange:c,title:"Work status",eyebrow:"Author publication state",closeLabel:"Close work status",children:e.jsx("div",{className:"sd-mobile-sheet-list",role:"listbox","aria-label":"Work status",children:G.map(u=>e.jsxs(S,{"aria-selected":u.value===r,className:`sd-status-sheet-row sd-work-status-sheet-row${u.value===r?" is-selected":""}`,onClick:()=>x(u.value),role:"option",type:"button",children:[e.jsx("span",{className:`sd-work-status-dot sd-work-status-dot--${u.value}`,"aria-hidden":!0}),e.jsxs("span",{className:"sd-work-status-menu-copy",children:[e.jsx("span",{children:u.label}),e.jsx("small",{children:u.detail})]}),u.value===r?e.jsx("span",{className:"sd-work-status-menu-selected",children:"Selected"}):null]},u.value))})})]})}function ct({collections:s=[],draftNotes:t,draftProgressValue:o,draftTags:n,entry:r,initiallyOpenReadingHistoryDate:d,onAddToCollection:c,onChangeRating:b,onChangeStatus:x,onClose:u,onOpenCollection:k,onNotesChange:N,notesDirt
1y:j,notesSavePending:M=!1,onRemove:C,onSaveNotes:i,onShare:m,onStartReading:L,onStartReread:h,onSetWorkStatusOverride:f,onUpdateReadingHistory:w,readingHistory:P=[],onTagsChange:F,setDraftProgressValue:E,showMobileBar:$=!0,startReadingPending:v=!1,story:y}){const I=Ce(y,r),X=de(y),O=Ws(y),H=Vs(y,r,o,O.workStatus),ee=y.relationships?.filter(Boolean)??[],q=(y.canonicalCharacters?.length?y.canonicalCharacters:y.characters).filter(Boolean),se=y.workTags?.filter(Boolean)??[],te=Ys({release:H,story:y}),z=Bs(y),W=qs(y),Q=Te(r.status),V=y.summary?.trim()??"";return e.jsxs("article",{className:"sd37-detail",children:[$?e.jsxs("div",{className:"sd37-mobile-bar",children:[e.jsxs(S,{"aria-label":"Back to Library",onClick:u,type:"button",children:[e.jsx("span",{"aria-hidden":"true",children:e.jsx(_,{name:"chevron",size:18})}),"Library"]}),e.jsxs("span",{children:[m?e.jsx(S,{"aria-label":"Share story",onClick:m,type:"button",children:e.jsx(_,{name:"share",size:18})}):null,e.jsx(S,{"aria-label":"More story actions",type:"button",children:e.jsx(_,{name:"more",size:18})})]})]}):null,e.jsxs("div",{className:"sd37-inner",children:[e.jsxs(S,{className:"sd37-back-desktop",onClick:u,type:"button",children:[e.jsx("span",{"aria-hidden":"true",children:e.jsx(_,{name:"chevron",size:15})}),"Back to Library"]}),e.jsxs("div",{className:"sd37-grid",children:[e.jsxs("main",{className:"sd37-main",children:[e.jsxs("div",{className:`sd37-kicker ${Q}`,children:[e.jsx("span",{"aria-hidden":"true"}),ne(r.status)]}),e.jsx("h1",{children:y.title}),e.jsxs("div",{className:"sd37-byline",children:["by ",e.jsx("b",{children:y.authors.filter(Boolean).join(", ")||"Unknown author"}),e.jsx("span",{"aria-hidden":"true",children:"·"}),W]}),e.jsx("div",{className:"sd37-mobile-track",children:e.jsx(ge,{entry:r,onChangeStatus:x,onOpenSource:void 0,onProgressChange:E,onStartReading:L,onStartReread:h,release:H,sourceHref:I,startReadingPending:v,startSourceHref:X,story:y})}),e.jsx("div",{className:"sd37-mobile-eval",children:e.jsx(we,{draftNotes:t,draftTags:n,collections:s,onAddToCollection:c,onChangeRating:b,onOpenCollection:k,onNotesChange:N,notesDirty:j,notesSavePending:M,onRemove:C,onSaveNotes:i,onShare:m,onTagsChange:F,value:r.rating??0})}),V?e.jsx("p",{className:"sd37-summary",children:V}):e.jsx("p",{className:"sd37-summary sd37-summary-missing",children:zs(y)}),e.jsxs("section",{className:"sd37-main-section sd37-details-section sd37-details-section-mobile",children:[e.jsx(U,{children:"Details"}),e.jsx("dl",{className:"sd37-meta-grid",children:te.map(([R,T])=>e.jsxs("div",{children:[e.jsx("dt",{children:e.jsx(ke,{label:R})}),e.jsx("dd",{children:T})]},R))}),e.jsx(Se,{onSetWorkStatusOverride:f,sourceName:z,state:O,story:y})]}),e.jsxs("section",{className:"sd37-main-section",children:[e.jsx(U,{children:"Relationships"}),e.jsx(ve,{kind:"ship",values:ee})]}),e.jsxs("section",{className:"sd37-main-section",children:[e.jsx(U,{children:"Characters"}),e.jsx(ve,{kind:"source",values:q})]}),e.jsxs("section",{className:"sd37-main-section",children:[e.jsx(U,{children:"Source tags"}),e.jsx(nt,{values:se})]}),e.jsxs("section",{className:"sd37-main-section sd37-details-section sd37-details-section-desktop",children:[e.jsx(U,{children:"Details"}),e.jsx("dl",{className:"sd37-meta-grid",children:te.map(([R,T])=>e.jsxs("div",{children:[e.jsx("dt",{children:e.jsx(ke,{label:R})}),e.jsx("dd",{children:T})]},R))})]}),e.jsx("section",{className:"sd37-main-section sd37-mobile-collections",children:e.jsx(Ae,{collections:s,onAddToCollection:c,onOpenCollection:k})}),e.jsx(ot,{entry:r,history:P,initiallyOpenReadNumber:d,onUpdate:w})]}),e.jsxs("aside",{className:"sd37-sidebar",children:[e.jsx("div",{className:"sd37-desktop-track",children:e.jsx(ge,{entry:r,onChangeStatus:x,onOpenSource:void 0,onProgressChange:E,onStartReading:L,onStartReread:h,release:H,sourceHref:I,startReadingPending:v,startSourceHref:X,story:y})}),e.jsx("div",{className:"sd37-desktop-eval",children:e.jsx(we,{draftNotes:t,draftTags:n,collections:s,includeActions:!0,includeCollections:!0,onAddToCollection:c,onChangeRating:b,onOpenCollection:k,onNotesChange:N,notesDirt
1y:j,notesSavePending:M,onRemove:C,onSaveNotes:i,onShare:m,onTagsChange:F,value:r.rating??0})}),e.jsx(Se,{onSetWorkStatusOverride:f,sourceName:z,state:O,story:y})]})]})]})]})}const dt=500;function ut(s){return!s||typeof s!="object"?void 0:("status"in s?s.status:void 0)===404?"This story is no longer in your library.":s instanceof Error?s.message:void 0}function ht(s,t){if(!s)return s;const o=s.data.collections??[];return o.some(n=>n.collection_id===t.collection_id)?s:{...s,data:{...s.data,collections:[...o,t]}}}function gt({storyUpdatesEnabled:s=!1}={}){const{entryId:t=""}=Je(),o=Xe(),n=es(),r=cs(),d=ss(),c=Ms(),[b,x]=l.useState(null),[u,k]=l.useState(null),N=l.useRef(null),j=l.useCallback((a,p=3e3,g=null)=>{x(a),k(g),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{x(null),k(null)},p)},[]);l.useEffect(()=>()=>{N.current&&clearTimeout(N.current)},[]);const M=ts({queryKey:D.library.detail(t),queryFn:()=>r.getLibraryEntry(t),enabled:r.isReady&&!!t,retry:(a,p)=>(p&&typeof p=="object"&&"status"in p?p.status:void 0)===404?!1:a<2,staleTime:6e4}),C=M.data?.data??null,{entry:i,story:m}=l.useMemo(()=>{if(!C)return{entry:null,story:null};const{entries:a,storiesMap:p}=Ls([C]),g=a[0]??null;return{entry:g,story:g?p[g.storyId]??null:null}},[C]),L=l.useMemo(()=>(C?.collections??[]).map(a=>({collectionId:a.collection_id,href:`/collections/${a.collection_id}`,title:a.title})),[C?.collections]),h=l.useMemo(()=>{const a=i?.storyUpdate;if(!s||!i||!m||!a)return null;const p=a.chapter_number?`Chapter ${a.chapter_number}`:"New chapter",g=a.kind==="new_chapter"?a.chapter_title?`${p} · ${a.chapter_title}`:`${p} announced`:a.kind==="backdated_work"?"Backdated work announced":"New work announced";return{id:`library:${i.id}`,groupKey:`library:${i.id}`,announcementSequence:a.announcement_sequence,libraryEntryId:i.id,kind:a.kind,title:m.title,byline:"Saved in your Library",latestAnnouncement:g,announcedAt:a.announced_at,announcedChapterHref:a.open_url,additionalAnnouncementCount:0,unseen:a.is_unseen,storyHref:`/library/${i.id}`}},[i,m,s]),f=l.useRef(null),w=as({mutationFn:a=>r.acknowledgeStoryUpdates({items:[{group_key:a.groupKey,announcement_sequence:a.announcementSequence}]}),onSuccess:async()=>{await Promise.all([d.invalidateQueries({queryKey:D.library.detail(t)}),d.invalidateQueries({queryKey:D.library.all}),d.invalidateQueries({queryKey:D.watches.all}),d.invalidateQueries({queryKey:D.collections.all})])}});l.useEffect(()=>{!s||!h?.unseen||f.current?.entryId!==t&&(f.current={entryId:t,item:h},w.mutate(h))},[h,t,s,w]);const P=l.useCallback(()=>{const a=f.current;!a||a.entryId!==t||w.mutate(a.item)},[w,t]),F=l.useRef(0),E=l.useCallback(()=>{d.invalidateQueries({queryKey:D.library.detail(t)}),d.invalidateQueries({queryKey:D.suggestions}),d.invalidateQueries({queryKey:D.stats.all})},[t,d]),$=l.useCallback((a=!1)=>{d.invalidateQueries({queryKey:D.library.all}),d.invalidateQueries({queryKey:D.suggestions}),d.invalidateQueries({queryKey:D.stats.all}),a&&d.invalidateQueries({queryKey:D.me})},[d]),{updateEntry:v,queuePatch:y,flushNow:I}=Rs({patchEntry:r.patchEntry,queryKeyPrefix:D.library.all,flushMs:dt,onPatchSettled:E,onPatchSuccess:({entryId:a,patch:p})=>{hs(a,p),ps()},onPatchError:a=>{if(a.status!==429){j("Could not save change");return}const p=Date.now();if(p-F.current<4e3)return;F.current=p;const g=a.retryAfterSec,A=typeof g=="number"&&g>0?` Try again in ~${g}s.`:"";j(`Too many updates too quickly.${A} Saving will resume in a moment.`,5e3)}});l.useEffect(()=>()=>I(t),[t,I]);const[X,O]=l.useState(0),[H,ee]=l.useState([]),[q,se]=l.useState(""),[te,z]=l.useState(""),[W,Q]=l.useState(!1),V=l.useRef(null);l.useEffect(()=>{if(i){if(V.current!==i.id){const a=i.notes||"";V.current=i.id,se(a),z(a),Q(!1)}ee([...i.tags||[]]),O(typeof i.progress?.value=="number"?i.progress.value:0)}},[i]);const R=l.useCallback(a=>
1{if(i)return v(i.id,a)},[i,v]),T=l.useCallback(a=>{i&&y(i.id,a)},[i,y]),ie=q!==te,Pe=l.useCallback(async()=>{if(!i||W||!ie)return;const a=q;Q(!0);try{await R({notes:a}),z(a)}catch{}finally{Q(!1)}},[q,i,ie,W,R]),[Fe,oe]=l.useState(!1),[Oe,ue]=l.useState(!1),[Ue,le]=l.useState(!1),[$e,he]=l.useState(!1),[Ie,pe]=l.useState(!1),ae=l.useMemo(()=>{const a=n.state;if(!a||typeof a!="object")return"/";const p=a.libraryReturnTo;return typeof p=="string"&&(p==="/"||p.startsWith("/?"))?p:"/"},[n.state]),me=l.useCallback(()=>{I(t),o(ae)},[t,I,ae,o]),Ke=l.useCallback(async()=>{if(i){ue(!0);try{await r.deleteEntry(i.id),oe(!1),$(!0),o(ae)}catch(a){console.error(a),j("Failed to remove")}finally{ue(!1)}}},[r,i,$,ae,o,j]),qe=l.useCallback(async()=>{if(!(!i||!m)){he(!0);try{await r.startReread(i.id),le(!1),j("Reread started"),$(!1),d.invalidateQueries({queryKey:D.library.detail(i.id)});const a=de(m);a&&window.location.assign(a)}catch(a){console.error(a),j("Failed to start re-read")}finally{he(!1)}}},[r,i,$,j,d,m]),Be=l.useCallback(async()=>{if(!(!i||!m||i.status!=="SAVED")){pe(!0);try{await R(ye(i,m,"READING"));const a=de(m);a&&window.location.assign(a)}catch{}finally{pe(!1)}}},[i,R,m]),He=l.useCallback(async(a,p)=>{if(i)try{const g=await r.updateReadingHistoryDate(i.id,a,p);d.setQueryData(D.library.detail(i.id),A=>A&&{...A,data:{...A.data,reading_history:A.data.reading_history.map(fe=>fe.read_number===a?g.data:fe)}}),d.invalidateQueries({queryKey:D.stats.all}),j(p.completedOn?"Finish date updated":"Finish date set to unknown")}catch(g){throw console.error(g),j("Could not update finish date"),g}},[r,i,j,d]),ze=l.useCallback(a=>{O(a),i&&T({progress:{...i.progress,unit:"CHAPTER",value:a}})},[i,T]),We=l.useCallback(a=>
1{if(!i)return;const p=ye(i,m??void 0,a),g=R(p);if(typeof p.progress?.value=="number"&&O(p.progress.value),a==="FINISHED"&&i.status!=="FINISHED"){const A=Es(i);j("Finished today",5e3,{label:"Undo",onClick:async()=>{await g?.catch(()=>{}),await R(A)?.catch(()=>{}),O(A.progress?.value??0),j("Completion undone")}})}},[i,R,j,m]),Qe=l.useCallback(a=>{if(!i)return;const p=typeof i.progress.total=="number"?Math.min(i.progress.total,a):a;O(p),T({progress:{...i.progress,unit:"CHAPTER",value:p}})},[i,T]),Ve=l.useCallback(a=>{R({story_snapshot:a?{work_status_override:a,abandoned_at_chapters_published:a==="abandoned"?void 0:null}:{work_status_override:null,abandoned_at_chapters_published:null}})},[R]),Ye=l.useCallback(a=>{if(!i||a==null||a<1)return;const p=Math.max(0,i.progress.value||0),g=p>a?a:p;O(g),T({progress:{...i.progress,unit:"CHAPTER",value:g,total:a}})},[i,T]),Ge=l.useCallback(async()=>{if(!i||!m)return;const a=Ce(m,i);if(!a){j("No source URL to copy");return}try{await navigator.clipboard.writeText(a),j("Story link copied")}catch(p){console.error(p),j("Could not copy story link")}},[i,j,m]),Ze=m?.title?`${m.title} · trace`:"Story detail · trace";return e.jsxs(e.Fragment,{children:[e.jsx(ns,{children:e.jsx("title",{children:Ze})}),e.jsxs(ds,{className:"archive-editorial-shell story-detail-route-shell",mobilePrimaryNavHidden:!0,children:[e.jsx("div",{className:"library-main-canvas story-detail-route-canvas",children:e.jsx("div",{className:"story-detail-route-wrap",children:M.isLoading?e.jsx(be,{variant:"loading",title:"Loading story detail",description:"Fetching your saved story and reading state.",loadingRows:3}):M.isError||!i||!m?e.jsx(be,{variant:"error",title:"Story detail unavailable",description:ut(M.error)??"We couldn't load this library entry.",actions:e.jsx("button",{className:"sd-footer-button",onClick:me,type:"button",children:"Back to library"})}):e.jsxs(e.Fragment,{children:[h?e.jsx("div",{className:"mb-4",children:e.jsx(_s,{item:h,acknowledgementPending:w.isPending,acknowledgementError:w.isError?us(w.error):null,onRetryAcknowledgement:P})}):null,e.jsx(ct,{collections:L,draftNotes:q,draftProgressValue:X,draftTags:H,entry:i,story:m,onClose:me,onStartReread:()=>le(!0),onStartReading:Be,startReadingPending:Ie,onChangeStatus:We,onChangeRating:a=>R({rating:a}),setDraftProgressValue:ze,onTagsChange:a=>{ee(a),T({tags:a})},onNotesChange:a=>{se(a)},notesDirty:ie,notesSavePending:W,onSaveNotes:Pe,onCatchUp:Qe,onSetWorkStatusOverride:Ve,onCommitProgressTotal:Ye,onCommitLastReadAt:a=>T({lastReadAt:a}),readingHistory:C?.reading_history??[],onUpdateReadingHistory:He,onOpenCollection:a=>{I(t),o(`/collections/${a}`)},onAddToCollection:()=>{c.openForEntry(i,m)},onRemove:()=>oe(!0),onShare:Ge,showMobileBar:!1})]})})}),e.jsx(Ts,{open:c.open,target:c.target,onClose:c.close,onSuccess:(a,p)=>{const g=p?.collection;g&&i&&d.setQueryData(D.library.detail(i.id),A=>ht(A,{collection_id:g.collection_id,title:g.title})),j(a,4500)}}),e.jsx(je,{open:Ue,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",loading:$e,surface:"archive",onConfirm:qe,onCancel:()=>le(!1)}),e.jsx(je,{open:Fe,title:"Remove from library",description:"Remove this story from your library? This can't be undone.",confirmLabel:"Remove",variant:"danger",loading:Oe,onConfirm:Ke,onCancel:()=>oe(!1)}),e.jsx(As,{message:b,action:u})]})]})}export{gt 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.