1import{r as o,o as q,cx as $,j as e,L as J,aZ as F,a4 as f,v as Q,aB as ee,_ as te,d as ae,e as se,f as re,g as ne,h as oe,ab as ie}from"./index-DwBWDKUZ.js";import{b as T}from"./useVisibilityAwareInterval-QXaFipjX.js";import{A as m}from"./AdminStatCard-B9AiNUqR.js";import{A as h,c as b}from"./AdminChartCard-CbE9g-0K.js";import{r as le,A as L}from"./AnalyticsDateRangePicker-BD34BRIq.js";import{T as ce}from"./target-sTphCb1S.js";import{A as de}from"./AreaChart-BGcCUiZW.js";import{C as N}from"./CartesianGrid-Cg0Z4r4D.js";import{X as k,Y as v,T as p,B as G,C as me}from"./generateCategoricalChart-CkYdcMCi.js";import{A as ue}from"./Area-DPWkIFjZ.js";import{C as xe}from"./ComposedChart-D6FK6W7H.js";import{a as ge}from"./LineChart-DlimvCMR.js";import{B as he}from"./BarChart-BIglGrpp.js";import{P as ve,a as pe}from"./PieChart-CUhnOR3x.js";import"./KpiCard-VyYYHTxz.js";import"./info-CSda9mCy.js";import"./arrow-up-right-DCliOP7D.js";import"./arrow-down-right-CBv3Pnci.js";import"./minus-B84IBUYK.js";import"./arrow-up-EfhAIT51.js";import"./arrow-down-CT73qb79.js";import"./ResponsiveContainer-DhRT-7hS.js";import"./index-VSm7vcrh.js";import"./index-Dh4i1-J3.js";const ye={pending:"#eab308",confirmed:"#3b82f6",ongoing:"#8b5cf6",completed:"#22c55e"};function ze(){const[I,C]=o.useState(!0),[n,K]=o.useState(null),[E,O]=o.useState([]),[V,P]=o.useState([]),[R,z]=o.useState([]),[S,M]=o.useState([]),[A,U]=o.useState(30),[u,D]=o.useState("30"),[x,_]=o.useState(void 0),[w,B]=o.useState(null);o.useEffect(()=>{Z()},[u,x]);const Z=async(t=!1)=>{C(!0),B(null);try{const{startDate:s,endDate:g}=le(u,x),y=s.toISOString(),j=g.toISOString();t&&T.invalidate(["revenue-summary","entered-date-v2",y,j]);const r=await T.get(["revenue-summary","entered-date-v2",y,j],async()=>{const{data:a,error:c}=await q.rpc("get_revenue_summary",{start_date:y,end_date:j});if(c)throw c;return a},{force:t}),l=(r==null?void 0:r.metrics)??{};K({totalRevenue:Number(l.total_revenue??0),totalBookings:Number(l.total_bookings??0),avgBookingValue:Number(l.avg_booking_value??0),avgDailyRate:Number(l.avg_daily_rate??0),avgRentalDays:Number(l.avg_rental_days??0),revenueGrowth:Number(l.revenue_growth_pct??0),bookingGrowth:Number(l.booking_growth_pct??0)}),U(Number(l.range_days??30));const X=((r==null?void 0:r.daily_revenue)??[]).map(a=>{const c=Number(a.revenue??0),d=Number(a.bookings??0);return{date:$(a.day_key,"short").replace(/^[A-Za-z]{3},?\s*/,""),revenue:c,bookings:d,avgValue:d>0?c/d:0}});O(X);const Y=((r==null?void 0:r.monthly_revenue)??[]).map(a=>({month:$(`${a.month_key}-01`,"short").replace(/^[A-Za-z]{3},?\s*\d+\s*/,""),revenue:Number(a.revenue??0),bookings:Number(a.bookings??0)}));P(Y);const H=((r==null?void 0:r.by_location)??[]).map(a=>{const c=Number(a.revenue??0),d=Number(a.bookings??0);return{location:a.location,revenue:c,bookings:d,avgValue:d>0?c/d:0}});z(H);const W=((r==null?void 0:r.by_status)??[]).map(a=>({status:a.status,revenue:Number(a.revenue??0),count:Number(a.cnt??0),color:ye[a.status]||"#6b7280"}));M(W)}catch(s){console.error("Error fetching revenue data:",s),B((s==null?void 0:s.message)||"Failed to load revenue insights.")}finally{C(!1)}},i=t=>`A$${(t??0).toLocaleString("en-AU",{minimumFractionDigits:2,maximumFractionDigits:2})}`;return I?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(J,{className:"h-8 w-8 animate-spin text-primary"})}):w?e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex justify-start sm:justify-end sm:-mt-10",children:e.jsx(L,{value:u,onChange:D,customRange:x,onCustomRangeChange:_})}),e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:[e.jsx("p",{className:"font-medium",children:"Couldn't load revenue insights"}),e.jsx("p",{className:"text-xs opacity-80 mt-0.5",children:w})]})]}):n?e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex justify-start sm:justify-end sm:-mt-10",children:e.jsx(L,{value:u,onChange:D,customRange:x,onCustomRangeChange:_})}),e.jsxs("div",{className:"grid gap-4 grid-cols-2 sm:grid-cols-3 lg:grid-cols-5",children:[e.jsx(m,{title:"Total Revenue",value:i(n.totalRevenue),icon:F,iconColor:"text-green-500",subtitle:`${n.revenueGrowth>=0?"+":""}${n.revenueGrowth.toFixed(1)}% vs previous ${A}
1d`,subtitleColor:n.revenueGrowth>=0?"text-green-500":"text-red-500"}),e.jsx(m,{title:"Total Bookings",value:n.totalBookings,icon:f,iconColor:"text-blue-500",subtitle:`${n.bookingGrowth>=0?"+":""}${n.bookingGrowth.toFixed(1)}% vs previous ${A}d`,subtitleColor:n.bookingGrowth>=0?"text-green-500":"text-red-500"}),e.jsx(m,{title:"Avg Booking Value",value:i(n.avgBookingValue),icon:ce,iconColor:"text-purple-500"}),e.jsx(m,{title:"Avg Daily Rate",value:i(n.avgDailyRate),icon:Q,iconColor:"text-amber-500"}),e.jsx(m,{title:"Avg Rental Days",value:n.avgRentalDays.toFixed(1),icon:f,iconColor:"text-cyan-500"})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(h,{title:"Daily Revenue",icon:ee,children:e.jsxs(de,{data:E,children:[e.jsx(N,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(k,{dataKey:"date",className:"text-xs",tick:{fontSize:9},interval:"preserveStartEnd"}),e.jsx(v,{className:"text-xs",tickFormatter:t=>`A$${(t/1e3).toFixed(0)}k`}),e.jsx(p,{contentStyle:b,formatter:(t,s)=>[s==="revenue"?i(t):t.toLocaleString(),s==="revenue"?"Revenue":"Bookings"]}),e.jsx(ue,{type:"monotone",dataKey:"revenue",stroke:"#22c55e",fill:"#22c55e",fillOpacity:.2})]})}),e.jsx(h,{title:"Monthly Revenue Trend",icon:f,children:e.jsxs(xe,{data:V,children:[e.jsx(N,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(k,{dataKey:"month",className:"text-xs",tick:{fontSize:10}}),e.jsx(v,{className:"text-xs",yAxisId:"left",tickFormatter:t=>`A$${(t/1e3).toFixed(0)}k`}),e.jsx(v,{className:"text-xs",yAxisId:"right",orientation:"right"}),e.jsx(p,{contentStyle:b}),e.jsx(G,{yAxisId:"left",dataKey:"revenue",fill:"#22c55e",radius:[4,4,0,0],name:"Revenue"}),e.jsx(ge,{yAxisId:"right",type:"monotone",dataKey:"bookings",stroke:"#3b82f6",strokeWidth:2,name:"Bookings"})]})})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsx(h,{title:"Revenue by Location",icon:te,children:e.jsxs(he,{data:R,layout:"vertical",children:[e.jsx(N,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(k,{type:"number",className:"text-xs",tickFormatter:t=>`A$${(t/1e3).toFixed(0)}k`}),e.jsx(v,{dataKey:"location",type:"category",className:"text-xs",width:100,tick:{fontSize:9}}),e.jsx(p,{contentStyle:b,formatter:t=>[i(t),"Revenue"]}),e.jsx(G,{dataKey:"revenue",fill:"#3b82f6",radius:[0,4,4,0]})]})}),e.jsx(h,{title:"Revenue by Booking Status",icon:F,children:e.jsxs(ve,{children:[e.jsx(pe,{data:S,cx:"50%",cy:"50%",innerRadius:60,outerRadius:100,paddingAngle:2,dataKey:"revenue",nameKey:"status",label:({status:t,percent:s})=>`${t} ${(s*100).toFixed(0)}%`,labelLine:!1,children:S.map((t,s)=>e.jsx(me,{fill:t.color},`cell-${s}`))}),e.jsx(p,{formatter:(t,s,g)=>[i(t),`${g.payload.status} (${g.payload.count} bookings)`]})]})})]}),e.jsxs(ae,{children:[e.jsxs(se,{children:[e.jsx(re,{className:"text-sm font-medium",children:"Top Revenue Locations"}),e.jsx(ne,{children:"Performance breakdown by pickup location"})]}),e.jsx(oe,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b",children:[e.jsx("th",{className:"text-left py-3 px-2 font-medium",children:"Location"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium",children:"Revenue"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium",children:"Bookings"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium",children:"Avg Value"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium",children:"Share"})]})}),e.jsx("tbody",{children:R.map((t,s)=>e.jsxs("tr",{className:"border-b last:border-0",children:[e.jsx("td",{className:"py-3 px-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground w-4",children:s+1}),e.jsx("span",{className:"truncate max-w-[200px]",children:t.location})]})}),e.jsx("td",{className:"text-right py-3 px-2 font-medium",children:i(t.revenue)}),e.jsx("td",{className:"text-right py-3 px-2",children:t.bookings}),e.jsx("td",{className:"text-right py-3 px-2",children:i(t.avgValue)}),e.jsx("td",{className:"text-right py-3 px-2",children:e.jsxs(ie,{variant:"secondary",children:[(t.revenue/n.totalRevenue*100).toFixed(1),"%"]})})]},t.location))})]})})})]})]}):null}export{ze 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.