PageSourceSearch

https://compubrainexpert.com/assets/dashboard-BPXuGna6.js

js compubrainexpert.com collected 2026-09-30 06:41:26 UTC 37,606 bytes, 1 lines download raw bytes

1import{i as $e,r,t as Ae,v as ze,c as _e,j as e,s as S,u as Ee,O as Pe,L as $,J as pe}from"./index-Bd8H2eI-.js";import{B as N,c as Se}from"./button-DUXNn62U.js";import{u as Ke}from"./use-auth-C0tpqzqO.js";import{T as Be}from"./sonner-Zon7UITo.js";import{t as L}from"./index-Dot946r2.js";import{u as qe}from"./use-is-admin-B1HLE8T6.js";import{R as we,a as Ie}from"./repair-status-Bhxanfi5.js";import{I as Q}from"./input-CcNwb0yS.js";import{L as ue}from"./label-C_CxEqSX.js";import{T as ve}from"./target-BKctV1VT.js";import{C as De}from"./check-B8_1mFvx.js";import{X as Le}from"./x-OROR5czD.js";import{P as Ye}from"./plus-a2v8IACL.js";import{T as Oe}from"./trash-2-B5FF4h8S.js";import{L as Ge,C as Ce}from"./log-out-BEitqMfM.js";import{L as He}from"./loader-circle-Dony5JSH.js";import{C as We}from"./circle-check-BuL_ZtWL.js";import{C as Xe}from"./clock-BN1X_fkV.js";import{g as Ve,X as he,Y as ge,B as H,f as Je,R as fe,C as be,T as je,L as Te}from"./generateCategoricalChart-DD8kK6LO.js";import"./index-SZnlieKp.js";function Ze(i){const h=$e(),p=r.useRef(void 0);return Ae(h.stores.location,C=>{const x=C;if(h.options.defaultStructuralSharing){const W=ze(p.current,x);return p.current=W,W}return x})}const Qe=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],et=_e("dollar-sign",Qe);const tt=[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"M13 5v2",key:"dyzc3o"}],["path",{d:"M13 17v2",key:"1ont0d"}],["path",{d:"M13 11v2",key:"1wjjxi"}]],st=_e("ticket",tt);var Ne=Ve({chartName:"BarChart",GraphicalChild:H,defaultTooltipEventType:"axis",validateTooltipEventTypes:["axis","item"],axisComponents:[{axisType:"xAxis",AxisComp:he},{axisType:"yAxis",AxisComp:ge}],formatAxisMap:Je});const j=i=>i.toLocaleString("en-US",{style:"currency",currency:"USD"}),G=i=>i.refunded||Number(i.cost)===0?0:Number(i.cost);function xe(i){return`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`}function at(i){const h=new Date(i.getFullYear(),i.getMonth(),i.getDate()),p=(h.getDay()+6)%7;return h.setDate(h.getDate()-p),h}function nt(){const i=new Date;return`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}`}function rt(){const[i,h]=r.useState(nt()),[p,C]=r.useState([]),[x,W]=r.useState([]),[se,de]=r.useState(!0),[ae,le]=r.useState(xe(new Date)),[q,oe]=r.useState(""),[X,ce]=r.useState(""),[A,I]=r.useState(!1),[B,Y]=r.useState(!1),[c,T]=r.useState(!1),[ie,U]=r.useState(""),[R,s]=r.useState(!1),[d,k]=r.useState(!1),[b,w]=r.useState({}),[D,u]=r.useState({}),[m,_]=i.split("-").map(Number),z=r.useMemo(()=>new Date(m,_-1,1),[m,_]),O=r.useMemo(()=>new Date(m,_,0),[m,_]),F=async()=>{de(!0);const t=xe(z),n=xe(O),[{data:a},{data:g}]=await Promise.all([S.from("thumbtack_leads").select("id, lead_date, lead_name, cost, converted, revenue, refunded, notes, source").gte("lead_date",t).lte("lead_date",n).order("lead_date",{ascending:!1}),S.from("thumbtack_weekly_budgets").select("id, week_start, budget")]);C(a??[]),W(g??[]),de(!1)};r.useEffect(()=>{F()},[i]);const P=r.useMemo(()=>p.filter(t=>t.source==="thumbtack"),[p]),V=r.useMemo(()=>p.filter(t=>t.source!=="thumbtack"),[p]),ne=r.useMemo(()=>{const t=new Map(x.map(g=>[g.week_start,g])),n=[];let a=at(z);for(;a<=O;){const g=xe(a),M=new Date(a);M.setDate(M.getDate()+6);const o=P.filter(y=>{const E=new Date(`${y.lead_date}T00:00:00`);return E>=a&&E<=M}),v=o.reduce((y,E)=>y+G(E),0),Re=o.filter(y=>y.converted).reduce((y,E)=>y+G(E),0),Fe=o.filter(y=>!y.converted).reduce((y,E)=>y+G(E),0),ye=o.filter(y=>y.converted).reduce((y,E)=>y+Number(E.revenue),0),ke=t.get(g);n.push({weekStart:g,label:`${a.toLocaleDateString("en-US",{month:"short",day:"numeric"})} – ${M.toLocaleDateString("en-US",{month:"short",day:"numeric"})}`,spend:v,gain:Re,loss:Fe,net:ye-v,revenue:ye,count:o.length,converted:o.filter(y=>y.converted).length,budget:ke?Number(ke.budget):null}),a=new Date(a),a.setDate(a.getDate()+7)}return n},[x,P,z,O]),K=r.useMemo(()=>{const t=P.reduce((o,v)=>o+G(v),0),n=P.filter(o=>o.converted).reduce((o,v)=>o+G(v),0),a=P.filter(o=>!o.converted).reduce((o,v)=>o+G(v),0),g=P.filter(o=>o.converted).reduce((o,v)=>o+Number(v.revenue),0),M=ne.reduce((o,v)=>o+(v.budget??0),0);return{paid:t,gain:n,loss:a,revenue:g,net:g-t,budget:M}},[P,ne]),l=r.useMemo(()=>{const t=V.reduce((a,g)=>a+G(g),0),n=V.filter(a=>a.converted).reduce((a,g)=>a+Number(g.revenue),0);return{paid:t,revenue:n,net:n-t,count:V.length}},[V]),f=K.net+l.net,me=async()=>{const t=A?0:parseFloat(X||"0");if(!A&&!R&&(Number.isNaN(t)||t<=0)){L.error("Enter a valid cost or mark the lead as free/refunded");return}
1if(R&&(Number.isNaN(t)||t<0)){L.error("Enter a valid cost");return}k(!0);const n=parseFloat(ie),{error:a}=await S.from("thumbtack_leads").insert({lead_date:ae,lead_name:q.trim()||null,cost:t,converted:c,refunded:B,revenue:c&&!Number.isNaN(n)&&n>0?n:0,source:R?"other":"thumbtack"});if(k(!1),a)return L.error(a.message);oe(""),ce(""),I(!1),Y(!1),T(!1),U(""),s(!1),L.success("Lead added"),F()},J=async t=>{const{error:n}=await S.from("thumbtack_leads").update({converted:!t.converted}).eq("id",t.id);if(n)return L.error(n.message);F()},Z=async t=>{const{error:n}=await S.from("thumbtack_leads").update({refunded:!t.refunded}).eq("id",t.id);if(n)return L.error(n.message);F()},re=async t=>{const n=b[t.id],a=parseFloat(n??"");if(Number.isNaN(a)||a<0){L.error("Enter a valid amount");return}const{error:g}=await S.from("thumbtack_leads").update({revenue:a}).eq("id",t.id);if(g)return L.error(g.message);w(M=>{const o={...M};return delete o[t.id],o}),L.success("Revenue saved"),F()},Me=async t=>{const{error:n}=await S.from("thumbtack_leads").delete().eq("id",t);if(n)return L.error(n.message);F()},Ue=async t=>{const n=D[t],a=parseFloat(n??"");if(Number.isNaN(a)||a<0){L.error("Enter a valid budget");return}const{error:g}=await S.from("thumbtack_weekly_budgets").upsert({week_start:t,budget:a},{onConflict:"week_start"});if(g)return L.error(g.message);u(M=>{const o={...M};return delete o[t],o}),L.success("Budget saved"),F()};return e.jsxs("div",{className:"rounded-xl border bg-card p-6 shadow-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-lg font-semibold",children:[e.jsx(ve,{className:"h-5 w-5 text-primary"})," Thumbtack leads"]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:["Month",e.jsx("input",{type:"month",value:i,onChange:t=>h(t.target.value),className:"rounded-md border bg-background px-2 py-1 text-sm text-foreground"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Paid this month"}),e.jsx("p",{className:"mt-1 text-2xl font-semibold",children:j(K.paid)})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Result"}),e.jsxs("p",{className:K.net>=0?"mt-1 text-2xl font-semibold text-emerald-600 dark:text-emerald-400":"mt-1 text-2xl font-semibold text-destructive",children:[K.net>=0?"Gain ":"Loss ",j(Math.abs(K.net))]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Loss (unconverted)"}),e.jsx("p",{className:"mt-1 text-2xl font-semibold text-destructive",children:j(K.loss)})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Weekly budget total"}),e.jsx("p",{className:"mt-1 text-2xl font-semibold",children:j(K.budget)})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Non-Thumbtack leads"}),e.jsx("p",{className:"mt-1 text-2xl font-semibold",children:l.count}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[j(l.revenue)," revenue · ",j(l.paid)," cost"]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Non-Thumbtack result"}),e.jsxs("p",{className:l.net>=0?"mt-1 text-2xl font-semibold text-emerald-600 dark:text-emerald-400":"mt-1 text-2xl font-semibold text-destructive",children:[l.net>=0?"Gain ":"Loss ",j(Math.abs(l.net))]})]}),e.jsxs("div",{className:"rounded-lg border p-4",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Combined result"}),e.jsxs("p",{className:f>=0?"mt-1 text-2xl font-semibold text-emerald-600 dark:text-emerald-400":"mt-1 text-2xl font-semibold text-destructive",children:[f>=0?"Gain ":"Loss ",j(Math.abs(f))]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Thumbtack + Non-Thumbtack"})]})]}),e.jsxs("div",{className:"mt-6",children:[e.jsx("h3",{className:"mb-2 text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Weekly budget vs spend"}),e.jsx("div",{className:"space-y-2",children:ne.map(t=>{const n=D[t.weekStart],a=n!==void 0,g=t.spend-t.gain,M=t.budget!=null&&g>t.budget;return e.jsxs("div",{className:"flex flex-wrap items-center gap-3 rounded-lg border p-3 text-sm",children:[e.jsxs("div",{className:"min-w-[140px] flex-1",children:[e.jsx("p",{className:"font-medium",children:t.label}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.count," leads · ",t.converted," paying"]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Spend"}),e.jsx("p",{className:M?"font-semibold text-destructive":"font-semibold",children:j(g)}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[j(t.spend)," − ",j(t.gain)," paying"]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Paying customers"}),e.jsx("p",{className:"font-semibold text-emerald-600 dark:text-emerald-400",children:j(t.gain)}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[j(t.revenue)," earned"]})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Loss"}),e.jsx("p",{className:"font-semibold text-destructive",children:j(t.loss)})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Result"}),t.count===0?e.jsx("p",{className:"font-semibold text-muted-foreground",children:"—"}):e.jsxs("p",{className:t.net>=0?"font-semibold text-emerald-600 dark:text-emerald-400":"font-semibold text-destructive",children:[t.net>=0?"Gain ":"Loss ",j(Math.abs(t.net))]})]}),e.jsx("div",{className:"flex items-center gap-2",children:a?e.jsxs(e.Fragment,{children:[e.jsx(Q,{type:"number",className:"w-24",placeholder:"Budget",value:n,onChange:o=>u(v=>({...v,[t.weekStart]:o.target.value}))}),e.jsx(N,{size:"icon",variant:"ghost",onClick:()=>Ue(t.weekStart),children:e.jsx(De,{className:"h-4 w-4"})}),e.jsx(N,{size:"icon",variant:"ghost",onClick:()=>u(o=>{const v={...o};return delete v[t.weekStart],v}),children:e.jsx(Le,{className:"h-4 w-4"})})]}):e.jsxs("button",{type:"button",onClick:()=>u(o=>({...o,[t.weekStart]:t.budget!=null?String(t.budget):""})),className:"text-right",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Budget"}),e.jsx("p",{className:"font-semibold underline decoration-dotted",children:t.budget!=null?j(t.budget):"Set"})]})})]},t.weekStart)})})]}),e.jsxs("div",{className:"mt-6 rounded-lg border bg-muted/30 p-4",children:[e.jsx("h3",{className:"mb-3 text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Log a lead"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(ue,{className:"text-xs",children:"Date"}),e.jsx(Q,{type:"date",value:ae,onChange:t=>le(t.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ue,{className:"text-xs",children:"Lead name"}),e.jsx(Q,{placeholder:"Optional",value:q,onChange:t=>oe(t.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ue,{className:"text-xs",children:"Cost"}),e.jsx(Q,{type:"number",placeholder:"0.00",value:X,disabled:A,onChange:t=>ce(t.target.value)})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(ue,{className:"text-xs",children:"Revenue earned"}),e.jsx(Q,{type:"number",placeholder:"0.00",value:ie,disabled:!c,onChange:t=>U(t.target.value)})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-4",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Status"}),e.jsxs("label",{className:R?"flex cursor-not-allowed items-center gap-2 text-sm opacity-50":"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:A,disabled:R,onChange:t=>{I(t.target.checked),t.target.checked&&Y(!1)},className:"h-4 w-4"}),"Free"]}),e.jsxs("label",{className:R?"flex cursor-not-allowed items-center gap-2 text-sm opacity-50":"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:B,disabled:R,onChange:t=>{Y(t.target.checked),t.target.checked&&I(!1)},className:"h-4 w-4"}),"Refunded"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:t=>T(t.target.checked),className:"h-4 w-4"}),"Converted"]}),e.jsxs("label",{className:"flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:R,onChange:t=>{s(t.target.checked),t.target.checked&&(I(!1),Y(!1))},className:"h-4 w-4"}),"Non-Thumbtack"]})]}),R&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:"This lead is tracked separately and won't affect Thumbtack budget, spend, or results."}),e.jsxs(N,{className:"mt-3 gap-1",size:"sm",onClick:me,disabled:d,children:[e.jsx(Ye,{className:"h-4 w-4"})," ",d?"Adding…":"Add lead"]})]}),e.jsxs("div",{className:"mt-6",children:[e.jsx("h3",{className:"mb-2 text-sm font-semibold uppercase tracking-wide text-muted-foreground",children:"Leads this month"}),se?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading…"}):p.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No leads logged for this month."}):e.jsx("ul",{className:"divide-y",children:p.map(t=>e.jsxs("li",{className:"flex items-center gap-3 py-2 text-sm",children:[e.jsx("span",{className:"w-20 shrink-0 text-xs text-muted-foreground",children:new Date(`${t.lead_date}T00:00:00`).toLocaleDateString("en-US",{month:"short",day:"numeric"})}),e.jsxs("span",{className:"flex flex-1 items-center gap-2 truncate",children:[e.jsx("span",{className:"truncate",children:t.lead_name||"—"}),t.source!=="thumbtack"&&e.jsx("span",{className:"shrink-0 rounded-full border border-border bg-muted px-2 py-0.5 text-[10px] uppercase tracking-wide text-muted-foreground",children:"Non-Thumbtack"})]}),e.jsx("span",{className:"w-20 text-right font-medium",children:t.refunded?"Refunded":Number(t.cost)===0?"Free":j(Number(t.cost))}),e.jsx("button",{type:"button",onClick:()=>J(t),className:t.converted?"rounded-full border border-emerald-500/30 bg-emerald-500/15 px-2 py-0.5 text-xs text-emerald-700 dark:text-emerald-300":"rounded-full border border-border bg-muted px-2 py-0.5 text-xs text-muted-foreground",children:t.converted?"Paying customer":"Not converted"}),e.jsx("button",{type:"button",onClick:()=>Z(t),className:t.refunded?"rounded-full border border-destructive/30 bg-destructive/15 px-2 py-0.5 text-xs text-destructive":"rounded-full border border-border bg-muted px-2 py-0.5 text-xs text-muted-foreground",children:t.refunded?"Refunded":"Mark refund"}),t.converted&&(b[t.id]!==void 0?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Q,{type:"number",className:"h-7 w-24",placeholder:"Revenue",value:b[t.id],onChange:n=>w(a=>({...a,[t.id]:n.target.value}))}),e.jsx(N,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>re(t),children:e.jsx(De,{className:"h-4 w-4"})}),e.jsx(N,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>w(n=>{const a={...n};return delete a[t.id],a}),children:e.jsx(Le,{className:"h-4 w-4"})})]}):e.jsx("button",{type:"button",onClick:()=>w(n=>({...n,[t.id]:t.revenue?String(t.revenue):""})),className:"text-xs font-medium text-emerald-600 underline decoration-dotted dark:text-emerald-400",children:t.revenue?`${j(Number(t.revenue))} earned`:"Add revenue"})),e.jsx(N,{size:"icon",variant:"ghost",className:"text-destructive",onClick:()=>Me(t.id),children:e.jsx(Oe,{className:"h-4 w-4"})})]},t.id))})]})]})}function Lt(){const i=Ze(),{user:h,session:p,loading:C}=Ke(),{isAdmin:x}=qe(),W=Ee(),[se,de]=r.useState(null),[ae,le]=r.useState(null),[q,oe]=r.useState(null),[X,ce]=r.useState(null),[A,I]=r.useState("2026-01-01"),[B,Y]=r.useState(()=>{const s=new Date;return`${s.getFullYear()}
1-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`});r.useEffect(()=>{if(!x)return;let s=!1;const d=()=>{S.from("repair_tickets").select("status, created_at, updated_at, payment_status, payment_amount").then(({data:b})=>{s||oe(b??[])})};d();const k=S.channel("dashboard-repair-tickets").on("postgres_changes",{event:"*",schema:"public",table:"repair_tickets"},()=>d()).subscribe();return()=>{s=!0,S.removeChannel(k)}},[x]),r.useEffect(()=>{if(!x)return;let s=!1;const d=()=>{S.from("thumbtack_leads").select("id, lead_date, lead_name, cost, converted, revenue, refunded, notes, source").order("lead_date",{ascending:!1}).then(({data:b})=>{s||ce(b??[])})};d();const k=S.channel("dashboard-thumbtack-leads").on("postgres_changes",{event:"*",schema:"public",table:"thumbtack_leads"},()=>d()).subscribe();return()=>{s=!0,S.removeChannel(k)}},[x]);const c=r.useMemo(()=>{if(!q)return null;const s=we.reduce((l,f)=>({...l,[f]:0}),{});let d=0,k=0,b=0;const w=new Date;w.setDate(1),w.setHours(0,0,0,0);const D=A?new Date(`${A}T00:00:00`):null,u=B?new Date(`${B}T23:59:59.999`):null,m=new Map;let _=0,z=0,O=0;const F=new Map;for(const l of q){s[l.status]=(s[l.status]??0)+1,l.status==="picked_up"&&(d+=new Date(l.updated_at).getTime()-new Date(l.created_at).getTime(),k+=1);const f=new Date(l.updated_at),me=(!D||f>=D)&&(!u||f<=u),J=`${f.getFullYear()}-${String(f.getMonth()+1).padStart(2,"0")}`;if(l.payment_status==="paid"&&l.payment_amount&&(f>=w&&(b+=Number(l.payment_amount)),me&&(m.set(J,(m.get(J)??0)+Number(l.payment_amount)),_+=Number(l.payment_amount))),me&&l.payment_amount){const Z=Number(l.payment_amount);if(l.payment_status==="failed"||l.payment_status==="pending"){const re=F.get(J)??{failed:0,pending:0};l.payment_status==="failed"?(z+=Z,re.failed+=Z):(O+=Z,re.pending+=Z),F.set(J,re)}}}const P=Array.from(m.entries()).sort(([l],[f])=>l<f?1:-1).map(([l,f])=>({key:l,amount:f})),V=Array.from(F.entries()).sort(([l],[f])=>l<f?1:-1).map(([l,f])=>({key:l,failed:f.failed,pending:f.pending,total:f.failed+f.pending})),ne=k?d/k:0,K=z+O;return{byStatus:s,total:q.length,avgMs:ne,revenueMonth:b,monthlyRevenue:P,rangeRevenue:_,lostFailed:z,lostPending:O,lostTotal:K,monthlyLost:V}},[q,A,B]),T=r.useMemo(()=>{if(!X)return null;const s=u=>u.refunded||Number(u.cost)===0?0:Number(u.cost),d=new Map;for(const u of X){const m=u.lead_date.slice(0,7),_=d.get(m)??{loss:0,net:0,nonTtNet:0},z=(u.converted?Number(u.revenue):0)-s(u);u.source==="thumbtack"?(_.loss+=u.converted?0:s(u),_.net+=z):_.nonTtNet+=z,d.set(m,_)}const k=Array.from(d.entries()).sort(([u],[m])=>u<m?-1:1).map(([u,m])=>({key:u,loss:m.loss,net:m.net,nonTtNet:m.nonTtNet})),b=new Date,w=`${b.getFullYear()}-${String(b.getMonth()+1).padStart(2,"0")}`,D=d.get(w)??{loss:0,net:0,nonTtNet:0};return{loss:D.loss,net:D.net,nonTtNet:D.nonTtNet,monthly:k}},[X]);r.useEffect(()=>{h&&S.from("profiles").select("display_name, avatar_url").eq("id",h.id).maybeSingle().then(({data:s,error:d})=>{d?le(d.message):(de(s),le(null))})},[h]);const ie=async()=>{await S.auth.signOut(),L.success("Signed out"),W({to:"/home"})},U=C?{tone:"loading",title:"Checking session…",detail:"Verifying your sign-in with the backend."}:ae?{tone:"error",title:"Profile failed to load",detail:ae}:p?{tone:"active",title:"Session active",detail:`Signed in as ${h?.email??"unknown"}.`}:{tone:"error",title:"No active session",detail:"We couldn't find a valid session."},R=U.tone==="loading"?He:U.tone==="active"?We:Ce;return i.pathname!=="/dashboard"?e.jsx(Pe,{}):e.jsxs("main",{className:"min-h-screen bg-muted/30 px-4 py-12",children:[e.jsxs("div",{className:"mx-auto max-w-3xl",children:[e.jsxs("div",{className:"mb-8 flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Dashboard"}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Welcome back",se?.display_name?`, ${se.display_name}`:"","."]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:x?"/repairs":"/my-tickets",children:x?"Repair tracker":"My tickets"})}),x&&e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/subscribers",children:"Subscribers"})}),x&&e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/dashboard/seo",children:"SEO status"})}),x&&e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/dashboard/contract",children:"Contract"})}),x&&e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/dashboard/sms-templates",children:"SMS templates"})}),x&&e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/dashboard/coupons",children:"Coupons"})}),x&&e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/dashboard/quotes",children:"Business quotes"})}),x&&e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/dashboard/conversions",children:"Lead conversions"})}),x&&e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/dashboard/email-status",children:"Email status"})}),e.jsx(N,{asChild:!0,variant:"outline",size:"sm",children:e.jsx($,{to:"/dashboard/settings",children:"Edit profile"})}),e.jsxs(N,{variant:"outline",size:"sm",className:"gap-2",onClick:ie,children:[e.jsx(Ge,{className:"h-4 w-4"}),"Sign out"]})]})]}),e.jsxs("div",{role:"status","aria-live":"polite",className:Se("mb-6 flex items-start gap-3 rounded-lg border p-4 text-sm",U.tone==="active"&&"border-emerald-500/30 bg-emerald-500/10 text-emerald-900 dark:text-emerald-200",U.tone==="loading"&&"border-border bg-muted text-muted-foreground",U.tone==="error"&&"border-destructive/40 bg-destructive/10 text-destructive"),children:[e.jsx(R,{className:Se("mt-0.5 h-4 w-4 shrink-0",U.tone==="loading"&&"animate-spin")}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:U.title}),e.jsx("p",{className:"opacity-80",children:U.detail})]})]}),x&&e.jsxs("section",{className:"mb-6 space-y-4",children:[e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(ee,{icon:e.jsx(st,{className:"h-4 w-4"}),label:"Active tickets",value:c?(c.total-(c.byStatus.picked_up??0)).toString():"—",hint:c?`${c.total} total`:void 0}),e.jsx(ee,{icon:e.jsx(Xe,{className:"h-4 w-4"}),label:"Avg turnaround",value:c?dt(c.avgMs):"—",hint:"From received to picked up"}),e.jsx(ee,{icon:e.jsx(et,{className:"h-4 w-4"}
1),label:"Revenue this month",value:c?c.revenueMonth.toLocaleString("en-US",{style:"currency",currency:"USD"}):"—",hint:"Paid tickets"}),e.jsx(ee,{icon:e.jsx(Ce,{className:"h-4 w-4"}),label:"Lost revenue (range)",value:c?c.lostTotal.toLocaleString("en-US",{style:"currency",currency:"USD"}):"—",hint:c?`Failed ${c.lostFailed.toLocaleString("en-US",{style:"currency",currency:"USD"})} · Pending ${c.lostPending.toLocaleString("en-US",{style:"currency",currency:"USD"})}`:"Unpaid + failed in selected range"}),e.jsx(ee,{icon:e.jsx(ve,{className:"h-4 w-4"}),label:"Thumbtack loss",value:T?T.loss.toLocaleString("en-US",{style:"currency",currency:"USD"}):"—",hint:"Unconverted leads this month"}),e.jsx(ee,{icon:e.jsx(ve,{className:"h-4 w-4"}),label:"Thumbtack result",value:T?T.net.toLocaleString("en-US",{style:"currency",currency:"USD"}):"—",hint:T?T.net>=0?"Gain this month":"Loss this month":"Revenue minus paid spend"})]}),e.jsx(pe,{className:"my-2",minHeight:90,label:"Dashboard Ad"}),e.jsxs("div",{className:"rounded-xl border bg-card p-6 shadow-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Lost revenue by month"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Failed + pending in selected range"})]}),c?c.monthlyLost.length===0?e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"No failed or pending payments in the selected range."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 h-64 w-full",children:e.jsx(fe,{width:"100%",height:"100%",children:e.jsxs(Ne,{data:c.monthlyLost.map(s=>({month:te(s.key),Failed:Number(s.failed.toFixed(2)),Pending:Number(s.pending.toFixed(2))})),margin:{top:8,right:8,left:0,bottom:0},children:[e.jsx(be,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(he,{dataKey:"month",tick:{fontSize:12}}),e.jsx(ge,{tick:{fontSize:12},tickFormatter:s=>s.toLocaleString("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0})}),e.jsx(je,{cursor:{fill:"hsl(var(--muted) / 0.3)"},content:({active:s,payload:d,label:k})=>{if(!s||!d||d.length===0)return null;const b=m=>m.toLocaleString("en-US",{style:"currency",currency:"USD"}),w=Number(d.find(m=>m.dataKey==="Failed")?.value??0),D=Number(d.find(m=>m.dataKey==="Pending")?.value??0),u=w+D;return e.jsxs("div",{className:"rounded-md border bg-popover px-3 py-2 text-xs shadow-md",children:[e.jsx("div",{className:"mb-1 font-medium text-foreground",children:k}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-sm",style:{background:"hsl(var(--destructive))"}}),"Failed"]}),e.jsx("span",{className:"font-medium text-foreground",children:b(w)})]}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-sm",style:{background:"hsl(var(--muted-foreground))"}}),"Pending"]}),e.jsx("span",{className:"font-medium text-foreground",children:b(D)})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between gap-4 border-t pt-1.5",children:[e.jsx("span",{className:"text-muted-foreground",children:"Total"}),e.jsx("span",{className:"font-semibold text-foreground",children:b(u)})]})]})}}),e.jsx(Te,{wrapperStyle:{fontSize:12}}),e.jsx(H,{dataKey:"Failed",stackId:"lost",fill:"hsl(var(--destructive))"}),e.jsx(H,{dataKey:"Pending",stackId:"lost",fill:"hsl(var(--muted-foreground))",radius:[4,4,0,0]})]})})}),e.jsxs("ul",{className:"mt-4 divide-y",children:[e.jsxs("li",{className:"flex items-center py-2 text-xs uppercase tracking-wide text-muted-foreground",children:[e.jsx("span",{className:"flex-1",children:"Month"}),e.jsx("span",{className:"w-28 text-right",children:"Failed"}),e.jsx("span",{className:"w-28 text-right",children:"Pending"}),e.jsx("span",{className:"w-28 text-right",children:"Total"})]}),c.monthlyLost.map(s=>e.jsxs("li",{className:"flex items-center py-2 text-sm",children:[e.jsx("span",{className:"flex-1 text-muted-foreground",children:te(s.key)}),e.jsx("span",{className:"w-28 text-right text-destructive",children:s.failed.toLocaleStr
1ing("en-US",{style:"currency",currency:"USD"})}),e.jsx("span",{className:"w-28 text-right",children:s.pending.toLocaleString("en-US",{style:"currency",currency:"USD"})}),e.jsx("span",{className:"w-28 text-right font-semibold",children:s.total.toLocaleString("en-US",{style:"currency",currency:"USD"})})]},s.key))]})]}):e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"—"})]}),e.jsxs("div",{className:"rounded-xl border bg-card p-6 shadow-sm",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Tickets by status"}),e.jsx("div",{className:"mt-4 grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-6",children:we.map(s=>e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:Ie[s]}),e.jsx("p",{className:"mt-1 text-2xl font-semibold",children:c?c.byStatus[s]??0:"—"})]},s))})]}),e.jsxs("div",{className:"rounded-xl border bg-card p-6 shadow-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Thumbtack loss vs. result by month"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Loss (unconverted) and net result"})]}),T?T.monthly.length===0?e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"No Thumbtack leads logged yet."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 h-64 w-full",children:e.jsx(fe,{width:"100%",height:"100%",children:e.jsxs(Ne,{data:T.monthly.map(s=>({month:te(s.key),Loss:Number(s.loss.toFixed(2)),Result:Number(s.net.toFixed(2)),"Non-Thumbtack":Number(s.nonTtNet.toFixed(2))})),margin:{top:8,right:8,left:0,bottom:0},children:[e.jsx(be,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(he,{dataKey:"month",tick:{fontSize:12}}),e.jsx(ge,{tick:{fontSize:12},tickFormatter:s=>s.toLocaleString("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0})}),e.jsx(je,{cursor:{fill:"hsl(var(--muted) / 0.3)"},content:({active:s,payload:d,label:k})=>{if(!s||!d||d.length===0)return null;const b=m=>m.toLocaleString("en-US",{style:"currency",currency:"USD"}),w=Number(d.find(m=>m.dataKey==="Loss")?.value??0),D=Number(d.find(m=>m.dataKey==="Result")?.value??0),u=Number(d.find(m=>m.dataKey==="Non-Thumbtack")?.value??0);return e.jsxs("div",{className:"rounded-md border bg-popover px-3 py-2 text-xs shadow-md",children:[e.jsx("div",{className:"mb-1 font-medium text-foreground",children:k}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-sm",style:{background:"hsl(var(--destructive))"}}),"Loss"]}),e.jsx("span",{className:"font-medium text-foreground",children:b(w)})]}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-sm",style:{background:"hsl(var(--chart-2))"}}),"Result"]}),e.jsx("span",{className:"font-medium text-foreground",children:b(D)})]}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-4",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-sm",style:{background:"hsl(var(--chart-4))"}}),"Non-Thumbtack"]}),e.jsx("span",{className:"font-medium text-foreground",children:b(u)})]})]})}}),e.jsx(Te,{wrapperStyle:{fontSize:12}}),e.jsx(H,{dataKey:"Loss",fill:"hsl(var(--destructive))"}),e.jsx(H,{dataKey:"Result",fill:"hsl(var(--chart-2))"}),e.jsx(H,{dataKey:"Non-Thumbtack",fill:"hsl(var(--chart-4))"})]})})}),e.jsxs("ul",{className:"mt-4 divide-y",children:[e.jsxs("li",{className:"flex items-center py-2 text-xs uppercase tracking-wide text-muted-foreground",children:[e.jsx("span",{className:"flex-1",children:"Month"}),e.jsx("span",{className:"w-28 text-right",children:"Loss"}),e.jsx("span",{className:"w-28 text-right",children:"Result"}),e.jsx("span",{className:"w-28 text-right",children:"Non-Thumbtack"})]}),T.monthly.map(s=>e.jsxs("li",{className:"flex items-center py-2 text-sm",children:[e.jsx("span",{className:"flex-1 text-muted-foreground",children:te(s.key)}),e.jsx("span",{className:"w-28 text-right text-destructive",children:s.loss.toLocaleStr
1ing("en-US",{style:"currency",currency:"USD"})}),e.jsx("span",{className:s.net>=0?"w-28 text-right text-emerald-600 dark:text-emerald-400":"w-28 text-right text-destructive",children:s.net.toLocaleString("en-US",{style:"currency",currency:"USD"})}),e.jsx("span",{className:s.nonTtNet>=0?"w-28 text-right text-emerald-600 dark:text-emerald-400":"w-28 text-right text-destructive",children:s.nonTtNet.toLocaleString("en-US",{style:"currency",currency:"USD"})})]},s.key))]})]}):e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"—"})]}),e.jsx(rt,{}),e.jsx(pe,{className:"my-2",minHeight:90,label:"Dashboard Ad"}),e.jsxs("div",{className:"rounded-xl border bg-card p-6 shadow-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Monthly revenue"}),c&&c.monthlyRevenue.length>0&&e.jsxs("span",{className:"text-sm text-muted-foreground",children:["Total:"," ",e.jsx("span",{className:"font-semibold text-foreground",children:c.rangeRevenue.toLocaleString("en-US",{style:"currency",currency:"USD"})})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-3",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-xs text-muted-foreground",children:["From",e.jsx("input",{type:"date",value:A,max:B||void 0,onChange:s=>I(s.target.value),className:"rounded-md border bg-background px-2 py-1 text-sm text-foreground"})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-xs text-muted-foreground",children:["To",e.jsx("input",{type:"date",value:B,min:A||void 0,onChange:s=>Y(s.target.value),className:"rounded-md border bg-background px-2 py-1 text-sm text-foreground"})]}),e.jsx(N,{variant:"outline",size:"sm",onClick:()=>{I("2026-01-01");const s=new Date;Y(`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`)},children:"Reset"})]}),c?c.monthlyRevenue.length===0?e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"No paid tickets in the selected range."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 h-64 w-full",children:e.jsx(fe,{width:"100%",height:"100%",children:e.jsxs(Ne,{data:c.monthlyRevenue.map(({key:s,amount:d})=>({month:te(s),revenue:Number(d.toFixed(2))})),margin:{top:8,right:8,left:0,bottom:0},children:[e.jsx(be,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(he,{dataKey:"month",tick:{fontSize:12}}),e.jsx(ge,{tick:{fontSize:12},tickFormatter:s=>s.toLocaleString("en-US",{style:"currency",currency:"USD",maximumFractionDigits:0})}),e.jsx(je,{formatter:s=>s.toLocaleString("en-US",{style:"currency",currency:"USD"}),contentStyle:{background:"hsl(var(--popover))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),e.jsx(H,{dataKey:"revenue",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})})}),e.jsx("ul",{className:"mt-4 divide-y",children:c.monthlyRevenue.map(({key:s,amount:d})=>e.jsxs("li",{className:"flex items-center justify-between py-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:te(s)}),e.jsx("span",{className:"font-semibold",children:d.toLocaleString("en-US",{style:"currency",currency:"USD"})})]},s))})]}):e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:"—"})]})]}),e.jsx(pe,{className:"my-2",minHeight:90,label:"Dashboard Ad"}),e.jsxs("div",{className:"rounded-xl border bg-card p-6 shadow-sm",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Your account"}),e.jsxs("dl",{className:"mt-4 grid gap-3 text-sm",children:[e.jsxs("div",{className:"flex justify-between border-b pb-2",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Email"}),e.jsx("dd",{className:"font-medium",children:h?.email})]}),e.jsxs("div",{className:"flex justify-between border-b pb-2",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Display name"}),e.jsx("dd",{className:"font-medium",children:se?.display_name??"—"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"User ID"}),e.jsx("dd",{className:"font-mono text-xs",children:h?.id})]})]})]}),e.jsx("p",{className:"mt-6 text-center text-sm",children:e.jsx($,{to:"/home",className:"text-muted-foreground hover:text-foreground",children:"← Back to site"})})]}),e.jsx(Be,{})]})}function ee({icon:i,label:h,value:p,hint:C}){return e.jsxs("div",{className:"rounded-xl border bg-card p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wide text-muted-foreground",children:[i,h]}),e.jsx("p",{className:"mt-2 text-3xl font-semibold",children:p}),C&&e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:C})]})}function dt(i){if(!i||i<0)return"—";const h=Math.floor(i/1e3),p=Math.floor(h/60),C=Math.floor(p/60),x=Math.floor(C/24);return x>0?`${x}d ${C%24}h`:C>0?`${C}h ${p%60}m`:p>0?`${p}m`:`${h}s`}function te(i){const[h,p]=i.split("-").map(Number);
1return new Date(h,(p??1)-1,1).toLocaleString("en-US",{month:"long",year:"numeric"})}export{Lt as component};

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.