1import{r as L,j as e}from"./vendor-react-jF_kt2JX.js";import{u as U,C as k,B as E}from"./AnalyticsLayout-flwJv0ii.js";import{L as F}from"./loader-circle-ntNPwhFH.js";import{D as R}from"./download-DwXKu_YJ.js";import{E as S}from"./external-link-CAOH7X5Z.js";import"./vendor-router-CWiOgDIQ.js";import"./vendor-react-dom-ClxaEcYq.js";import"./client-CHISRhpI.js";import"./vendor-radix-CP7hthBf.js";import"./index-DmBTdXAg.js";import"./vendor-query-BrIDhjy6.js";import"./motorsales-analytics-logo-DGpcfBHD.js";import"./log-out-DagcJt9d.js";import"./chart-column-CheTwbQm.js";import"./file-text-i-BHVr2h.js";import"./sparkles-IMwTwlXY.js";import"./mail-B7-9JC8q.js";import"./refresh-cw-BCD2v5UL.js";const C={book_demo_click:{label:"Demo (click)",color:"bg-amber-500/15 text-amber-300 border-amber-500/30"},book_demo_completed:{label:"Demo (booked)",color:"bg-emerald-500/15 text-emerald-300 border-emerald-500/30"},chat_completed:{label:"Chat",color:"bg-blue-500/15 text-blue-300 border-blue-500/30"},whatsapp_click:{label:"WhatsApp",color:"bg-[#25D366]/15 text-[#25D366] border-[#25D366]/30"},email_click:{label:"Email",color:"bg-purple-500/15 text-purple-300 border-purple-500/30"},connected_qr_submitted:{label:"Connected QR application",color:"bg-[#F01767]/15 text-[#F01767] border-[#F01767]/30"}};function ee(){const{data:s,loading:o,error:x}=U("leads"),[d,u]=L.useState("all"),h=L.useMemo(()=>s?d==="all"?s.leads:s.leads.filter(t=>t.type===d):[],[s,d]),T=()=>{if(!s)return;const a=[["Time","Type","Path","Dealer","Dealer City","Listing count","FCA status","UTM source","UTM medium","UTM campaign","UTM content","Referrer","Landing"],...h.map(r=>{var m,j,b,f,w,g,N,_,y,v;return[r.ts,r.type,r.path??"",((m=r.dealer)==null?void 0:m.seller_name)??"",((j=r.dealer)==null?void 0:j.city)??"",((b=r.dealer)==null?void 0:b.listing_count)??"",((f=r.dealer)==null?void 0:f.fca_status)??"",((w=r.session)==null?void 0:w.utm_source)??"",((g=r.session)==null?void 0:g.utm_medium)??"",((N=r.session)==null?void 0:N.utm_campaign)??"",((_=r.session)==null?void 0:_.utm_content)??"",((y=r.session)==null?void 0:y.referrer)??"",((v=r.session)==null?void 0:v.landing_path)??""]})].map(r=>r.map(m=>`"${String(m).replace(/"/g,'""')}"`).join(",")).join(` 2`),n=new Blob([a],{type:"text/csv"}),i=URL.createObjectURL(n),p=document.createElement("a");p.href=i,p.download=`leads-${new Date().toISOString().slice(0,10)}.csv`,p.click(),URL.revokeObjectURL(i)};return o?e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(F,{className:"h-6 w-6 animate-spin text-white/40"})}):x?e.jsxs(k,{children:["Error: ",x]}
2):s?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex gap-1 flex-wrap",children:[e.jsxs(D,{active:d==="all",onClick:()=>u("all"),children:["All (",s.leads.length,")"]}),Object.entries(C).map(([t,a])=>{const n=s.leads.filter(i=>i.type===t).length;return e.jsxs(D,{active:d===t,onClick:()=>u(t),children:[a.label," (",n,")"]},t)})]}),e.jsxs("button",{onClick:T,className:"text-xs px-3 py-1.5 rounded-md bg-white/5 hover:bg-white/10 text-white/80 inline-flex items-center gap-1.5",children:[e.jsx(R,{className:"h-3.5 w-3.5"})," Export CSV"]})]}),e.jsx(k,{className:"p-0 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-white/[0.03] text-white/50 text-xs uppercase tracking-wider",children:e.jsxs("tr",{children:[e.jsx(l,{children:"Time"}),e.jsx(l,{children:"Type"}),e.jsx(l,{children:"Dealer"}),e.jsx(l,{children:"Page"}),e.jsx(l,{children:"UTM"}),e.jsx(l,{children:"Referrer"})]})}),e.jsxs("tbody",{children:[h.map(t=>{var n,i;const a=C[t.type]??{label:t.type,color:"bg-white/10 text-white"};return e.jsxs("tr",{className:"border-t border-white/5 hover:bg-white/[0.02] align-top",children:[e.jsx(c,{className:"text-xs text-white/60 whitespace-nowrap",children:new Date(t.ts).toLocaleString("en-GB")}),e.jsx(c,{children:e.jsx("span",{className:`inline-block text-xs px-2 py-0.5 rounded border ${a.color}`,children:a.label})}),e.jsx(c,{children:t.dealer?e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 font-medium text-white",children:[e.jsx(E,{className:"h-3.5 w-3.5 text-[#F01767]"}),t.dealer.seller_name]}),e.jsxs("div",{className:"text-xs text-white/50",children:[t.dealer.city," · ",t.dealer.listing_count??"?"," listings · FCA ",t.dealer.fca_status??"â"]}),t.dealer.inventory_url&&e.jsxs("a",{href:`https://${t.dealer.inventory_url}`,target:"_blank",rel:"noreferrer",className:"text-xs text-[#F01767] hover:underline inline-flex items-center gap-1",children:[t.dealer.inventory_url," ",e.jsx(S,{className:"h-3 w-3"})]})]}):e.jsx("span",{className:"text-white/30 text-xs",children:"Unidentified"})}),e.jsx(c,{className:"font-mono text-xs text-white/70",children:t.path}),e.jsx(c,{className:"text-xs text-white/60",children:(n=t.session)!=null&&n.utm_source?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[t.session.utm_source," / ",t.session.utm_medium]}),e.jsx("div",{className:"text-white/40",children:t.session.utm_campaign}),t.session.utm_content&&e.jsx("div",{className:"text-white/40",children:t.session.utm_content})]}):e.jsx("span",{className:"text-white/30",children:"(direct)"})}),e.jsx(c,{className:"text-xs text-white/50",children:A((i=t.session)==null?void 0:i.referrer)??"â"})]},t.id)}),!h.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"text-center py-12 text-white/40 text-sm",children:"No leads in this range"})})]})]})})})]}):null}function D({children:s,active:o,onClick:x}){return e.jsx("button",{onClick:x,className:`text-xs px-3 py-1.5 rounded-md ${o?"bg-white/10 text-white":"text-white/50 hover:text-white hover:bg-white/5"}`,children:s})}function l({children:s}){return e.jsx("th",{className:"text-left px-4 py-3 font-medium",children:s})}function c({children:s,className:o=""}){return e.jsx("td",{className:`px-4 py-3 ${o}`,children:s})}function A(s){if(!s)return null;try{return new URL(s).hostname}catch{return null}}export{ee 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.