1import{c as H,u as V,z as oe,e as ie,r,E as U,s as f,j as e,A as de,aC as ce,W as ue,aU as N,S as me,D as Y,bj as pe,l as xe,g as O,aD as fe,aE as be,h as w}from"./index-CICaNWwF.js";import{L as Z}from"./legal-notice-CPWEDsdJ.js";import{d as he}from"./download-BGTo9dTh.js";import{P as Q}from"./plus-DJdEYRbO.js";import{B as K}from"./banknote-pdH7ZyGI.js";import{M as ge}from"./mail-Ci9HYoPE.js";import"./info-BDJowwQ2.js";import"./chevron-down-C_HsAtoj.js";const ye=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],je=H("arrow-down",ye);const we=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Ne=H("arrow-up",we),_e=[1e4,25e3,5e4,1e5,2e5,5e5];function ve(a){const C=["Date","Kind","Amount (INR)","Status","Note"],i=l=>{const u=l==null?"":String(l);return/[",\n]/.test(u)?`"${u.replace(/"/g,'""')}"`:u},o=a.map(l=>[new Date(l.created_at).toISOString(),l.kind??"",(Number(l.amount_cents??0)/100).toFixed(2),l.status??"",l.note??""]),k=[C,...o].map(l=>l.map(i).join(",")).join(` 2`),_=new Date().toISOString().slice(0,10);he(`wallet-statement-${_}.csv`,k)}function Ue(){const{user:a}=V(),C=oe(),i=ie(),[o,k]=r.useState(!1),[_,l]=r.useState("all"),{data:u}=U({queryKey:["wallet",a?.id],enabled:!!a,queryFn:async()=>{await f.rpc("ensure_wallet",{_uid:a.id});const{data:t}=await f.from("wallets").select("balance_cents,hold_cents,earned_balance_cents").eq("user_id",a.id).maybeSingle();return t||{balance_cents:0,hold_cents:0,earned_balance_cents:0}}}),{data:b}=U({queryKey:["wallet-txns",a?.id],enabled:!!a,queryFn:async()=>{const{data:t}=await f.from("wallet_transactions").select("id,kind,amount_cents,note,created_at,status").eq("user_id",a.id).order("created_at",{ascending:!1}).limit(100);return t||[]}}),{data:S}=U({queryKey:["pending-topups",a?.id],enabled:!!a,refetchInterval:3e4,queryFn:async()=>{const{data:t}=await f.from("wallet_topups").select("id,amount_cents,status,created_at").eq("user_id",a.id).eq("status","pending").order("created_at",{ascending:!1}).limit(10);return t||[]}}),{data:A}=U({queryKey:["withdrawals",a?.id],enabled:!!a,queryFn:async()=>{const{data:t}=await f.from("withdrawal_requests").select("id,amount_cents,method,status,reference,admin_note,created_at,processed_at").eq("user_id",a.id).order("created_at",{ascending:!1}).limit(20);return t||[]}}),p=u?.balance_cents||0,P=u?.earned_balance_cents||0,D=Math.max(0,p-P),I=r.useMemo(()=>{const t=b||[];switch(_){case"credits":return t.filter(n=>(n.amount_cents??0)>0);case"debits":return t.filter(n=>(n.amount_cents??0)<0);case"ads":return t.filter(n=>/^ad_/.test(n.kind||"")||n.kind==="ad_spend");case"topups":return t.filter(n=>n.kind==="topup");case"referrals":return t.filter(n=>/referr|ref_reward/i.test(n.kind||"")||/referr/i.test(n.note||""));default:return t}},[b,_]);return e.jsxs("div",{className:"mx-auto max-w-md pb-24",children:[e.jsxs("header",{className:"safe-top px-4 py-3 flex items-center gap-3",children:[e.jsx("button",{onClick:()=>ce(),"aria-label":"Back",className:"size-9 rounded-full bg-card shadow-soft flex items-center justify-center",children:e.jsx(de,{className:"size-4"})}),e.jsx("h1",{className:"font-display font-semibold text-lg",children:"Wallet"})]}),e.jsxs("div",{className:"mx-5 mt-4 rounded-3xl bg-gradient-warm text-primary-foreground p-5 shadow-card",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[10px] uppercase font-bold tracking-wider opacity-90",children:[e.jsx(ue,{className:"size-3.5"})," Available balance"]}),e.jsx("p",{className:"mt-1 font-display text-3xl font-bold",children:N(p)}),e.jsxs("div",{className:"mt-3 grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-2xl bg-white/15 p-2.5",children:[e.jsxs("p",{className:"text-[10px] uppercase font-semibold opacity-90 inline-flex items-center gap-1",children:[e.jsx(Q,{className:"size-3"})," Added"]}),e.jsx("p",{className:"font-bold text-base",children:N(D)}),e.jsx("p",{className:"text-[10px] opacity-80",children:"In-app only"})]}),e.jsxs("div",{className:"rounded-2xl bg-white/15 p-2.5",children:[e.jsxs("p",{className:"text-[10px] uppercase font-semibold opacity-90 inline-flex items-center gap-1",children:[e.jsx(me,{className:"size-3"})," Earned"]}),e.jsx("p",{className:"font-bold text-base",children:N(P)}),e.jsx("p",{className:"text-[10px] opacity-80",children:"Withdrawable"})]})]}),e.jsxs("div",{className:"mt-4 flex gap-2",children:[e.jsxs("button",{onClick:()=>k(!0),className:"flex-1 inline-flex items-center justify-center gap-2 rounded-full bg-white/95 text-foreground px-4 py-2 text-sm font-semibold active:scale-95",children:[e.jsx(Q,{className:"size-4"})," Add money"]}),e.jsxs("button",{onClick:()=>i({to:"/app/withdraw"}),className:"flex-1 inline-flex items-center justify-center gap-2 rounded-full bg-black/25 text-primary-foreground px-4 py-2 text-sm font-semibold active:scale-95 disabled:opacity-60",children:[e.jsx(K,{className:"size-4"})," Withdraw"]})]})]}),e.jsx("div",{className:"mx-5 mt-3",children:e.jsxs(Z,{title:"How TBuddy Wallet works",children:[e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-foreground",children:"Added money"})," is non-refundable in-app credit and can only be spent on TBuddy services (ads, promotions, memberships, boosts). It cannot be withdrawn to your bank or UPI."]}),e.jsxs("p",{children:[e.jsx("span",{className:"font-semibold text-foreground",children:"Earnings"})," from referrals, sold ads, promotions and payouts are the only balance that can be withdrawn to UPI/bank after verification."]}),e.jsx("p",{className:"opacity-80",children:"TBuddy is not a bank, NBFC or prepaid payment instrument (PPI). The wallet is a closed-loop ledger for services provided on TBuddy. No interest is paid on balance."})]})}),!!A?.length&&e.jsxs("section",{className:"mt-5 px-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Recent withdrawals"}),e.jsx("button",{onClick:()=>i({to:"/app/withdraw"}),className:"text-[11px] font-semibold text-primary",children:"View all"})]}),e.jsx("ul",{className:"rounded-2xl bg-card shadow-soft border border-border/60 overflow-hidden",children:A.slice(0,3).map(t=>e.jsxs("li",{className:"flex items-center gap-3 px-3 py-3 border-t border-border/40 first:border-t-0",children:[e.jsx("div",{className:`size-9 rounded-full flex items-center justify-center ${t.status==="paid"?"bg-emerald-500/15 text-emerald-600":t.status==="rejected"?"bg-destructive/15 text-destructive":"bg-primary/15 text-primary"}`,children:e.jsx(K,{className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("p",{className:"text-sm font-semibold truncate",children:[N(t.amount_cents)," · ",String(t.method).toUpperCase()]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground truncate",children:[t.status==="paid"?`Paid${t.reference?` · Ref ${t.reference}`:""}`:t.status==="rejected"?`Rejected · ${t.admin_note||"returned to wallet"}`:"Pending admin review"," · ",new Date(t.created_at).toLocaleDateString()]})]}),e.jsx("span",{className:`text-[10px] font-bold uppercase px-2 py-1 rounded-full shrink-0 ${t.status==="paid"?"bg-emerald-500/15 text-emerald-600":t.status==="rejected"?"bg-destructive/15 text-destructive":"bg-amber-500/15 text-amber-600"}`,children:t.status})]},t.id))})]}),e.jsxs("section",{className:"mt-6 px-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Transactions"}),!!b?.length&&e.jsxs("button",{type:"button",onClick:()=>ve(I.length?I:b),className:"inline-flex items-center gap-1 rounded-full bg-muted hover:bg-muted/70 transition text-[11px] font-semibold px-2.5 py-1 text-foreground
2/80",children:[e.jsx(Y,{className:"size-3"})," Export CSV"]})]}),!!b?.length&&e.jsx("div",{className:"flex gap-1.5 overflow-x-auto no-scrollbar mb-2 -mx-1 px-1",children:[{k:"all",label:"All"},{k:"credits",label:"Credits"},{k:"debits",label:"Debits"},{k:"topups",label:"Top-ups"},{k:"ads",label:"Promote"},{k:"referrals",label:"Referrals"}].map(t=>e.jsx("button",{onClick:()=>l(t.k),className:`px-3 py-1 rounded-full text-[11px] font-semibold whitespace-nowrap transition ${_===t.k?"bg-foreground text-background":"bg-card border border-border text-muted-foreground"}`,children:t.label},t.k))}),b?.length?I.length===0?e.jsx("div",{className:"rounded-2xl bg-card border border-border/60 p-6 text-center text-sm text-muted-foreground",children:"No matching transactions."}):e.jsx("ul",{className:"rounded-2xl bg-card shadow-soft border border-border/60 overflow-hidden",children:I.map(t=>{const n=t.amount_cents>0;return e.jsxs("li",{className:"flex items-center gap-3 px-3 py-3 border-t border-border/40 first:border-t-0",children:[e.jsx("div",{className:`size-9 rounded-full flex items-center justify-center ${n?"bg-emerald-500/15 text-emerald-600":"bg-destructive/15 text-destructive"}`,children:n?e.jsx(je,{className:"size-4"}):e.jsx(Ne,{className:"size-4"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-semibold truncate",children:ke(t.kind)}),e.jsxs("p",{className:"text-[11px] text-muted-foreground truncate",children:[t.note||t.kind," · ",new Date(t.created_at).toLocaleString()]})]}),e.jsxs("p",{className:`text-sm font-bold shrink-0 ${n?"text-emerald-600":"text-destructive"}`,children:[n?"+":"",N(Math.abs(t.amount_cents))]})]},t.id)})}):e.jsx("div",{className:"rounded-2xl bg-card border border-border/60 p-6 text-center text-sm text-muted-foreground",children:"No transactions yet. Add money to get started."})]}),o&&e.jsx(Se,{onClose:()=>k(!1),onSubmitted:()=>{C.invalidateQueries({queryKey:["wallet-txns",a?.id]}),C.invalidateQueries({queryKey:["wallet",a?.id]})}})]})}function ke(a){switch(a){case"topup":return"Wallet top-up";case"ad_spend":return"Ad spend";case"promo_payout_out":return"Promo payout sent";case"promo_payout_in":return"Promo payout received";case"refund":return"Refund";case"adjust":return"Adjustment";case"earning":return"Earnings credit";case"withdraw_hold":return"Withdrawal requested";case"withdraw_paid":return"Withdrawal paid";case"withdraw_refund":return"Withdrawal refund";case"platform_fee":return"Platform fee";case"direct_pay_fee":return"Wallet payment fee";default:return a}}function Se({onClose:a,onSubmitted:C}){const{user:i}=V(),[o,k]=r.useState(25e3),[_,l]=r.useState(!1),[u,b]=r.useState("amount"),[S,A]=r.useState(null),[p,P]=r.useState(null),[D,I]=r.useState(!1),[t,n]=r.useState("tbuddy@upi"),[G,J]=r.useState("[email protected]"),[X,ee]=r.useState("Wallet top-up â {amount}"),[te,se]=r.useState(`Hi TBuddy team, 3 4I paid {amount} via UPI ({upi}) for a wallet top-up. 5 6Top-up ID: {topup_id} 7User ID: {user_id} 8Email: {user_email} 9 10Thanks!`),[z,ae]=r.useState("personal_savings"),[$,R]=r.useState(!1),[B,W]=r.useState(!1);r.useEffect(()=>{i&&f.from("profiles").select("wallet_tnc_accepted_at").eq("id",i.id).maybeSingle().then(({data:s})=>{s?.wallet_tnc_accepted_at&&(R(!0),W(!0))})},[i?.id]),r.useEffect(()=>{f.rpc("get_public_app_setting",{_key:"payment_instructions"}).then(({data:s})=>{s&&(s.upi&&n(s.upi),s.email&&J(s.email),s.email_subject&&ee(s.email_subject),s.email_body&&se(s.email_body))})},[]);const M=r.useMemo(()=>`upi://pay?pa=${encodeURIComponent(t)}&pn=TBuddy&am=${(o/100).toFixed(2)}&cu=INR&tn=${encodeURIComponent(`Wallet ${S||""}`)}`,[t,o,S]);r.useEffect(()=>{if(u!=="pay"||p)return;let s=!1;return(async()=>{try{const m=document.createElement("canvas");await pe.toCanvas(m,M,{width:640,margin:2,errorCorrectionLevel:"H",color:{dark:"#111111",light:"#ffffff"}});const v=await new Promise((c,T)=>{const h=new Image;h.onload=()=>c(h),h.onerror=T,h.src=xe}),d=m.getContext("2d");if(d){const c=Math.round(m.width*.24),T=Math.round((m.width-c)/2),h=Math.round((m.height-c)/2),x=Math.round(c*.06),g=Math.round(c*.22),y=T-x,j=h-x,q=c+x*2,E=c+x*2;d.fillStyle="#ffffff",d.beginPath(),d.moveTo(y+g,j),d.arcTo(y+q,j,y+q,j+E,g),d.arcTo(y+q,j+E,y,j+E,g),d.arcTo(y,j+E,y,j,g),d.arcTo(y,j,y+q,j,g),d.closePath(),d.fill(),d.drawImage(v,T,h,c,c)}s||P(m.toDataURL("image/png"))}catch{}})(),()=>{s=!0}},[u,p,M]),r.useEffect(()=>{u!=="pay"||!S||P(null)},[S]);const re=async()=>
10{if(!i)return;if(o<1e3){w.error("Minimum â¹10");return}if(!$){w.error("Please accept the wallet terms.");return}if(!z){w.error("Select a source of funds.");return}const s=1e6,L=1e7;if(o>s){w.error("Max â¹10,000 per top-up. For larger amounts, please use direct payment.");return}l(!0);try{const m=new Date(Date.now()-864e5).toISOString(),v=new Date(Date.now()-720*60*60*1e3).toISOString(),{data:d}=await f.from("wallet_topups").select("amount_cents, created_at, status").eq("user_id",i.id).gte("created_at",v).in("status",["pending","verified","completed","approved"]),c=d||[],T=c.filter(x=>x.created_at>=m).reduce((x,g)=>x+(g.amount_cents||0),0),h=c.reduce((x,g)=>x+(g.amount_cents||0),0);if(T+o>s){w.error("Daily add-money limit is â¹10,000. Use direct payment for larger amounts."),l(!1);return}if(h+o>L){w.error("Monthly add-money limit is â¹1,00,000. Use direct payment for larger amounts."),l(!1);return}}catch{}if(!B)try{await f.from("profiles").update({wallet_tnc_accepted_at:new Date().toISOString()}).eq("id",i.id),W(!0)}catch{}l(!1),b("pay"),(async()=>{try{const{data:m,error:v}=await f.from("wallet_topups").insert({user_id:i.id,amount_cents:o,source_of_funds:z}).select("id").maybeSingle();if(v){/duplicate_pending_topup/i.test(v.message||"")?w.message("A pending top-up with this amount already exists."):/Unverified wallets are capped/i.test(v.message||"")&&(w.error(v.message),b("amount"));return}m?.id&&A(m.id)}catch{}})()},F=s=>s.replace(/\{amount\}/g,N(o)).replace(/\{upi\}/g,t).replace(/\{topup_id\}/g,S||"").replace(/\{user_id\}/g,i?.id||"").replace(/\{user_email\}/g,i?.email||""),ne=encodeURIComponent(F(X)),le=encodeURIComponent(F(te));return e.jsxs("div",{className:"fixed inset-0 z-[95] flex items-end justify-center",onClick:a,children:[e.jsx("div",{className:"absolute inset-0 bg-black/50"}),e.jsx("div",{className:"relative w-full max-w-md bg-background rounded-t-3xl p-5 pb-8 safe-bottom",onClick:s=>s.stopPropagation(),children:u==="amount"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-display font-bold text-lg",children:"Add money"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose an amount to load into your wallet."}),e.jsx("div",{className:"mt-3",children:e.jsxs(Z,{title:"Limits & wallet rules",children:[e.jsx("p",{children:"Limits: â¹10,000 per day · â¹1,00,000 per month. For larger amounts, use direct payment."}),e.jsx("p",{children:"Wallet money is non-refundable in-app credit for TBuddy services. Only earnings are withdrawable to UPI/bank."})]})}),e.jsx("div",{className:"mt-4 grid grid-cols-3 gap-2",children:_e.map(s=>e.jsx("button",{onClick:()=>k(s),className:`rounded-2xl px-2 py-2.5 text-sm font-bold border ${o===s?"bg-gradient-warm text-primary-foreground border-transparent":"bg-card border-border"}`,children:N(s)},s))}),e.jsxs("label",{className:"block mt-4",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase text-muted-foreground",children:"Custom amount (â¹)"}),e.jsx("input",{type:"number",min:10,value:o/100,onChange:s=>k(Math.max(1e3,Math.floor(Number(s.target.value||0)*100))),className:"mt-1 w-full rounded-2xl bg-card border border-border px-4 py-3 text-sm outline-none"})]}),e.jsxs("label",{className:"block mt-4",children:[e.jsx("span",{className:"text-[11px] font-semibold uppercase text-muted-foreground",children:"Source of funds"}),e.jsxs("select",{value:z,onChange:s=>ae(s.target.value),className:"mt-1 w-full rounded-2xl bg-card border border-border px-4 py-3 text-sm outline-none",children:[e.jsx("option",{value:"personal_savings",children:"Personal savings"}),e.jsx("option",{value:"salary",children:"Salary / income"}),e.jsx("option",{value:"business",children:"Business income"}),e.jsx("option",{value:"gift",children:"Gift / family"}),e.jsx("option",{value:"other",children:"Other"})]})]}),!B&&e.jsxs("label",{className:"mt-3 flex items-start gap-2 text-[11px] text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:$,onChange:s=>R(s.target.checked),className:"mt-0.5"}),e.jsxs("span",{children:["I confirm the money is from a lawful source and accept the"," ",e.jsx("a",{href:"/legal/wallet",target:"_blank",rel:"noreferrer",className:"underline font-semibold",children:"Wallet Terms"})," ","and"," ",e.jsx("a",{href:"/legal/refunds",target:"_blank",rel:"noreferrer",className:"underline font-semibold",children:"Refund policy"}),"."]})]}),e.jsxs("button",{onClick:re,disabled:_,className:"mt-5 w-full inline-flex items-center justify-center gap-2 rounded-2xl bg-gradient-warm text-primary-foreground font-semibold py-3 disabled:opacity-60",children:[_&&e.jsx(O,{className:"size-4 animate-spin"})," Continue to payment · ",N(o)]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"font-display font-bold text-lg",children:["Pay ",N(o)]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Scan the QR or pay to the UPI ID below. Your wallet is credited once we verify (usually within a few hours)."}),e.jsxs("div",{className:"mt-4 rounded-2xl bg-white p-3 flex flex-col items-center",children:[p?e.jsx("img",{src:p,alt:"UPI QR",className:"w-56 h-56 object-contain"}):e.jsx("div",{className:"w-56 h-56 flex items-center justify-center bg-neutral-100 rounded-xl animate-pulse",children:e.jsx(O,{className:"size-6 animate-spin text-neutral-400"})}),e.jsxs("a",{href:p||"#","aria-disabled":!p,download:`tbuddy-wallet-${S}.png`,className:`mt-2 inline-flex items-center gap-1 text-xs font-semibold ${p?"text-primary":"text-muted-foreground pointer-events-none opacity-50"}`,children:[e.jsx(Y,{className:"size-3.5"})," Download QR"]})]}),e.jsxs("div",{className:"mt-3 rounded-2xl bg-primary/10 border border-primary/30 p-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[10px] uppercase font-semibold text-primary",children:"Pay to UPI ID"}),e.jsx("p",{className:"text-base font-bold truncate",children:t})]}),e.jsxs("button",{onClick:()=>{navigator.clipboard.writeText(t),I(!0),w.success("UPI ID copied"),setTimeout(()=>I(!1),1500)},className:"inline-flex items-center gap-1.5 rounded-full bg-primary text-primary-foreground px-3 h-9 text-xs font-semibold shrink-0",children:[D?e.jsx(fe,{className:"size-4"}):e.jsx(be,{className:"size-4"})," ",D?"Copied":"Copy"]})]}),e.jsx("a",{href:M,className:"mt-3 w-full inline-flex items-center justify-center gap-2 rounded-2xl bg-gradient-warm text-primary-foreground font-semibold py-3 text-sm",children:"Pay via UPI app"}),e.jsxs("a",{href:`mailto:${G}?subject=${ne}&body=${le}`,className:"mt-3 w-full inline-flex items-center justify-center gap-2 rounded-2xl bg-card border border-border font-semibold py-3 text-sm",children:[e.jsx(ge,{className:"size-4"})," Email confirmation"]}),e.jsx("button",{onClick:()=>{C(),a()},className:"mt-2 w-full rounded-2xl bg-card border border-border font-semibold py-2.5 text-sm",children:"Done"})]})})]})}export{Ue 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.