1import{r as n,j as e,g as R,h as C,b as D,u as k,t as g}from"./index-Ca1a5u06.js";import{A as F}from"./AdminShell-1jktnkVT.js";import{c as P,a as $,B as v}from"./button-d0EJVEI7.js";import{c as _}from"./utils-BQHNewu7.js";import{D as A,a as E,b as I,c as M,d as O,e as L}from"./dialog-CgzjH3Xw.js";import{r as T}from"./auth-middleware--OOLmZ00.js";import"./createLucideIcon-Atiu4W-D.js";import"./log-out-lhLgbybw.js";import"./x-DpyMv8Yy.js";import"./eye-B7oAn7Zw.js";import"./quote-qk-AqLBN.js";import"./index-Cs0e6FuL.js";import"./index-DS2G1HP2.js";const y=n.forwardRef(({className:t,type:a,...s},i)=>e.jsx("input",{type:a,className:_("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-sage focus-visible:border-sage disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:i,...s}));y.displayName="Input";var B=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],U=B.reduce((t,a)=>{const s=P(`Primitive.${a}`),i=n.forwardRef((o,u)=>{const{asChild:d,...m}=o,p=d?s:a;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(p,{...m,ref:u})});return i.displayName=`Primitive.${a}`,{...t,[a]:i}},{}),q="Label",S=n.forwardRef((t,a)=>e.jsx(U.label,{...t,ref:a,onMouseDown:s=>{s.target.closest("button, input, select, textarea")||(t.onMouseDown?.(s),!s.defaultPrevented&&s.detail>1&&s.preventDefault())}}));S.displayName=q;var w=S;const z=$("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),N=n.forwardRef(({className:t,...a},s)=>e.jsx(w,{ref:s,className:_(z(),t),...a}));N.displayName=w.displayName;const H=R({method:"POST"}).middleware([T]).handler(C("5899156816e0b277812a1cb3a10ba6140bec14fc4141d788b59e7985be50bc3b"));function j(t,a="usd"){try{return new Intl.NumberFormat("en-US",{style:"currency",currency:a.toUpperCase()}).format((t??0)/100)}catch{return`$${((t??0)/100).toFixed(2)}`}}function V(t){return t==="seven_stories_47"?"Seven Stories That Sell":t==="signature_experience_997"?"Signature Experience":t}function G(t){const s={paid:"bg-sage/30 text-espresso border-sage",refunded:"bg-rose-100 text-rose-900 border-rose-300",partially_refunded:"bg-amber-100 text-amber-900 border-amber-300"}[t]??"bg-cream text-charcoal/70 border-border";return e.jsx("span",{className:`inline-block px-2 py-1 border text-xs font-mono uppercase tracking-[0.14em] ${s}`,children:t.replace(/_/g," ")})}function le(){const[t,a]=n.useState([]),[s,i]=n.useState(!0),[o,u]=n.useState("all"),[d,m]=n.useState(""),[p,x]=n.useState(null),f=async()=>{i(!0);const{data:r}=await D.from("orders").select("id, customer_email, product_id, price_id, amount_total, currency, status, refunded_amount, refunded_at, refund_reason, environment, created_at, stripe_payment_intent_id").order("created_at",{ascending:!1});a(r??[]),i(!1)};n.useEffect(()=>{f()},[]);const h=n.useMemo(()=>{const r=d.trim().toLowerCase();return t.filter(b=>!(o!=="all"&&b.status!==o||r&&!(b.customer_email??"").toLowerCase().includes(r)))},[t,o,d]);return e.jsxs(F,{title:"Orders",eyebrow:"Payments",children:[e.jsxs("div",{className:"mb-6 flex flex-wrap items-center gap-3",children:[e.jsx("div",{className:"flex gap-2",children:["all","paid","partially_refunded","refunded"].map(r=>e.jsx("button",{onClick:()=>u(r),className:`px-3 py-1.5 border text-xs font-mono uppercase tracking-[0.14em] ${o===r?"bg-espresso text-paper border-espresso":"bg-paper text-charcoal/70 border-border hover:bg-cream"}`,children:r.replace(/_/g," ")},r))}),e.jsx("div",{className:"ml-auto w-full max-w-xs",children:e.jsx(y,{placeholder:"Search by emailâ¦",value:d,onChange:r=>m(r.target.value)})})]}),e.jsx("div",{className:"bg-paper border border-border overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left",children:[e.jsx("th",{className:"px-4 py-3 text-xs font-mono uppercase tracking-[0.18em] text-charcoal/55",children:"Date"}),e.jsx("th",{className:"px-4 py-3 text-xs font-mono uppercase tracking-[0.18em] text-charcoal/55",children:"Customer"}),e.jsx("th",{className:"px-4 py-3 text-xs font-mono uppercase tracking-[0.18em] text-charcoal/55",children:"Product"}),e.jsx("th",{className:"px-4 py-3 text-xs font-mono uppercase tracking-[0.18em] text-charcoal/55",children:"Amount"}),e.jsx("th",{className:"px-4 py-3 text-xs font-mono uppercase tracking-[0.18em] text-charcoal/55",children:"Refunded"}),e.jsx("th",{className:"px-4 py-3 text-xs font-mono uppercase tracking-[0.18em] text-charcoal/55",children:"Status"}),e.jsx("th",{className:"px-4 py-3 text-xs font-mono uppercase tracking-[0.18em] text-charcoal/55 text-right",children:"Action"})]})}),e.jsx("tbody",{children:s?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-charcoal/55",children:"Loadingâ¦"})}):h.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-8 text-center text-charcoal/55",children:"No orders."})}):h.map(r=>{const l=(r.amount_total??0)-(r.refunded_amount??0)>
10&&!!r.stripe_payment_intent_id;return e.jsxs("tr",{className:"border-b border-border/60 hover:bg-cream/40",children:[e.jsx("td",{className:"px-4 py-3 text-sm font-mono text-charcoal/65",children:new Date(r.created_at).toLocaleDateString()}),e.jsx("td",{className:"px-4 py-3 text-charcoal/85",children:r.customer_email??"â"}),e.jsx("td",{className:"px-4 py-3 text-charcoal/75",children:V(r.price_id)}),e.jsx("td",{className:"px-4 py-3 font-mono text-charcoal/85",children:j(r.amount_total,r.currency)}),e.jsx("td",{className:"px-4 py-3 font-mono text-charcoal/65",children:r.refunded_amount>0?j(r.refunded_amount,r.currency):"â"}),e.jsx("td",{className:"px-4 py-3",children:G(r.status)}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx(v,{size:"sm",variant:"outline",disabled:!l,onClick:()=>x(r),children:"Issue Refund"})})]},r.id)})})]})}),e.jsx(J,{order:p,onClose:()=>x(null),onDone:()=>{x(null),f()}})]})}function J({order:t,onClose:a,onDone:s}){const i=k(H),[o,u]=n.useState("full"),[d,m]=n.useState(""),[p,x]=n.useState(""),[f,h]=n.useState(!1);if(n.useEffect(()=>{t&&(u("full"),m(""),x(""))},[t]),!t)return null;const r=(t.amount_total??0)-(t.refunded_amount??0),b=async()=>{let l;if(o==="partial"){const c=Number(d);if(!Number.isFinite(c)||c<=0){g.error("Enter a valid refund amount");return}if(l=Math.round(c*100),l>r){g.error(`Max refundable is ${j(r,t.currency)}`);return}}h(!0);try{const c=await i({data:{orderId:t.id,amount:l,reason:p||void 0}});"error"in c&&c.error?g.error(c.error):(g.success("Refund issued"),s())}catch(c){g.error(c?.message??"Refund failed")}finally{h(!1)}};return e.jsx(A,{open:!!t,onOpenChange:l=>!l&&a(),children:e.jsxs(E,{children:[e.jsxs(I,{children:[e.jsx(M,{children:"Issue Refund"}),e.jsxs(O,{children:["Refund ",t.customer_email??"this customer"," via Stripe. This action cannot be undone. Remaining refundable: ",e.jsx("strong",{children:j(r,t.currency)}),"."]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{onClick:()=>u("full"),className:`flex-1 px-3 py-2 border text-sm font-mono uppercase tracking-[0.14em] ${o==="full"?"bg-espresso text-paper border-espresso":"bg-paper text-charcoal/70 border-border"}`,children:["Full (",j(r,t.currency),")"]}),e.jsx("button",{onClick:()=>u("partial"),className:`flex-1 px-3 py-2 border text-sm font-mono uppercase tracking-[0.14em] ${o==="partial"?"bg-espresso text-paper border-espresso":"bg-paper text-charcoal/70 border-border"}`,children:"Partial"})]}),o==="partial"&&e.jsxs("div",{children:[e.jsx(N,{htmlFor:"amount",children:"Amount (USD)"}),e.jsx(y,{id:"amount",type:"number",step:"0.01",min:"0",value:d,onChange:l=>m(l.target.value),placeholder:"0.00"})]}),e.jsxs("div",{children:[e.jsx(N,{htmlFor:"reason",children:"Internal note (optional)"}),e.jsx(y,{id:"reason",value:p,onChange:l=>x(l.target.value),placeholder:"e.g. duplicate purchase"})]}),e.jsx("p",{className:"text-xs text-charcoal/55",children:"A full refund will also reverse any pending affiliate commission tied to this order."})]}),e.jsxs(L,{children:[e.jsx(v,{variant:"outline",onClick:a,disabled:f,children:"Cancel"}),e.jsx(v,{onClick:b,disabled:f,children:f?"Refundingâ¦":"Issue Refund"})]})]})})}export{le as component};
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.