1import{u as le,j as e}from"./vendor-query-BJ5Fw6ip.js";import{s as u,ah as G,$ as F,I as ce,b1 as W,Q as Y,av as b,aw as j,B as P,b0 as me,U as q,aQ as S,aR as E,e as de}from"./index-vS3UXLsm.js";import{T as xe,a as he,b as Q,c as X}from"./tabs-sUhHp3M2.js";import{L as A}from"./vendor-react-BT7e8nQi.js";import{m as C}from"./vendor-motion-C0dDRZUy.js";import{F as ue}from"./file-text-cHGt8E6I.js";import{R as B,X as M,Y as z,T,C as pe,B as J}from"./generateCategoricalChart-DttulYMt.js";import{A as ge,a as fe}from"./AreaChart-sf38yzOr.js";import{P as be,a as je}from"./PieChart-B2dAVvSW.js";import{B as H}from"./BarChart-CzxguOi2.js";import"./vendor-ui-D27gcjqV.js";import"./vendor-supabase-B5vpo0AN.js";const Z=new Set(["DECLINED","REJECTED","VOID","VOIDED","REVERSED","REVERSAL","CANCELLED","CANCELED","CORRECTED","CORRECTION","DENIED","INVALID"]),ee=i=>(i||"").trim().toUpperCase(),we=i=>{const m=ee(i.status),n=ee(i.payment_status);return!Z.has(m)&&!Z.has(n)&&(i.commission_amount||0)>0},ye=i=>{var m,n;return le({queryKey:["commission-analytics",(m=i==null?void 0:i.start)==null?void 0:m.toISOString(),(n=i==null?void 0:i.end)==null?void 0:n.toISOString()],queryFn:async()=>{var R,U,V,K,$;const w=await(async()=>{const s=[];for(let o=0;;o+=1e3){let D=u.from("booking_commissions").select("*").order("booking_date",{ascending:!1}).range(o,o+1e3-1);const{data:N,error:r}=await D;if(r)throw r;if(s.push(...N||[]),!N||N.length<1e3)break}return s})(),x=new Date,c=new Date(x.getFullYear(),x.getMonth(),1),h=w||[],l=h.filter(we),a=h.length-l.length,d=l.reduce((t,s)=>t+(s.commission_amount||0),0),te=l.reduce((t,s)=>t+(s.booking_value||0),0),se=l.filter(t=>["pending","approved"].includes((t.payment_status||"").toLowerCase())).reduce((t,s)=>t+(s.commission_amount||0),0),ie=l.filter(t=>(t.payment_status||"").toLowerCase()==="paid"&&t.payment_date&&new Date(t.payment_date)>=c).reduce((t,s)=>t+(s.creator_commission_amount||0),0),v=new Map;for(const t of l){const s=t.property_id||"unknown",o=v.get(s)||{amount:0,count:0};v.set(s,{amount:o.amount+(t.commission_amount||0),count:o.count+1})}const g=Array.from(v.keys()).filter(t=>t!=="unknown"),f={};if(g.length>0){const[t,s,o,D,N]=await Promise.all([u.from("hotels").select("id, name").in("id",g),u.from("restaurants").select("id, name").in("id",g),u.from("spas").select("id, name").in("id",g),u.from("bars").select("id, name").in("id",g),u.from("activities").select("id, name").in("id",g)]);(R=t.data)==null||R.forEach(r=>{f[r.id]=r.name}),(U=s.data)==null||U.forEach(r=>{f[r.id]=r.name}),(V=o.data)==null||V.forEach(r=>{f[r.id]=r.name}),(K=D.data)==null||K.forEach(r=>{f[r.id]=r.name}),($=N.data)==null||$.forEach(r=>{f[r.id]=r.name})}const ae=Array.from(v.entries()).map(([t,s])=>({name:f[t]||"Unknown Property",amount:s.amount,count:s.count})).sort((t,s)=>s.amount-t.amount).slice(0,10),k=new Map;for(const t of l)if(t.creator_id){const s=t.creator_id,o=k.get(s)||{amount:0,count:0};k.set(s,{amount:o.amount+(t.creator_commission_amount||0),count:o.count+1})}const I=Array.from(k.keys()),O={};if(I.length>0){const{data:t}=await u.from("profiles").select("id, full_name").in("id",I);t==null||t.forEach(s=>{O[s.id]=s.full_name||"Unknown Creator"})}const oe=Array.from(k.entries()).map(([t,s])=>({name:O[t]||"Unknown Creator",amount:s.amount,count:s.count})).sort((t,s)=>s.amount-t.amount).slice(0,10),y=new Map;for(let t=11;t>=0;t--){const s=new Date;s.setMonth(s.getMonth()-t);const o=`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}`;y.set(o,{amount:0,count:0})}for(const t of l)if(t.booking_date){const s=t.booking_date.substring(0,7);if(y.has(s)){const o=y.get(s);y.set(s,{amount:o.amount+(t.commission_amount||0),count:o.count+1})}}const re=Array.from(y.entries()).map(([t,s])=>({month:t,amount:s.amount,count:s.count})),L=new Map;for(const t of l){const s=t.status||t.payment_status||"pending",o=L.get(s)||{amount:0,count:0};L.set(s,{amount:o.amount+(t.commission_amount||0),count:o.count+1})}const ne=Array.from(L.entries()).map(([t,s])=>({status:t,amount:s.amount,count:s.count}));return{totalCommissions:d,totalBookingValue:te,pendingPayouts:se,paidThisMonth:ie,validBookingCount:l.length,excludedBookingCount:a,commissionsByProperty:ae,commissionsByCreator:oe,monthlyTrend:re,statusBreakdown:ne}},refetchInterval:3e5})},_=["hsl(142, 71%, 45%)","hsl(38, 92%, 50%)","hsl(239, 84%, 67%)","hsl(330, 81%, 60%)"],Ne=({title:i,value:m,subtitle:n,icon:p,bgColor:w,iconColor:x,growth:c,delay:h=0})=>e.jsx(C.div,{initial:{opacity:0,y:20}
1,animate:{opacity:1,y:0},transition:{duration:.4,delay:h},children:e.jsx(b,{className:"bg-white/5 backdrop-blur-sm border-white/10 hover:bg-white/10 transition-all duration-300",children:e.jsxs(j,{className:"p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("div",{className:`p-3 rounded-xl ${w}`,children:e.jsx(p,{className:`h-6 w-6 ${x}`})}),c!==void 0&&c!==0&&e.jsxs(de,{variant:"outline",className:`${c>0?"bg-green-500/20 text-green-300 border-green-500/30":"bg-red-500/20 text-red-300 border-red-500/30"}`,children:[c>0?"+":"",c.toFixed(1),"%"]})]}),e.jsx("p",{className:"text-white/60 text-sm mb-1",children:i}),e.jsx("p",{className:"text-white text-3xl font-bold tabular-nums",children:m}),e.jsx("p",{className:"text-white/40 text-xs mt-1",children:n})]})})}),Ae=()=>{var x,c,h,l;const{data:i,isLoading:m}=ye(),n=a=>new Intl.NumberFormat("en-GB",{style:"currency",currency:"GBP",minimumFractionDigits:2}).format(a),p=a=>a>=1e3?`£${(a/1e3).toFixed(1)}k`:`£${a.toFixed(0)}`,w=[{title:"Total Commissions",value:n((i==null?void 0:i.totalCommissions)||0),icon:G,bgColor:"bg-green-500/10",iconColor:"text-green-400",subtitle:"All Time Earnings"},{title:"Total Booking Value",value:n((i==null?void 0:i.totalBookingValue)||0),icon:F,bgColor:"bg-blue-500/10",iconColor:"text-blue-400",subtitle:"Gross Bookings"},{title:"Pending Payouts",value:n((i==null?void 0:i.pendingPayouts)||0),icon:ce,bgColor:"bg-yellow-500/10",iconColor:"text-yellow-400",subtitle:"Awaiting Payment"},{title:"Paid This Month",value:n((i==null?void 0:i.paidThisMonth)||0),icon:W,bgColor:"bg-purple-500/10",iconColor:"text-purple-400",subtitle:"Monthly Disbursements"}];return m?e.jsx("div",{className:"min-h-screen bg-[#0B0E14]",children:e.jsxs("div",{className:"space-y-8 max-w-7xl mx-auto p-6",children:[e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs("div",{children:[e.jsx(Y,{className:"h-8 w-64 mb-2 bg-white/10"}),e.jsx(Y,{className:"h-4 w-48 bg-white/10"})]})}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[1,2,3,4].map(a=>e.jsx(b,{className:"bg-white/5 border-white/10",children:e.jsx(j,{className:"p-6",children:e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-12 w-12 bg-white/10 rounded-xl mb-4"}),e.jsx("div",{className:"h-4 bg-white/10 rounded mb-2"}),e.jsx("div",{className:"h-8 bg-white/10 rounded mb-2"}),e.jsx("div",{className:"h-3 bg-white/10 rounded w-1/2"})]})})},a))})]})}):e.jsx("div",{className:"min-h-screen bg-[#0B0E14]",children:e.jsxs("div",{className:"space-y-8 max-w-7xl mx-auto p-6",children:[e.jsxs(C.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{duration:.3},className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-white flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-gradient-to-r from-[#F97316]/20 to-[#FB923C]/20 border border-[#F97316]/20",children:e.jsx(G,{className:"h-6 w-6 text-[#F97316]"})}),"Commission Dashboard"]}),e.jsx("p",{className:"text-white/50 text-sm mt-2",children:"Track performance and manage creator payouts"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(P,{asChild:!0,variant:"outline",size:"sm",className:"bg-white/5 border-white/10 text-white/70 hover:bg-white/10 hover:text-white",children:e.jsxs(A,{to:"/admin/commissions/import",children:[e.jsx(me,{className:"h-4 w-4 mr-2"}),"Import commissions"]})}),e.jsx(P,{asChild:!0,variant:"outline",size:"sm",className:"bg-white/5 border-white/10 text-white/70 hover:bg-white/10 hover:text-white",children:e.jsxs(A,{to:"/admin/commissions/records",children:[e.jsx(ue,{className:"h-4 w-4 mr-2"}),"View transactions"]})}),e.jsx(P,{asChild:!0,size:"sm",className:"bg-gradient-to-r from-[#F97316] to-[#FB923C] hover:from-[#F97316]/90 hover:to-[#FB923C]/90 text-white border-0",children:e.jsxs(A,{to:"/admin/commissions/payouts",children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Creator payouts"]})})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:w.map((a,d)=>e.jsx(Ne,{title:a.title,value:a.value,subtitle:a.subtitle,icon:a.icon,bgColor:a.bgColor,
1iconColor:a.iconColor,delay:d*.1},a.title))}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsx(C.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.4,delay:.2},className:"lg:col-span-2",children:e.jsxs(b,{className:"bg-white/5 backdrop-blur-sm border-white/10",children:[e.jsx(S,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-xl bg-green-500/10",children:e.jsx(F,{className:"h-5 w-5 text-green-400"})}),e.jsxs("div",{children:[e.jsx(E,{className:"text-lg font-medium text-white",children:"Commission Trend"}),e.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:"Monthly performance over 12 months"})]})]})}),e.jsx(j,{children:e.jsx("div",{className:"h-[280px]",children:e.jsx(B,{width:"100%",height:"100%",children:e.jsxs(ge,{data:(i==null?void 0:i.monthlyTrend)||[],margin:{top:10,right:10,left:0,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"commissionGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#22c55e",stopOpacity:.3}),e.jsx("stop",{offset:"100%",stopColor:"#22c55e",stopOpacity:0})]})}),e.jsx(M,{dataKey:"month",axisLine:!1,tickLine:!1,tick:{fill:"rgba(255,255,255,0.4)",fontSize:11},dy:10}),e.jsx(z,{axisLine:!1,tickLine:!1,tick:{fill:"rgba(255,255,255,0.4)",fontSize:11},tickFormatter:a=>p(a),dx:-10}),e.jsx(T,{contentStyle:{backgroundColor:"rgba(11, 14, 20, 0.95)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"12px",boxShadow:"0 4px 24px rgba(0,0,0,0.4)"},labelStyle:{color:"#fff",fontWeight:500,marginBottom:4},itemStyle:{color:"#22c55e"},formatter:a=>[n(a),"Commission"]}),e.jsx(fe,{type:"monotone",dataKey:"amount",stroke:"#22c55e",strokeWidth:2.5,fill:"url(#commissionGradient)",dot:!1,activeDot:{r:6,fill:"#22c55e",stroke:"#0B0E14",strokeWidth:2}})]})})})})]})}),e.jsx(C.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.4,delay:.3},children:e.jsxs(b,{className:"bg-white/5 backdrop-blur-sm border-white/10 h-full",children:[e.jsx(S,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-xl bg-indigo-500/10",children:e.jsx(W,{className:"h-5 w-5 text-indigo-400"})}),e.jsxs("div",{children:[e.jsx(E,{className:"text-lg font-medium text-white",children:"Payment Status"}),e.jsx("p",{className:"text-xs text-white/50 mt-0.5",children:"Distribution by status"})]})]})}),e.jsxs(j,{children:[e.jsx("div",{className:"h-[200px]",children:e.jsx(B,{width:"100%",height:"100%",children:e.jsxs(be,{children:[e.jsx(je,{data:(i==null?void 0:i.statusBreakdown)||[],dataKey:"amount",nameKey:"status",cx:"50%",cy:"50%",innerRadius:45,outerRadius:75,paddingAngle:2,children:(x=i==null?void 0:i.statusBreakdown)==null?void 0:x.map((a,d)=>e.jsx(pe,{fill:_[d%_.length],stroke:"transparent"},`cell-${d}`))}),e.jsx(T,{contentStyle:{backgroundColor:"rgba(11, 14, 20, 0.95)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"12px",boxShadow:"0 4px 24px rgba(0,0,0,0.4)"},itemStyle:{color:"#fff"},formatter:a=>n(a)})]})})}),e.jsx("div",{className:"flex flex-wrap gap-3 justify-center mt-2",children:(c=i==null?void 0:i.statusBreakdown)==null?void 0:c.map((a,d)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:_[d%_.length]}}),e.jsx("span",{className:"text-xs text-white/50 capitalize",children:a.status})]},a.status))})]})]})})]}),e.jsx(C.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.4,delay:.4},children:e.jsxs(xe,{defaultValue:"properties",className:"w-full",children:[e.jsxs(he,{className:"bg-white/5 border border-white/10 mb-4",children:[e.jsx(Q,{value:"properties",className:"data-[state=active]:bg-white/10 data-[state=active]:text-white text-white/60",children:"Top Properties"}),e.jsx(Q,{value:"creators",className:"data-[state=active]:bg-white/10 data-[state=active]:text-white text-white/60",children:"Top Creators"})]}),e.jsx(X,{value:"properties",children:e.jsxs(b,{className:"bg-white/5 backdrop-blur-sm border-white/10",children:[e.jsx(S,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-xl bg-blue-500/10",children:e.jsx(F,{className:"h-5 w-5 text-blue-400"})}),e.jsxs("div",{children:[e.jsx(E,{className:"text-lg font-medium text-white",children:"Top Performing Properties"}),e.jsx("p",{className:"text-xs text-white/50",children:"Properties generating the highest commissions"})]})]})}),e.jsx(j,{children:(h=i==null?void 0:i.commissionsByProperty)!=null&&h.length?e.jsx("div",{className:"h-[280px]",children:e.jsx(B,{width:"100%",height:"100%",children:e.jsxs(H,{data:i.commissionsByProperty,layout:"vertical",margin:{left:20}
1,children:[e.jsx(M,{type:"number",axisLine:!1,tickLine:!1,tick:{fill:"rgba(255,255,255,0.4)",fontSize:11},tickFormatter:a=>p(a)}),e.jsx(z,{type:"category",dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:"rgba(255,255,255,0.6)",fontSize:11},width:140}),e.jsx(T,{contentStyle:{backgroundColor:"rgba(11, 14, 20, 0.95)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"12px",boxShadow:"0 4px 24px rgba(0,0,0,0.4)"},labelStyle:{color:"#fff"},itemStyle:{color:"#3b82f6"},formatter:a=>[n(a),"Commission"],cursor:{fill:"rgba(255,255,255,0.05)"}}),e.jsx(J,{dataKey:"amount",fill:"#3b82f6",radius:[0,6,6,0],maxBarSize:32})]})})}):e.jsx("div",{className:"flex items-center justify-center h-[200px]",children:e.jsx("p",{className:"text-white/40 text-sm",children:"No commission data yet"})})})]})}),e.jsx(X,{value:"creators",children:e.jsxs(b,{className:"bg-white/5 backdrop-blur-sm border-white/10",children:[e.jsx(S,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-xl bg-green-500/10",children:e.jsx(q,{className:"h-5 w-5 text-green-400"})}),e.jsxs("div",{children:[e.jsx(E,{className:"text-lg font-medium text-white",children:"Top Earning Creators"}),e.jsx("p",{className:"text-xs text-white/50",children:"Creators with the highest earnings"})]})]})}),e.jsx(j,{children:(l=i==null?void 0:i.commissionsByCreator)!=null&&l.length?e.jsx("div",{className:"h-[280px]",children:e.jsx(B,{width:"100%",height:"100%",children:e.jsxs(H,{data:i.commissionsByCreator,layout:"vertical",margin:{left:20},children:[e.jsx(M,{type:"number",axisLine:!1,tickLine:!1,tick:{fill:"rgba(255,255,255,0.4)",fontSize:11},tickFormatter:a=>p(a)}),e.jsx(z,{type:"category",dataKey:"name",axisLine:!1,tickLine:!1,tick:{fill:"rgba(255,255,255,0.6)",fontSize:11},width:140}),e.jsx(T,{contentStyle:{backgroundColor:"rgba(11, 14, 20, 0.95)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"12px",boxShadow:"0 4px 24px rgba(0,0,0,0.4)"},labelStyle:{color:"#fff"},itemStyle:{color:"#22c55e"},formatter:a=>[n(a),"Earnings"],cursor:{fill:"rgba(255,255,255,0.05)"}}),e.jsx(J,{dataKey:"amount",fill:"#22c55e",radius:[0,6,6,0],maxBarSize:32})]})})}):e.jsx("div",{className:"flex items-center justify-center h-[200px]",children:e.jsx("p",{className:"text-white/40 text-sm",children:"No creator earnings data yet"})})})]})})]})})]})})};export{Ae 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.