import{bt as y,r as d,a as g,u as P,aE as D,m as I,p as z}from"./gmbjJHmd.js";const E=y`
fragment MagazineEntryFragment on magazines_default_Entry {
id
postDate
title
uri
volume
issue
year
jstorId
coverImage @skip(if: $skipDetails) {
... on images_Asset {
id
uid
title
alt
url
height
width
filename
caption
}
}
tableOfContents {
... on tableOfContents_contentItem_BlockType {
id
item {
id
title
uri
... on poems_default_Entry {
authors(status: ["live", "disabled"]) {
id
title
uri
}
}
... on articles_legacy_Entry {
authors(status: ["live", "disabled"]) {
id
title
uri
}
}
... on articles_default_Entry {
authors(status: ["live", "disabled"]) {
id
title
uri
}
}
}
jstorId
pages {
pageStart
pageEnd
jstorPageStart
jstorPageEnd
}
}
}
}
`;y`
query MagazineEntries($volume: [QueryArgument]!, $issue: [QueryArgument]!, $skipDetails: Boolean = false) {
magazinesEntries(volume: $volume, issue: $issue, limit: 1) {
...MagazineEntryFragment
}
}
${E}
`;const b=y`
query MagazineEntries($prevPostDate: String, $nextPostDate: String, $skipDetails: Boolean = true) {
prevIssue: magazinesEntries(before: $prevPostDate, limit: 1, orderBy: "postDate DESC") {
...MagazineEntryFragment
}
nextIssue: magazinesEntries(after: $nextPostDate, limit: 1, orderBy: "postDate ASC") {
...MagazineEntryFragment
}
}
${E}
`,h=y`
query MagazineEntries($volume: [QueryArgument]!, $issue: [QueryArgument]!, $skipDetails: Boolean = false) {
magazinesEntries(volume: $volume, issue: $issue, limit: 1) {
...MagazineEntryFragment
}
}
${E}
`,l=t=>{const u=Array.isArray(t)?t[0]:t;return u===void 0?0:parseInt(u,10)},q=t=>{if(!t)return"";const u=Object.keys(t).reduce((o,s)=>{var e;return{...o,[s]:(e=t[s])==null?void 0:e.toString()}},{});return`?${new URLSearchParams(u).toString()}`},_=(t,{page:u,contentId:i})=>{const o=l(i),s=u||d(0),{tocRows:e,tocPages:r,issueData:c}=M(t),v=g(()=>!t.value||!s.value?null:`https://static.poetryfoundation.org/jstor/${t.value.jstorId}/pages/${m.value}.png`),m=g(()=>{var a,n;return s.value?s.value:((n=(a=p.value)==null?void 0:a[0])==null?void 0:n.pages[0])||0}),p=g(()=>{var a;return(a=e.value)==null?void 0:a.filter(n=>{var $;return o?(($=n==null?void 0:n.entry)==null?void 0:$.id)===o.toString():n==null?void 0:n.pages.includes(s.value)})}),f=g(()=>{var a;return((a=p.value)==null?void 0:a.map(n=>n.entry))||[]});return{contentImage:v,contentPage:m,currentContentEntries:f,currentTocRows:p,issueData:c,tocPages:r,tocRows:e}},M=t=>{const u=g(()=>{var s;return(s=t.value)==null?void 0:s.tableOfContents.map(e=>{if(!e.pages)return;const[r]=e.pages;if(!r)return;const[c]=(e==null?void 0:e.item)||[];return{entry:c,jstorId:e.jstorId,pages:Array.from({length:r.jstorPageEnd-r.jstorPageStart+1},(v,m)=>m+r.jstorPageStart),...r}}).filter(e=>e)}),i=g(()=>{var s;return u.value?(s=u.value)==null?void 0:s.reduce((e,r)=>r?[...e,...r.pages]:e,[]).filter(e=>e).sort((e,r)=>e-r):[]}),o=g(()=>{var s,e,r;return{postDate:((s=t.value)==null?void 0:s.postDate)||"",volume:parseInt(((e=t.value)==null?void 0:e.volume)||""),issue:parseInt(((r=t.value)==null?void 0:r.issue)||""),firstPage:i.value.at(0),lastPage:i.value.at(-1)}});return{tocPages:i,tocRows:u,issueData:o}},A=async()=>{const t=P(),u=d(l(t.query.volume)),i=d(l(t.query.issue)),o=d(l(t.query.page)),s=D({volume:l(t.query.volume),issue:l(t.query.issue)}),{data:e,refresh:r,pending:c}=await I(h,s),v=g(()=>{var a,n;return(n=(a=e.value)==null?void 0:a.magazinesEntries)==null?void 0:n[0]}),{contentImage:m,currentContentEntries:p,issueData:f}=_(v,{page:o});return z(()=>t.query,async a=>{a.volume&&(u.value=l(a.volume)),a.issue&&(i.value=l(a.issue)),a.page&&(o.value=l(a.page))}),z([u,i],([a,n])=>{s.volume=a,s.issue=n,r()}),{volume:u,issue:i,page:o,magazineEntry:v,issueData:f,currentContentEntries:p,contentImage:m,pending:c}};export{b as M,A as a,E as b,q as c,_ as d,M as u};