1import{u as L,r as T,j as e}from"./vendor-query-B0-uRJqS.js";import{s as A,u as B,a0 as x,cq as F,ac as K,B as k,bo as P,b2 as R,W as z,aK as $,db as E,ay as h,bF as y,bG as N,az as p,N as f}from"./index-DNYOfx3x.js";import{T as W,a as q,b,c as v}from"./tabs-CqKbtoGh.js";import{a as O}from"./vendor-react-CW1TH9gT.js";import{D as G}from"./dollar-sign-BoI2Hlw4.js";import{M as I}from"./mouse-pointer-BO4oZ1c1.js";import{R as w,f as X,C as _,X as S,Y as M,T as D,g as C,B as Y,a as H}from"./vendor-charts-BGFylbhW.js";import"./vendor-radix-Mcgp0sn6.js";function Q(r,l,n,c){const d=n||new Date(Date.now()-2592e6).toISOString().split("T")[0],j=c||new Date().toISOString().split("T")[0],{data:i,isLoading:t,error:g,refetch:a}=L({queryKey:["boost-analytics",r,l,d,j],queryFn:async()=>{if(!r)return null;const{data:o,error:m}=await A.rpc("get_advertiser_analytics",{p_user_id:r,p_boost_id:null,p_date_start:d,p_date_end:j});if(m)throw m;return o},enabled:!!r});return{analytics:i!=null&&i.success?{kpis:i.kpis,daily:i.daily,campaigns:i.campaigns}:null,isLoading:t,error:g,refetch:a}}function u({icon:r,label:l,value:n,sub:c,color:d}){return e.jsx(h,{children:e.jsx(p,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-12 h-12 rounded-xl ${d} flex items-center justify-center`,children:e.jsx(r,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:n}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l}),c&&e.jsx("p",{className:"text-xs text-muted-foreground",children:c})]})]})})})}function re(){const r=O(),{user:l}=B(),[n,c]=T.useState("30d"),d={"7d":7,"14d":14,"30d":30,"90d":90}[n],j=x(F(new Date,d),"yyyy-MM-dd"),i=x(new Date,"yyyy-MM-dd"),{analytics:t,isLoading:g}=Q(l==null?void 0:l.id,void 0,j,i),a=t==null?void 0:t.kpis,o=(t==null?void 0:t.daily)||[],m=(t==null?void 0:t.campaigns)||[];return e.jsx(K,{title:"Ads Analytics",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(k,{variant:"ghost",size:"icon",onClick:()=>r("/hr/boosts"),children:e.jsx(P,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(R,{className:"h-6 w-6 text-primary"}),"Ads Analytics"]}),e.jsx("p",{className:"text-muted-foreground",children:"Performance metrics across all campaigns"})]})]}),e.jsx("div",{className:"flex gap-1",children:["7d","14d","30d","90d"].map(s=>e.jsx(k,{size:"sm",variant:n===s?"default":"outline",onClick:()=>c(s),children:s},s))})]}),g?e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[1,2,3,4].map(s=>e.jsx(z,{className:"h-24"},s))}):a?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(u,{icon:G,label:"Total Spend",value:`à§³${Number(a.total_spend).toLocaleString()}`,color:"bg-green-500/10 text-green-500"}),e.jsx(u,{icon:$,label:"Impressions",value:Number(a.total_impressions).toLocaleString(),color:"bg-blue-500/10 text-blue-500"}),e.jsx(u,{icon:I,label:"Clicks",value:Number(a.total_clicks).toLocaleString(),sub:`${a.ctr}% CTR`,color:"bg-purple-500/10 text-purple-500"}),e.jsx(u,{icon:E,label:"Conversions",value:Number(a.total_applications).toLocaleString(),sub:a.cpa>0?`à§³${a.cpa} CPA`:void 0,color:"bg-orange-500/10 text-orange-500"})]}),e.jsxs(W,{defaultValue:"performance",children:[e.jsxs(q,{children:[e.jsx(b,{value:"performance",children:"Performance"}),e.jsxs(b,{value:"campaigns",children:["Campaigns (",m.length,")"]}),e.jsx(b,{value:"budget",children:"Budget Pacing"})]}),e.jsx(v,{value:"performance",className:"mt-4",children:e.jsxs(h,{children:[e.jsx(y,{children:e.jsx(N,{children:"Performance Over Time"})}),e.jsx(p,{children:o.length>0?e.jsx(w,{width:"100%",height:300,children:e.jsxs(X,{data:o,children:[e.jsx(_,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(S,{dataKey:"date",tickFormatter:s=>x(new Date(s),"MMM d"),className:"text-xs"}),e.jsx(M,{className:"text-xs"}),e.jsx(D,{labelFormatter:s=>x(new Date(s),"MMM d, yyyy")}),e.jsx(C,{type:"monotone",dataKey:"impressions",stroke:"hsl(var(--primary))",strokeWidth:2,dot:!1}),e.jsx(C,{type:"monotone",dataKey:"clicks",stroke:"hsl(var(--chart-2))",strokeWidth:2,dot:!1}),e.jsx(C,{type:"monotone",dataKey:"applications",stroke:"hsl(var(--chart-3))",strokeWidth:2,dot:!1})]})}):e.jsx("p",{className:"text-center text-muted-foreground py-12",children:"No data for this period"})})]})}),e.jsx(v,{value:"campaigns",className:"mt-4",children:e.jsxs(h,{children:[e.jsx(y,{children:e.jsx(N,{children:"Campaign Comparison"})}),e.jsx(p,{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 text-muted-foreground",children:[e.jsx("th",{className:"text-left py-2 px-3",children:"Campaign"}),e.jsx("th",{className:"text-right py-2 px-3",children:"Status"}),e.jsx("th",{className:"text-right py-2 px-3",children:"Impressions"}),e.jsx("th",{className:"text-right py-2 px-3",children:"Clicks"}),e.jsx("th",{className:"text-right py-2 px-3",children:"CTR"}),e.jsx("th",{className:"text-right py-2 px-3",children:"Conversions"}),e.jsx("th",{className:"text-right py-2 px-3",children:"CPA"}),e.jsx("th",{className:"text-right py-2 px-3",children:"Spend"}),e.jsx("th",{className:"text-right py-2 px-3",children:"Budget"}),e.jsx("th",{className:"text-right py-2 px-3",children:"Fraud"})]})}),e.jsx("tbody",{children:m.map(s=>e.jsxs("tr",{className:"border-b hover:bg-muted/50",children:[e.jsx("td",{className:"py-2 px-3",children:e.jsx(f,{variant:"outline",className:"capitalize text-xs",children:s.content_type})}),e.jsx("td",{className:"text-right py-2 px-3",children:e.jsx(f,{variant:s.status==="active"?"default":"secondary",className:"capitalize text-xs",children:s.status})}),e.jsx("td",{className:"text-right py-2 px-3 font-medium",children:Number(s.total_impressions).toLocaleStr
1ing()}),e.jsx("td",{className:"text-right py-2 px-3",children:Number(s.total_clicks).toLocaleString()}),e.jsxs("td",{className:"text-right py-2 px-3",children:[s.ctr,"%"]}),e.jsx("td",{className:"text-right py-2 px-3",children:Number(s.conversions)}),e.jsx("td",{className:"text-right py-2 px-3",children:Number(s.cpa)>0?`à§³${s.cpa}`:"â"}),e.jsxs("td",{className:"text-right py-2 px-3 font-medium",children:["à§³",Number(s.total_spend).toLocaleString()]}),e.jsxs("td",{className:"text-right py-2 px-3 text-muted-foreground",children:["à§³",Number(s.budget).toLocaleString()]}),e.jsx("td",{className:"text-right py-2 px-3",children:Number(s.fraud_flags)>0&&e.jsx(f,{variant:"destructive",className:"text-xs",children:s.fraud_flags})})]},s.boost_id))})]})})})]})}),e.jsx(v,{value:"budget",className:"mt-4",children:e.jsxs(h,{children:[e.jsx(y,{children:e.jsx(N,{children:"Daily Spend"})}),e.jsx(p,{children:o.length>0?e.jsx(w,{width:"100%",height:300,children:e.jsxs(Y,{data:o,children:[e.jsx(_,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(S,{dataKey:"date",tickFormatter:s=>x(new Date(s),"MMM d"),className:"text-xs"}),e.jsx(M,{className:"text-xs"}),e.jsx(D,{labelFormatter:s=>x(new Date(s),"MMM d, yyyy")}),e.jsx(H,{dataKey:"spend",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})}):e.jsx("p",{className:"text-center text-muted-foreground py-12",children:"No spend data"})})]})})]})]}):e.jsx(h,{children:e.jsx(p,{className:"py-12 text-center text-muted-foreground",children:"No analytics data available"})})]})})}export{re 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.