1import{r as h,u as R,j as e}from"./vendor-CSpQeQFa.js";import{C as i,c}from"./uploadLimits-Bk-o1hAt.js";import{B as f,R as C,C as S,s as $}from"./entry-main-PLc9_a6q.js";import{B as z}from"./BonusExpiryCountdown-DZAQV4Wx.js";import{I as V}from"./globalAnnouncements-nxd9yA1b.js";import{S as P,a as q,b as B,c as O,d as l}from"./contestPrizeTypes-lwm66WfQ.js";import{T as U,a as H,b as T,c as r,d as Q,e as n}from"./table-Dm0CIfFe.js";import{D as J,a as G,b as K,c as M,d as Y}from"./creationMetadata-DV63esj7.js";import{S as W}from"./skeleton-3ZprAnf9.js";import{a as X,g as Z,h as ee}from"./useProductHuntRedemption-zAUPPnZC.js";import{a as p}from"./zerionWallet-YD6NMGW7-anviiTIZ.js";import{R as k}from"./receipt-85vg7g1N.js";import{C as L}from"./blog-editorial-defaults-GYihUdxa.js";import{D as se}from"./prizeUtils-9swa3d5r.js";import{S as te}from"./plural-BbOexbm1.js";import{C as ae}from"./csvExport-B0IDrPcm.js";import{E as ie}from"./adCenterPlatform-Cp7ggMTG.js";const j={payment_initiated:{label:"Initiated",color:"bg-blue-500/20 text-blue-300 border-blue-500/30"},payment_verified:{label:"Verified",color:"bg-electric-cyan/20 text-cyan-300 border-electric-cyan/30"},contest_created:{label:"Completed",color:"bg-green-500/20 text-green-300 border-green-500/30"},payment_failed:{label:"Failed",color:"bg-red-500/20 text-red-300 border-red-500/30"},verification_failed:{label:"Verification Failed",color:"bg-orange-500/20 text-orange-300 border-orange-500/30"},contest_creation_failed:{label:"Creation Failed",color:"bg-red-500/20 text-red-300 border-red-500/30"}};function ve(){const[x,D]=h.useState("all"),[N,I]=h.useState(""),[t,g]=h.useState(null),[A,v]=h.useState(null),{data:d,isLoading:E,isError:u,refetch:_,isRefetching:m}=R({queryKey:["admin-payment-logs",x],queryFn:async()=>{let s=$.from("contest_payment_logs").select("*").order("created_at",{ascending:!1}).limit(200);x!=="all"&&(s=s.eq("event_type",x));const{data:a,error:y}=await s;if(y)throw y;return a||[]}}),w=d?.filter(s=>{if(!N)return!0;const a=N.toLowerCase();return s.user_email?.toLowerCase().includes(a)||s.contest_title?.toLowerCase().includes(a)||s.stripe_session_id?.toLowerCase().includes(a)||s.stripe_customer_id?.toLowerCase().includes(a)}),o={total:d?.length??0,completed:d?.filter(s=>s.event_type==="contest_created").length??0,failed:d?.filter(s=>["payment_failed","verification_failed","contest_creation_failed"].includes(s.event_type)).length??0,totalAmount:d?.filter(s=>s.event_type==="contest_created").reduce((s,a)=>s+(a.total_amount??a.prize_amount??0),0)??0},b=s=>u?"â":s.toLocaleString(),F=(s,a)=>{navigator.clipboard.writeText(s),v(a),setTimeout(()=>v(null),2e3)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-white",children:"Payment Logs"}),e.jsx("p",{className:"text-zinc-400 text-sm mt-1",children:"View and debug contest payment transactions"})]}),e.jsxs(f,{variant:"outline",onClick:()=>_(),disabled:m,className:"border-zinc-700 text-zinc-300 hover:bg-zinc-800",children:[e.jsx(C,{className:p("h-4 w-4 mr-2",m&&"animate-spin")}),"Refresh"]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(i,{className:"bg-zinc-900 border-zinc-800",children:e.jsx(c,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-500/10 rounded-lg",children:e.jsx(k,{className:"h-5 w-5 text-blue-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-zinc-400",children:"Total Events"}),e.jsx("p",{className:"text-2xl font-bold text-white",children:b(o.total)})]})]})})}),e.jsx(i,{className:"bg-zinc-900 border-zinc-800",children:e.jsx(c,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-green-500/10 rounded-lg",children:e.jsx(L,{className:"h-5 w-5 text-green-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-zinc-400",children:"Completed"}),e.jsx("p",{className:"text-2xl font-bold text-white",children:b(o.completed)})]})]})})}),e.jsx(i,{className:"bg-zinc-900 border-zinc-800",children:e.jsx(c,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-red-500/10 rounded-lg",children:e.jsx(S,{className:"h-5 w-5 text-red-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-zinc-400",children:"Failed"}),e.jsx("p",{className:"text-2xl font-bold text-white",children:b(o.failed)})]})]})})}),e.jsx(i,{className:"bg-zinc-900 border-zinc-800",children:e.jsx(c,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-purple-500/10 rounded-lg",children:e.jsx(se,{className:"h-5 w-5 text-purple-400"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-zinc-400",children:"Total Revenue"}),e.jsx("p",{className:"text-2xl font-bold text-white",children:u?"â":`$${o.totalAmount.toLocaleStr
1ing()}`})]})]})})})]}),e.jsx(i,{className:"bg-zinc-900 border-zinc-800",children:e.jsx(c,{className:"p-4",children:e.jsxs("div",{className:"flex flex-col md:flex-row gap-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(te,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-zinc-500"}),e.jsx(V,{placeholder:"Search by email, contest, or Stripe ID...",value:N,onChange:s=>I(s.target.value),className:"pl-9 bg-zinc-800 border-zinc-700 text-white"})]}),e.jsxs(P,{value:x,onValueChange:D,children:[e.jsx(q,{className:"w-full md:w-[200px] bg-zinc-800 border-zinc-700 text-white",children:e.jsx(B,{placeholder:"Filter by status"})}),e.jsxs(O,{className:"bg-zinc-800 border-zinc-700",children:[e.jsx(l,{value:"all",children:"All Events"}),e.jsx(l,{value:"payment_initiated",children:"Initiated"}),e.jsx(l,{value:"payment_verified",children:"Verified"}),e.jsx(l,{value:"contest_created",children:"Completed"}),e.jsx(l,{value:"payment_failed",children:"Failed"}),e.jsx(l,{value:"verification_failed",children:"Verification Failed"})]})]})]})})}),e.jsx(i,{className:"bg-zinc-900 border-zinc-800",children:e.jsx(c,{className:"p-0",children:E?e.jsx("div",{className:"p-6 space-y-4",children:[...Array(5)].map((s,a)=>e.jsx(W,{className:"h-12 w-full bg-zinc-800"},a))}):u?e.jsxs("div",{className:"p-12 text-center",children:[e.jsx(S,{className:"h-12 w-12 text-red-400 mx-auto mb-4"}),e.jsx("p",{className:"text-red-400 font-medium",children:"Couldn't load payment logs"}),e.jsx("p",{className:"text-zinc-400 text-sm mt-1",children:"No transactions were read â this is not an empty ledger. Retry below."}),e.jsxs(f,{variant:"outline",onClick:()=>_(),disabled:m,className:"mt-4 border-zinc-700 text-zinc-300 hover:bg-zinc-800",children:[e.jsx(C,{className:p("h-4 w-4 mr-2",m&&"animate-spin")}),"Retry"]})]}):w?.length?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(U,{children:[e.jsx(H,{children:e.jsxs(T,{className:"border-zinc-800 hover:bg-transparent",children:[e.jsx(r,{className:"text-zinc-400",children:"Time"}),e.jsx(r,{className:"text-zinc-400",children:"User"}),e.jsx(r,{className:"text-zinc-400",children:"Contest"}),e.jsx(r,{className:"text-zinc-400",children:"Amount"}),e.jsx(r,{className:"text-zinc-400",children:"Status"}),e.jsx(r,{className:"text-zinc-400",children:"Actions"})]})}),e.jsx(Q,{children:w.map(s=>e.jsxs(T,{className:"border-zinc-800 hover:bg-zinc-800/50",children:[e.jsx(n,{className:"text-zinc-300",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm",children:X(s.created_at)}),e.jsx("span",{className:"text-xs text-zinc-500",children:Z(s.created_at)})]})}),e.jsx(n,{children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm text-white truncate max-w-[180px]",children:s.user_email||"â"}),s.stripe_customer_id&&e.jsxs("button",{onClick:()=>F(s.stripe_customer_id,s.id+"-cust"),className:"text-xs text-zinc-500 hover:text-zinc-300 flex items-center gap-1 truncate max-w-[180px]",children:[A===s.id+"-cust"?e.jsx(L,{className:"h-3 w-3"}):e.jsx(ae,{className:"h-3 w-3"}),s.stripe_customer_id]})]})}),e.jsxs(n,{children:[e.jsx("span",{className:"text-sm text-white truncate max-w-[200px] block",children:s.contest_title||"â"}),s.visibility!=null&&s.visibility!=="public"&&e.jsx(z,{variant:"outline",className:"mt-1 text-xs border-zinc-700 text-zinc-400",children:"Private"})]}),e.jsxs(n,{children:[e.jsx("span",{className:"text-sm text-white font-medium",children:s.total_amount!=null||s.prize_amount!=null?`$${(s.total_amount??s.prize_amount??0).toLocaleString()}`:"â"}),s.platform_fees&&s.platform_fees>0&&e.jsxs("span",{className:"text-xs text-zinc-500 block",children:["+$",s.platform_fees.toLocaleString()," fees"]})]}),e.jsxs(n,{children:[e.jsx(z,{variant:"outline",className:p("text-xs",j[s.event_type]?.color||"bg-zinc-500/20 text-zinc-300"),children:j[s.event_type]?.label||s.event_type}),s.error_message&&e.jsx("p",{className:"text-xs text-red-400 mt-1 truncate max-w-[120px]",title:s.error_message,children:s.error_message})]}),e.jsx(n,{children:e.jsx(f,{variant:"ghost",size:"sm",onClick:()=>g(s),className:"text-zinc-400 hover:text-white hover:bg-zinc-800",children:e.jsx(ie,{className:"h-4 w-4"})})})]},s.id))})]})}):e.jsxs("div",{className:"p-12 text-center",children:[e.jsx(k,{className:"h-12 w-12 text-zinc-600 mx-auto mb-4"}),e.jsx("p",{className:"text-zinc-400",children:"No payment logs found"})]})})}),e.jsx(J,{open:!!t,onOpenChange:()=>g(null),children:e.jsxs(G,{className:"bg-zinc-900 border-zinc-800 max-w-2xl max-h-[80vh] overflow-y-auto",children:[e.jsxs(K,{children:[e.jsx(M,{className:"text-white",children:"Payment Log Details"}),e.jsx(Y,{className:"text-zinc-400",children:"Full details for this payment event"})]}
1),t&&e.jsxs("div",{className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-zinc-500 uppercase tracking-wider",children:"Event Type"}),e.jsx(z,{variant:"outline",className:p("mt-1",j[t.event_type]?.color),children:j[t.event_type]?.label||t.event_type})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-zinc-500 uppercase tracking-wider",children:"Timestamp"}),e.jsx("p",{className:"text-sm text-white mt-1",children:ee(t.created_at)})]})]}),e.jsxs("div",{className:"border-t border-zinc-800 pt-4",children:[e.jsx("p",{className:"text-xs text-zinc-500 uppercase tracking-wider mb-2",children:"User Info"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Email:"})," ",e.jsx("span",{className:"text-white",children:t.user_email||"â"})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"User ID:"})," ",e.jsx("span",{className:"text-white font-mono text-xs",children:t.user_id||"â"})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"IP:"})," ",e.jsx("span",{className:"text-white",children:t.ip_address||"â"})]})]})]}),e.jsxs("div",{className:"border-t border-zinc-800 pt-4",children:[e.jsx("p",{className:"text-xs text-zinc-500 uppercase tracking-wider mb-2",children:"Contest Info"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Title:"})," ",e.jsx("span",{className:"text-white",children:t.contest_title||"â"})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Contest ID:"})," ",e.jsx("span",{className:"text-white font-mono text-xs",children:t.contest_id||"â"})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Visibility:"})," ",e.jsx("span",{className:"text-white capitalize",children:t.visibility||"â"})]})]})]}),e.jsxs("div",{className:"border-t border-zinc-800 pt-4",children:[e.jsx("p",{className:"text-xs text-zinc-500 uppercase tracking-wider mb-2",children:"Payment Info"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Prize Amount:"})," ",e.jsx("span",{className:"text-white",children:t.prize_amount!=null?`$${t.prize_amount.toLocaleString()}`:"â"})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Platform Fees:"})," ",e.jsx("span",{className:"text-white",children:t.platform_fees!=null?`$${t.platform_fees.toLocaleString()}`:"â"})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Total:"})," ",e.jsx("span",{className:"text-white font-semibold",children:t.total_amount!=null?`$${t.total_amount.toLocaleString()}`:"â"})]})]})]}),e.jsxs("div",{className:"border-t border-zinc-800 pt-4",children:[e.jsx("p",{className:"text-xs text-zinc-500 uppercase tracking-wider mb-2",children:"Stripe IDs"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Session:"})," ",e.jsx("span",{className:"text-white font-mono text-xs break-all",children:t.stripe_session_id||"â"})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Customer:"})," ",e.jsx("span",{className:"text-white font-mono text-xs break-all",children:t.stripe_customer_id||"â"})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"text-zinc-500",children:"Subscription:"})," ",e.jsx("span",{className:"text-white font-mono text-xs break-all",children:t.stripe_subscription_id||"â"})]})]})]}),t.error_message&&e.jsxs("div",{className:"border-t border-zinc-800 pt-4",children:[e.jsx("p",{className:"text-xs text-red-400 uppercase tracking-wider mb-2",children:"Error Message"}),e.jsx("p",{className:"text-sm text-red-300 bg-red-500/10 p-3 rounded-lg",children:t.error_message})]}),t.details&&Object.keys(t.details).length>0&&e.jsxs("div",{className:"border-t border-zinc-800 pt-4",children:[e.jsx("p",{className:"text-xs text-zinc-500 uppercase tracking-wider mb-2",children:"Additional Details (JSON)"}),e.jsx("pre",{className:"text-xs text-zinc-300 bg-zinc-800 p-3 rounded-lg overflow-x-auto",children:JSON.stringify(t.details,null,2)})]}),t.user_agent&&e.jsxs("div",{className:"border-t border-zinc-800 pt-4",children:[e.jsx("p",{className:"text-xs text-zinc-500 uppercase tracking-wider mb-2",children:"User Agent"}),e.jsx("p",{className:"text-xs text-zinc-400 break-all",children:t.user_agent})]})]})]})})]})}export{ve 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.