1import{r,j as e,L as x,J as R,_ as T}from"./index-W04rzwDS.js";import{r as B}from"./ProductImage-DxdKdEFd.js";import{S as P}from"./StoreCollectionCard-CcbwgzEW.js";import{S as E}from"./StorefrontSkeleton-CcfRzVRz.js";import"./ProductCardShell-DkRiI_im.js";const $=[{value:"updated_desc",label:"Last updated · newest first"},{value:"updated_asc",label:"Last updated · oldest first"},{value:"name_asc",label:"Title · AâZ"},{value:"name_desc",label:"Title · ZâA"},{value:"sku_asc",label:"Product ID · ascending"},{value:"sku_desc",label:"Product ID · descending"}];function M(l){return[l.category,l.subCategory].filter(Boolean).join(" / ")}function c(l){if(!l)return"";const o=new Date(l);return Number.isNaN(o.getTime())?l:new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric"}).format(o)}function q(l){return[l.status,l.lastUpdatedAt?`Updated: ${c(l.lastUpdatedAt)}`:"",l.lastDownloadedAt?`Last downloaded: ${c(l.lastDownloadedAt)}`:"",l.releaseDate?`Release: ${c(l.releaseDate)}`:""].filter(Boolean).join(" · ")}function H(l,o){if(!l)return!1;const d=new Date(l).getTime();return Number.isNaN(d)?!1:d>=Date.now()-o*24*60*60*1e3}function z(){const[l,o]=r.useState(null),[d,m]=r.useState(!0),[v,N]=r.useState(null),[I,b]=r.useState(!1),[y,D]=r.useState("updated_desc"),[g,S]=r.useState(""),[n,C]=r.useState(""),[u,f]=r.useState(""),[p,L]=r.useState("all"),[h,U]=r.useState("all"),[i,k]=r.useState("all");async function _(a){m(!0),N(null);try{const s=await T({sort:a});if(!s.ok){b(!0),o(null);return}b(!1),o(s.data??null)}catch(s){b(!1),N(s instanceof Error?s.message:"Library request failed")}finally{m(!1)}}r.useEffect(()=>{_(y)},[y]);const A=r.useMemo(()=>l?Array.from(new Set(l.items.map(a=>a.category).filter(Boolean))).sort((a,s)=>a.localeCompare(s)):[],[l]),O=r.useMemo(()=>l?Array.from(new Set(l.items.filter(a=>!n||a.category===n).map(a=>a.subCategory).filter(Boolean))).sort((a,s)=>a.localeCompare(s)):[],[l,n]),w=r.useMemo(()=>{if(!l)return[];const a=g.trim().toLocaleLowerCase(),s=h==="all"?null:Number(h);return l.items.filter(t=>!(a&&![t.description,t.productId,t.category,t.subCategory,t.status,t.downloadableFilename].filter(Boolean).join(" ").toLocaleLowerCase().includes(a)||n&&t.category!==n||u&&t.subCategory!==u||p==="ready"&&!t.hasDownloadFile||p==="pending"&&t.hasDownloadFile||s!==null&&!H(t.lastUpdatedAt,s)||i==="updated"&&t.downloadState!=="updated_since_download"||i==="current"&&t.downloadState!=="up_to_date"||i==="unrecorded"&&t.downloadState!=="no_recorded_download"))},[l,g,n,u,p,h,i]);function F(){S(""),C(""),f(""),L("all"),U("all"),k("all"),D("updated_desc")}if(d&&!l)return e.jsx(E,{title:"Digital library",message:"Loading owned downloads and file availabilityâ¦",layout:"library"});if(v)return e.jsx("p",{className:"error",children:v});if(I)return e.jsxs("section",{className:"stack",children:[e.jsxs("div",{className:"panel",children:[e.jsx("h2",{children:"Digital library"}),e.jsx("p",{className:"muted",children:"Please sign in to access your owned downloads."})]}),e.jsxs("div",{className:"result-card",children:[e.jsx("p",{className:"error",children:"Please log in to view owned downloads."}),e.jsx(x,{className:"button-link",to:"/account",children:"Go to account login"})]})]});if(!l||!l.meta.hasItems)return e.jsx("section",{className:"stack",children:e.jsxs("div",{className:"panel",children:[e.jsx("div",{className:"page-header",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Digital library"}),e.jsx("p",{className:"muted",children:"Owned downloadable titles will appear here after purchase. This page is your download center: open purchased digital products, check file availability, and download ready files again whenever you need them."})]})}),e.jsxs("div",{className:"result-card",children:[e.jsx("p",{children:"No downloadable purchases were found for this account yet."}),e.jsx(x,{className:"button-link empty-state-browse-button",to:"/products",children:"Browse products"})]})]})});const j=l.meta.updatedSinceLastDownloadCount??0;return e.jsxs("section",{className:"stack",children:[e.jsx("div",{className:"panel",children:e.jsx("div",{className:"page-header",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Digital library"}),e.jsxs("p",{className:"muted",children:[l.meta.count," owned download",l.meta.count===1?"":"s"," in your library."]}),e.jsx("p",{className:"muted compact-copy",children:"Search your collection, filter it, and sort by actual downloadable-file update time, title, or product ID."}),l.meta.downloadHistoryAvailable&&j>0?e.jsxs("p",{className:"muted compact-copy",children:[j," title",j===1?" has":"s have"," been updated since your last recorded download."]}):null]})})}),e.jsxs("div",{className:"catalog-toolbar catalog-toolbar-panel","aria-label":"Digital library filters",children:[e.jsxs("div",{className:"catalog-filters catalog-filters-inline",children:[e.jsx("input",{type:"search",value:g,onChange:a=>S(a.target.value),placeholder:"Search title, product ID, categoryâ¦","aria-label":"Search digital library"}),e.jsxs("select",{value:n,onChange:a=>{C(a.target.value),f("")},"aria-label":"Filter by category",children:[e.jsx("option",{value:"",children:"Category · all"}),A.map(a=>e.jsx("option",{value:a,children:a},a))]}),e.jsxs("select",{value:u,onChange:a=>f(a.target.value),"aria-label":"Filter by subcategory",children:[e.jsx("option",{value:"",children:"Subcategory · all"}),O.map(a=>e.jsx("option",{value:a,children:a},a))]}),e.jsxs("select",{value:p,onChange:a=>L(a.target.value),"aria-label":"Filter by download availability",children:[e.jsx("option",{value:"all",children:"Files · all"}),e.jsx("option",{value:"ready",children:"Ready to download"}),e.jsx("option",{value:"pending",children:"File pending"})]}),e.jsxs("select",{value:h,onChange:a=>U(a.target.value),"aria-label":"Filter by last update",children:[e.jsx("option",{value:"all",children:"Updated · anytime"}),e.jsx("option",{value:"7",children:"Updated · last 7 days"}),e.jsx("option",{value:"30",children:"Updated · last 30 days"}),e.jsx("option",{value:"90",children:"Updated · last 90 days"})]}),e.jsxs("select",{value:i,onChange:a=>k(a.target.value),"aria-label":"Filter by download history",children:[e.jsx("option",{value:"all",children:"Download history · all"}),e.jsx("option",{value:"updated",children:"Updated since last download"}),e.jsx("option",{value:"current",children:"Downloaded · up to date"}),e.jsx("option",{value:"unrecorded",children:"No recorded download"})]}),e.jsx("select",{value:y,onChange:a=>D(a.target.value),"aria-label":"Sort digital library",children:$.map(a=>e.jsx("option",{value:a.value,children:a.label},a.value))}),e.jsx("div",{className:"catalog-filter-actions",children:e.jsx("button",{type:"button",className:"button-secondary",onClick:F,children:"Reset"})})]}),e.jsxs("p",{className:"muted compact-copy","aria-live":"polite",children:["Showing ",w.length," of ",l.meta.count," title",l.meta.count===1?"":"s",".",d?" Updating sortâ¦":""]})]}),w.length===0?e.jsxs("div",{className:"result-card",children:[e.jsx("p",{children:"No downloads match the current filters."}),e.jsx("button",{type:"button",className:"button-secondary",onClick:F,children:"Clear filters"})]}):e.jsx("div",{className:"library-grid product-grid-catalog",children:w.map(a=>{var s,t;return e.jsx(P,{href:`/products/${encodeURIComponent(a.productId)}`,title:a.description,productId:a.productId,categoryLabel:M(a),priceLabel:a.price||"â",summary:q(a),imageUrl:B(a.image,{width:360,format:"webp"}),imageAlt:a.description,cornerBadge:a.updatedSinceLastDownload?"Update available":a.hasDownloadFile?"Owned download":"Owned item",badges:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"badge",children:["Owned à ",a.quantity]}),a.hasDownloadFile?e.jsx("span",{className:"badge badge-accent",children:"Ready to download"}):e.jsx("span",{className:"badge subtle",children:"File pending"}),a.updatedSinceLastDownload?e.jsx("span",{className:"badge badge-accent",children:"Updated since your last download"}):null,a.downloadState==="up_to_date"?e.jsx("span",{className:"badge subtle",children:"Downloaded · up to date"}):null,a.downloadState==="no_recorded_download"?e.jsx("span",{className:"badge subtle",children:"No recorded download"}):null,a.lastDownloadedAt?e.jsxs("span",{className:"badge subtle",children:["Last downloaded ",c(a.lastDownloadedAt)]}):null,a.lastUpdatedAt?e.jsxs("span",{className:"badge subtle",children:["Updated ",c(a.lastUpdatedAt)]}):null,a.downloadableFilename?e.jsx("span",{className:"badge subtle",children:a.downloadableFilename}):null,(s=a.latestOrder)!=null&&s.orderId?e.jsxs("span",{className:"badge subtle",children:["Order ",a.latestOrder.orderId]}):null]}),actions:e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"button-link button-link-secondary",to:`/products/${encodeURIComponent(a.productId)}`,children:"View product"}),a.hasDownloadFile?e.jsx("a",{className:"button-link",href:R(a.productId,(t=a.latestOrder)==null?void 0:t.orderId),children:"Download now"}):e.jsx("span",{className:"button-link button-link-secondary disabled-action","aria-disabled":"true",children:"Download pending"})]})},a.productId)})})]})}export{z as LibraryPage};
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.