1import{r as t,e as v,j as e,B as i,C as L}from"./edge-BOITG1XR.js";import{C as f,c as g,a as D,b as S}from"./mod-DgQ0OFXm.js";import{I as P}from"./mod-BUsEZZHX.js";import{D as y}from"./mod-LfxHWGtW.js";import{R as k}from"./mod-RPxq32x0.js";import{S as R}from"./mod-CKg_ZYcm.js";import{C as z}from"./mod-B33gStZf.js";import{C as A}from"./mod-E2spV6fa.js";import{C as _}from"./mod-Dzi2dmtd.js";import{E as T}from"./mod-B_npTkgx.js";import{C as B}from"./mod-qF7UVkYF.js";const U=()=>{const[r,o]=t.useState([]),[d,N]=t.useState(!0),[c,C]=t.useState(""),[l,m]=t.useState(1),[x,b]=t.useState(0),w=25,h=t.useCallback(async()=>{N(!0);try{const s=await v.get("/admin/download-links",{params:{search:c,page:l,per_page:w}});o(s.data?.data||s.data||[]),b(s.data?.total||0)}catch{try{const s=await v.get("/admin/orders",{params:{per_page:100}}),j=s.data?.data||s.data||[],n=[];j.forEach(a=>{a.download_links&&a.download_links.forEach(E=>{n.push({...E,order_id:a.id,customer_name:a.user?.name||"N/A",customer_email:a.user?.email||"N/A"})})}),o(n),b(n.length)}catch{o([])}}finally{N(!1)}},[c,l]);t.useEffect(()=>{h()},[h]);const p=Math.ceil(x/w),u=s=>s?new Date(s)<new Date:!1;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(y,{className:"w-6 h-6 text-blue-600"})," Download Links Manager"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Track all download links issued to customers for digital products."})]}),e.jsxs(i,{variant:"outline",size:"sm",onClick:h,disabled:d,children:[e.jsx(k,{className:`w-4 h-4 mr-1 ${d?"animate-spin":""}`})," Refresh"]})]}),e.jsx(f,{children:e.jsx(g,{className:"pt-4",children:e.jsxs("div",{className:"relative",children:[e.jsx(R,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(P,{placeholder:"Search by product name, token, or customer...",value:c,onChange:s=>{C(s.target.value),m(1)},className:"pl-9"})]})})}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Total Links",value:x,icon:y,color:"text-blue-600"},{label:"Active",value:r.filter(s=>!u(s.expires_at)&&(s.remaining_downloads===null||s.remaining_downloads>0)).length,icon:z,color:"text-emerald-600"},{label:"Expired",value:r.filter(s=>u(s.expires_at)).length,icon:A,color:"text-red-600"},{label:"Exhausted",value:r.filter(s=>s.remaining_downloads!==null&&s.remaining_downloads<=0).length,icon:_,color:"text-amber-600"}].map(s=>e.jsx(f,{children:e.jsx(g,{className:"pt-4 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.icon,{className:`w-5 h-5 ${s.color}`}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:s.value}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s.label})]})]})})},s.label))}),e.jsxs(f,{children:[e.jsx(D,{className:"pb-2",children:e.jsx(S,{className:"text-base",children:"Download Links"})}),e.jsxs(g,{children:[d?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{className:"w-6 h-6 animate-spin text-blue-500"})}):r.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(_,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:"No download links found."}),e.jsx("p",{className:"text-xs mt-1",children:"Links are created when a digital order is fulfilled."})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-left text-xs font-semibold text-muted-foreground uppercase tracking-wider",children:[e.jsx("th",{className:"py-2 pr-3",children:"Product"}),e.jsx("th",{className:"py-2 pr-3",children:"Customer"}),e.jsx("th",{className:"py-2 pr-3",children:"Order"}),e.jsx("th",{className:"py-2 pr-3",children:"Downloads"}),e.jsx("th",{className:"py-2 pr-3",children:"Expires"}),e.jsx("th",{className:"py-2 pr-3",children:"Status"}),e.jsx("th",{className:"py-2",children:"Link"})]})}),e.jsx("tbody",{children:r.map((s,j)=>{const n=u(s.expires_at),a=s.remaining_downloads!==null&&s.remaining_downloads<=0;return e.jsxs("tr",{className:"border-b last:border-0 hover:bg-gray-50",children:[e.jsx("td",{className:"py-2.5 pr-3 font-medium",children:s.product_name||s.product?.name||s.file_name||"Digital Product"}),e.jsxs("td",{className:"py-2.5 pr-3",children:[e.jsx("div",{className:"text-xs",children:s.customer_name||s.user?.name||"â"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.customer_email||s.user?.email||""})]}),e.jsxs("td",{className:"py-2.5 pr-3 text-xs text-muted-foreground",children:["#",s.order_id]}),e.jsxs("td",{className:"py-2.5 pr-3",children:[e.jsx("span",{className:"text-sm font-semibold",children:s.download_count||0}),s.remaining_downloads!==null&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:[" / ",s.max_downloads||"â"]})]}),e.jsx("td",{className:"py-2.5 pr-3 text-xs text-muted-foreground",children:s.expires_at?new Date(s.expires_at).toLocaleDateString():"Never"}),e.jsx("td",{className:"py-2.5 pr-3",children:n?e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-semibold bg-red-100 text-red-700",children:"Expired"}):a?e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-semibold bg-amber-100 text-amber-700",children:"Exhausted"}):e.jsx("span",{className:"px-2 py-0.5 rounded-full text-xs font-semibold bg-emerald-100 text-emerald-700",children:"Active"})}),e.jsx("td",{className:"py-2.5",children:s.token&&e.jsx(i,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx("a",{href:`/api/downloads/${s.token}`,target:"_blank",rel:"noopener noreferrer",children:e.jsx(T,{className:"w-3.5 h-3.5"})})})})]},s.id||j)})})]})}),p>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4 pt-3 border-t",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Page ",l," of ",p," (",x," total)"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(i,{variant:"outline",size:"sm",disabled:l<=1,onClick:()=>m(s=>s-1),children:e.jsx(B,{className:"w-4 h-4"})}),e.jsx(i,{variant:"outline",size:"sm",disabled:l>=p,onClick:()=>m(s=>s+1),children:e.jsx(L,{className:"w-4 h-4"})})]})]})]})]})]})};export{U 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.