1import{J as $,u as R,a as M,c as P,r,j as e,N as B,L as F,B as x,ab as H,D as O,h as I,i as J,k as U,R as V,s as i,d as l}from"./index-BWIthYLv.js";import{C as G}from"./clock-BrFK6817.js";import{C as K}from"./circle-check-DALdbxsK.js";import{D as Q}from"./dollar-sign-BtZovwWe.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const X=$("Wallet",[["path",{d:"M19 7V4a1 1 0 0 0-1-1H5a2 2 0 0 0 0 4h15a1 1 0 0 1 1 1v4h-3a2 2 0 0 0 0 4h3a1 1 0 0 0 1-1v-2a1 1 0 0 0-1-1",key:"18etb6"}],["path",{d:"M3 5v14a2 2 0 0 0 2 2h15a1 1 0 0 0 1-1v-4",key:"xoc0q4"}]]),d=a=>`$${(a/100).toFixed(2)}`,te=()=>{const{t:a}=R(),{user:o,loading:u}=M(),b=P(),[c,w]=r.useState(null),[s,z]=r.useState(null),[h,k]=r.useState([]),[p,S]=r.useState([]),[C,D]=r.useState(!0),[q,m]=r.useState(!1),[g,f]=r.useState(""),[j,N]=r.useState(!1);r.useEffect(()=>{!u&&!o&&b("/sign-in")},[o,u,b]);const v=async()=>{if(!o)return;const[{data:t},{data:n},{data:W},{data:T}]=await Promise.all([i.from("monetization_partners").select("*").eq("user_id",o.id).maybeSingle(),i.rpc("partner_wallet_summary",{p_user_id:o.id}),i.from("monetization_referrals").select("id,partner_user_id,referred_user_id,status,stripe_subscription_id,amount_cents,paid_to_partner,created_at,converted_at").eq("partner_user_id",o.id).order("created_at",{ascending:!1}),i.from("monetization_payouts").select("*").eq("partner_user_id",o.id).order("requested_at",{ascending:!1})]);if(!t){b("/monetization/onboarding");return}w(t);const E=Array.isArray(n)?n[0]:n;z(E||{available_cents:0,pending_cents:0,lifetime_cents:0,paid_out_cents:0}),k(W||[]),S(T||[]),D(!1)};r.useEffect(()=>{o&&v()},[o]);const _=c?`https://voxprep.ai/sign-up?mref=${c.referral_code}`:"",L=()=>{navigator.clipboard.writeText(_),l.success(a("monetization.dashboard.copied"))},A=async()=>{const t=Math.round(parseFloat(g)*100);if(!t||t<=0){l.error(a("monetization.dashboard.invalidAmount"));return}if(s&&t>s.available_cents){l.error(a("monetization.dashboard.exceedsBalance"));return}N(!0);const{error:n}=await i.functions.invoke("request-monetization-payout",{body:{amount_cents:t}});if(N(!1),n){l.error(n.message);return}l.success(a("monetization.dashboard.withdrawSuccess")),m(!1),f(""),v()};if(u||C)return e.jsx("div",{className:"min-h-screen bg-background"});if(!c||!s)return null;const y=t=>a(`monetization.dashboard.status.${t}`,t);return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(B,{}),e.jsx("main",{className:"pt-24 pb-16",children:e.jsxs("div",{className:"container mx-auto px-4 max-w-5xl",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-extrabold tracking-tight",children:a("monetization.dashboard.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("monetization.dashboard.subtitle")})]}),e.jsx(F,{to:"/dashboard",className:"text-sm text-muted-foreground hover:text-foreground",children:a("monetization.dashboard.back")})]}),e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4 mb-6",children:[e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5",children:[e.jsx(X,{className:"h-5 w-5 text-primary mb-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("monetization.dashboard.available")}),e.jsx("p",{className:"text-2xl font-extrabold",children:d(s.available_cents)})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5",children:[e.jsx(G,{className:"h-5 w-5 text-amber-500 mb-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("monetization.dashboard.pending")}),e.jsx("p",{className:"text-2xl font-extrabold",children:d(s.pending_cents)})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5",children:[e.jsx(K,{className:"h-5 w-5 text-emerald-500 mb-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("monetization.dashboard.paidOut")}),e.jsx("p",{className:"text-2xl font-extrabold",children:d(s.paid_out_cents)})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-5",children:[e.jsx(Q,{className:"h-5 w-5 text-primary mb-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("monetization.dashboard.lifetime")}
6),e.jsx("p",{className:"text-2xl font-extrabold",children:d(s.lifetime_cents)})]})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6 mb-6",children:[e.jsx("h2",{className:"font-bold mb-3",children:a("monetization.dashboard.linkTitle")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{readOnly:!0,value:_,className:"flex-1 rounded-lg border border-border bg-secondary px-3 py-2.5 text-sm font-mono"}),e.jsxs(x,{onClick:L,variant:"outline",children:[e.jsx(H,{className:"h-4 w-4 mr-2"}),a("monetization.dashboard.copy")]})]}),e.jsxs(x,{onClick:()=>m(!0),disabled:s.available_cents<=0,className:"mt-4 bg-primary hover:bg-primary/90",children:[a("monetization.dashboard.requestWithdrawal")," (",d(s.available_cents),")"]})]}),e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6",children:[e.jsxs("h2",{className:"font-bold mb-3",children:[a("monetization.dashboard.referralsTitle")," (",h.length,")"]}),h.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:a("monetization.dashboard.referralsEmpty")}):e.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:h.map(t=>e.jsxs("div",{className:"flex items-center justify-between text-sm border-b border-border last:border-0 py-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t.referred_email||a("monetization.dashboard.anonymousUser")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(t.created_at).toLocaleDateString()})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"font-bold",children:d(t.amount_cents)}),e.jsx("p",{className:`text-xs ${t.status==="converted"?"text-emerald-500":t.status==="paid"?"text-muted-foreground":"text-amber-500"}`,children:y(t.status)})]})]},t.id))})]}),e.jsxs("div",{className:"rounded-2xl border border-border bg-card p-6",children:[e.jsxs("h2",{className:"font-bold mb-3",children:[a("monetization.dashboard.payoutsTitle")," (",p.length,")"]}),p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:a("monetization.dashboard.payoutsEmpty")}):e.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:p.map(t=>e.jsxs("div",{className:"flex items-center justify-between text-sm border-b border-border last:border-0 py-2",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium",children:[d(t.amount_cents)," ",a("monetization.dashboard.via")," ",t.method]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(t.requested_at).toLocaleDateString()}),t.admin_note&&e.jsx("p",{className:"text-xs text-muted-foreground italic mt-0.5",children:t.admin_note})]}),e.jsx("span",{className:`text-xs px-2 py-1 rounded ${t.status==="paid"?"bg-emerald-500/10 text-emerald-500":t.status==="rejected"?"bg-destructive/10 text-destructive":"bg-amber-500/10 text-amber-500"}`,children:y(t.status)})]},t.id))})]})]})]})}),e.jsx(O,{open:q,onOpenChange:m,children:e.jsxs(I,{children:[e.jsx(J,{children:e.jsx(U,{children:a("monetization.dashboard.withdrawTitle")})}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[a("monetization.dashboard.withdrawAvailable")," ",e.jsx("strong",{children:d(s.available_cents)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-1.5",children:a("monetization.dashboard.withdrawAmount")}),e.jsx("input",{type:"number",step:"0.01",min:"0",max:s.available_cents/100,value:g,onChange:t=>f(t.target.value),className:"w-full rounded-lg border border-border bg-secondary px-3 py-2.5 text-sm focus:outline-none focus:ring-2 focus:ring-primary/40",placeholder:"0.00"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("monetization.dashboard.withdrawHelper",{method:c.payout_method})})]}),e.jsxs(V,{children:[e.jsx(x,{variant:"outline",onClick:()=>m(!1),children:a("monetization.dashboard.cancel")}),e.jsx(x,{onClick:A,disabled:j,className:"bg-primary hover:bg-primary/90",children:a(j?"monetization.dashboard.submitting":"monetization.dashboard.submitRequest")})]})]})})]})};export{te 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.