1import{r as d,s as j,j as e,C as f,d as N,$ as B,B as i,L as w,e as F,f as S,D as k,h as y,a0 as b,i as _,F as q,N as T}from"./index-C-GMF1w8.js";import{u as R}from"./useDigitalDownload-DC86wq7l.js";const H=()=>{const[l,v]=d.useState([]),[D,C]=d.useState(!0),{downloadDigitalProduct:L,downloading:c}=R(),{toast:E}=T();d.useEffect(()=>{P()},[]);const P=async()=>{try{const{data:{user:s}}=await j.auth.getUser();if(!s)return;const{data:t,error:a}=await j.from("order_items").select(` 2 *, 3 orders!inner ( 4 id, 5 order_number, 6 payment_status, 7 created_at 8 ), 9 products!inner ( 10 id, 11 title, 12 is_digital, 13 download_limit, 14 file_format, 15 product_images (image_url, is_primary) 16 ) 17 `).eq("orders.buyer_id",s.id).eq("orders.payment_status","paid").eq("is_digital",!0).order("created_at",{ascending:!1});if(a)throw a;v(t||[])}catch(s){console.error("Error fetching digital products:",s),E({title:"Error",description:"Failed to load your digital library",variant:"destructive"})}finally{C(!1)}};return D?e.jsx("div",{className:"container mx-auto px-4 py-8",children:e.jsxs("div",{className:"animate-pulse space-y-4",children:[e.jsx("div",{className:"h-8 bg-muted rounded w-1/4"}),e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:[1,2,3].map(s=>e.jsx("div",{className:"h-48 bg-muted rounded"},s))})]})}):e.jsxs("main",{className:"container mx-auto px-4 py-8",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl font-bold mb-2",children:"Digital Library"}),e.jsx("p",{className:"text-muted-foreground",children:"Access all your purchased digital products"})]}),l.length===0?e.jsx(f,{children:e.jsxs(N,{className:"text-center py-12",children:[e.jsx(B,{className:"h-16 w-16 text-muted-foreground mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"No Digital Products Yet"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"You haven't purchased any digital products yet"}),e.jsx(i,{asChild:!0,children:e.jsx(w,{to:"/search",children:"Browse Products"})})]})}):e.jsx("div",{className:"grid gap-6 md:grid-cols-2 lg:grid-cols-3",children:l.map(s=>{var u,m,x,h,p,g;const t=new Date(s.download_expires_at),a=t<new Date,n=((u=s.products)==null?void 0:u.download_limit)||3,r=n-(s.download_count||0),o=(x=(m=s.products)==null?void 0:m.product_images)==null?void 0:x.find(A=>A.is_primary);return e.jsxs(f,{className:a?"opacity-60":"",children:[e.jsxs(F,{className:"pb-4",children:[o&&e.jsx("img",{src:o.image_url,alt:(h=s.products)==null?void 0:h.title,className:"w-full h-32 object-cover rounded mb-4"}),e.jsx(S,{className:"text-lg",children:(p=s.products)==null?void 0:p.title})]}),e.jsxs(N,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Format:"}),e.jsx(k,{variant:"secondary",children:(g=s.products)==null?void 0:g.file_format})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Downloads:"}),e.jsxs("span",{className:"font-medium",children:[r," / ",n]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Purchased:"}),e.jsx("span",{children:new Date(s.orders.created_at).toLocaleDateString()})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Expires:"}),e.jsx("span",{className:a?"text-destructive":"",children:t.toLocaleDateString()})]})]}),a&&e.jsxs(y,{variant:"destructive",children:[e.jsx(b,{className:"h-4 w-4"}),e.jsx(_,{children:"Download link expired. Contact support for assistance."})]}),r===0&&!a&&e.jsxs(y,{children:[e.jsx(b,{className:"h-4 w-4"}),e.jsx(_,{children:"Download limit reached. Contact support if you need additional downloads."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(i,{onClick:()=>L(s.id),disabled:c||a||r===0,className:"flex-1",children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),c?"Downloading...":"Download"]}),e.jsx(i,{variant:"outline",asChild:!0,children:e.jsx(w,{to:`/orders/${s.orders.id}`,children:"View Order"})})]})]})]},s.id)})})]})};export{H 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.