PageSourceSearch

https://oriabuilders.com/assets/campaign-dashboard-I1L33wQd.js

js oriabuilders.com collected 2026-10-08 10:41:52 UTC 63,401 bytes, 1 lines download raw bytes

1import{r as A,j as e}from"./vendor-react-B2RT89U9.js";import{u as H,c as be}from"./vendor-tanstack-MRWYOJqo.js";import{C as b,a as N,b as k,c as $}from"./card-CV4rleUf.js";import{a as Ne,B as w,A as re,R as ve,aa as we,u as J,W,a9 as ee,K as le,C as ne,X as Ce,ab as Se,Y as Z,S as Le,h as Ae}from"./index-gDpiPSoZ.js";import{B as C}from"./badge-BLy_vRrO.js";import{T as ke,a as $e,b as U,c as G}from"./tabs-hjRNQtMh.js";import{I as se}from"./input-Ds8nB8-7.js";import{L as Q}from"./label-C2dLx4EC.js";import{D as Te,a as Be,b as De,c as Pe,e as Re}from"./dialog-DJNN0GXk.js";import{S as Fe,a as Ie,b as ze,c as Oe,d as Ee}from"./select-CUmIl25z.js";import{R}from"./refresh-cw-DICdVNqw.js";import{B as ce,N as K}from"./admin-DYuprVRr.js";import{E as Me}from"./eye-B8C_Tsf8.js";import{M as _e}from"./mouse-pointer-click-PfyHRhY4.js";import{U as He}from"./users-CPXtjG0y.js";import{T as Ve}from"./trending-up-DugfB21r.js";import{T as X}from"./target-C_CoXNWQ.js";import{C as Ue}from"./calendar-Dim9-jMT.js";import{G as V}from"./globe-DiR4E9al.js";import{L as Ge}from"./lightbulb-VeTUH0Zl.js";import{I as Ke}from"./info-CLi5qy0Y.js";import{T as oe}from"./triangle-alert-DM6P9QYL.js";import{C as M}from"./circle-check-big-DYqNqHzq.js";import{D as te}from"./dollar-sign-B7rzcbEI.js";import{L as E}from"./loader-circle-CCVKtMXL.js";import{D as qe}from"./download-CercQkiz.js";import{S as Ye}from"./save-DLjbQjzj.js";import{P as Qe}from"./pen-line-gznI2waW.js";import{L as We}from"./layers-Kv23Rxa-.js";import{Z as de}from"./zap-BrFbhTAN.js";import{A as Je}from"./arrow-up-down-Cgvlf9tX.js";import{C as _}from"./copy-BIT5d8yx.js";import"./vendor-radix-PXtjYgzj.js";import"./check-DyEIay8l.js";import"./activity-bLOBFm9D.js";import"./heart-BoIkHwYj.js";import"./house-_7-4E52f.js";import"./handshake-BSY7VkCR.js";import"./star-XDI8enhw.js";import"./building-2-DHjl6nLG.js";import"./share-2-BVhv9RbF.js";import"./settings-CfHJr-Nz.js";import"./log-out-BTh1C3R-.js";import"./hard-hat-BGeEdA9X.js";import"./chevron-right-C5oNxS6D.js";const Ze="hsl(174,62%,47%)",Xe="hsl(30,80%,52%)",z="#4285F4",O="#1877F2",D="#FF5722",ae={draft:"bg-gray-100 text-gray-700 border-gray-300",active:"bg-green-100 text-green-700 border-green-300",paused:"bg-yellow-100 text-yellow-700 border-yellow-300",completed:"bg-blue-100 text-blue-700 border-blue-300",pending_approval:"bg-orange-100 text-orange-700 border-orange-300",winner:"bg-green-100 text-green-700 border-green-300",loser:"bg-red-100 text-red-700 border-red-300"},ie={kitchen_remodel:"Kitchen Remodel",bathroom_remodel:"Bathroom Remodel",adu:"ADU Construction",room_addition:"Room Addition",full_remodel:"Full Home Remodel"};function I({title:l,value:r,subtitle:c,icon:o,color:i}){return e.jsx(b,{"data-testid":`stat-${l.toLowerCase().replace(/\s/g,"-")}`,children:e.jsx(N,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500 uppercase tracking-wide",children:l}),e.jsx("p",{className:"text-2xl font-bold mt-1",style:{color:i},children:r}),c&&e.jsx("p",{className:"text-xs text-gray-400 mt-1",children:c})]}),e.jsx("div",{className:"p-2 rounded-lg",style:{backgroundColor:`${i}15`},children:e.jsx(o,{className:"w-5 h-5",style:{color:i}})})]})})})}function es({stats:l}){const r=l.totalVisits,c=l.visits.filter(n=>n.utmSource).reduce((n,p)=>n+p.visitCount,0),o=l.leadsBySource.reduce((n,p)=>n+p.leadCount,0),i=l.leadsBySource.filter(n=>n.utmSource).reduce((n,p)=>n+p.leadCount,0),a=c>0?(i/c*100).toFixed(1):"0",g=r>0?(o/r*100).toFixed(1):"0",x=[{label:"All Page Views",value:r,color:"hsl(174, 62%, 47%)"},{label:"Campaign Clicks",value:c,color:"hsl(200, 70%, 50%)"},{label:"Total Leads",value:o,color:"hsl(30, 80%, 52%)"},{label:"Campaign Leads",value:i,color:"hsl(0, 70%, 50%)"}];return e.jsxs(b,{"data-testid":"card-conversion-funnel",children:[e.jsx(k,{className:"pb-2",children:e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(X,{className:"w-4 h-4 text-[hsl(30,80%,52%)]"}),"Conversion Funnel"]})}),e.jsxs(N,{children:[e.jsx("div",{className:"space-y-3",children:x.map((n,p)=>{const v=Math.max(...x.map(j=>j.value),1),L=Math.max(n.value/v*100,8);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-1",children:[e.jsx("span",{className:"text-gray-600",children:n.label}),e.jsx("span",{className:"font-semibold",children:n.value.toLocaleStr
1ing()})]}),e.jsx("div",{className:"h-6 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-500 flex items-center justify-end pr-2",style:{width:`${L}%`,backgroundColor:n.color},children:L>20&&e.jsx("span",{className:"text-white text-[10px] font-bold",children:n.value})})}),p<x.length-1&&e.jsx("div",{className:"flex justify-center py-0.5",children:e.jsx(re,{className:"w-3 h-3 text-gray-300 rotate-90"})})]},n.label)})}),e.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-blue-50 rounded-lg p-3 text-center",children:[e.jsx("p",{className:"text-xs text-blue-600",children:"Campaign Conv. Rate"}),e.jsxs("p",{className:"text-xl font-bold text-blue-700",children:[a,"%"]})]}),e.jsxs("div",{className:"bg-green-50 rounded-lg p-3 text-center",children:[e.jsx("p",{className:"text-xs text-green-600",children:"Overall Conv. Rate"}),e.jsxs("p",{className:"text-xl font-bold text-green-700",children:[g,"%"]})]})]})]})]})}function ss({stats:l}){const r=new Map;for(const o of l.visits){const i=[o.utmSource||"direct",o.utmMedium||"-",o.utmCampaign||"-"].join(" | ");r.has(i)||r.set(i,{visits:0,leads:0,pages:new Set});const a=r.get(i);a.visits+=o.visitCount,a.pages.add(o.pagePath)}for(const o of l.leadsBySource){const i=[o.utmSource||"direct",o.utmMedium||"-",o.utmCampaign||"-"].join(" | ");r.has(i)||r.set(i,{visits:0,leads:0,pages:new Set}),r.get(i).leads+=o.leadCount}const c=Array.from(r.entries()).sort((o,i)=>i[1].visits-o[1].visits);return e.jsxs(b,{"data-testid":"card-campaign-breakdown",children:[e.jsx(k,{className:"pb-2",children:e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4 text-[hsl(174,62%,47%)]"}),"Campaign Breakdown"]})}),e.jsx(N,{children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-gray-500",children:[e.jsx("th",{className:"text-left py-2 pr-2",children:"Source / Medium / Campaign"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Visits"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Leads"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Conv %"}),e.jsx("th",{className:"text-right py-2 pl-2",children:"Pages"})]})}),e.jsxs("tbody",{children:[c.map(([o,i])=>e.jsxs("tr",{className:"border-b border-gray-50 hover:bg-gray-50",children:[e.jsx("td",{className:"py-2 pr-2 font-medium",children:o}),e.jsx("td",{className:"text-right py-2 px-2",children:i.visits.toLocaleString()}),e.jsx("td",{className:"text-right py-2 px-2",children:e.jsx("span",{className:i.leads>0?"text-green-600 font-bold":"text-gray-400",children:i.leads})}),e.jsxs("td",{className:"text-right py-2 px-2",children:[i.visits>0?(i.leads/i.visits*100).toFixed(1):"0","%"]}),e.jsx("td",{className:"text-right py-2 pl-2",children:i.pages.size})]},o)),c.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"py-8 text-center text-gray-400",children:"No campaign data yet. Visits will appear as users arrive via UTM links."})})]})]})})})]})}function ts({pages:l}){const r=Math.max(...l.map(c=>c.visitCount),1);return e.jsxs(b,{"data-testid":"card-top-pages",children:[e.jsx(k,{className:"pb-2",children:e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4 text-[hsl(174,62%,47%)]"}),"Top Landing Pages"]})}),e.jsx(N,{children:e.jsxs("div",{className:"space-y-2",children:[l.slice(0,10).map(c=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-0.5",children:[e.jsx("span",{className:"text-gray-700 font-medium truncate max-w-[200px]",children:c.pagePath}),e.jsx("span",{className:"text-gray-500 ml-2",children:c.visitCount.toLocaleString()})]}),e.jsx("div",{className:"h-2 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-[hsl(174,62%,47%)] rounded-full",style:{width:`${c.visitCount/r*100}%`}})})]},c.pagePath)),l.length===0&&e.jsx("p",{className:"text-xs text-gray-400 py-4 text-center",children:"No page visit data yet"})]})})]})}function as({visitsByDay:l}){const r=new Map;for(const i of l){r.has(i.day)||r.set(i.day,{total:0,campaigns:new Map});const a=r.get(i.day);a.total+=i.visitCount;const g=i.utmSource?`${i.utmSource}/${i.utmCampaign||"direct"}`:"organic";a.campaigns.set(g,(a.campaigns.get(g)||0)+i.visitCount)}const c=Array.from(r.entries()).sort((i,a)=>i[0].localeCompare(a[0])),o=Math.max(...c.map(([,i])=>i.total),1);return e.jsxs(b,{"data-testid":"card-daily-traffic",children:[e.jsx(k,{className:"pb-2",children:e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(Ue,{className:"w-4 h-4 text-[hsl(30,80%,52%)]"}),"Daily Traffic (",c.length," days)"]})}),e.jsx(N,{children:c.length===0?e.jsx("p",{className:"text-xs text-gray-400 py-4 text-center",children:"No traffic data yet. Check back after some visitors arrive."}):e.jsx("div",{className:"space-y-1 max-h-[300px] overflow-y-auto",children:c.map(([i,a])=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-gray-500 w-16 shrink-0",children:new Date(i+"T12:00:00").toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsxs("div",{className:"flex-1 h-5 bg-gray-50 rounded overflow-hidden relative",children:[e.jsx("div",{className:"h-full bg-[hsl(174,62%,47%)] rounded",style:{width:`${a.total/o*100}%`}}),e.jsx("span",{className:"absolute right-1 top-0 text-[10px] text-gray-500 leading-5",children:a.total})]})]},i))})})]})}function is({consentStats:l}){const r=l.reduce((n,p)=>n+p.consentCount,0),c=l.filter(n=>n.consentAction==="accept_all").reduce((n,p)=>n+p.consentCount,0),o=l.filter(n=>n.consentAction==="reject_all").reduce((n,p)=>n+p.consentCount,0),i=l.filter(n=>n.consentAction==="customize").reduce((n,p)=>n+p.consentCount,0),a=l.filter(n=>n.marketing).reduce((n,p)=>n+p.consentCount,0),g=l.filter(n=>n.analytics).reduce((n,p)=>n+p.consentCount,0),x=n=>
1r>0?(n/r*100).toFixed(0):"0";return e.jsxs(b,{"data-testid":"card-cookie-insights",children:[e.jsx(k,{className:"pb-2",children:e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(we,{className:"w-4 h-4 text-[hsl(30,80%,52%)]"}),"Cookie Consent (",r," total)"]})}),e.jsxs(N,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2 mb-3",children:[e.jsxs("div",{className:"bg-green-50 rounded p-2 text-center",children:[e.jsx("p",{className:"text-lg font-bold text-green-700",children:c}),e.jsxs("p",{className:"text-[10px] text-green-600",children:["Accept All (",x(c),"%)"]})]}),e.jsxs("div",{className:"bg-red-50 rounded p-2 text-center",children:[e.jsx("p",{className:"text-lg font-bold text-red-700",children:o}),e.jsxs("p",{className:"text-[10px] text-red-600",children:["Reject All (",x(o),"%)"]})]}),e.jsxs("div",{className:"bg-blue-50 rounded p-2 text-center",children:[e.jsx("p",{className:"text-lg font-bold text-blue-700",children:i}),e.jsxs("p",{className:"text-[10px] text-blue-600",children:["Custom (",x(i),"%)"]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-0.5",children:[e.jsx("span",{className:"text-gray-600",children:"Marketing Consent"}),e.jsxs("span",{className:"font-medium",children:[x(a),"% (",a,")"]})]}),e.jsx("div",{className:"h-2 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-[hsl(30,80%,52%)] rounded-full",style:{width:`${x(a)}%`}})})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between text-xs mb-0.5",children:[e.jsx("span",{className:"text-gray-600",children:"Analytics Consent"}),e.jsxs("span",{className:"font-medium",children:[x(g),"% (",g,")"]})]}),e.jsx("div",{className:"h-2 bg-gray-100 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-[hsl(174,62%,47%)] rounded-full",style:{width:`${x(g)}%`}})})]})]}),e.jsxs("p",{className:"text-[10px] text-gray-400 mt-2",children:["Taboola pixel only fires when marketing consent is given (",x(a),"% of visitors)."]})]})]})}const rs=[{service:"Kitchen Remodeling",googleHeadlines:["LA Kitchen Remodeling Pros","Dream Kitchen Starts Here","Licensed Kitchen Experts"],googleDescription:"Transform your kitchen with Oria Builders. Licensed CSLB #1029255. Free estimates in Los Angeles. Call (877) 778-6742 today!",metaPrimary:"Ready for the kitchen you've always dreamed of? Oria Builders transforms outdated kitchens into stunning, functional spaces. Serving Los Angeles & surrounding areas. CSLB Lic. #1029255. Dreams Constructed Here.",metaHeadline:"Kitchen Remodeling in Los Angeles",metaDescription:"Free estimate from a licensed CA contractor. Call (877) 778-6742 or visit oriabuilders.com"},{service:"Bathroom Remodeling",googleHeadlines:["Bathroom Remodel Experts","Luxury Bath Renovations","Licensed Bath Contractors"],googleDescription:"Beautiful bathroom remodels by Oria Builders. CSLB #1029255. Serving LA. Free estimates. Call (877) 778-6742 now!",metaPrimary:"Your bathroom deserves an upgrade. Oria Builders delivers beautiful, spa-like bathroom transformations in Los Angeles. Licensed CSLB #1029255. Dreams Constructed Here.",metaHeadline:"Bathroom Remodeling – Free Estimate",metaDescription:"Licensed LA contractor. Call (877) 778-6742 or get a free quote online."},{service:"ADU Construction",googleHeadlines:["Build Your ADU in LA","ADU Experts – Free Quote","Accessory Dwelling Units"],googleDescription:"Oria Builders designs & builds ADUs in Los Angeles. Maximize property value. CSLB #1029255. Call (877) 778-6742!",metaPrimary:"Add an ADU to your property for family, guests or rental income. Oria Builders handles permits, design & construction. Serving Los Angeles. CSLB Lic. #1029255. Dreams Constructed Here.",metaHeadline:"ADU Construction in Los Angeles",metaDescription:"Full-service ADU builder. Permits to keys. Call (877) 778-6742 for a free consultation."},{service:"Room Additions",googleHeadlines:["Room Additions in LA","Expand Your Living Space","Licensed Addition Builder"],googleDescription:"Need more space? Oria Builders adds rooms seamlessly. Licensed CSLB #1029255. Free estimates. Call (877) 778-6742!",metaPrimary:"Running out of space? Oria Builders creates beautiful room additions that blend seamlessly with your home. Serving Los Angeles. CSLB Lic. #1029255. Dreams Constructed Here.",metaHeadline:"Room Additions – Los Angeles",metaDescription:"Expert room additions by a licensed CA contractor. Call (877) 778-6742 today."},{service:"Full Home Remodeling",googleHeadlines:["Full Home Remodel in LA","Complete Home Renovation","Dreams Constructed Here"],googleDescription:"Complete home remodeling by Ori
1a Builders. Licensed CSLB #1029255. Transform your entire home. Call (877) 778-6742!",metaPrimary:"Transform your entire home with Oria Builders. From kitchen to bathroom to flooring — one team handles it all. A licensed Los Angeles remodeling contractor. CSLB Lic. #1029255. Dreams Constructed Here.",metaHeadline:"Full Home Remodeling – LA",metaDescription:"One contractor for your whole home. Licensed CSLB #1029255. Call (877) 778-6742."}],ls=[{name:"All Website Visitors",description:"Visitors from last 30/60/90 days — broad awareness retargeting pool",platform:"Both",intent:"Low"},{name:"Estimator Page Visitors",description:"Users who visited the cost estimator — high purchase intent signal",platform:"Both",intent:"High"},{name:"Booking Page Visitors",description:"Users who reached the booking page but didn't complete scheduling",platform:"Both",intent:"High"},{name:"Photo Quote Submitters",description:"Users who submitted a photo quote — extremely qualified leads",platform:"Meta",intent:"High"},{name:"Service Page Visitors",description:"Users who browsed specific service pages (Kitchen/Bath/ADU) — interested in specific services",platform:"Both",intent:"Medium"},{name:"Chatbot Engaged Users",description:"Users who interacted with the AI chatbot — engaged and exploring",platform:"Google",intent:"Medium"}];function ns(){const[l,r]=A.useState(null),{toast:c}=J(),o=(i,a)=>{navigator.clipboard.writeText(i),c({title:"Copied!",description:`${a} copied to clipboard.`})};return e.jsxs(b,{"data-testid":"card-ad-copy-templates",children:[e.jsxs(k,{className:"pb-2",children:[e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(W,{className:"w-4 h-4 text-[hsl(174,62%,47%)]"}),"Ad Copy Templates"]}),e.jsx("p",{className:"text-xs text-gray-500",children:"Ready-to-use ad copy for Google Ads & Meta/Facebook"})]}),e.jsx(N,{children:e.jsx("div",{className:"space-y-2",children:rs.map(i=>{const a=l===i.service;return e.jsxs("div",{className:"border rounded-lg overflow-hidden",children:[e.jsxs("button",{className:"w-full flex items-center justify-between p-3 text-left hover:bg-gray-50 transition-colors",onClick:()=>r(a?null:i.service),"data-testid":`button-toggle-${i.service.toLowerCase().replace(/\s/g,"-")}`,children:[e.jsx("span",{className:"text-sm font-medium text-gray-800",children:i.service}),a?e.jsx(le,{className:"w-4 h-4 text-gray-400"}):e.jsx(ne,{className:"w-4 h-4 text-gray-400"})]}),a&&e.jsxs("div",{className:"px-3 pb-3 space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx(C,{variant:"outline",className:"text-[10px] border-blue-300 text-blue-600",children:"Google Ads"})}),e.jsxs("div",{className:"space-y-1.5",children:[i.googleHeadlines.map((g,x)=>e.jsxs("div",{className:"flex items-center justify-between bg-gray-50 rounded px-2 py-1.5",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"text-[10px] text-gray-400 mr-2",children:["H",x+1]}),e.jsx("span",{className:"text-xs font-medium",children:g}),e.jsxs("span",{className:"text-[10px] text-gray-400 ml-1",children:["(",g.length,"/30)"]})]}),e.jsx(w,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>o(g,`Headline ${x+1}`),"data-testid":`button-copy-google-headline-${i.service.toLowerCase().replace(/\s/g,"-")}-${x}`,children:e.jsx(_,{className:"w-3 h-3"})})]},x)),e.jsxs("div",{className:"flex items-start justify-between bg-gray-50 rounded px-2 py-1.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("span",{className:"text-[10px] text-gray-400 block",children:["Description (",i.googleDescription.length,"/90)"]}),e.jsx("span",{className:"text-xs",children:i.googleDescription})]}),e.jsx(w,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0 mt-1",onClick:()=>o(i.googleDescription,"Google Description"),"data-testid":`button-copy-google-desc-${i.service.toLowerCase().replace(/\s/g,"-")}`,children:e.jsx(_,{className:"w-3 h-3"})})]})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx(C,{variant:"outline",className:"text-[10px] border-purple-300 text-purple-600",children:"Meta / Facebook"})}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between bg-gray-50 rounded px-2 py-1.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[10px] text-gray-400 block",children:"Primary Text"}),e.jsx("span",{className:"text-xs",children:i.metaPrimary})]}),e.jsx(w,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0 mt-1",onClick:()=>o(i.metaPrimary,"Meta Primary Text"),"data-testid":`button-copy-meta-primary-${i.service.toLowerCase().replace(/\s/g,"-")}`,children:e.jsx(_,{className:"w-3 h-3"})})]}),e.jsxs("div",{className:"flex items-center justify-between bg-gray-50 rounded px-2 py-1.5",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[10px] text-gray-400 mr-2",children:"Headline"}),e.jsx("span",{className:"text-xs font-medium",children:i.metaHeadline})]}),e.jsx(w,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>o(i.metaHeadline,"Meta Headline"),"data-testid":`button-copy-meta-headline-${i.service.toLowerCase().replace(/\s/g,"-")}`,children:e.jsx(_,{className:"w-3 h-3"})})]}),e.jsxs("div",{className:"flex items-start justify-between bg-gray-50 rounded px-2 py-1.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[10px] text-gray-400 block",children:"Description"}),e.jsx("span",{className:"text-xs",children:i.metaDescription})]}),e.jsx(w,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0 mt-1",onClick:()=>o(i.metaDescription,"Meta Description"),"data-testid":`button-copy-meta-desc-${i.service.toLowerCase().replace(/\s/g,"-")}`,children:e.jsx(_,{className:"w-3 h-3"})})]})]})]})]})]},i.service)})})})]})}function cs(){const l=r=>r==="High"?"bg-green-100 text-green-700":r==="Medium"?"bg-yellow-100 text-yellow-700":"bg-gray-100 text-gray-600";return e.jsxs(b,{"data-testid":"card-retargeting-audiences",children:[e.jsxs(k,{className:"pb-2",children:[e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(X,{className:"w-4 h-4 text-[hsl(174,62%,47%)]"}),"Retargeting Audiences"]}
1),e.jsx("p",{className:"text-xs text-gray-500",children:"Suggested audience segments for retargeting campaigns"})]}),e.jsx(N,{children:e.jsx("div",{className:"space-y-2",children:ls.map((r,c)=>e.jsxs("div",{className:"border rounded-lg p-3 hover:bg-gray-50 transition-colors","data-testid":`card-audience-${c}`,children:[e.jsxs("div",{className:"flex items-start justify-between mb-1",children:[e.jsx("span",{className:"text-sm font-medium text-gray-800",children:r.name}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(C,{variant:"outline",className:"text-[10px]","data-testid":`badge-platform-${c}`,children:r.platform}),e.jsxs(C,{className:`text-[10px] ${l(r.intent)} border-0`,"data-testid":`badge-intent-${c}`,children:[r.intent," Intent"]})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:r.description})]},r.name))})})]})}function os({stats:l}){const r=l.totalVisits,c=l.visits.filter(h=>h.utmSource).reduce((h,y)=>h+y.visitCount,0),o=l.leadsBySource.reduce((h,y)=>h+y.leadCount,0),i=l.leadsBySource.filter(h=>h.utmSource).reduce((h,y)=>h+y.leadCount,0),a=r>0?o/r*100:0,g=r-c,x=new Map;for(const h of l.visits){const y=h.utmSource||"organic";x.has(y)||x.set(y,{visits:0,leads:0}),x.get(y).visits+=h.visitCount}for(const h of l.leadsBySource){const y=h.utmSource||"organic";x.has(y)||x.set(y,{visits:0,leads:0}),x.get(y).leads+=h.leadCount}let n="",p=0;Array.from(x.entries()).forEach(([h,y])=>{if(y.visits>0){const t=y.leads/y.visits*100;t>p&&(p=t,n=h)}});const v=[];a<2&&r>50&&v.push({type:"warning",text:`Your overall conversion rate is ${a.toFixed(1)}% — consider improving landing page speed, adding stronger CTAs, or A/B testing your hero section to boost conversions above 2%.`}),a>=2&&r>50&&v.push({type:"success",text:`Great job! Your conversion rate of ${a.toFixed(1)}% is solid for the construction industry. Keep optimizing to push it higher.`}),g>c*3&&c<50&&v.push({type:"info",text:`Most of your traffic (${g} visits) is organic. Consider starting paid campaigns on Google Ads or Meta to amplify your reach and capture high-intent searchers.`}),i===0&&c>10&&v.push({type:"warning",text:`You have ${c} campaign visits but 0 leads. Test different ad copy, landing pages, or adjust targeting. Make sure your CTA is clear and above the fold.`}),i===0&&c===0&&v.push({type:"info",text:"No paid campaign traffic detected yet. Launch your first campaign using the Ad Copy Templates below — start with Google Ads for high-intent search traffic."}),n&&p>0&&n!=="organic"&&v.push({type:"success",text:`"${n}" has the highest conversion rate at ${p.toFixed(1)}%. Consider increasing budget for this source to maximize ROI.`}),o>0&&o<5&&v.push({type:"info",text:"You're getting initial leads — great start! Focus on retargeting website visitors (see Retargeting Audiences below) to nurture them back to your site."}),v.push({type:"info",text:"Best practice: Construction companies see highest ROI from Google Search Ads targeting service + city keywords (e.g., 'kitchen remodeling Los Angeles'). Combine with Meta retargeting for maximum impact."}),v.push({type:"info",text:"Ensure your Google Business Profile is complete and linked to your ad campaigns. Local service ads (LSAs) often outperform standard search ads for contractors."});const L={success:M,warning:oe,info:Ke},j={success:"text-green-600",warning:"text-amber-500",info:"text-blue-500"},u={success:"bg-green-50 border-green-200",warning:"bg-amber-50 border-amber-200",info:"bg-blue-50 border-blue-200"};return e.jsxs(b,{"data-testid":"card-smart-recommendations",children:[e.jsxs(k,{className:"pb-2",children:[e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(Ge,{className:"w-4 h-4 text-[hsl(30,80%,52%)]"}),"Smart Recommendations"]}),e.jsx("p",{className:"text-xs text-gray-500",children:"AI-powered insights based on your campaign performance"})]}),e.jsx(N,{children:e.jsx("div",{className:"space-y-2",children:v.map((h,y)=>{const t=L[h.type];return e.jsxs("div",{className:`border rounded-lg p-3 flex items-start gap-2.5 ${u[h.type]}`,"data-testid":`recommendation-${y}`,children:[e.jsx(t,{className:`w-4 h-4 shrink-0 mt-0.5 ${j[h.type]}`}),e.jsx("p",{className:"text-xs text-gray-700 leading-relaxed",children:h.text})]},y)})})})]})}function ds({platform:l,size:r="sm"}){const c=r==="md"?"w-5 h-5":"w-3.5 h-3.5",o=r==="md"?"p-2":"p-1";return e.jsxs("div",{className:"flex items-center gap-1","data-testid":`platform-icons-${l}`,children:[(l==="google"||l==="both"||l==="google_meta"||l==="all")&&e.jsx("div",{className:`${o} rounded`,style:{backgroundColor:`${z}15`},title:"Google Ads",children:e.jsx(V,{className:c,style:{color:z}})}),(l==="meta"||l==="both"||l==="google_meta"||l==="all")&&e.jsx("div",{className:`${o} rounded`,style:{backgroundColor:`${O}15`},title:"Meta Ads",children:e.jsx(Z,{className:c,style:{color:O}})}),(l==="taboola"||l==="all")&&e.jsx("div",{className:`${o} rounded`,style:{backgroundColor:`${D}15`},title:"Taboola",children:e.jsx(K,{className:c,style:{color:D}})})]})}function ms(){const[l,r]=A.useState(null),[c,o]=A.useState(!1),[i,a]=A.useState(!1),[g,x]=A.useState([]),[n,p]=A.useState(!1),[v,L]=A.useState(null),[j,u]=A.useState({name:"",dailyBudget:"",service:""}),[h,y]=A.useState(!1),{toast:t}=J();be();const{data:d,isLoading:P,refetch:F}=H({queryKey:["/api/admin/ad-campaigns"],queryFn:async()=>{const s=await fetch("/api/admin/ad-campaigns",{credentials:"include"});if(!s.ok)throw new Error("Failed to load campaigns");return s.json()}}),me=async()=>{p(!0);try{const s=await fetch("/api/admin/taboola/campaigns",{credentials:"include"});if(!s.ok)throw new Error("Failed to load Taboola campaigns");const f=await s.json();x(f),o(!0)}catch(s){t({title:"Error",description:s.message,variant:"destructive"})}finally{p(!1)}},xe=async s=>{a(!0);try{const f=await fetch("/api/admin/taboola/import-campaign",{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({taboolaCampaignId:String(s.id),name:s.name,dailyBudget:s.daily_cap||s.spending_limit||50,service:"adu"})});if(!f.ok){const S=await f.json();throw new Error(S.error||"Import failed")}t({title:"Imported!",description:`"${s.name}" imported with historical performance data`}),x(S=>S.map(T=>T.id===s.id?{...T,alreadyImported:!0}
1:T)),F()}catch(f){t({title:"Error",description:f.message,variant:"destructive"})}finally{a(!1)}},pe=async(s,f)=>{const S=f==="active"?"pause":"activate";try{const T=await fetch(`/api/admin/ad-campaigns/${s}/${S}`,{method:"POST",credentials:"include"});if(!T.ok)throw new Error(`Failed to ${S} campaign`);const Y=await T.json(),m=S==="pause"?"Campaign Paused":"Campaign Activated",B=Y.platformWarnings;t({title:m,description:B?.length?`Campaign ${S==="pause"?"paused":"activated"} locally. Warning: ${B.join("; ")}`:`Campaign #${s} ${S==="pause"?"paused":"activated"} on all platforms`,variant:B?.length?"destructive":void 0}),F()}catch(T){t({title:"Error",description:T.message,variant:"destructive"})}},he=s=>{L(s.id),u({name:s.name,dailyBudget:String(s.dailyBudget||""),service:s.service||"adu"})},ge=async s=>{y(!0);try{const f={name:j.name,service:j.service};if(j.dailyBudget&&(f.dailyBudget=parseFloat(j.dailyBudget)),!(await fetch(`/api/admin/ad-campaigns/${s}`,{method:"PUT",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)})).ok)throw new Error("Update failed");t({title:"Saved",description:"Campaign updated"}),L(null),F()}catch(f){t({title:"Error",description:f.message,variant:"destructive"})}finally{y(!1)}},q=async(s,f)=>{try{if(!(await fetch(`/api/admin/ad-campaigns/${s}/sync-${f}`,{method:"POST",credentials:"include"})).ok)throw new Error("Sync failed");t({title:"Sync Complete",description:`${f} sync successful for campaign #${s}`}),F()}catch{t({title:"Sync Failed",description:`Could not sync ${f}`,variant:"destructive"})}},ue=d?.length||0,je=d?.filter(s=>s.campaign.status==="active").length||0,ye=d?.reduce((s,f)=>s+(f.totals?.spend||0),0)||0,fe=d?.reduce((s,f)=>s+(f.totals?.conversions||0),0)||0;return P?e.jsx("div",{className:"flex items-center justify-center min-h-[300px]","data-testid":"loading-campaigns",children:e.jsx(R,{className:"w-6 h-6 animate-spin text-[hsl(174,62%,47%)]"})}):e.jsxs("div",{className:"space-y-4","data-testid":"active-campaigns-tab",children:[e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 flex-1",children:[e.jsx(I,{title:"Total Campaigns",value:ue,icon:W,color:Ze}),e.jsx(I,{title:"Active Campaigns",value:je,icon:ee,color:"#22c55e"}),e.jsx(I,{title:"Total Spend",value:`$${ye.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`,icon:te,color:Xe}),e.jsx(I,{title:"Total Leads",value:fe,icon:X,color:"#3b82f6"})]})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(w,{size:"sm",variant:"outline",className:"text-xs",style:{borderColor:D,color:D},onClick:me,disabled:n,"data-testid":"button-import-taboola",children:[n?e.jsx(E,{className:"w-3 h-3 mr-1 animate-spin"}):e.jsx(qe,{className:"w-3 h-3 mr-1"}),"Import from Taboola"]})}),e.jsx(Te,{open:c,onOpenChange:o,children:e.jsxs(Be,{className:"max-w-lg max-h-[80vh] overflow-y-auto",children:[e.jsx(De,{children:e.jsxs(Pe,{className:"flex items-center gap-2",children:[e.jsx(K,{className:"w-5 h-5",style:{color:D}}),"Import Taboola Campaigns"]})}),g.length===0?e.jsx("p",{className:"text-sm text-gray-500 py-4 text-center",children:"No Taboola campaigns found in your account."}):e.jsx("div",{className:"space-y-3",children:g.map(s=>e.jsx(b,{className:"border",children:e.jsxs(N,{className:"p-3",children:[e.jsxs("div",{className:"flex items-start justify-between mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm truncate",children:s.name}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx(C,{variant:"outline",className:s.is_active?"bg-green-100 text-green-700 border-green-300":"bg-yellow-100 text-yellow-700 border-yellow-300",children:s.is_active?"Active":"Paused"}),s.daily_cap&&e.jsxs("span",{className:"text-xs text-gray-500",children:["$",s.daily_cap,"/day"]}),s.cpc&&e.jsxs("span",{className:"text-xs text-gray-500",children:["CPC: $",s.cpc]})]})]}),s.alreadyImported?e.jsxs(C,{variant:"outline",className:"bg-blue-50 text-blue-600 border-blue-200",children:[e.jsx(M,{className:"w-3 h-3 mr-1"})," Imported"]}):e.jsx(w,{size:"sm",className:"text-xs h-7",style:{backgroundColor:D},onClick:()=>xe(s),disabled:i,"data-testid":`button-import-campaign-${s.id}`,children:i?e.jsx(E,{className:"w-3 h-3 animate-spin"}):"Import"})]}),s.performance&&e.jsxs("div",{className:"grid grid-cols-4 gap-2 text-xs text-gray-500 mt-2 pt-2 border-t",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-800",children:(s.performance.impressions||0).toLocaleStr
1ing()}),e.jsx("p",{children:"Impressions"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-800",children:(s.performance.clicks||0).toLocaleString()}),e.jsx("p",{children:"Clicks"})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-gray-800",children:["$",(s.performance.spend||0).toFixed(2)]}),e.jsx("p",{children:"Spend"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-800",children:(s.performance.conversions||0).toLocaleString()}),e.jsx("p",{children:"Conversions"})]})]})]})},s.id))}),e.jsx(Re,{children:e.jsx(w,{variant:"outline",onClick:()=>o(!1),children:"Close"})})]})}),!d||d.length===0?e.jsx(b,{children:e.jsxs(N,{className:"py-12 text-center text-gray-400","data-testid":"text-no-campaigns",children:[e.jsx(W,{className:"w-10 h-10 mx-auto mb-3 opacity-30"}),e.jsx("p",{className:"text-sm",children:"No campaigns yet. Create campaigns in the Ad Management tab."})]})}):e.jsx("div",{className:"space-y-3",children:d.map(({campaign:s,variations:f,totals:S})=>{const T=l===s.id,Y=[{name:"Google",id:s.googleCampaignId,color:z},{name:"Meta",id:s.metaCampaignId,color:O},{name:"Taboola",id:s.taboolaCampaignId,color:D}];return e.jsx(b,{"data-testid":`card-campaign-${s.id}`,children:e.jsxs(N,{className:"p-0",children:[e.jsx("button",{className:"w-full p-4 text-left hover:bg-gray-50/50 transition-colors",onClick:()=>r(T?null:s.id),"data-testid":`button-expand-campaign-${s.id}`,children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-sm text-gray-900",children:s.name}),e.jsx(C,{variant:"outline",className:ae[s.status]||"bg-gray-100 text-gray-600","data-testid":`badge-status-${s.id}`,children:s.status.replace(/_/g," ")}),e.jsx(C,{variant:"outline",className:"text-[10px] border-purple-300 text-purple-600","data-testid":`badge-service-${s.id}`,children:ie[s.service]||s.service})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-gray-500 mb-2",children:[e.jsx(ds,{platform:s.platform}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(te,{className:"w-3 h-3"}),s.dailyBudget?`$${s.dailyBudget}/day`:"—"]}),s.totalBudget?e.jsxs("span",{className:"text-gray-400",children:["$",Number(s.totalBudget).toLocaleString()," total"]}):null]}),e.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[e.jsxs("span",{className:"text-gray-500",children:["Leads: ",e.jsx("span",{className:"font-semibold text-gray-800",children:s.leadsAchieved||0}),s.leadTarget?e.jsxs("span",{className:"text-gray-400",children:[" / ",s.leadTarget]}):null]}),e.jsxs("span",{className:"text-gray-500",children:["Ads: ",e.jsx("span",{className:"font-semibold text-gray-800",children:f?.length||0})]})]}),e.jsx("div",{className:"flex items-center gap-2 mt-2 flex-wrap",children:Y.map(m=>e.jsxs(C,{variant:"outline",className:"text-[10px]",style:{borderColor:m.id?m.color:"#d1d5db",color:m.id?m.color:"#9ca3af",backgroundColor:m.id?`${m.color}10`:void 0},"data-testid":`badge-published-${m.name.toLowerCase()}-${s.id}`,children:[m.id?e.jsx(M,{className:"w-3 h-3 mr-1"}):null,m.name," ",m.id?"Published":"Not Published"]},m.name))})]}),e.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 text-xs text-gray-500 text-center",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900",children:(S?.impressions||0).toLocaleString()}),e.jsx("p",{children:"Impr."})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900",children:(S?.clicks||0).toLocaleString()}),e.jsx("p",{children:"Clicks"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900",children:(S?.conversions||0).toLocaleString()}),e.jsx("p",{children:"Conv."})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-gray-900",children:["$",(S?.spend||0).toFixed(2)]}),e.jsx("p",{children:"Spend"})]})]}),T?e.jsx(le,{className:"w-4 h-4 text-gray-400"}):e.jsx(ne,{className:"w-4 h-4 text-gray-400"})]})]})}),T&&e.jsxs("div",{className:"border-t px-4 pb-4 pt-3 space-y-3","data-testid":`expanded-campaign-${s.id}`,children:[v===s.id?e.jsxs("div",{className:"bg-gray-50 rounded-lg p-3 border space-y-3",children:[e.jsx("p",{className:"text-xs font-semibold text-gray-600",children:"Edit Campaign"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx(Q,{className:"text-xs",children:"Campaign Name"}),e.jsx(se,{value:j.name,onChange:m=>u(B=>({...B,name:m.target.value})),className:"h-8 text-sm","data-testid":`input-edit-name-${s.id}`})]}),e.jsxs("div",{children:[e.jsx(Q,{className:"text-xs",children:"Daily Budget ($)"}),e.jsx(se,{type:"number",value:j.dailyBudget,onChange:m=>u(B=>({...B,dailyBudget:m.target.value})),className:"h-8 text-sm","data-testid":`input-edit-budget-${s.id}`})]}),e.jsxs("div",{children:[e.jsx(Q,{className:"text-xs",children:"Service"}),e.jsxs(Fe,{value:j.service,onValueChange:m=>u(B=>({...B,service:m})),children:[e.jsx(Ie,{className:"h-8 text-sm","data-testid":`select-edit-service-${s.id}`,children:e.jsx(ze,{})}),e.jsx(Oe,{children:Object.entries(ie).map(([m,B])=>e.jsx(Ee,{value:m,children:B},m))})]})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{size:"sm",className:"text-xs h-7",onClick:()=>ge(s.id),disabled:h,"data-testid":`button-save-edit-${s.id}`,children:[h?e.jsx(E,{className:"w-3 h-3 animate-spin mr-1"}):e.jsx(Ye,{className:"w-3 h-3 mr-1"}),"Save"]}),e.jsxs(w,{size:"sm",variant:"outline",className:"text-xs h-7",onClick:()=>L(null),"data-testid":`button-cancel-edit-${s.id}`,children:[e.jsx(Ce,{className:"w-3 h-3 mr-1"})," Cancel"]})]})]}):null,e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(w,{size:"sm",variant:"outline",className:"text-xs h-7",onClick:m=>{m.stopPropagation(),pe(s.id,s.status)},"data-testid":`button-pauseresume-${s.id}`,children:s.status==="active"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{className:"w-3 h-3 mr-1"})," Pause"]}):e.jsxs(e.Fragment,{children:[e.jsx(ee,{className:"w-3 h-3 mr-1"})," Resume"]})}),e.jsxs(w,{size:"sm",variant:"outline",className:"text-xs h-7",onClick:m=>{m.stopPropagation(),he(s)},"data-testid":`button-edit-${s.id}`,children:[e.jsx(Qe,{className:"w-3 h-3 mr-1"})," Edit"]}),(s.platform==="google"||s.platform==="both"||s.platform==="google_meta"||s.platform==="all")&&e.jsxs(w,{size:"sm",variant:"outline",className:"text-xs h-7",style:{borderColor:z,color:z},onClick:m=>{m.stopPropagation(),q(s.id,"google")},"data-testid":`button-sync-google-${s.id}`,children:[e.jsx(R,{className:"w-3 h-3 mr-1"})," Sync Google"]}),(s.platform==="meta"||s.platform==="both"||s.platform==="google_meta"||s.platform==="all")&&e.jsxs(w,{size:"sm",variant:"outline",className:"text-xs h-7",style:{borderColor:O,color:O},onClick:m=>{m.stopPropagation(),q(s.id,"meta")},"data-testid":`button-sync-meta-${s.id}`,children:[e.jsx(R,{className:"w-3 h-3 mr-1"})," Sync Meta"]}),(s.platform==="taboola"||s.platform==="all")&&e.jsxs(w,{size:"sm",variant:"outline",className:"text-xs h-7",style:{borderColor:D,color:D},onClick:m=>{m.stopPropagation(),q(s.id,"taboola")},"data-testid":`button-sync-taboola-${s.id}`,children:[e.jsx(R,{className:"w-3 h-3 mr-1"})," Sync Taboola"]})]}),f&&f.length>0?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{className:"text-xs font-semibold text-gray-600 flex items-center gap-1",children:[e.jsx(We,{className:"w-3 h-3"})," Ad Variations (",f.length,")"]}),e.jsx("div",{className:"grid gap-2",children:f.map(m=>e.jsx("div",{className:"bg-gray-50 rounded-lg p-3 border","data-testid":`card-variation-${m.id}`,children:e.jsxs("div",{className:"flex items-start justify-between mb-1",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(C,{variant:"outline",className:ae[m.status]||"bg-gray-100 text-gray-600","data-testid":`badge-variation-status-${m.id}`,children:m.status.replace(/_/g," ")}),e.jsx(C,{variant:"outline",className:"text-[10px] capitalize",children:m.platform}),m.aiGenerated&&e.jsxs(C,{variant:"outline",className:"text-[10px] border-purple-300 text-purple-600",children:[e.jsx(de,{className:"w-2.5 h-2.5 mr-0.5"}),"AI"]})]}),e.jsx("p",{className:"text-xs font-medium text-gray-800 truncate",children:[m.headline1,m.headline2,m.headline3].filter(
1Boolean).join(" | ")||m.primaryText?.slice(0,80)||"No copy"})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-2 text-[10px] text-gray-500 text-center ml-4 shrink-0",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-800",children:m.impressions.toLocaleString()}),e.jsx("p",{children:"Impr"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-800",children:m.clicks.toLocaleString()}),e.jsx("p",{children:"Clicks"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-800",children:m.conversions}),e.jsx("p",{children:"Conv"})]}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-semibold text-gray-800",children:["$",m.spend.toFixed(2)]}),e.jsx("p",{children:"Spend"})]})]})]})},m.id))})]}):e.jsx("p",{className:"text-xs text-gray-400 text-center py-3","data-testid":`text-no-variations-${s.id}`,children:"No ad variations yet"})]})]})},s.id)})})]})}function xs(){const{data:l,isLoading:r}=H({queryKey:["/api/admin/ad-campaigns"],queryFn:async()=>{const a=await fetch("/api/admin/ad-campaigns",{credentials:"include"});if(!a.ok)throw new Error("Failed to load campaigns");return a.json()}}),{data:c}=H({queryKey:["/api/admin/ad-settings"],queryFn:async()=>{const a=await fetch("/api/admin/ad-settings",{credentials:"include"});if(!a.ok)throw new Error("Failed to load settings");return a.json()}});if(r)return e.jsx("div",{className:"flex items-center justify-center min-h-[300px]","data-testid":"loading-platform-performance",children:e.jsx(R,{className:"w-6 h-6 animate-spin text-[hsl(174,62%,47%)]"})});const o=a=>{const g=(l||[]).filter(t=>{const d=t.campaign.platform;return a==="google"?d==="google"||d==="both"||d==="google_meta"||d==="all":a==="meta"?d==="meta"||d==="both"||d==="google_meta"||d==="all":a==="taboola"?d==="taboola"||d==="all":!1}),x=g.filter(t=>t.campaign.status==="active").length,n=g.reduce((t,d)=>t+(d.variations?.filter(P=>P.platform===a).length||0),0),p=g.flatMap(t=>(t.variations||[]).filter(d=>d.platform===a)),v=p.reduce((t,d)=>t+d.impressions,0),L=p.reduce((t,d)=>t+d.clicks,0),j=p.reduce((t,d)=>t+d.conversions,0),u=p.reduce((t,d)=>t+d.spend,0),h=v>0?L/v*100:0,y=j>0?u/j:0;return{campaigns:g.length,activeCampaigns:x,totalVariations:n,impressions:v,clicks:L,conversions:j,spend:u,ctr:h,cpa:y}},i=[{key:"google",name:"Google Ads",icon:V,color:z,connected:c?.googleAdsConnected||!1},{key:"meta",name:"Meta / Facebook",icon:Z,color:O,connected:c?.metaAdsConnected||!1},{key:"taboola",name:"Taboola",icon:K,color:D,connected:!1}];return e.jsxs("div",{className:"space-y-4","data-testid":"platform-performance-tab",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:i.map(a=>{const g=o(a.key),x=a.icon;return e.jsxs(b,{"data-testid":`card-platform-${a.key}`,children:[e.jsx(k,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs($,{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx("div",{className:"p-1.5 rounded",style:{backgroundColor:`${a.color}15`},children:e.jsx(x,{className:"w-4 h-4",style:{color:a.color}})}),a.name]}),e.jsx(C,{variant:"outline",className:a.connected?"text-green-600 border-green-300 bg-green-50":"text-gray-400 border-gray-300","data-testid":`badge-connection-${a.key}`,children:a.connected?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"w-3 h-3 mr-1"})," Connected"]}):"Not Connected"})]})}),e.jsx(N,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"bg-gray-50 rounded-lg p-2 text-center",children:[e.jsx("p",{className:"text-lg font-bold",style:{color:a.color},children:g.activeCampaigns}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Active Campaigns"})]}),e.jsxs("div",{className:"bg-gray-50 rounded-lg p-2 text-center",children:[e.jsx("p",{className:"text-lg font-bold",style:{color:a.color},children:g.totalVariations}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Ad Variations"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"Impressions"}),e.jsx("span",{className:"font-semibold text-gray-800","data-testid":`text-impressions-${a.key}
1`,children:g.impressions.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"Clicks"}),e.jsx("span",{className:"font-semibold text-gray-800","data-testid":`text-clicks-${a.key}`,children:g.clicks.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"Conversions"}),e.jsx("span",{className:"font-semibold text-gray-800","data-testid":`text-conversions-${a.key}`,children:g.conversions.toLocaleString()})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"Spend"}),e.jsxs("span",{className:"font-semibold text-gray-800","data-testid":`text-spend-${a.key}`,children:["$",g.spend.toFixed(2)]})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"CTR"}),e.jsxs("span",{className:"font-semibold text-gray-800","data-testid":`text-ctr-${a.key}`,children:[g.ctr.toFixed(2),"%"]})]}),e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"CPA"}),e.jsx("span",{className:"font-semibold text-gray-800","data-testid":`text-cpa-${a.key}`,children:g.cpa>0?`$${g.cpa.toFixed(2)}`:"—"})]})]})]})})]},a.key)})}),e.jsx(ns,{}),e.jsx(cs,{})]})}function ps(){const{toast:l}=J(),[r,c]=A.useState(!1),[o,i]=A.useState(!1),[a,g]=A.useState(null),{data:x,isLoading:n,refetch:p}=H({queryKey:["/api/admin/ai-optimizer/status"],queryFn:async()=>{const t=await fetch("/api/admin/ai-optimizer/status",{credentials:"include"});if(!t.ok)throw new Error("Failed to load optimizer status");return t.json()},refetchInterval:6e4}),v=async()=>{c(!0);try{const t=await fetch("/api/admin/ai-optimizer/run",{method:"POST",credentials:"include"});if(!t.ok)throw new Error("Optimization failed");const d=await t.json();g(d),l({title:"Optimization Complete",description:d.summary}),p()}catch(t){l({title:"Error",description:t.message,variant:"destructive"})}finally{c(!1)}},L=async()=>{i(!0);try{const t=await fetch("/api/admin/ai-optimizer/sync",{method:"POST",credentials:"include"});if(!t.ok)throw new Error("Sync failed");const P=(await t.json()).results?.filter(F=>F.success).length||0;l({title:"Sync Complete",description:`${P} platform(s) synced successfully`}),p()}catch(t){l({title:"Error",description:t.message,variant:"destructive"})}finally{i(!1)}};if(n)return e.jsx("div",{className:"flex items-center justify-center min-h-[300px]",children:e.jsx(E,{className:"w-6 h-6 animate-spin text-[hsl(174,62%,47%)]"})});const j=x?.portfolioHealth,u=x?.retargetingOpportunities||[],h=x?.leadQuality||[],y=x?.recentDecisions||[];return e.jsxs("div",{className:"space-y-4","data-testid":"ai-optimizer-tab",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{className:"w-5 h-5 text-purple-600"}),e.jsx("h3",{className:"text-base font-bold text-gray-900",children:"Autonomous AI Optimizer"}),e.jsx(C,{variant:"outline",className:"text-[10px] bg-purple-50 text-purple-700 border-purple-200",children:x?.lastRunAt?`Last run: ${new Date(x.lastRunAt).toLocaleString()}`:"Not yet run"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{size:"sm",variant:"outline",className:"text-xs h-7",onClick:L,disabled:o,"data-testid":"button-sync-platforms",children:[o?e.jsx(E,{className:"w-3 h-3 mr-1 animate-spin"}):e.jsx(R,{className:"w-3 h-3 mr-1"}),"Sync All Platforms"]}),e.jsxs(w,{size:"sm",className:"text-xs h-7 bg-purple-600 hover:bg-purple-700",onClick:v,disabled:r,"data-testid":"button-run-optimizer",children:[r?e.jsx(E,{className:"w-3 h-3 mr-1 animate-spin"}):e.jsx(Le,{className:"w-3 h-3 mr-1"}),r?"Optimizing...":"Run AI Optimization"]})]})]}),e.jsx(b,{className:"border-purple-200 bg-gradient-to-r from-purple-50 to-indigo-50",children:e.jsx(N,{className:"py-3 px-4",children:e.jsx("p",{className:"text-xs text-purple-800",children:"The AI Optimizer runs every 4 hours automatically. It syncs real performance data from Google, Meta, and Taboola, then uses AI to analyze ALL campaigns together - rebalancing budgets, pausing underperformers, scaling winners, and building cross-platform retargeting flows to get you the best leads at the lowest cost."})})}),j&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-6 gap-3",children:[e.jsx(b,{children:e.jsxs(N,{className:"py-3 px-4 text-center",children:[e.jsx("p",{className:"text-lg font-bold text-gray-900","data-testid":"text-total-campaigns",children:j.totalCampaigns}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Total Campaigns"})]})}),e.jsx(b,{children:e.jsxs(N,{className:"py-3 px-4 text-center",children:[e.jsx("p",{className:"text-lg font-bold text-green-600","data-testid":"text-active-campaigns",children:j.activeCampaigns}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Active"})]})}),e.jsx(b,{children:e.jsxs(N,{className:"py-3 px-4 text-center",children:[e.jsx("p",{className:"text-lg font-bold text-blue-600","data-testid":"text-published-campaigns",children:j.publishedCampaigns}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Published (Live)"})]})}),e.jsx(b,{children:e.jsxs(N,{className:"py-3 px-4 text-center",children:[e.jsxs("p",{className:"text-lg font-bold text-gray-900","data-testid":"text-total-spend",children:["$",j.totalSpend30d.toLocaleStr
1ing()]}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"30d Spend"})]})}),e.jsx(b,{children:e.jsxs(N,{className:"py-3 px-4 text-center",children:[e.jsx("p",{className:"text-lg font-bold text-green-600","data-testid":"text-total-leads",children:j.totalLeads30d}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"30d Leads"})]})}),e.jsx(b,{children:e.jsxs(N,{className:"py-3 px-4 text-center",children:[e.jsx("p",{className:"text-lg font-bold text-orange-600","data-testid":"text-overall-cpa",children:j.overallCPA?`$${j.overallCPA}`:"—"}),e.jsx("p",{className:"text-[10px] text-gray-500",children:"Overall CPA"})]})})]}),j?.platforms?.length>0&&e.jsxs(b,{children:[e.jsx(k,{className:"py-3 px-4",children:e.jsxs($,{className:"text-sm flex items-center gap-2",children:[e.jsx(V,{className:"w-4 h-4"}),"Cross-Platform Performance"]})}),e.jsx(N,{className:"px-4 pb-3",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:j.platforms.map(t=>{const d=t.platform==="google"?z:t.platform==="meta"?O:D,F=t.platform==="google"?V:t.platform==="meta"?Z:K;return e.jsxs("div",{className:"bg-gray-50 rounded-lg p-3 border",style:{borderColor:d+"40"},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(F,{className:"w-4 h-4",style:{color:d}}),e.jsx("span",{className:"text-sm font-semibold capitalize",style:{color:d},children:t.platform})]}),e.jsxs("div",{className:"space-y-1 text-xs",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500",children:"Campaigns"}),e.jsx("span",{className:"font-semibold",children:t.campaigns})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500",children:"Spend"}),e.jsxs("span",{className:"font-semibold",children:["$",t.spend.toLocaleString()]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500",children:"Leads"}),e.jsx("span",{className:"font-semibold",children:t.leads})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-gray-500",children:"CPA"}),e.jsx("span",{className:"font-semibold",children:t.leads>0?`$${(t.spend/t.leads).toFixed(2)}`:"—"})]})]})]},t.platform)})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[h.length>0&&e.jsxs(b,{children:[e.jsx(k,{className:"py-3 px-4",children:e.jsxs($,{className:"text-sm flex items-center gap-2",children:[e.jsx(Ae,{className:"w-4 h-4 text-green-600"}),"Lead Quality by Campaign"]})}),e.jsx(N,{className:"px-4 pb-3",children:e.jsx("div",{className:"space-y-3",children:h.map(t=>e.jsxs("div",{className:"bg-gray-50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-xs font-semibold text-gray-900 truncate max-w-[200px]",children:t.campaignName}),e.jsxs(C,{variant:"outline",className:`text-[10px] ${t.qualityScore>=50?"bg-green-50 text-green-700 border-green-200":t.qualityScore>=25?"bg-yellow-50 text-yellow-700 border-yellow-200":"bg-red-50 text-red-700 border-red-200"}`,children:[t.qualityScore,"% high-intent"]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-gray-500 mb-1",children:[e.jsxs("span",{children:[t.totalLeads," total leads"]}),e.jsxs("span",{children:[t.highIntentLeads," high-intent"]})]}),e.jsx("div",{className:"w-full bg-gray-200 rounded-full h-1.5",children:e.jsx("div",{className:`h-1.5 rounded-full ${t.qualityScore>=50?"bg-green-500":t.qualityScore>=25?"bg-yellow-500":"bg-red-500"}`,style:{width:`${Math.min(100,t.qualityScore)}%`}})}),t.topIntentSignals.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:t.topIntentSignals.map((d,P)=>e.jsx("span",{className:"text-[9px] bg-blue-50 text-blue-600 px-1.5 py-0.5 rounded",children:d},P))})]},t.campaignId))})})]}),u.length>0&&e.jsxs(b,{children:[e.jsx(k,{className:"py-3 px-4",children:e.jsxs($,{className:"text-sm flex items-center gap-2",children:[e.jsx(Je,{className:"w-4 h-4 text-blue-600"}),"Cross-Platform Retargeting"]})}),e.jsx(N,{className:"px-4 pb-3",children:e.jsx("div",{className:"space-y-3",children:u.map((t,d)=>e.jsxs("div",{className:"bg-gray-50 rounded-lg p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(C,{variant:"outline",className:"text-[10px] capitalize",children:t.sourceplatform}),e.jsx(re,{className:"w-3 h-3 text-gray-400"}),e.jsx(C,{variant:"outline",className:"text-[10px] capitalize",children:t.targetPlatform})]}),e.jsx("p",{className:"text-[10px] font-semibold text-gray-800 mb
1-0.5",children:t.audienceType}),e.jsx("p",{className:"text-[10px] text-gray-500",children:t.recommendation}),e.jsxs("span",{className:"text-[9px] text-purple-600 font-medium mt-1 inline-block",children:["~",t.estimatedSize.toLocaleString()," visitors"]})]},d))})})]})]}),e.jsxs(b,{children:[e.jsx(k,{className:"py-3 px-4",children:e.jsxs($,{className:"text-sm flex items-center gap-2",children:[e.jsx(de,{className:"w-4 h-4 text-yellow-500"}),"Recent AI Decisions"]})}),e.jsx(N,{className:"px-4 pb-3",children:y.length===0?e.jsx("p",{className:"text-xs text-gray-400 text-center py-4",children:'No AI optimization decisions yet. Click "Run AI Optimization" to start.'}):e.jsx("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:y.slice(0,20).map((t,d)=>{const P={ai_budget_increase:"bg-green-100 text-green-700",ai_budget_decrease:"bg-red-100 text-red-700",ai_pause:"bg-yellow-100 text-yellow-700",ai_platform_shift:"bg-blue-100 text-blue-700",ai_generate_ads:"bg-purple-100 text-purple-700"};return e.jsxs("div",{className:"flex items-start gap-2 bg-gray-50 rounded-lg p-2",children:[e.jsx(C,{variant:"outline",className:`text-[9px] shrink-0 ${P[t.action]||"bg-gray-100 text-gray-700"}`,children:t.action?.replace("ai_","").replace(/_/g," ").toUpperCase()}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-[10px] text-gray-700 leading-snug",children:t.reason}),e.jsx("p",{className:"text-[9px] text-gray-400 mt-0.5",children:t.timestamp?new Date(t.timestamp).toLocaleString():""})]})]},d)})})})]}),a&&e.jsxs(b,{className:"border-purple-200",children:[e.jsx(k,{className:"py-3 px-4",children:e.jsxs($,{className:"text-sm flex items-center gap-2",children:[e.jsx(M,{className:"w-4 h-4 text-green-600"}),"Latest Optimization Cycle"]})}),e.jsxs(N,{className:"px-4 pb-3",children:[e.jsx("p",{className:"text-xs text-gray-700 mb-2",children:a.summary}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3 mb-3",children:[e.jsxs("div",{className:"bg-blue-50 rounded-lg p-2",children:[e.jsx("p",{className:"text-[10px] text-blue-600 font-semibold mb-1",children:"Platform Sync"}),a.syncResults?.map((t,d)=>e.jsxs("div",{className:"flex items-center gap-1 text-[10px]",children:[t.success?e.jsx(M,{className:"w-3 h-3 text-green-500"}):e.jsx(oe,{className:"w-3 h-3 text-red-500"}),e.jsxs("span",{className:"capitalize",children:[t.platform,": ",t.success?`${t.campaignssynced} synced`:t.error]})]},d))]}),e.jsxs("div",{className:"bg-purple-50 rounded-lg p-2",children:[e.jsx("p",{className:"text-[10px] text-purple-600 font-semibold mb-1",children:"AI Decisions"}),e.jsx("p",{className:"text-xs font-bold text-purple-800",children:a.aiDecisions?.length||0}),e.jsxs("p",{className:"text-[10px] text-purple-500",children:[a.aiDecisions?.filter(t=>t.action!=="no_change").length||0," actions taken"]})]}),e.jsxs("div",{className:"bg-green-50 rounded-lg p-2",children:[e.jsx("p",{className:"text-[10px] text-green-600 font-semibold mb-1",children:"Retargeting"}),e.jsxs("p",{className:"text-xs font-bold text-green-800",children:[a.retargetingInsights?.length||0," opportunities"]}),e.jsx("p",{className:"text-[10px] text-green-500",children:"Cross-platform audience flows"})]})]}),a.aiDecisions?.filter(t=>t.action!=="no_change").length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[10px] font-semibold text-gray-600 mb-1",children:"Actions Taken:"}),a.aiDecisions.filter(t=>t.action!=="no_change").map((t,d)=>e.jsxs("div",{className:"text-[10px] bg-gray-50 rounded p-1.5",children:[e.jsxs("span",{className:"font-semibold capitalize",children:[t.action?.replace(/_/g," "),":"]})," ",t.campaignName," — ",t.reason]},d))]})]})]})]})}function rt({embedded:l}){Ne("Admin | Oria Builders","Internal admin page",{noIndex:!0});const[r,c]=A.useState(30),[o,i]=A.useState("overview"),{data:a,isLoading:g,isError:x,error:n,refetch:p}=H({queryKey:["/api/admin/campaign-stats",r],queryFn:async()=>{const u=await fetch(`/api/admin/campaign-stats?days=${r}`,{credentials:"include"});if(!u.ok){const h=await u.json().catch(()=>({}));throw new Error(h.error||`HTTP ${u.status}`)}return u.json()},retry:1}),v=a?.visits.filter(u=>u.utmSource).reduce((u,h)=>u+h.visitCount,0)||0,L=a?.leadsBySource.reduce((u,h)=>u+h.leadCount,0)||0,j=a?.leadsBySource.filter(u=>u.utmSource).reduce((u,h)=>u+h.leadCount,0)||0;return e.jsxs("div",{className:l?"p-4 max-w-[1600px] mx-auto":"p-6","data-testid":"campaign-dashboard",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-bold text-gray-900","data-testid":"text-campaign-title",children:"Ad Analytics"}),e.jsx("p",{className:"text-xs text-gray-500",children:"Track campaigns, traffic, and conversion performance across all platforms"})]}),o==="overview"&&e.jsxs("div",{className:"flex items-center gap-2",children:[[7,14,30,60,90].map(u=>e.jsxs(w,{size:"sm",variant:r===u?"default":"outline",className:`text-xs h-7 ${r===u?"bg-[hsl(174,62%,47%)] hover:bg-[hsl(174,62%,40%)]":""}`,onClick:()=>c(u),"data-testid":`button-days-${u}`,children:[u,"d"]},u)),e.jsx(w,{size:"sm",variant:"outline",className:"h-7",onClick:()=>p(),"data-testid":"button-refresh-campaigns",children:e.jsx(R,{className:"w-3 h-3"})})]})]}),e.jsxs(ke,{value:o,onValueChange:i,className:"w-full",children:[e.jsxs($e,{className:"mb-4","data-testid":"tabs-list",children:[e.jsx(U,{value:"overview","data-testid":"tab-overview",children:"Overview"}),e.jsx(U,{value:"active-campaigns","data-testid":"tab-active-campaigns",children:"Active Campaigns"}),e.jsx(U,{value:"platform-performance","data-testid":"tab-platform-performance",children:"Platform Performance"}),e.jsxs(U,{value:"ai-optimizer","data-testid":"tab-ai-optimizer",className:"gap-1",children:[e.jsx(ce,{className:"w-3 h-3"}),"AI Optimizer"]})]}),e.jsx(G,{value:"overview","data-testid":"tab-content-overview",children:g?e.jsx("div",{className:"flex items-center justify-center min-h-[300px]",children:e.jsx(R,{className:"w-6 h-6 animate-spin text-[hsl(174,62%,47%)]"})}):a?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsx(I,{title:"Total Visits",value:a.totalVisits.toLocaleStr
1ing(),subtitle:`Last ${r} days`,icon:Me,color:"hsl(174, 62%, 47%)"}),e.jsx(I,{title:"Campaign Clicks",value:v.toLocaleString(),subtitle:"UTM-tagged visits",icon:_e,color:"hsl(200, 70%, 50%)"}),e.jsx(I,{title:"Total Leads",value:L,subtitle:"All sources",icon:He,color:"hsl(30, 80%, 52%)"}),e.jsx(I,{title:"Campaign Leads",value:j,subtitle:v>0?`${(j/v*100).toFixed(1)}% conv rate`:"No campaign visits",icon:Ve,color:"hsl(120, 50%, 40%)"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(es,{stats:a}),e.jsx(as,{visitsByDay:a.visitsByDay})]}),e.jsx(ss,{stats:a}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(ts,{pages:a.topPages}),e.jsx(is,{consentStats:a.consentStats})]}),e.jsx(os,{stats:a})]}):x?e.jsx(b,{children:e.jsxs(N,{className:"py-12 text-center",children:[e.jsx("p",{className:"text-gray-500 mb-3",children:n?.message==="Not authenticated"?"Please log in to view campaign data.":"Failed to load campaign data."}),e.jsxs(w,{size:"sm",variant:"outline",onClick:()=>p(),"data-testid":"button-retry-campaigns",children:[e.jsx(R,{className:"w-4 h-4 mr-2"}),"Retry"]})]})}):e.jsx(b,{children:e.jsx(N,{className:"py-12 text-center text-gray-400",children:"No campaign data available yet."})})}),e.jsx(G,{value:"active-campaigns","data-testid":"tab-content-active-campaigns",children:e.jsx(ms,{})}),e.jsx(G,{value:"platform-performance","data-testid":"tab-content-platform-performance",children:e.jsx(xs,{})}),e.jsx(G,{value:"ai-optimizer","data-testid":"tab-content-ai-optimizer",children:e.jsx(ps,{})})]})]})}export{rt as CampaignDashboard,rt 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.