1import{by as q,r as x,g as O,i as b,j as e,bO as f,_ as F,Y as L,bA as $,K as B}from"./vendor-B3bqREfz.js";import{u as K,B as r,C as S,d as w,g as Q,D as y,h as I,j as k,k as D,m as T,I as o,f as j}from"./index-BHZdkTHk.js";import{T as R}from"./textarea-BFtGXtJd.js";import{S as U,a as M,b as z,c as H,d as V}from"./select-CdK0CD7c.js";const Y={open:"bg-red-100 text-red-700",won:"bg-green-100 text-green-700",lost:"bg-gray-100 text-gray-700",withdrawn:"bg-amber-100 text-amber-700"};function J(){const{toast:C}=K(),v=q(),[l,d]=x.useState(null),[h,m]=x.useState({status:"",adminNotes:""}),[A,c]=x.useState(!1),[t,i]=x.useState({userId:"",orderId:"",amountCents:"",reason:"",stripeChargeId:""}),{data:n,isLoading:P}=O({queryKey:["/api/admin/chargebacks"],queryFn:()=>j("GET","/api/admin/chargebacks").then(a=>a.json())}),g=b({mutationFn:({id:a,updates:s})=>j("PATCH",`/api/admin/chargebacks/${a}`,s).then(E=>E.json()),onSuccess:()=>{v.invalidateQueries({queryKey:["/api/admin/chargebacks"]}),d(null),C({title:"Updated"})}}),p=b({mutationFn:a=>j("POST","/api/admin/chargebacks",a).then(s=>s.json()),onSuccess:()=>{v.invalidateQueries({queryKey:["/api/admin/chargebacks"]}),c(!1),C({title:"Chargeback created"})}}),N=(n==null?void 0:n.items)??[],u=(n==null?void 0:n.stats)??{};return e.jsxs("div",{className:"max-w-5xl mx-auto px-4 py-8",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(f,{className:"h-6 w-6 text-red-500"})," Chargebacks"]}),e.jsxs(r,{size:"sm",onClick:()=>c(!0),children:[e.jsx(F,{className:"h-4 w-4 mr-1"})," Add"]})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-4 mb-6",children:[{label:"Total",val:u.total??0,icon:L,color:"text-blue-600"},{label:"Open",val:u.open??0,icon:f,color:"text-red-500"},{label:"Won",val:u.won??0,icon:$,color:"text-green-500"},{label:"Lost",val:u.lost??0,icon:B,color:"text-gray-500"}].map(a=>e.jsx(S,{children:e.jsxs(w,{className:"pt-4",children:[e.jsx(a.icon,{className:`h-5 w-5 mb-1 ${a.color}`}),e.jsx("p",{className:"text-2xl font-bold",children:a.val}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a.label})]})},a.label))}),P?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):e.jsxs("div",{className:"space-y-3",children:[N.map(a=>e.jsx(S,{className:"hover:shadow-sm transition-shadow",children:e.jsxs(w,{className:"flex items-center justify-between pt-4 flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"font-medium",children:["#",a.id]}),e.jsx(Q,{className:`text-xs ${Y[a.status]}`,children:a.status}),e.jsxs("span",{className:"font-semibold text-red-600",children:["$",(a.amountCents/100).toFixed(2)]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[a.reason??"No reason"," · ",new Date(a.createdAt).toLocaleDateString(),a.stripeChargeId&&` · ${a.stripeChargeId}`]}),a.adminNotes&&e.jsx("p",{className:"text-xs text-muted-foreground italic mt-0.5",children:a.adminNotes})]}),e.jsx(r,{size:"sm",variant:"outline",onClick:()=>{d(a),m({status:a.status,adminNotes:a.adminNotes??""})},children:"Edit"})]})},a.id)),N.length===0&&e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"No chargebacks found."})]}),e.jsx(y,{open:!!l,onOpenChange:()=>d(null),children:e.jsxs(I,{children:[e.jsx(k,{children:e.jsxs(D,{children:["Update Chargeback #",l==null?void 0:l.id]})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(U,{value:h.status,onValueChange:a=>m(s=>({...s,status:a})),children:[e.jsx(M,{children:e.jsx(z,{placeholder:"Status"})}),e.jsx(H,{children:["open","won","lost","withdrawn"].map(a=>e.jsx(V,{value:a,children:a},a))})]}),e.jsx(R,{placeholder:"Admin notes...",value:h.adminNotes,onChange:a=>m(s=>({...s,adminNotes:a.target.value})),rows:3})]}),e.jsxs(T,{children:[e.jsx(r,{variant:"outline",onClick:()=>d(null),children:"Cancel"}),e.jsx(r,{disabled:g.isPending,onClick:()=>g.mutate({id:l.id,updates:h}),children:g.isPending?"Saving...":"Save"})]})]})}),e.jsx(y,{open:A,onOpenChange:c,children:e.jsxs(I,{children:[e.jsx(k,{children:e.jsx(D,{children:"Create Chargeback Record"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(o,{placeholder:"User ID (optional)",value:t.userId,onChange:a=>i(s=>({...s,userId:a.target.value}))}),e.jsx(o,{placeholder:"Order ID (optional)",value:t.orderId,onChange:a=>i(s=>({...s,orderId:a.target.value}))}),e.jsx(o,{placeholder:"Stripe Charge ID (optional)",value:t.stripeChargeId,onChange:a=>i(s=>({...s,stripeChargeId:a.target.value}))}),e.jsx(o,{placeholder:"Amount (cents) *",type:"number",value:t.amountCents,onChange:a=>i(s=>({...s,amountCents:a.target.value}))}),e.jsx(o,{placeholder:"Reason",value:t.reason,onChange:a=>i(s=>({...s,reason:a.target.value}))})]}),e.jsxs(T,{children:[e.jsx(r,{variant:"outline",onClick:()=>c(!1),children:"Cancel"}),e.jsx(r,{disabled:!t.amountCents||p.isPending,onClick:()=>p.mutate({...t,userId:t.userId||void 0,orderId:t.orderId||void 0,amountCents:parseInt(t.amountCents)}),children:p.isPending?"Creating...":"Create"})]})]})})]})}export{J 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.