PageSourceSearch

https://vitaapps.dev/assets/AdminView-Jt5BZBVq.js

js vitaapps.dev collected 2026-09-24 15:01:25 UTC 32,756 bytes, 5 lines download raw bytes

1import{j as e}from"./index-376A2J5H.js";import{r as i}from"./vendor-react-0R6VX6ld.js";import{u as z,a as U,n as b,p as Q,e as v,L as V,b as W,i as N,c as _,d as q,f as H,g as J,h as K,j as X,k as Z,l as ee,m as te,o as se}from"./payoutPdf-uMJniZTb.js";import{g as ae}from"./LynkrDashboard-azBE6jpK.js";import"./vendor-three-dec0Z_i3.js";import"./vendor-framer-JqHIcSWX.js";import"./vendor-icons-LlCGcXb-.js";import"./useInfiniteQuery-J-lWAN95.js";import"./jspdf.es.min-6-6ucsSz.js";import"./index-9ccb475d-PhXEXAVG.js";import"./index.esm-9ScWneaz.js";import"./index.esm-8Nbthlc-.js";const O=[{key:"7d",label:"7 Days"},{key:"30d",label:"30 Days"},{key:"90d",label:"90 Days"},{key:"thisMonth",label:"This Month"},{key:"lastMonth",label:"Last Month"},{key:"custom",label:"Custom"}];function le(t){var a;return((a=O.find(s=>s.key===t))==null?void 0:a.label)??""}const re=()=>{var k,S,A;const[t,a]=i.useState("thisMonth"),[s,d]=i.useState(oe),[r,c]=i.useState(()=>f(B())),o=$(s)&&$(r)&&s<=r,[p,m]=i.useState(!1),x=i.useRef(null);i.useEffect(()=>{if(!p)return;const h=T=>{x.current&&!x.current.contains(T.target)&&m(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[p]);const y=t==="custom"?o?{fromDate:s,toDate:r}:E("30d"):E(t),n=z(y),u=U(),l=n.data??null,g=n.isLoading||u.isLoading,w=((k=n.error)==null?void 0:k.message)??((S=u.error)==null?void 0:S.message)??null,C=(((A=u.data)==null?void 0:A.influencers)??[]).filter(h=>h.active).slice().sort((h,T)=>T.stats.mtdPayoutCents-h.stats.mtdPayoutCents).slice(0,3);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-white",children:"Overview"}),e.jsxs("div",{ref:x,className:"relative",children:[e.jsx("div",{className:"flex flex-wrap items-center gap-1 rounded-lg border border-gympal-dark2 bg-gympal-cards p-1",children:O.map(h=>e.jsx("button",{type:"button",onClick:()=>{a(h.key),m(h.key==="custom")},className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${t===h.key?"bg-gympal-yellow text-black":"text-gympal-darkTypo hover:text-white"}`,children:h.label},h.key))}),p&&e.jsxs("div",{className:"absolute right-0 top-full z-30 mt-2 flex flex-col gap-3 rounded-lg border border-gympal-dark2 bg-gympal-cards p-3 shadow-xl shadow-black/40",children:[e.jsxs("label",{className:"flex items-center justify-between gap-3 text-xs text-gympal-darkTypo",children:["From",e.jsx("input",{type:"date",value:s,max:r||void 0,onChange:h=>d(h.target.value),className:"rounded-md border border-gympal-dark2 bg-gympal-bg px-2 py-1 text-xs text-white"})]}),e.jsxs("label",{className:"flex items-center justify-between gap-3 text-xs text-gympal-darkTypo",children:["To",e.jsx("input",{type:"date",value:r,min:s||void 0,onChange:h=>c(h.target.value),className:"rounded-md border border-gympal-dark2 bg-gympal-bg px-2 py-1 text-xs text-white"})]}),!o&&e.jsx("span",{className:"max-w-[14rem] text-xs text-gympal-orange",children:"Pick a valid range (showing last 30 days meanwhile)"})]})]})]}),w&&e.jsx("div",{className:"rounded-xl border border-gympal-orange/40 bg-gympal-orange/10 p-3 text-sm text-gympal-orange",children:w}),g&&!l&&e.jsx("div",{className:"flex justify-center py-12",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-gympal-yellow border-t-transparent"})}),l&&e.jsx(ne,{data:l,topInfluencers:C,loading:g,rangeText:t==="custom"&&o?`${s} – ${r}`:le(t)})]})},ne=({data:t,topInfluencers:a,loading:s,rangeText:d})=>{const{stats:r,charts30d:c}=t,o=L(c.revenue),p=L(c.refunds);return e.jsxs("div",{className:`space-y-4 transition-opacity ${s?"opacity-60":""}`,children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-12",children:[e.jsx(R,{label:"Total Users",value:b(r.totalUsers),extra:e.jsxs("div",{className:"mt-2 flex flex-wrap gap-x-3 gap-y-1 text-xs",children:[e.jsxs("span",{className:"text-gympal-yellow",children:["+",b(r.signupsLast7d)," (7d)"]}),e.jsxs("span",{className:"text-gympal-yellow",children:["+",b(r.signupsLast30d)," (30d)"]}
1)]})}),e.jsx(R,{label:"Active Users",value:`${b(r.dau)} / ${b(r.wau)} / ${b(r.mau)}`,sub:`Stickiness ${Q(r.stickiness)}`}),e.jsx(R,{label:`Revenue · ${d}`,value:v(o),sub:`${v(p)} refunds · ${v(r.mtdRevenueCents)} MTD · ${b(r.weeklySubsActive)}W · ${b(r.threeMonthSubsActive)}3M · ${b(r.yearlySubsActive)}Y active`})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-12",children:[e.jsx(M,{title:"Daily Active Users",points:c.dau,formatY:b}),e.jsx(M,{title:"New Signups",points:c.signups,formatY:b}),e.jsx(M,{title:"New Subs",points:c.newSubs,formatY:b})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-12",children:[e.jsx(M,{title:"Revenue",points:c.revenue,formatY:v,span:"lg:col-span-6"}),e.jsx(M,{title:"Refunds",points:c.refunds,formatY:v,span:"lg:col-span-6",note:`${v(r.refundsThisMonthCents)} this month`})]}),e.jsx(de,{influencers:a,totalActive:r.activeInfluencers})]})},R=({label:t,value:a,sub:s,extra:d})=>e.jsxs("div",{className:"rounded-xl border border-gympal-dark2 bg-gympal-bg p-6 lg:col-span-4",children:[e.jsx("div",{className:"mb-2 text-xs uppercase tracking-wider text-gympal-darkTypo",children:t}),e.jsx("div",{className:"text-3xl font-bold text-white",children:a}),s&&e.jsx("div",{className:"mt-2 text-xs text-gympal-darkTypo",children:s}),d]}),M=({title:t,points:a,formatY:s,span:d="lg:col-span-4",note:r})=>e.jsxs("div",{className:`rounded-xl border border-gympal-dark2 bg-gympal-bg p-5 ${d}`,children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("div",{className:"text-xs uppercase tracking-wider text-gympal-darkTypo",children:t}),r&&e.jsx("div",{className:"text-xs text-gympal-darkTypo",children:r})]}),e.jsx(V,{points:a??[],formatY:s})]}),de=({influencers:t,totalActive:a})=>e.jsxs("div",{className:"rounded-xl border border-gympal-dark2 bg-gympal-bg p-5",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("div",{className:"text-xs uppercase tracking-wider text-gympal-darkTypo",children:"Top Influencers · MTD"}),e.jsxs("span",{className:"text-[10px] text-gympal-darkTypo",children:[b(a)," active"]})]}),t.length===0?e.jsx("div",{className:"py-6 text-center text-sm text-gympal-darkTypo",children:"No influencer payouts this month yet."}):e.jsx("div",{className:"divide-y divide-gympal-dark2",children:t.map((s,d)=>e.jsxs("div",{className:"flex items-center justify-between py-3 first:pt-1 last:pb-1",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-gympal-yellow/15 text-xs font-semibold text-gympal-yellow",children:d+1}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-white",children:s.name}),e.jsx("div",{className:"font-mono text-xs text-gympal-darkTypo",children:s.code})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-sm font-semibold text-gympal-yellow",children:v(s.stats.mtdPayoutCents)}),e.jsxs("div",{className:"text-[10px] text-gympal-darkTypo",children:[b(s.stats.totalSubs)," Subs · ",s.payoutPercent,"% Share"]})]})]},s.id))})]});function f(t){const a=t.getUTCFullYear(),s=String(t.getUTCMonth()+1).padStart(2,"0"),d=String(t.getUTCDate()).padStart(2,"0");return`${a}-${s}-${d}`}function B(){const t=new Date;return new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()))}function oe(){return f(new Date(B().getTime()-29*864e5))}function $(t){return/^\d{4}-\d{2}-\d{2}$/.test(t)}function L(t){return(t??[]).reduce((a,s)=>a+(Number(s.value)||0),0)}function E(t){const a=new Date,s=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate()));if(t==="7d"||t==="30d"||t==="90d"){const c=t==="7d"?7:t==="30d"?30:90,o=new Date(s.getTime()-(c-1)*864e5);return{fromDate:f(o),toDate:f(s)}}if(t==="thisMonth"){const c=new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth(),1));return{fromDate:f(c),toDate:f(s)}}const d=new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth()-1,1)),r=new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth(),0));return{fromDate:f(d),toDate:f(r)}}const ce=()=>{const[t,a]=i.useState("all"),[s,d]=i.useState("all"),r=i.useMemo(()=>({type:t,status:s}),[t,s]),{data:c,error:o,isFetching:p,isFetchingNextPage:m,fetchNextPage:x,hasNextPage:y}=W(r),n=i.useMemo(()=>((c==null?void 0:c.pages)??[]).flatMap(l=>l.rows),[c]),u=(o==null?void 0:o.message)??null;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("select",{value:t,onChange:l=>a(l.target.value),className:"gympal-select rounded-lg border border-gympal-dark2 bg-gympal-cards px-3 py-1.5 text-xs text-white",children:[e.jsx("option",{value:"all",children:"All Types"}),e.jsx("option",{value:"weekly",children:"Weekly"}),e.jsx("option",{value:"threeMonth",children:"3 Months"}),e.jsx("option",{value:"yearly",children:"Yearly"})]}),e.jsxs("select",{value:s,onChange:l=>d(l.target.value),className:"gympal-select rounded-lg border border-gympal-dark2 bg-gympal-cards px-3 py-1.5 text-xs text-white",children:[e.jsx("option",{value:"all",children:"All Statuses"}),e.jsx("option",{value:"active",children:"Active"}),e.jsx("option",{value:"cancelled",children:"Cancelled"}),e.jsx("option",{value:"expired",children:"Expired"}),e.jsx("option",{value:"refunded",children:"Refunded"}),e.jsx("option",{value:"billing_issue",children:"Billing Issue"})]}),e.jsxs("span",{className:"text-xs text-gympal-darkTypo",children:[n.length," entries"]}),e.jsx("button",{type:"button",onClick:()=>xe(n),disabled:n.length===0,className:"ml-auto rounded-lg border border-gympal-dark2 bg-gympal-cards px-3 py-1.5 text-xs text-white transition-colors hover:border-gympal-yellow/50 disabled:opacity-50",children:"Export CSV"})]}),u&&e.jsx("div",{className:"rounded-xl border border-gympal-orange/40 bg-gympal-orange/10 p-3 text-sm text-gympal-orange",children:u}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-gympal-dark2",children:e.jsxs("table",{className:"w-full min-w-[1100px] text-left text-sm",children:[e.jsx("thead",{className:"bg-gympal-bg text-xs uppercase text-gympal-darkTypo",children:e.jsx("tr",{children:["User","Type","Product","Store","Gross","Net","Promo","Influencer","Start","End","Status"].map(l=>e.jsx("th",{className:"px-4 py-3 font-medium",children:l},l))})}),e.jsxs("tbody",{className:"divide-y divide-gympal-dark2",children:[n.map(l
1=>e.jsxs("tr",{className:"text-gray-200",children:[e.jsxs("td",{className:"px-4 py-2 font-mono text-xs text-gympal-darkTypo",children:[l.userId.slice(0,10),"…"]}),e.jsx("td",{className:"px-4 py-2",children:ie(l.type)}),e.jsx("td",{className:"px-4 py-2 font-mono text-xs",children:l.productId}),e.jsx("td",{className:"px-4 py-2",children:l.store}),e.jsx("td",{className:"px-4 py-2",children:v(l.grossCents)}),e.jsx("td",{className:"px-4 py-2",children:v(l.netToUsCents)}),e.jsx("td",{className:"px-4 py-2",children:l.isPromo?e.jsxs("span",{className:"rounded bg-gympal-yellow/20 px-2 py-0.5 text-xs text-gympal-yellow",children:["-",l.discountTier,"%"]}):e.jsx("span",{className:"text-gympal-darkTypo",children:"–"})}),e.jsx("td",{className:"px-4 py-2 font-mono text-xs text-gympal-yellow",children:l.influencerCode??"–"}),e.jsx("td",{className:"px-4 py-2 text-xs",children:N(l.startedAt)}),e.jsx("td",{className:"px-4 py-2 text-xs",children:N(l.expiresAt)}),e.jsx("td",{className:"px-4 py-2 text-xs",children:l.status})]},l.id)),!p&&n.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:11,className:"px-4 py-8 text-center text-gympal-darkTypo",children:"No subscriptions found."})})]})]})}),e.jsx("div",{className:"flex justify-center",children:y&&e.jsx("button",{type:"button",onClick:()=>x(),disabled:m,className:"rounded-lg border border-gympal-dark2 px-4 py-2 text-xs text-white hover:border-gympal-yellow/50 disabled:opacity-50",children:m?"Loading…":"Load more"})})]})};function ie(t){switch(t){case"weekly":return"Wk.";case"threeMonth":return"3M.";case"yearly":return"Yr."}}function xe(t){const a=";",s=["id","userId","type","productId","store","currency","grossCents","netToUsCents","isPromo","discountTier","influencerCode","startedAt","expiresAt","status","refundedAt"],d=/[";\n\r]/,r=n=>{if(n==null)return"";const u=String(n);return d.test(u)?'"'+u.replace(/"/g,'""')+'"':u},c=[s.join(a)];for(const n of t)c.push([n.id,n.userId,n.type,n.productId,n.store,n.currency,n.grossCents,n.netToUsCents,n.isPromo,n.discountTier,n.influencerCode,n.startedAt,n.expiresAt,n.status,n.refundedAt].map(r).join(a));const o="\uFEFF"+c.join(`\r
2`)+`\r
3`,p=new Blob([o],{type:"text/csv;charset=utf-8"}),m=URL.createObjectURL(p),x=document.createElement("a");x.href=m;const y=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);
3x.download=`gympal-subscriptions-${y}.csv`,document.body.appendChild(x),x.click(),document.body.removeChild(x),URL.revokeObjectURL(m)}const pe=[10,20,30,50],me=()=>{const{data:t,isLoading:a,error:s}=U(),d=(t==null?void 0:t.influencers)??[],r=(s==null?void 0:s.message)??null,c=_(),[o,p]=i.useState(null),[m,x]=i.useState(!1),[y,n]=i.useState(null),u=async l=>{window.confirm(`Really deactivate "${l.name}"?`)&&await c.mutateAsync(l.id)};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold text-white",children:"Influencers"}),e.jsx("button",{type:"button",onClick:()=>x(!0),className:"rounded-lg bg-gympal-yellow px-4 py-2 text-xs font-semibold text-black hover:brightness-110",children:"New Influencer"})]}),r&&e.jsx("div",{className:"rounded-xl border border-gympal-orange/40 bg-gympal-orange/10 p-3 text-sm text-gympal-orange",children:r}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-gympal-dark2",children:e.jsxs("table",{className:"w-full min-w-[900px] text-left text-sm",children:[e.jsx("thead",{className:"bg-gympal-bg text-xs uppercase text-gympal-darkTypo",children:e.jsx("tr",{children:["Name","Email","Code","Discount","Share","Active","Subs","MTD","Lifetime","Actions"].map(l=>e.jsx("th",{className:"px-4 py-3 font-medium",children:l},l))})}),e.jsxs("tbody",{className:"divide-y divide-gympal-dark2",children:[a&&e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"px-4 py-8 text-center text-gympal-darkTypo",children:"Loading…"})}),!a&&d.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:10,className:"px-4 py-8 text-center text-gympal-darkTypo",children:"No influencers yet."})}),d.map(l=>e.jsxs("tr",{className:"text-gray-200",children:[e.jsx("td",{className:"px-4 py-3",children:l.name}),e.jsx("td",{className:"px-4 py-3 text-gympal-darkTypo",children:l.email}),e.jsx("td",{className:"px-4 py-3 font-mono text-gympal-yellow",children:l.code}),e.jsxs("td",{className:"px-4 py-3",children:[l.discountTier,"%"]}),e.jsxs("td",{className:"px-4 py-3",children:[l.payoutPercent,"%"]}),e.jsx("td",{className:"px-4 py-3",children:l.active?e.jsx("span",{className:"rounded bg-gympal-yellow/20 px-2 py-0.5 text-xs text-gympal-yellow",children:"Active"}):e.jsx("span",{className:"rounded bg-gympal-dark2 px-2 py-0.5 text-xs text-gympal-darkTypo",children:"Inactive"})}),e.jsx("td",{className:"px-4 py-3",children:b(l.stats.totalSubs)}),e.jsx("td",{className:"px-4 py-3",children:v(l.stats.mtdPayoutCents)}),e.jsx("td",{className:"px-4 py-3",children:v(l.stats.lifetimePayoutCents)}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",onClick:()=>p(l),className:"rounded border border-gympal-dark2 px-2 py-1 text-xs hover:border-gympal-yellow/50",children:"Edit"}),e.jsx("button",{type:"button",onClick:()=>n(l),className:"rounded border border-gympal-dark2 px-2 py-1 text-xs hover:border-gympal-yellow/50",children:"Report"}),l.active&&e.jsx("button",{type:"button",onClick:()=>u(l),className:"rounded border border-gympal-orange/30 px-2 py-1 text-xs text-gympal-orange hover:bg-gympal-orange/10",children:"Deactivate"})]})})]},l.id))]})]})}),m&&e.jsx(Y,{mode:"create",onClose:()=>x(!1),onSaved:()=>x(!1)}),o&&e.jsx(Y,{mode:"edit",initial:o,onClose:()=>p(null),onSaved:()=>p(null)}),y&&e.jsx(ue,{influencer:y,onClose:()=>n(null)})]})},Y=({mode:t,initial:a,onClose:s,onSaved:d})=>{var T,F;const[r,c]=i.useState((a==null?void 0:a.name)??""),[o,p]=i.useState((a==null?void 0:a.email)??""),[m,x]=i.useState((a==null?void 0:a.code)??""),[y,n]=i.useState((a==null?void 0:a.discountTier)??20),[u,l]=i.useState((a==null?void 0:a.payoutPercent)??4),[g,w]=i.useState((a==null?void 0:a.active)??!0),C=q(),k=H(),S=C.isPending||k.isPending,A=((T=C.error)==null?void 0:T.message)??((F=k.error)==null?void 0:F.message)??null,h=async()=>{try{if(t==="create")(await C.mutateAsync({name:r,email:o,code:m,discountTier:y,payoutPercent:u})).roleAssigned?window.alert(`Influencer created. Dashboard role auto-assigned to ${o}.`):window.alert(`Influencer created.
4
5No Firebase Auth user found for ${o} yet — once they sign up, assign the role from the "Admins / Roles" tab.`);else if(a){const j={name:r,email:o,code:m,discountTier:y,payoutPercent:u,active:g};await k.mutateAsync({influencerId:a.id,fields:j})}d()}catch{}};return e.jsx(G,{title:t==="create"?"New Influencer":"Edit Influencer",onClose:s,children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(I,{label:"Name",value:r,onChange:c}),e.jsx(I,{label:"Email",value:o,onChange:p,type:"email"}),e.jsx(I,{label:"Code",value:m,onChange:j=>x(j.toUpperCase())}),e.jsxs("div",{children:[e.jsx(P,{children:"Discount Tier"}),e.jsx("select",{value:y,onChange:j=>n(Number(j.target.value)),className:"gympal-select w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white outline-none focus:border-gympal-yellow/60",children:pe.map(j=>e.jsxs("option",{value:j,children:[j,"%"]},j))})]}),e.jsxs("div",{children:[e.jsx(P,{children:"Influencer Share (%)"}),e.jsx("input",{type:"number",min:0,max:100,step:.5,value:u,onChange:j=>l(Number(j.target.value)),className:"w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white outline-none focus:border-gympal-yellow/60"})]}),t==="edit"&&e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gympal-darkTypo",children:[e.jsx("input",{type:"checkbox",checked:g,onChange:j=>w(j.target.checked)}),"Active"]}),A&&e.jsx("div",{className:"rounded bg-gympal-orange/10 p-2 text-xs text-gympal-orange",children:A}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:s,className:"rounded-lg border border-gympal-dark2 px-4 py-2 text-xs text-gympal-darkTypo hover:text-white",children:"Cancel"}),e.jsx("button",{type:"button",disabled:S,onClick:h,className:"rounded-lg bg-gympal-yellow px-4 py-2 text-xs font-semibold text-black hover:brightness-110 disabled:opacity-50",children:S?"Saving…":"Save"})]})]})})},ue=({influencer:t,onClose:a})=>{const s=new Date,d=`${s.getFullYear()}
5-${String(s.getMonth()+1).padStart(2,"0")}`,[r,c]=i.useState(d),[o,p]=i.useState(!1),[m,x]=i.useState(null),y=async()=>{p(!0),x(null);try{const n=await ae({influencerId:t.id,period:r});J(n),a()}catch(n){x(n.message)}finally{p(!1)}};return e.jsx(G,{title:`Report for ${t.name}`,onClose:a,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(P,{children:"Month"}),e.jsx("input",{type:"month",value:r,onChange:n=>c(n.target.value),className:"w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white outline-none focus:border-gympal-yellow/60"})]}),e.jsxs("div",{className:"text-xs text-gympal-darkTypo",children:["Created on: ",N(new Date().toISOString())]}),m&&e.jsx("div",{className:"rounded bg-gympal-orange/10 p-2 text-xs text-gympal-orange",children:m}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:a,className:"rounded-lg border border-gympal-dark2 px-4 py-2 text-xs text-gympal-darkTypo hover:text-white",children:"Cancel"}),e.jsx("button",{type:"button",disabled:o,onClick:y,className:"rounded-lg bg-gympal-yellow px-4 py-2 text-xs font-semibold text-black hover:brightness-110 disabled:opacity-50",children:o?"Generating…":"Download PDF"})]})]})})},P=({children:t})=>e.jsx("label",{className:"mb-1 block text-xs uppercase tracking-wider text-gympal-darkTypo",children:t}),I=({label:t,value:a,onChange:s,type:d="text"})=>e.jsxs("div",{children:[e.jsx(P,{children:t}),e.jsx("input",{type:d,value:a,onChange:r=>s(r.target.value),className:"w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white outline-none focus:border-gympal-yellow/60"})]}),G=({title:t,onClose:a,children:s})=>e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:e.jsxs("div",{className:"w-full max-w-md rounded-2xl border border-gympal-dark2 bg-gympal-cards p-6",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h3",{className:"text-base font-semibold text-white",children:t}),e.jsx("button",{type:"button",onClick:a,className:"text-gympal-darkTypo hover:text-white",children:"✕"})]}),s]})}),ye=()=>{const[t,a]=i.useState("open"),s=i.useMemo(()=>({status:t}),[t]),{data:d,error:r,isFetching:c,isFetchingNextPage:o,fetchNextPage:p,hasNextPage:m}=K(s),x=i.useMemo(()=>((d==null?void 0:d.pages)??[]).flatMap(l=>l.rows),[d]),y=(r==null?void 0:r.message)??null,[n,u]=i.useState(null);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("select",{value:t,onChange:l=>a(l.target.value),className:"gympal-select rounded-lg border border-gympal-dark2 bg-gympal-cards px-3 py-1.5 text-xs text-white",children:[e.jsx("option",{value:"open",children:"Open"}),e.jsx("option",{value:"answered",children:"Answered"}),e.jsx("option",{value:"all",children:"All"})]}),e.jsxs("span",{className:"text-xs text-gympal-darkTypo",children:[x.length," entries"]})]}),y&&e.jsx("div",{className:"rounded-xl border border-gympal-orange/40 bg-gympal-orange/10 p-3 text-sm text-gympal-orange",children:y}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-gympal-dark2",children:e.jsxs("table",{className:"w-full min-w-[800px] text-left text-sm",children:[e.jsx("thead",{className:"bg-gympal-bg text-xs uppercase text-gympal-darkTypo",children:e.jsx("tr",{children:["Date","Subject","Message","Reply?","Status"].map(l=>e.jsx("th",{className:"px-4 py-3 font-medium",children:l},l))})}),e.jsxs("tbody",{className:"divide-y divide-gympal-dark2",children:[x.map(l=>e.jsxs("tr",{className:"cursor-pointer text-gray-200 hover:bg-white/[0.02]",onClick:()=>u(l),children:[e.jsx("td",{className:"whitespace-nowrap px-4 py-3 text-xs",children:N(l.createdAt)}),e.jsx("td",{className:"px-4 py-3",children:l.subject||e.jsx("span",{className:"text-gympal-darkTypo",children:"(no subject)"})}),e.jsx("td",{className:"max-w-[420px] truncate px-4 py-3 text-gympal-darkTypo",children:l.message}),e.jsx("td",{className:"px-4 py-3 text-xs",children:l.wantsReply?e.jsx("span",{className:"text-gympal-yellow",children:"Yes"}):e.jsx("span",{className:"text-gympal-darkTypo",children:"No"})}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(ge,{status:l.status})})]},l.id)),!c&&x.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-8 text-center text-gympal-darkTypo",children:"No entries."})})]})]})}),e.jsx("div",{className:"flex justify-center",children:m&&e.jsx("button",{type:"button",onClick:()=>p(),disabled:o,className:"rounded-lg border border-gympal-dark2 px-4 py-2 text-xs text-white hover:border-gympal-yellow/50 disabled:opacity-50",children:o?"Loading…":"Load more"})}),n&&e.jsx(he,{row:n,onClose:()=>u(null),onChanged:()=>u(null)})]})},ge=({status:t})=>t==="open"?e.jsx("span",{className:"rounded bg-gympal-orange/15 px-2 py-0.5 text-xs text-gympal-orange",children:"Open"}):e.jsx("span",{className:"rounded bg-gympal-yellow/20 px-2 py-0.5 text-xs text-gympal-yellow",children:"Answered"}),he=({row:t,onClose:a,onChanged:s})=>{var n,u;const[d,r]=i.useState(t.notes??""),c=X(),o=Z(),p=c.isPending||o.isPending,m=((n=c.error)==null?void 0:n.message)??((u=o.error)==null?void 0:u.message)??null,x=async()=>{try{await c.mutateAsync({id:t.id,notes:d.trim()?d.trim():void 0}),s()}catch{}},y=async()=>{try{await o.mutateAsync(t.id),s()}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",children:e.jsxs("div",{className:"w-full max-w-lg rounded-2xl border border-gympal-dark2 bg-gympal-cards p-6",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsxs("h3",{className:"text-base font-semibold text-white",children:["Feedback"," ",e.jsx("span",{className:"ml-2 text-xs font-normal text-gympal-darkTypo",children:N(t.createdAt)})]}),e.jsx("button",{type:"button",onClick:a,className:"text-gympal-darkTypo hover:text-white",children:"✕"})]}),e.jsxs("div",{className:"space-y-3 text-sm",children:[t.subject&&e.jsxs("div",{children:[e.jsx(D,{children:"Subject"}),e.jsx("div",{className:"text-white",children:t.subject})]}),e.jsxs("div",{children:[e.jsx(D,{children:"Message"}),e.jsx("div",{className:"whitespace-pre-wrap rounded-lg border border-gympal-dark2 bg-gympal-bg p-3 text-white",children:t.message})]}),t.wantsReply&&e.jsxs("div",{children:[e.jsx(D,{children:"Reply requested to"}),e.jsx("a",{href:`mailto:${t.replyEmail}?subject=Re: ${encodeURIComponent(t.subject||"Your feedback to Lynkr")}`,className:"text-gympal-yellow underline",children:t.replyEmail})]}),e.jsxs("div",{children:[e.jsx(D,{children:"User"}),e.jsx("div",{className:"font-mono text-xs text-gympal-darkTypo",children:t.uid??"anonymous"})]}),e.jsxs("div",{children:[e.jsx(D,{children:"Internal notes (optional)"}),e.jsx("textarea",{value:d,onChange:l=>r(l.target.value),rows:3,className:"w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white outline-none focus:border-gympal-yellow/60",placeholder:"E.g. 'replied via email on …'"})]}),t.status==="answered"&&e.jsxs("div",{className:"text-xs text-gympal-darkTypo",children:["Answered on ",N(t.answeredAt)]}),m&&e.jsx("div",{className:"rounded bg-gympal-orange/10 p-2 text-xs text-gympal-orange",children:m}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{type:"button",onClick:a,className:"rounded-lg border border-gympal-dark2 px-4 py-2 text-xs text-gympal-darkTypo hover:text-white",children:"Close"}),t.status==="open"?e.jsx("button",{type:"button",disabled:p,onClick:x,className:"rounded-lg bg-gympal-yellow px-4 py-2 text-xs font-semibold text-black hover:brightness-110 disabled:opacity-50",children:p?"Saving…":"Mark as answered"}):e.jsx("button",{type:"button",disabled:p,onClick:y,className:"rounded-lg border border-gympal-dark2 px-4 py-2 text-xs text-white hover:border-gympal-yellow/50 disabled:opacity-50",children:p?"Saving…":"Reopen"})]})]})]})})},D=({children:t})=>e.jsx("div",{className:"mb-1 text-xs uppercase tracking-wider text-gympal-darkTypo",children:t}),be=()=>{var y;const{data:t,isLoading:a,error:s}=ee(),d=te(),[r,c]=i.useState(10),[o,p]=i.useState(null);i.useEffect(()=>{t&&c(t.costPercentage)},[t]);const m=async()=>{p(null);
5try{await d.mutateAsync(r),p(new Date().toLocaleString("en-GB"))}catch{}};if(a)return e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-gympal-yellow border-t-transparent"})});const x=(s==null?void 0:s.message)??((y=d.error)==null?void 0:y.message)??null;return e.jsxs("div",{className:"max-w-xl space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-white",children:"Revenue Settings"}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs uppercase tracking-wider text-gympal-darkTypo",children:"Cost Share (%)"}),e.jsx("input",{type:"number",min:0,max:100,step:.5,value:r,onChange:n=>c(Number(n.target.value)),className:"w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white outline-none focus:border-gympal-yellow/60"}),e.jsx("p",{className:"mt-2 text-xs text-gympal-darkTypo",children:"Share of net revenue withheld for AI and server costs before the influencer share is calculated."})]}),(t==null?void 0:t.updatedAt)&&e.jsxs("div",{className:"text-xs text-gympal-darkTypo",children:["Last updated: ",N(t.updatedAt)]}),x&&e.jsx("div",{className:"rounded-xl border border-gympal-orange/40 bg-gympal-orange/10 p-3 text-sm text-gympal-orange",children:x}),o&&e.jsxs("div",{className:"rounded-xl border border-gympal-yellow/40 bg-gympal-yellow/10 p-3 text-sm text-gympal-yellow",children:["Saved at ",o]}),e.jsx("button",{type:"button",onClick:m,disabled:d.isPending,className:"rounded-lg bg-gympal-yellow px-4 py-2 text-xs font-semibold text-black hover:brightness-110 disabled:opacity-50",children:d.isPending?"Saving…":"Save"})]})},je=()=>{var l;const{data:t}=U(),a=se(),[s,d]=i.useState(""),[r,c]=i.useState("admin"),[o,p]=i.useState(""),[m,x]=i.useState(null),y=((t==null?void 0:t.influencers)??[]).filter(g=>g.active),n=async()=>{x(null);try{const g=r==="influencer"?{email:s,role:r,influencerId:o}:{email:s,role:r},w=await a.mutateAsync(g);x(`Role assigned for UID ${w.uid}.`),d("")}catch{}},u=((l=a.error)==null?void 0:l.message)??null;return e.jsxs("div",{className:"max-w-xl space-y-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-white",children:"Assign Roles"}),e.jsx("p",{className:"text-xs text-gympal-darkTypo",children:"The user must already exist in Firebase Auth (must have signed up). This action only sets their role."}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs uppercase tracking-wider text-gympal-darkTypo",children:"Email"}),e.jsx("input",{type:"email",value:s,onChange:g=>d(g.target.value),placeholder:"[email protected]",className:"w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white outline-none focus:border-gympal-yellow/60"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs uppercase tracking-wider text-gympal-darkTypo",children:"Role"}),e.jsxs("select",{value:r,onChange:g=>c(g.target.value),className:"gympal-select w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white",children:[e.jsx("option",{value:"admin",children:"Admin"}),e.jsx("option",{value:"influencer",children:"Influencer"}),e.jsx("option",{value:"none",children:"None (remove)"})]})]}),r==="influencer"&&e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-xs uppercase tracking-wider text-gympal-darkTypo",children:"Influencer"}),e.jsxs("select",{value:o,onChange:g=>p(g.target.value),className:"gympal-select w-full rounded-lg border border-gympal-dark2 bg-gympal-bg px-3 py-2 text-sm text-white",children:[e.jsx("option",{value:"",children:"– please select –"}),y.map(g=>e.jsxs("option",{value:g.id,children:[g.name," (",g.code,")"]},g.id))]})]}),u&&e.jsx("div",{className:"rounded-xl border border-gympal-orange/40 bg-gympal-orange/10 p-3 text-sm text-gympal-orange",children:u}),m&&e.jsx("div",{className:"rounded-xl border border-gympal-yellow/40 bg-gympal-yellow/10 p-3 text-sm text-gympal-yellow",children:m}),e.jsx("button",{type:"button",disabled:a.isPending||!s||r==="influencer"&&!o,onClick:n,className:"rounded-lg bg-gympal-yellow px-4 py-2 text-xs font-semibold text-black hover:brightness-110 disabled:opacity-50",children:a.isPending?"Saving…":"Assign Role"})]})},ve=[{key:"overview",label:"Overview"},{key:"subscriptions",label:"Subscriptions"},{key:"influencers",label:"Influencers"},{key:"feedback",label:"Feedback"},{key:"settings",label:"Settings"},{key:"users",label:"Admins / Roles"}],Ie=()=>{const[t,a]=i.useState("overview");return e.jsxs("div",{className:"overflow-hidden rounded-xl border border-gympal-dark2 bg-gympal-cards",children:[e.jsx("div",{className:"flex flex-wrap gap-1 border-b border-gympal-dark2 p-2",children:ve.map(s=>e.jsx("button",{type:"button",onClick:()=>a(s.key),className:`rounded-lg px-4 py-2 text-sm font-medium transition-all duration-200 ${t===s.key?"bg-gympal-yellow/20 text-gympal-yellow shadow-lg shadow-gympal-yellow/10":"text-gympal-darkTypo hover:bg-white/5 hover:text-white"}`,children:s.label},s.key))}),e.jsxs("div",{className:"p-4 sm:p-6",children:[t==="overview"&&e.jsx(re,{}),t==="subscriptions"&&e.jsx(ce,{}),t==="influencers"&&e.jsx(me,{}),t==="feedback"&&e.jsx(ye,{}),t==="settings"&&e.jsx(be,{}),t==="users"&&e.jsx(je,{})]})]})};export{Ie 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.