PageSourceSearch

https://foreseek.ai/assets/AffiliateView-ZdNXIfy_.js

js foreseek.ai collected 2026-10-05 14:11:22 UTC 47,541 bytes, 11 lines download raw bytes

1import{a as Be,E as Ne,r as d,j as e,am as Te,an as V,F as U,C as h,g as O,h as z,l as u,N as $,B as g,A as I,I as Q,ak as we,L as he,R as Xe,n as ue,a5 as Ce,a9 as Qe,s as A,t as E,ah as oe,aS as Re,a1 as De,T as J,aW as Ke,af as ie,a3 as fe,Q as ne,ag as Je,ap as ke,aq as es,aU as ss,aV as ts,aa as as,d as rs,u as ns,az as ls,k as Ae,W as is,cc as cs,X as os,Y as ds,_ as xs,$ as ms,M as hs}from"./index-CBgzuWa3.js";import{i as us,M as fs,P as gs,f as ps,g as js,h as Ns,T as Ee,a as $e,b as ce,c as W,d as Oe,e as G}from"./PieChart-c5w4jAxm.js";import{T as vs,a as ys,b as ve,c as ye}from"./tabs-fSN46brg.js";import{S as bs}from"./share-2-C3ETmM-N.js";import{C as Se}from"./copy-C0F_OvVf.js";import{c as ws,e as ze,s as Fe,b as Me}from"./subMonths-w0WSKCKt.js";import{C as Cs}from"./calendar-BSRMNT4o.js";import{R as ae,X as de,Y as xe,T as re,L as Ve,B as _e,A as be,C as Ue}from"./generateCategoricalChart-D_1-83TC.js";import{B as He,e as Pe,A as qe}from"./AreaChart-DPl2YXjm.js";import{C as me}from"./CartesianGrid-lPd2PpaF.js";import{f as L}from"./format-BF1Rjqon.js";import{p as X}from"./parseISO-QrV2fSX8.js";import{F as ks}from"./file-text-BuGM9m-4.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 Ye=Be("Medal",[["path",{d:"M7.21 15 2.66 7.14a2 2 0 0 1 .13-2.2L4.4 2.8A2 2 0 0 1 6 2h12a2 2 0 0 1 1.6.8l1.6 2.14a2 2 0 0 1 .14 2.2L16.79 15",key:"143lza"}],["path",{d:"M11 12 5.12 2.2",key:"qhuxz6"}],["path",{d:"m13 12 5.88-9.8",key:"hbye0f"}],["path",{d:"M8 7h8",key:"i86dvs"}],["circle",{cx:"12",cy:"17",r:"5",key:"qbz8iq"}],["path",{d:"M12 18v-2h-.5",key:"fawc4q"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Ss=Be("PartyPopper",[["path",{d:"M5.8 11.3 2 22l10.7-3.79",key:"gwxi1d"}],["path",{d:"M4 3h.01",key:"1vcuye"}],["path",{d:"M22 8h.01",key:"1mrtc2"}],["path",{d:"M15 2h.01",key:"1cjtqr"}],["path",{d:"M22 20h.01",key:"1mrys2"}],["path",{d:"m22 2-2.24.75a2.9 2.9 0 0 0-1.96 3.12c.1.86-.57 1.63-1.45 1.63h-.38c-.86 0-1.6.6-1.76 1.44L14 10",key:"hbicv8"}],["path",{d:"m22 13-.82-.33c-.86-.34-1.82.2-1.98 1.11c-.11.7-.72 1.22-1.43 1.22H17",key:"1i94pl"}],["path",{d:"m11 2 .33.82c.34.86-.2 1.82-1.11 1.98C9.52 4.9 9 5.52 9 6.23V7",key:"1cofks"}],["path",{d:"M11 13c1.93 1.93 2.83 4.17 2 5-.83.83-3.07-.07-5-2-1.93-1.93-2.83-4.17-2-5 .83-.83 3.07.07 5 2Z",key:"4kbmks"}]]);function We(n,t){const o=+Ne(n),[C,N]=[+Ne(t.start),+Ne(t.end)].sort((m,v)=>m-v);return o>=C&&o<=N}function Ge(n,t){return ws(n,-t)}const te=["welcome","slug","code","share","complete"];function Ms({affiliateId:n,fullName:t,existingSlug:o,existingCode:C,onComplete:N}){const[m,v]=d.useState("welcome"),[w,M]=d.useState(o||""),[i,a]=d.useState(C||""),[x,l]=d.useState(null),[p,r]=d.useState(null),[y,c]=d.useState(!1),[f,S]=d.useState(!1),[_,T]=d.useState(!1),b="https://foreseek.ai",R=w?`${b}/${w}`:`${b}?ref=${i||n.slice(0,8)}`;d.useEffect(()=>{if(!o&&!w&&t){const j=t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,20);M(j)}},[t,o,w]),d.useEffect(()=>{!C&&!i&&P()},[C,i]);const P=()=>{const j=Math.random().toString(36).substring(2,8).toUpperCase();a(j),r(null)},F=async j=>{if(!/^[a-z0-9-]{3,30}$/.test(j.toLowerCase()))return l("3-30 characters, lowercase letters, numbers, and hyphens only"),!1;const{data:k}=await A.from("reserved_slugs").select("slug").eq("slug",j.toLowerCase()).single();if(k)return l("This URL is reserved. Try a different one."),!1;const{data:se}=await A.from("affiliates").select("id").eq("custom_slug",j.toLowerCase()).neq("id",n).single();return se?(l("This URL is already taken. Try a different one."),!1):(l(null),!0)},B=async j=>{if(!/^[A-Z0-9]{4,8}$/.test(j.toUpperCase()))return r("4-8 characters, letters and numbers only"),!1;const{data:k}=await A.from("affiliates").select("id").eq("custom_code",j.toUpperCase()).neq("id",n).single();return k?(r("This code is already taken. Try a different one."),!1):(r(null),!0)},K=async()=>
11{if(c(!0),!await F(w)){c(!1);return}const{error:s}=await A.from("affiliates").update({custom_slug:w.toLowerCase()}).eq("id",n);if(s){s.code==="23505"?l("This URL is already taken."):E.error("Failed to save URL"),c(!1);return}c(!1),Z()},H=async()=>{if(c(!0),!await B(i)){c(!1);return}const{error:s}=await A.from("affiliates").update({custom_code:i.toUpperCase()}).eq("id",n);if(s){s.code==="23505"?r("This code is already taken."):E.error("Failed to save code"),c(!1);return}c(!1),Z()},D=async()=>{try{await navigator.clipboard.writeText(R),S(!0),E.success("Link copied!"),setTimeout(()=>S(!1),2e3)}catch{E.error("Failed to copy")}},q=()=>{const j=encodeURIComponent(`Check out Foreseek - AI-powered prediction markets! ${R}`);window.open(`https://twitter.com/intent/tweet?text=${j}`,"_blank")},le=()=>{D(),E.success("Link copied! Paste it in Discord.")},Z=()=>{const j=te.indexOf(m);if(j<te.length-1){const s=te[j+1];v(s),s==="complete"&&(T(!0),setTimeout(()=>T(!1),3e3))}},ee=te.indexOf(m),ge=()=>{switch(m){case"welcome":return e.jsxs(V.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"text-center space-y-6",children:[e.jsx("div",{className:"w-16 h-16 mx-auto bg-gradient-to-br from-primary/20 to-accent/20 rounded-2xl flex items-center justify-center",children:e.jsx(Qe,{className:"w-8 h-8 text-primary"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground mb-2",children:"Welcome to the Partner Program! 🎉"}),e.jsx("p",{className:"text-muted-foreground",children:"Let's set up your referral links so you can start earning commissions."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 max-w-sm mx-auto",children:[e.jsx(h,{className:"bg-muted/30 border-border/50",children:e.jsxs(u,{className:"pt-4 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-gradient",children:"20%"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Year 1"})]})}),e.jsx(h,{className:"bg-muted/30 border-border/50",children:e.jsxs(u,{className:"pt-4 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-gradient",children:"5%"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:"Lifetime"})]})})]}),e.jsxs(g,{onClick:Z,className:"gap-2",children:["Get Started",e.jsx(I,{className:"w-4 h-4"})]})]});case"slug":return e.jsxs(V.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto bg-primary/10 rounded-xl flex items-center justify-center mb-4",children:e.jsx(Ce,{className:"w-6 h-6 text-primary"})}),e.jsx("h2",{className:"text-xl font-bold text-foreground mb-2",children:"Create Your Custom URL"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Choose a memorable URL that represents you."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{htmlFor:"slug",className:"text-sm",children:"Your Referral URL"}),e.jsxs("div",{className:"flex items-center gap-1 bg-muted/50 rounded-lg p-3 border border-border/50",children:[e.jsxs("span",{className:"text-muted-foreground text-sm shrink-0",children:[b,"/"]}),e.jsx(Q,{id:"slug",value:w,onChange:j=>{M(j.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),l(null)},placeholder:"yourname",className:"border-0 bg-transparent p-0 h-auto text-foreground font-medium focus-visible:ring-0"})]}),x&&e.jsx("p",{className:"text-destructive text-xs",children:x}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This will be your unique referral link."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(g,{variant:"outline",onClick:()=>v("welcome"),className:"flex-1",children:"Back"}),e.jsxs(g,{onClick:K,disabled:y||!w,className:"flex-1 gap-2",children:[y?e.jsx(ue,{className:"w-4 h-4 animate-spin"}):null,"Continue",e.jsx(I,{className:"w-4 h-4"})]})]})]});case"code":return e.jsxs(V.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto bg-accent/10 rounded-xl flex items-center justify-center mb-4",children:e.jsx($,{className:"text-lg px-3 py-1",children:"#"})}),e.jsx("h2",{className:"text-xl font-bold text-foreground mb-2",children:"Choose Your Referral Code"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"A short code for sharing in conversations."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(he,{htmlFor:"code",className:"text-sm",children:"Your Code"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1 bg-muted/50 rounded-lg p-3 border border-border/50 flex-1",children:[e.jsx("span",{className:"text-muted-foreground text-sm shrink-0",children:"?ref="}),e.jsx(Q,{id:"code",value:i,onChange:j=>{a(j.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,8)),r(null)},placeholder:"CODE",className:"border-0 bg-transparent p-0 h-auto text-foreground font-mono font-bold focus-visible:ring-0 uppercase"})]}),e.jsx(g,{variant:"outline",size:"icon",onClick:P,children:e.jsx(Xe,{className:"w-4 h-4"})})]}),p&&e.jsx("p",{className:"text-destructive text-xs",children:p}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"People can use this when signing up."})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(g,{variant:"outline",onClick:()=>v("slug"),className:"flex-1",children:"Back"}),e.jsxs(g,{onClick:H,disabled:y||!i,className:"flex-1 gap-2",children:[y?e.jsx(ue,{className:"w-4 h-4 animate-spin"}):null,"Continue",e.jsx(I,{className:"w-4 h-4"})]})]})]});case"share":return e.jsxs(V.div,{initial:{opacity:0,y:20}
11,animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 mx-auto bg-chart-3/10 rounded-xl flex items-center justify-center mb-4",children:e.jsx(bs,{className:"w-6 h-6 text-chart-3"})}),e.jsx("h2",{className:"text-xl font-bold text-foreground mb-2",children:"Make Your First Share"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Share your link to start earning!"})]}),e.jsx(h,{className:"bg-muted/30 border-border/50",children:e.jsxs(u,{className:"pt-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-background/50 rounded-lg p-3 border border-border/30",children:[e.jsx(Q,{value:R,readOnly:!0,className:"border-0 bg-transparent p-0 h-auto text-sm font-mono"}),e.jsx(g,{variant:"ghost",size:"icon",className:"shrink-0",onClick:D,children:f?e.jsx(we,{className:"w-4 h-4 text-chart-3"}):e.jsx(Se,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs($,{variant:"outline",className:"text-xs",children:["Code: ",i]})})]})}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs(g,{variant:"outline",onClick:q,className:"gap-2",children:[e.jsx(us,{className:"w-4 h-4"}),"Share on X"]}),e.jsxs(g,{variant:"outline",onClick:le,className:"gap-2",children:[e.jsx(fs,{className:"w-4 h-4"}),"Copy for Discord"]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(g,{variant:"outline",onClick:()=>v("code"),className:"flex-1",children:"Back"}),e.jsxs(g,{onClick:Z,className:"flex-1 gap-2",children:["Complete Setup",e.jsx(I,{className:"w-4 h-4"})]})]})]});case"complete":return e.jsxs(V.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0},className:"text-center space-y-6",children:[e.jsx("div",{className:"w-20 h-20 mx-auto bg-gradient-to-br from-chart-3/20 to-chart-3/10 rounded-full flex items-center justify-center",children:e.jsx(Ss,{className:"w-10 h-10 text-chart-3"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-foreground mb-2",children:"You're All Set! 🚀"}),e.jsx("p",{className:"text-muted-foreground",children:"Your affiliate links are ready. Start sharing to earn commissions!"})]}),e.jsxs(h,{className:"bg-muted/30 border-border/50 text-left",children:[e.jsx(O,{className:"pb-2",children:e.jsx(z,{className:"text-sm",children:"Your Links"})}),e.jsxs(u,{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"URL"}),e.jsxs("code",{className:"text-xs font-mono text-foreground",children:[b,"/",w]})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Code"}),e.jsx($,{variant:"secondary",className:"font-mono",children:i})]})]})]}),e.jsxs(g,{onClick:N,className:"w-full gap-2",children:["Go to Dashboard",e.jsx(I,{className:"w-4 h-4"})]})]})}};return e.jsxs("div",{className:"relative",children:[e.jsx(Te,{children:_&&e.jsx(V.div,{initial:{opacity:0}
11,animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 pointer-events-none z-50 overflow-hidden",children:[...Array(50)].map((j,s)=>e.jsx(V.div,{initial:{y:-20,x:Math.random()*400-200,opacity:1,rotate:0},animate:{y:500,x:Math.random()*400-200,opacity:0,rotate:Math.random()*360},transition:{duration:2+Math.random(),delay:Math.random()*.5,ease:"easeOut"},className:U("absolute w-2 h-2 rounded-full",s%5===0&&"bg-primary",s%5===1&&"bg-accent",s%5===2&&"bg-chart-3",s%5===3&&"bg-chart-4",s%5===4&&"bg-chart-5"),style:{left:"50%",top:0}},s))})}),e.jsx("div",{className:"flex items-center justify-center gap-2 mb-6",children:te.slice(0,-1).map((j,s)=>e.jsx("div",{className:U("w-2 h-2 rounded-full transition-all duration-300",s<ee?"bg-primary":s===ee?"bg-primary w-6":"bg-muted")},j))}),e.jsx(Te,{mode:"wait",children:ge()})]})}function _s({referrals:n,commissions:t}){const[o,C]=d.useState("week"),{currentPeriod:N,previousPeriod:m,comparison:v}=d.useMemo(()=>{const a=oe(new Date);let x,l,p,r;o==="week"?(x=Re(a,{weekStartsOn:1}),l=ze(a,{weekStartsOn:1}),p=Re(Ge(a,1),{weekStartsOn:1}),r=ze(Ge(a,1),{weekStartsOn:1})):(x=Fe(a),l=De(a),p=Fe(Me(a,1)),r=De(Me(a,1)));const y=(_,T)=>{const b=n.filter(D=>{const q=X(D.clicked_at);return We(q,{start:_,end:T})}),R=t.filter(D=>{const q=X(D.created_at);return We(q,{start:_,end:T})}),P=b.length,F=b.filter(D=>D.signed_up_at).length,B=b.filter(D=>D.converted_at).length,K=R.reduce((D,q)=>D+q.commission_amount,0),H=P>0?B/P*100:0;return{clicks:P,signups:F,conversions:B,earnings:K,conversionRate:H}},c=y(x,l),f=y(p,r),S=(_,T)=>T===0?_>0?100:0:(_-T)/T*100;return{currentPeriod:{stats:c,label:o==="week"?`This Week (${L(x,"MMM d")} - ${L(l,"MMM d")})`:`This Month (${L(x,"MMMM yyyy")})`,shortLabel:o==="week"?"This Week":"This Month"},previousPeriod:{stats:f,label:o==="week"?`Last Week (${L(p,"MMM d")} - ${L(r,"MMM d")})`:`Last Month (${L(p,"MMMM yyyy")})`,shortLabel:o==="week"?"Last Week":"Last Month"},comparison:{clicks:S(c.clicks,f.clicks),signups:S(c.signups,f.signups),conversions:S(c.conversions,f.conversions),earnings:S(c.earnings,f.earnings),conversionRate:S(c.conversionRate,f.conversionRate)}}},[n,t,o]),w=[{metric:"Clicks",current:N.stats.clicks,previous:m.stats.clicks},{metric:"Signups",current:N.stats.signups,previous:m.stats.signups},{metric:"Conversions",current:N.stats.conversions,previous:m.stats.conversions}],M=(a,x="")=>{const l=a>=0;return e.jsxs("span",{className:U("inline-flex items-center gap-0.5 text-xs font-medium",l?"text-chart-3":"text-destructive"),children:[l?e.jsx(J,{className:"w-3 h-3"}):e.jsx(Ke,{className:"w-3 h-3"}),l?"+":"",a.toFixed(1),"%",x]})},i=({active:a,payload:x,label:l})=>!a||!x?null:e.jsxs("div",{className:"bg-popover border border-border rounded-lg p-3 shadow-lg",children:[e.jsx("p",{className:"text-sm font-medium text-foreground mb-1",children:l}),x.map((p,r)=>e.jsxs("p",{className:"text-sm",style:{color:p.fill},children:[p.name,": ",p.value]},r))]});return e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsxs(O,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(z,{className:"text-base flex items-center gap-2",children:[e.jsx(Cs,{className:"w-4 h-4"}),"Period Comparison"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(g,{variant:o==="week"?"secondary":"ghost",size:"sm",onClick:()=>C("week"),className:"h-7 px-3 text-xs",children:"Weekly"}),e.jsx(g,{variant:o==="month"?"secondary":"ghost",size:"sm",onClick:()=>C("month"),className:"h-7 px-3 text-xs",children:"Monthly"})]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[m.shortLabel," ",e.jsx(I,{className:"w-3 h-3"})," ",N.shortLabel]})]}),e.jsxs(u,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Clicks"}),e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"text-lg font-bold text-foreground",children:N.stats.clicks}),M(v.clicks)]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["vs ",m.stats.clicks," ",m.shortLabel.toLowerCase()]})]}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Signups"}),e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"text-lg font-bold text-foreground",children:N.stats.signups}),M(v.signups)]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["vs ",m.stats.signups," ",m.shortLabel.toLowerCase()]})]}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Conversions"}),e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsx("span",{className:"text-lg font-bold text-foreground",children:N.stats.conversions}),M(v.conversions)]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["vs ",m.stats.conversions," ",m.shortLabel.toLowerCase()]})]}),e.jsxs("div",{className:"bg-muted/30 rounded-lg p-3 space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Earnings"}),e.jsxs("div",{className:"flex items-baseline justify-between gap-2",children:[e.jsxs("span",{className:"text-lg font-bold text-gradient",children:["$",N.stats.earnings.toFixed(2)]}),M(v.earnings)]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["vs $",m.stats.earnings.toFixed(2)," ",m.shortLabel.toLowerCase()]})]})]}),e.jsx("div",{className:"h-48",children:e.jsx(ae,{width:"100%",height:"100%",children:e.jsxs(He,{data:w,barCategoryGap:"20%",children:[e.jsx(me,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(de,{dataKey:"metric",tick:{fill:"hsl(var(--muted-foreground))",fontSize:11}
11,tickLine:!1,axisLine:!1}),e.jsx(xe,{tick:{fill:"hsl(var(--muted-foreground))",fontSize:10},tickLine:!1,axisLine:!1,allowDecimals:!1}),e.jsx(re,{content:e.jsx(i,{})}),e.jsx(Ve,{formatter:a=>e.jsx("span",{className:"text-xs text-muted-foreground",children:a})}),e.jsx(_e,{dataKey:"previous",name:m.shortLabel,fill:"hsl(var(--muted-foreground))",radius:[4,4,0,0],opacity:.5}),e.jsx(_e,{dataKey:"current",name:N.shortLabel,fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})}),e.jsxs("div",{className:"flex items-center justify-between p-3 bg-muted/30 rounded-lg",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Conversion Rate"}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[e.jsxs("span",{className:"text-lg font-bold text-foreground",children:[N.stats.conversionRate.toFixed(1),"%"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["vs ",m.stats.conversionRate.toFixed(1),"%"]})]})]}),M(v.conversionRate," pts")]})]})]})}function Ls({referrals:n,commissions:t}){const o=d.useMemo(()=>{const i=oe(new Date),a=ie(i,29);return Pe({start:a,end:i}).map(l=>{const p=L(l,"yyyy-MM-dd"),r=n.filter(f=>L(X(f.clicked_at),"yyyy-MM-dd")===p),y=r.filter(f=>f.signed_up_at).length,c=r.filter(f=>f.converted_at).length;return{date:L(l,"MMM d"),clicks:r.length,signups:y,conversions:c}})},[n]),C=d.useMemo(()=>{const i=oe(new Date),a=ie(i,29),x=Pe({start:a,end:i});let l=0;return x.map(p=>{const r=L(p,"yyyy-MM-dd"),c=t.filter(f=>L(X(f.created_at),"yyyy-MM-dd")===r).reduce((f,S)=>f+S.commission_amount,0);return l+=c,{date:L(p,"MMM d"),daily:c,cumulative:l}})},[t]),N=d.useMemo(()=>{const i=n.length,a=n.filter(l=>l.signed_up_at).length,x=n.filter(l=>l.converted_at).length;return[{name:"Clicks",value:i,fill:"hsl(var(--primary))"},{name:"Signups",value:a,fill:"hsl(var(--accent))"},{name:"Conversions",value:x,fill:"hsl(var(--chart-3))"}]},[n]),m=d.useMemo(()=>{const i={};return n.forEach(a=>{const x=a.referral_source||"direct";i[x]=(i[x]||0)+1}),Object.entries(i).map(([a,x])=>({name:a.charAt(0).toUpperCase()+a.slice(1),value:x})).sort((a,x)=>x.value-a.value).slice(0,5)},[n]),v=d.useMemo(()=>{const i=n.length,a=n.filter(b=>b.signed_up_at).length,x=n.filter(b=>b.converted_at).length,l=t.reduce((b,R)=>b+R.commission_amount,0),p=i>0?a/i*100:0,r=a>0?x/a*100:0,y=oe(new Date),c=ie(y,14),f=ie(y,29),S=n.filter(b=>X(b.clicked_at)>=c),_=n.filter(b=>{const R=X(b.clicked_at);return R>=f&&R<c}),T=_.length>0?(S.length-_.length)/_.length*100:S.length>0?100:0;return{totalClicks:i,totalSignups:a,totalConversions:x,totalEarnings:l,clickToSignup:p,signupToConversion:r,recentTrend:T}},[n,t]),w=["hsl(var(--primary))","hsl(var(--accent))","hsl(var(--chart-3))","hsl(var(--chart-4))","hsl(var(--chart-5))"],M=({active:i,payload:a,label:x})=>!i||!a?null:e.jsxs("div",{className:"bg-popover border border-border rounded-lg p-3 shadow-lg",children:[e.jsx("p",{className:"text-sm font-medium text-foreground mb-1",children:x}),a.map((l,p)=>e.jsxs("p",{className:"text-sm",style:{color:l.color},children:[l.name,": ",l.name.includes("$")||l.name==="daily"||l.name==="cumulative"?`$${Number(l.value).toFixed(2)}`:l.value]},p))]});return n.length===0&&t.length===0?e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"py-12 text-center",children:[e.jsx(J,{className:"w-12 h-12 mx-auto text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-2",children:"No Data Yet"}),e.jsx("p",{className:"text-muted-foreground",children:"Start sharing your referral link to see analytics here."})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsx(_s,{referrals:n,commissions:t}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(h,{className:"glass-card border-border/50",children:e.jsx(u,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Clicks"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:v.totalClicks})]}),e.jsxs("div",{className:U("flex items-center gap-1 text-xs",v.recentTrend>=0?"text-chart-3":"text-destructive"),children:[v.recentTrend>=0?e.jsx(J,{className:"w-3 h-3"}):e.jsx(Ke,{className:"w-3 h-3"}),Math.abs(v.recentTrend).toFixed(0),"%"]})]})})}),e.jsx(h,{className:"glass-card border-border/50",children:e.jsx(u,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Signups"}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:v.totalSignups})]}),e.jsx(fe,{className:"w-5 h-5 text-muted-foreground"})]})})}),e.jsx(h,{className:"glass-card border-border/50",children:e.jsx(u,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click → Signup"}),e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:[v.clickToSignup.toFixed(1),"%"]})]}),e.jsx(gs,{className:"w-5 h-5 text-muted-foreground"})]})})}),e.jsx(h,{className:"glass-card border-border/50",children:e.jsx(u,{className:"pt-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Earnings"}),e.jsxs("p",{className:"text-2xl font-bold text-gradient",children:["$",v.totalEarnings.toFixed(2)]})]}),e.jsx(ne,{className:"w-5 h-5 text-muted-foreground"})]})})})]}),e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsx(O,{className:"pb-2",children:e.jsxs(z,{className:"text-base flex items-center gap-2",children:[e.jsx(J,{className:"w-4 h-4"}),"Referral Trends (30 Days)"]})}),e.jsx(u,{children:e.jsx("div",{className:"h-64",children:e.jsx(ae,{width:"100%",height:"100%",children:e.jsxs(qe,{data:o,children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"clicksGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",
11stopColor:"hsl(var(--primary))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--primary))",stopOpacity:0})]}),e.jsxs("linearGradient",{id:"signupsGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"hsl(var(--accent))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--accent))",stopOpacity:0})]})]}),e.jsx(me,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(de,{dataKey:"date",tick:{fill:"hsl(var(--muted-foreground))",fontSize:10},tickLine:!1,axisLine:!1,interval:"preserveStartEnd"}),e.jsx(xe,{tick:{fill:"hsl(var(--muted-foreground))",fontSize:10},tickLine:!1,axisLine:!1,allowDecimals:!1}),e.jsx(re,{content:e.jsx(M,{})}),e.jsx(be,{type:"monotone",dataKey:"clicks",name:"Clicks",stroke:"hsl(var(--primary))",fill:"url(#clicksGradient)",strokeWidth:2}),e.jsx(be,{type:"monotone",dataKey:"signups",name:"Signups",stroke:"hsl(var(--accent))",fill:"url(#signupsGradient)",strokeWidth:2})]})})})})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsx(O,{className:"pb-2",children:e.jsxs(z,{className:"text-base flex items-center gap-2",children:[e.jsx(ne,{className:"w-4 h-4"}),"Earnings Over Time"]})}),e.jsx(u,{children:e.jsx("div",{className:"h-52",children:e.jsx(ae,{width:"100%",height:"100%",children:e.jsxs(qe,{data:C,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"earningsGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"hsl(var(--chart-3))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--chart-3))",stopOpacity:0})]})}),e.jsx(me,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(de,{dataKey:"date",tick:{fill:"hsl(var(--muted-foreground))",fontSize:10},tickLine:!1,axisLine:!1,interval:"preserveStartEnd"}),e.jsx(xe,{tick:{fill:"hsl(var(--muted-foreground))",fontSize:10},tickLine:!1,axisLine:!1,tickFormatter:i=>`$${i}`}),e.jsx(re,{content:e.jsx(M,{})}),e.jsx(be,{type:"monotone",dataKey:"cumulative",name:"Total Earnings",stroke:"hsl(var(--chart-3))",fill:"url(#earningsGradient)",strokeWidth:2})]})})})})]}),e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsx(O,{className:"pb-2",children:e.jsxs(z,{className:"text-base flex items-center gap-2",children:[e.jsx(Je,{className:"w-4 h-4"}),"Conversion Funnel"]})}),e.jsx(u,{children:e.jsx("div",{className:"h-52",children:e.jsx(ae,{width:"100%",height:"100%",children:e.jsxs(He,{data:N,layout:"vertical",children:[e.jsx(me,{strokeDasharray:"3 3",stroke:"hsl(var(--border))",horizontal:!1}),e.jsx(de,{type:"number",tick:{fill:"hsl(var(--muted-foreground))",fontSize:10},tickLine:!1,axisLine:!1}),e.jsx(xe,{type:"category",dataKey:"name",tick:{fill:"hsl(var(--muted-foreground))",fontSize:11},tickLine:!1,axisLine:!1,width:80}),e.jsx(re,{content:e.jsx(M,{})}),e.jsx(_e,{dataKey:"value",radius:[0,4,4,0],children:N.map((i,a)=>e.jsx(Ue,{fill:i.fill},`cell-${a}`))})]})})})})]})]}),m.length>0&&e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsx(O,{className:"pb-2",children:e.jsxs(z,{className:"text-base flex items-center gap-2",children:[e.jsx(fe,{className:"w-4 h-4"}),"Traffic Sources"]})}),e.jsx(u,{children:e.jsx("div",{className:"h-52",children:e.jsx(ae,{width:"100%",height:"100%",children:e.jsxs(ps,{children:[e.jsx(js,{data:m,cx:"50%",cy:"50%",innerRadius:50,outerRadius:80,paddingAngle:2,dataKey:"value",children:m.map((i,a)=>e.jsx(Ue,{fill:w[a%w.length]},`cell-${a}`))}),e.jsx(re,{content:e.jsx(M,{})}),e.jsx(Ve,{verticalAlign:"middle",align:"right",layout:"vertical",formatter:i=>e.jsx("span",{className:"text-sm text-muted-foreground",children:i})})]})})})})]})]})}function Ts({leaderboardData:n,currentAffiliateId:t}){const[o,C]=d.useState("referrals"),[N,m]=d.useState("thisMonth"),v=d.useMemo(()=>[...n].sort((r,y)=>y[o]-r[o]).slice(0,10),[n,o]),w=d.useMemo(()=>{if(!t)return null;const y=[...n].sort((c,f)=>f[o]-c[o]).findIndex(c=>c.affiliate_id===t);return y>=0?y+1:null},[n,o,t]),M=d.useMemo(()=>t?n.find(r=>r.affiliate_id===t):null,[n,t]),i=r=>{switch(r){case 1:return e.jsx(as,{className:"w-5 h-5 text-chart-4"});case 2:return e.jsx(Ye,{className:"w-5 h-5 text-muted-foreground"});case 3:return e.jsx(Ye,{className:"w-5 h-5 text-chart-5"});default:return e.jsxs("span",{className:"w-5 text-center text-sm font-medium text-muted-foreground",children:["#",r]})}},a=r=>{switch(r){case 1:return"bg-chart-4/20 text-chart-4 border-chart-4/30";
11case 2:return"bg-muted-foreground/20 text-muted-foreground border-muted-foreground/30";case 3:return"bg-chart-5/20 text-chart-5 border-chart-5/30";default:return""}},x=(r,y)=>y==="earnings"?`$${r.toFixed(2)}`:r.toString(),l=r=>{switch(r){case"referrals":return"Referrals";case"conversions":return"Conversions";case"earnings":return"Earnings"}},p=r=>{switch(r){case"thisMonth":return L(new Date,"MMMM yyyy");case"lastMonth":return L(Me(new Date,1),"MMMM yyyy");case"allTime":return"All Time"}};return n.length===0?e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"py-12 text-center",children:[e.jsx(ke,{className:"w-12 h-12 mx-auto text-chart-4 mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-2",children:"Leaderboard Coming Soon"}),e.jsx("p",{className:"text-muted-foreground",children:"Start referring to appear on the leaderboard!"})]})}):e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsxs(O,{className:"pb-2",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs(z,{className:"text-base flex items-center gap-2",children:[e.jsx(ke,{className:"w-4 h-4 text-chart-4"}),"Affiliate Leaderboard"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(g,{variant:N==="thisMonth"?"secondary":"ghost",size:"sm",onClick:()=>m("thisMonth"),className:"h-7 px-2 text-xs",children:"This Month"}),e.jsx(g,{variant:N==="lastMonth"?"secondary":"ghost",size:"sm",onClick:()=>m("lastMonth"),className:"h-7 px-2 text-xs",children:"Last Month"}),e.jsx(g,{variant:N==="allTime"?"secondary":"ghost",size:"sm",onClick:()=>m("allTime"),className:"h-7 px-2 text-xs",children:"All Time"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:p(N)})]}),e.jsxs(u,{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-1 p-1 bg-muted/30 rounded-lg w-fit",children:[e.jsxs(g,{variant:o==="referrals"?"secondary":"ghost",size:"sm",onClick:()=>C("referrals"),className:"h-8 px-3 text-xs gap-1.5",children:[e.jsx(fe,{className:"w-3.5 h-3.5"}),"Referrals"]}),e.jsxs(g,{variant:o==="conversions"?"secondary":"ghost",size:"sm",onClick:()=>C("conversions"),className:"h-8 px-3 text-xs gap-1.5",children:[e.jsx(J,{className:"w-3.5 h-3.5"}),"Conversions"]}),e.jsxs(g,{variant:o==="earnings"?"secondary":"ghost",size:"sm",onClick:()=>C("earnings"),className:"h-8 px-3 text-xs gap-1.5",children:[e.jsx(ne,{className:"w-3.5 h-3.5"}),"Earnings"]})]}),w&&M&&e.jsxs("div",{className:U("flex items-center justify-between p-3 rounded-lg border",w<=3?"bg-primary/5 border-primary/20":"bg-muted/30 border-border/50"),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex items-center justify-center w-8 h-8 rounded-full bg-primary/10",children:w<=3?e.jsx(es,{className:"w-4 h-4 text-primary"}):e.jsxs("span",{className:"text-sm font-bold text-primary",children:["#",w]})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-foreground",children:"Your Rank"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[x(M[o],o)," ",l(o).toLowerCase()]})]})]}),w<=10&&e.jsx($,{variant:"outline",className:"text-chart-3 border-chart-3/30 bg-chart-3/10",children:"Top 10"})]}),e.jsx("div",{className:"space-y-2",children:v.map((r,y)=>{const c=y+1,f=r.affiliate_id===t;return e.jsxs("div",{className:U("flex items-center gap-3 p-3 rounded-lg transition-colors",f?"bg-primary/10 border border-primary/20":c<=3?"bg-muted/50":"bg-muted/20 hover:bg-muted/30"),children:[e.jsx("div",{className:"flex items-center justify-center w-8",children:i(c)}),e.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[e.jsx(ss,{className:"w-8 h-8",children:e.jsx(ts,{className:U("text-xs font-medium",c<=3?a(c):"bg-muted"),children:r.display_name.slice(0,2).toUpperCase()})}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("p",{className:U("text-sm font-medium truncate",f?"text-primary":"text-foreground"),children:[r.display_name,f&&e.jsx("span",{className:"text-xs ml-1",children:"(You)"})]})})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:U("text-sm font-bold",o==="earnings"?"text-gradient":"text-foreground"),children:x(r[o],o)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l(o
11)})]}),c<=3&&e.jsxs($,{variant:"outline",className:U("ml-2",a(c)),children:["#",c]})]},r.affiliate_id)})}),n.length>10&&e.jsxs("p",{className:"text-xs text-center text-muted-foreground pt-2",children:["Showing top 10 of ",n.length," affiliates"]})]})]})}function Rs(){const{user:n}=rs(),[t,o]=d.useState(null),[C,N]=d.useState([]),[m,v]=d.useState([]),[w,M]=d.useState(0),[i,a]=d.useState([]),[x,l]=d.useState(!0),[p,r]=d.useState(null),[y,c]=d.useState(!1),[f,S]=d.useState(!1),[_,T]=d.useState(""),[b,R]=d.useState(""),[P,F]=d.useState(!1),B="https://foreseek.ai",K=d.useCallback(async()=>{if(n)try{const{data:s,error:k}=await A.from("affiliates").select("*").eq("user_id",n.id).single();if(k){console.error("Error fetching affiliate:",k);return}o(s),T(s.custom_slug||""),R(s.custom_code||""),s.status==="approved"&&(!s.custom_slug||!s.custom_code)&&c(!0);const{data:se}=await A.from("affiliate_referrals").select("*").eq("affiliate_id",s.id).order("clicked_at",{ascending:!1}).limit(50);N(se||[]);const{data:Ze}=await A.from("affiliate_commissions").select("*").eq("affiliate_id",s.id).order("created_at",{ascending:!1}).limit(50);v(Ze||[]);const{count:Ie}=await A.from("waitlist_signups").select("*",{count:"exact",head:!0}).eq("affiliate_id",s.id);M(Ie||0);const{data:Le}=await A.from("affiliates").select("id, full_name, total_referrals, total_earnings").eq("status","approved");if(Le){const{data:pe}=await A.from("affiliate_referrals").select("affiliate_id, converted_at"),je={};pe==null||pe.forEach(Y=>{Y.converted_at&&(je[Y.affiliate_id]=(je[Y.affiliate_id]||0)+1)}),a(Le.map(Y=>({affiliate_id:Y.id,display_name:Y.full_name||"Anonymous",referrals:Y.total_referrals||0,conversions:je[Y.id]||0,earnings:Y.total_earnings||0})))}}catch(s){console.error("Error fetching affiliate data:",s)}finally{l(!1)}},[n]);d.useEffect(()=>{K()},[K]);const H=async(s,k)=>{try{await navigator.clipboard.writeText(s),r(k),E.success("Copied to clipboard!"),setTimeout(()=>r(null),2e3)}catch{E.error("Failed to copy")}},D=async()=>{if(t){F(!0);try{const s={};if(_!==t.custom_slug){if(!/^[a-z0-9-]{3,30}$/.test(_.toLowerCase())){E.error("Slug must be 3-30 characters, lowercase letters, numbers, and hyphens only"),F(!1);return}const{data:se}=await A.from("reserved_slugs").select("slug").eq("slug",_.toLowerCase()).single();if(se){E.error("This slug is reserved"),F(!1);return}s.custom_slug=_.toLowerCase()}if(b!==t.custom_code){if(!/^[A-Z0-9]{4,8}$/.test(b.toUpperCase())){E.error("Code must be 4-8 characters, uppercase letters and numbers only"),F(!1);return}s.custom_code=b.toUpperCase()}if(Object.keys(s).length>0){const{error:k}=await A.from("affiliates").update(s).eq("id",t.id);if(k){if(k.code==="23505")E.error("This slug or code is already taken");else throw k;F(!1);return}E.success("Settings saved!"),K()}S(!1)}catch(s){console.error("Error saving settings:",s),E.error("Failed to save settings")}finally{F(!1)}}},q=async()=>{try{const{data:s,error:k}=await A.rpc("generate_affiliate_code");if(k)throw k;R(s)}catch(s){console.error("Error generating code:",s),E.error("Failed to generate code")}};if(x)return e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(ue,{className:"w-8 h-8 animate-spin text-primary"})});if(!t)return e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"py-12 text-center",children:[e.jsx("p",{className:"text-muted-foreground mb-4",children:"You don't have an affiliate account yet."}),e.jsx(g,{onClick:()=>window.location.href="/affiliate",children:"Apply to Become an Affiliate"})]})});if(t.status==="pending")return e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"py-12 text-center",children:[e.jsx($,{variant:"secondary",className:"mb-4",children:"Pending Review"}),e.jsx("h3",{className:"text-xl font-semibold text-foreground mb-2",children:"Application Under Review"}),e.jsx("p",{className:"text-muted-foreground",children:"Your affiliate application is being reviewed. We'll notify you once it's approved."})]})});if(t.status==="rejected"||t.status==="suspended")return e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"py-12 text-center",children:[e.jsx($,{variant:"destructive",className:"mb-4",children:t.status==="rejected"?"Application Rejected":"Account Suspended"}),e.jsx("h3",{className:"text-xl font-semibold text-foreground mb-2",children:t.status==="rejected"?"Application Not Approved":"Account Suspended"}),e.jsx("p",{className:"text-muted-foreground",children:"Please contact support for more information."})]})});if(y)return e.jsx(h,{className:"glass-card border-border/50 max-w-md mx-auto",children:e.jsx(u,{className:"py-8",children:e.jsx(Ms,{affiliateId:t.id,fullName:t.full_name,existingSlug:t.custom_slug,existingCode:t.custom_code,onComplete:()=>{c(!1),K()}})})});const le=t.custom_slug?`${B}/${t.custom_slug}`:`${B}
11?ref=${t.custom_code||t.id.slice(0,8)}`,Z=m.filter(s=>s.status==="pending").reduce((s,k)=>s+k.commission_amount,0);m.filter(s=>s.status==="paid").reduce((s,k)=>s+k.commission_amount,0);const ee=C.filter(s=>s.signed_up_at).length,ge=C.filter(s=>s.converted_at).length,j=ns();return e.jsxs(vs,{defaultValue:"overview",className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs(ys,{className:"grid w-full grid-cols-3 max-w-md",children:[e.jsxs(ve,{value:"overview",className:"gap-2",children:[e.jsx(Ce,{className:"w-4 h-4"}),"Overview"]}),e.jsxs(ve,{value:"analytics",className:"gap-2",children:[e.jsx(ls,{className:"w-4 h-4"}),"Analytics"]}),e.jsxs(ve,{value:"leaderboard",className:"gap-2",children:[e.jsx(ke,{className:"w-4 h-4"}),"Leaderboard"]})]}),e.jsxs(g,{variant:"outline",onClick:()=>j("/dashboard/affiliate/resources"),children:[e.jsx(ks,{className:"w-4 h-4 mr-2"}),"Resources"]})]}),e.jsxs(ye,{value:"overview",className:"space-y-6",children:[e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsx(O,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(z,{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"w-5 h-5"}),"Your Referral Link"]}),e.jsx(Ae,{children:"Share this link to earn commissions"})]}),e.jsxs(is,{open:f,onOpenChange:S,children:[e.jsx(cs,{asChild:!0,children:e.jsxs(g,{variant:"outline",size:"sm",children:[e.jsx(Ns,{className:"w-4 h-4 mr-2"}),"Customize"]})}),e.jsxs(os,{children:[e.jsxs(ds,{children:[e.jsx(xs,{children:"Customize Your Links"}),e.jsx(ms,{children:"Create a custom slug for your URL and a short code for sharing."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(he,{htmlFor:"slug",children:"Custom URL Slug"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[B,"/"]}),e.jsx(Q,{id:"slug",value:_,onChange:s=>T(s.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:"yourname",className:"flex-1"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"3-30 characters, lowercase letters, numbers, and hyphens only"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(he,{htmlFor:"code",children:"Short Code"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{id:"code",value:b,onChange:s=>R(s.target.value.toUpperCase().replace(/[^A-Z0-9]/g,"").slice(0,8)),placeholder:"TRADER",className:"flex-1"}),e.jsx(g,{variant:"outline",size:"sm",onClick:q,children:"Generate"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["4-8 characters, used as ?ref=",b||"CODE"]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(g,{variant:"outline",onClick:()=>S(!1),children:"Cancel"}),e.jsxs(g,{onClick:D,disabled:P,children:[P?e.jsx(ue,{className:"w-4 h-4 animate-spin mr-2"}):null,"Save Changes"]})]})]})]})]})}),e.jsxs(u,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{value:le,readOnly:!0,className:"font-mono text-sm"}),e.jsx(g,{variant:"outline",size:"icon",onClick:()=>H(le,"url"),children:p==="url"?e.jsx(we,{className:"w-4 h-4 text-chart-3"}):e.jsx(Se,{className:"w-4 h-4"})})]}),t.custom_code&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Code:"}),e.jsx("code",{className:"px-2 py-1 bg-muted rounded text-sm font-mono",children:t.custom_code}),e.jsx(g,{variant:"ghost",size:"sm",onClick:()=>H(t.custom_code,"code"),children:p==="code"?e.jsx(we,{className:"w-4 h-4 text-chart-3"}):e.jsx(Se,{className:"w-4 h-4"})})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-5 gap-4",children:[e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"pt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(fe,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:"Total Clicks"})]}),e.jsx("div",{className:"text-2xl font-bold text-foreground",children:C.length})]})}),e.jsx(h,{className:"glass-card border-border/50 border-primary/30 bg-primary/5",children:e.jsxs(u,{className:"pt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-primary mb-1",children:[e.jsx(hs,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm font-medium",children:"Waitlist"})]}),e.jsx("div",{className:"text-2xl font-bold text-primary",children:w})]})}),e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"pt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(J,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:"Signups"})]}),e.jsx("div",{className:"text-2xl font-bold text-foreground",children:ee})]})}),e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"pt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(ne,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:"Pending"})]}),e.jsxs("div",{className:"text-2xl font-bold text-foreground",children:["$",Z.toFixed(2)]})]})}),e.jsx(h,{className:"glass-card border-border/50",children:e.jsxs(u,{className:"pt-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground mb-1",children:[e.jsx(ne,{className:"w-4 h-4"}),e.jsx("span",{className:"text-sm",children:"Total Earned"})]}),e.jsxs("div",{className:"text-2xl font-bold text-gradient",children:["$",t.total_earnings.toFixed(2)]})]})})]}),e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsx(O,{children:e.jsx(z,{className:"text-lg",children:"Your Commission Rates"})}),e.jsx(u,{children:e.jsxs("div",{className:"flex items-center gap-8",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-3xl font-bold text-gradient",children:[t.commission_year1,"%"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"First Year"})]}),e.jsxs("div",{children:[e.jsxs("span",{className:"text-3xl font-bold text-gradient",children:[t.commission_lifetime,"%"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Lifetime"})]})]})})]}),e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsxs(O,{children:[e.jsx(z,{className:"text-lg",children:"Recent Referrals"}),e.jsxs(Ae,{children:[ee," signups, ",ge," converted"]})]}),e.jsx(u,{children:C.length===0?e.jsx("p",{className:"text-muted-foreground text-center py-8",children:"No referrals yet. Share your link to get started!"}):e.jsxs(Ee,{children:[e.jsx($e,{children:e.jsxs(ce,{children:[e.jsx(W,{children:"Email"}),e.jsx(W,{children:"Source"}),e.jsx(W,{children:"Status"}),e.jsx(W,{children:"Date"})]})}),e.jsx(Oe,{children:C.slice(0,10).map(s=>e.jsxs(ce,{children:[e.jsx(G,{className:"font-mono text-sm",children:s.referred_email?s.referred_email.replace(/(.{2}).*(@.*)/,"$1***$2"):"—"}),e.jsx(G,{children:e.jsx($,{variant:"outline",className:"capitalize",children:s.referral_source})}),e.jsx(G,{children:s.converted_at?e.jsx($,{className:"bg-foreseek-success/20 text-foreseek-success border-0",children:"Converted"}):s.signed_up_at?e.jsx($,{variant:"secondary",children:"Signed Up"}):e.jsx($,{variant:"outline",children:"Clicked"})}),e.jsx(G,{className:"text-muted-foreground text-sm",children:L(new Date(s.clicked_at),"MMM d, yyyy")})]},s.id))})]})})]}),m.length>0&&e.jsxs(h,{className:"glass-card border-border/50",children:[e.jsx(O,{children:e.jsx(z,{className:"text-lg",children:"Commission History"})}),e.jsx(u,{children:e.jsxs(Ee,{children:[e.jsx($e,{children:e.jsxs(ce,{children:[e.jsx(W,{children:"Period"}),e.jsx(W,{children:"Spend"}),e.jsx(W,{children:"Rate"}),e.jsx(W,{children:"Earned"}),e.jsx(W,{children:"Status"})]})}),e.jsx(Oe,{children:m.map(s=>e.jsxs(ce,{children:[e.jsxs(G,{className:"text-sm",children:[L(new Date(s.period_start),"MMM d")," - ",L(new Date(s.period_end),"MMM d, yyyy")]}),e.jsxs(G,{className:"font-mono",children:["$",s.spend_amount.toFixed(2)]}),e.jsxs(G,{children:[s.commission_rate,"%"]}),e.jsxs(G,{className:"font-mono font-semibold text-foreseek-success",children:["$",s.commission_amount.toFixed(2)]}),e.jsx(G,{children:e.jsx($,{variant:s.status==="paid"?"default":"secondary",className:s.status==="paid"?"bg-foreseek-success/20 text-foreseek-success border-0":"",children:s.status})})]},s.id))})]})})]})]}),e.jsx(ye,{value:"analytics",children:e.jsx(Ls,{referrals:C,commissions:m})}),e.jsx(ye,{value:"leaderboard",children:e.jsx(Ts,{leaderboardData:i,currentAffiliateId:t.id})})]})}function Bs(){return e.jsx(Rs,{})}export{Bs 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.