1import{r as h,j as e}from"./vendor-react-B2RT89U9.js";import{c as Y,u as v,b as N}from"./vendor-tanstack-MRWYOJqo.js";import{C as u,a as g,b as R,c as P}from"./card-CV4rleUf.js";import{u as Z,B as m,a9 as X,T as y,d as E}from"./index-gDpiPSoZ.js";import{I as l}from"./input-Ds8nB8-7.js";import{B as L}from"./badge-BLy_vRrO.js";import{S as ee}from"./switch-BULs2WFJ.js";import{L as c}from"./label-C2dLx4EC.js";import{S as M}from"./star-XDI8enhw.js";import{R as se}from"./refresh-cw-DICdVNqw.js";import{L as b}from"./loader-circle-CCVKtMXL.js";import{S as _}from"./settings-CfHJr-Nz.js";import{S as F}from"./send-itjC8_Us.js";import{U as ae}from"./users-CPXtjG0y.js";import{C as B}from"./clock-CL0zg-Qj.js";import{T as te}from"./trending-up-DugfB21r.js";import{Z as ie}from"./zap-BrFbhTAN.js";import{C as I}from"./circle-check-big-DYqNqHzq.js";import{S as re}from"./search-DYoyvokB.js";import"./vendor-radix-PXtjYgzj.js";async function w(o){const t=await fetch(o,{credentials:"include"});if(!t.ok)throw new Error(await t.text());return t.json()}async function $(o,t){const a=await fetch(o,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)});if(!a.ok)throw new Error(await a.text());return a.json()}async function ne(o,t){const a=await fetch(o,{method:"PATCH",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(t)});if(!a.ok)throw new Error(await a.text());return a.json()}const le={sequence_pending:"bg-blue-100 text-blue-700",sequence_complete:"bg-gray-100 text-gray-600",reviewed:"bg-green-100 text-green-700",draft:"bg-yellow-100 text-yellow-700",sent:"bg-purple-100 text-purple-700"},ce={sequence_pending:"Pending",sequence_complete:"Sequence Done",reviewed:"Reviewed â",draft:"Draft",sent:"Sent"};function f({label:o,value:t,sub:a,icon:j,color:S}){return e.jsx(u,{className:`border-0 shadow-sm bg-gradient-to-br ${S}`,children:e.jsx(g,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-gray-500 mb-1",children:o}),e.jsx("p",{className:"text-2xl font-bold text-gray-800",children:t}),a&&e.jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:a})]}),e.jsx("div",{className:"p-2 rounded-xl bg-white/60",children:e.jsx(j,{className:"w-4 h-4 text-gray-600"})})]})})})}function Re({embedded:o}){const{toast:t}=Z(),a=Y(),[j,S]=h.useState(!1),[C,A]=h.useState(!1),[T,O]=h.useState(""),[x,p]=h.useState({clientName:"",clientEmail:"",clientPhone:"",projectType:""}),{data:V,isLoading:oe}=v({queryKey:["/api/admin/reviews/dashboard"],queryFn:()=>w("/api/admin/reviews/dashboard"),refetchInterval:6e4}),{data:G,isLoading:H}=v({queryKey:["/api/admin/reviews/sequences"],queryFn:()=>w("/api/admin/reviews/sequences"),refetchInterval:6e4}),{data:W}=v({queryKey:["/api/admin/reviews/config"],queryFn:()=>w("/api/admin/reviews/config")}),{data:K}=v({queryKey:["/api/admin/reviews/leads-search",T],queryFn:()=>w(`/api/admin/reviews/leads-search?q=${encodeURIComponent(T)}`),enabled:C}),[J,d]=h.useState(null),Q=W?.config,r=J??Q??{},D=N({mutationFn:()=>$("/api/admin/reviews/run-now",{}),onSuccess:s=>{t({title:"Scheduler Run Complete",description:`${s.processed} due, ${s.fired} messages fired`}),a.invalidateQueries({queryKey:["/api/admin/reviews/dashboard"]}),a.invalidateQueries({queryKey:["/api/admin/reviews/sequences"]})},onError:s=>t({title:"Error",description:s.message,variant:"destructive"})}),k=N({mutationFn:s=>$("/api/admin/reviews/config",s),onSuccess:()=>{t({title:"Config Saved",description:"Review automation settings updated"}),a.invalidateQueries({queryKey:["/api/admin/reviews/config"]}),d(null)},onError:s=>t({title:"Save Failed",description:s.message,variant:"destructive"})}),q=N({mutationFn:s=>$("/api/admin/reviews/trigger",s),onSuccess:()=>{t({title:"Sequence Started",description:`Review sequence triggered â step 1 SMS fires in ${r.step1DelayDays??3} days`}),a.invalidateQueries({queryKey:["/api/admin/reviews/dashboard"]}),a.invalidateQueries({queryKey:["/api/admin/reviews/sequences"]}),p({clientName:"",clientEmail:"",clientPhone:"",projectType:""}),A(!1)},onError:s=>t({title:"Error",description:s.message,variant:"destructive"})}),U=N({mutationFn:s=>ne(`/api/admin/reviews/sequences/${s}/mark-reviewed`,{}),onSuccess:()=>{t({title:"Marked as Reviewed â"}),a.invalidateQueries({queryKey:["/api/admin/reviews/dashboard"]}),a.invalidateQueries({queryKey:["/api/admin/reviews/sequences"]})},onError:s=>t({title:"Error",description:s.message,variant:"destructive"})}),n=V?.stats,z=G?.sequences||[];return e.jsxs("div",{className:`space-y-6 ${o?"p-0":"p-6 max-w-6xl mx-auto"}`,children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xl font-bold text-gray-800 flex items-center gap-2",children:[e.jsx(M,{className:"w-5 h-5 text-yellow-500 fill-yellow-400"}),"Google Review Automation"]}),e.jsx("p",{className:"text-sm text-gray-500 mt-0.5",children:"3-step sequence: Day 3 SMS â Day 7 Email â Day 14 SMS. Auto-fires on project completion."})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(m,{size:"sm",variant:"outline",onClick:()=>{a.invalidateQueries({queryKey:["/api/admin/reviews/dashboard"]}),a.invalidateQueries({queryKey:["/api/admin/reviews/sequences"]})},"data-testid":"button-refresh-reviews",children:[e.jsx(se,{className:"w-3.5 h-3.5 mr-1.5"}),"Refresh"]}),e.jsxs(m,{size:"sm",variant:"outline",onClick:()=>D.mutate(),disabled:D.isPending,"data-testid":"button-run-scheduler",children:[D.isPending?e.jsx(b,{className:"w-3.5 h-3.5 animate-spin mr-1.5"}):e.jsx(X,{className:"w-3.5 h-3.5 mr-1.5"}),"Run Scheduler Now"]}),e.jsxs(m,{size:"sm",variant:"outline",onClick:()=>S(!j),"data-testid":"button-config",children:[e.jsx(_,{className:"w-3.5 h-3.5 mr-1.5"}),"Settings"]}),e.jsxs(m,{size:"sm",onClick:()=>A(!C),className:"bg-[#2ab5a0] hover:bg-[#22968a] text-white","data-testid":"button-trigger",children:[e.jsx(F,{className:"w-3.5 h-3.5 mr-1.5"}),"Manual Trigger"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(f,{label:"Total Sequences",value:n?.total??"â",sub:`${n?.autoTriggered??0} auto-triggered`,icon:ae,color:"from-[#2ab5a0]/10 to-teal-50/30"}),e.jsx(f,{label:"Pending",value:n?.pending??"â",sub:"active in sequence",icon:B,color:"from-blue-50 to-indigo-50/30"}),e.jsx(f,{label:"Sent This Week",value:n?.sentThisWeek??"â",sub:`${n?.sentToday??0} today`,icon:te,color:"from-purple-50 to-violet-50/30"}),e.jsx(f,{label:"Left Reviews",value:n?.reviewed??"â",sub:"confirmed reviews",icon:M,color:"from-yellow-50 to-amber-50/30"})]}),n&&e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{label:"Step 1 â Day 3 SMS",count:n.byStep.step1,icon:y,color:"bg-blue-100 text-blue-700"},{label:"Step 2 â Day 7 Email",count:n.byStep.step2,icon:E,color:"bg-indigo-100 text-indigo-700"},{label:"Step 3 â Day 14 SMS",count:n.byStep.step3,icon:y,color:"bg-purple-100 text-purple-700"}].map(s=>e.jsx(u,{className:"border shadow-sm",children:e.jsxs(g,{className:"p-3 flex items-center gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${s.color.replace("text-","bg-").replace("700","100")} `,children:e.jsx(s.icon,{className:`w-4 h-4 ${s.color.split(" ")[1]}`})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-gray-500",children:s.label}),e.jsxs("p",{className:"text-xl font-bold text-gray-800",children:[s.count," waiting"]})]})]})},s.label))}),e.jsx(u,{className:"border border-[#2ab5a0]/30 bg-gradient-to-br from-[#2ab5a0]/5 to-teal-50/20",children:e.jsxs(g,{className:"p-4",children:[e.jsx("p",{className:"text-xs font-semibold text-gray-500 uppercase tracking-wider mb-3",children:"How It Works"}),e.jsx("div",{className:"flex flex-wrap gap-2 items-center text-xs text-gray-600",children:[{icon:ie,label:"Project Marked Complete / DocuSign Signed",color:"bg-[#2ab5a0] text-white"},{icon:y,label:"Day 3: Personal SMS with Google review link",color:"bg-blue-100 text-blue-700"},{icon:E,label:"Day 7: Branded email with star rating CTA",color:"bg-indigo-100 text-indigo-700"},{icon:y,label:"Day 14: Final nudge SMS",color:"bg-purple-100 text-purple-700"},{icon:I,label:"Sequence Complete",color:"bg-green-100 text-green-700"}].map((s,i)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[i>0&&e.jsx("span",{className:"text-gray-300",children:"â"}),e.jsxs("span",{className:`flex items-center gap-1 px-2 py-1 rounded-full font-medium ${s.color}`,children:[e.jsx(s.icon,{className:"w-3 h-3"}),s.label]})]},i))})]})}),j&&Q&&e.jsxs(u,{className:"border",children:[e.jsx(R,{className:"pb-3",children:e.jsxs(P,{className:"text-sm flex items-center gap-2",children:[e.jsx(_,{className:"w-4 h-4"}),"Review Automation Settings"]})}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Google Review Link"}),e.jsx(l,{className:"text-xs h-8",value:r.googleReviewLink??"",onChange:s=>d(i=>
1({...r,googleReviewLink:s.target.value})),"data-testid":"input-google-review-link"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Yelp Review Link"}),e.jsx(l,{className:"text-xs h-8",value:r.yelpReviewLink??"",onChange:s=>d(i=>({...r,yelpReviewLink:s.target.value})),"data-testid":"input-yelp-review-link"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Step 1 Delay (days)"}),e.jsx(l,{type:"number",className:"text-xs h-8",value:r.step1DelayDays??3,onChange:s=>d(i=>({...r,step1DelayDays:s.target.value})),"data-testid":"input-step1-delay"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Step 2 Delay (days)"}),e.jsx(l,{type:"number",className:"text-xs h-8",value:r.step2DelayDays??7,onChange:s=>d(i=>({...r,step2DelayDays:s.target.value})),"data-testid":"input-step2-delay"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Step 3 Delay (days)"}),e.jsx(l,{type:"number",className:"text-xs h-8",value:r.step3DelayDays??14,onChange:s=>d(i=>({...r,step3DelayDays:s.target.value})),"data-testid":"input-step3-delay"})]}),e.jsxs("div",{className:"flex items-center gap-3 pt-4",children:[e.jsx(ee,{checked:r.autoTriggerOnComplete??!0,onCheckedChange:s=>d(i=>({...r,autoTriggerOnComplete:s})),"data-testid":"switch-auto-trigger"}),e.jsx(c,{className:"text-xs",children:"Auto-trigger on project completion"})]})]}),e.jsxs(m,{size:"sm",onClick:()=>k.mutate(r),disabled:k.isPending,className:"bg-[#2ab5a0] hover:bg-[#22968a] text-white","data-testid":"button-save-config",children:[k.isPending?e.jsx(b,{className:"w-3.5 h-3.5 animate-spin mr-1.5"}):null,"Save Settings"]})]})]}),C&&e.jsxs(u,{className:"border border-[#2ab5a0]/40",children:[e.jsx(R,{className:"pb-3",children:e.jsxs(P,{className:"text-sm flex items-center gap-2",children:[e.jsx(F,{className:"w-4 h-4 text-[#2ab5a0]"}),"Manually Trigger Review Sequence"]})}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(l,{placeholder:"Search leads by name...",value:T,onChange:s=>O(s.target.value),className:"text-xs h-8","data-testid":"input-lead-search"}),e.jsx(re,{className:"w-4 h-4 text-gray-400 mt-2 shrink-0"})]}),K?.leads?.length>0&&e.jsx("div",{className:"border rounded-lg divide-y max-h-48 overflow-y-auto",children:K.leads.map(s=>e.jsxs("button",{className:"w-full flex items-center justify-between px-3 py-2 text-xs hover:bg-gray-50 text-left",onClick:()=>p({clientName:s.name,clientEmail:s.email||"",clientPhone:s.phone||"",projectType:s.projectType||""}),"data-testid":`lead-select-${s.id}`,children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:"text-gray-400 ml-2",children:s.projectType})]}),e.jsx(L,{className:`text-[10px] ${s.pipelineStage==="completed"?"bg-green-100 text-green-700":"bg-gray-100 text-gray-600"}`,children:s.pipelineStage})]},s.id))}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Client Name *"}),e.jsx(l,{className:"text-xs h-8",value:x.clientName,onChange:s=>p(i=>({...i,clientName:s.target.value})),"data-testid":"input-trigger-name"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Phone (for SMS)"}),e.jsx(l,{className:"text-xs h-8",value:x.clientPhone,onChange:s=>p(i=>({...i,clientPhone:s.target.value})),"data-testid":"input-trigger-phone"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Email (for Day 7 email)"}),e.jsx(l,{className:"text-xs h-8",value:x.clientEmail,onChange:s=>p(i=>({...i,clientEmail:s.target.value})),"data-testid":"input-trigger-email"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(c,{className:"text-xs",children:"Project Type"}),e.jsx(l,{className:"text-xs h-8",placeholder:"Kitchen Remodel, ADU, etc.",value:x.projectType,onChange:s=>p(i=>({...i,projectType:s.target.value})),"data-testid":"input-trigger-project"})]})]}),e.jsxs(m,{size:"sm",onClick:()=>q.mutate(x),disabled:q.isPending||!x.clientName,className:"bg-[#2ab5a0] hover:bg-[#22968a] text-white","data-testid":"button-trigger-sequence",children:[q.isPending?e.jsx(b,{className:"w-3.5 h-3.5 animate-spin mr-1.5"}):e.jsx(F,{className:"w-3.5 h-3.5 mr-1.5"}),"Start Review Sequence"]})]})]}),e.jsxs(u,{className:"border",children:[e.jsx(R,{className:"pb-3",children:e.jsxs(P,{className:"text-sm flex items-center gap-2",children:[e.jsx(B,{className:"w-4 h-4 text-[#2ab5a0]"}),"Active Sequences",H&&e.jsx(b,{className:"w-3.5 h-3.5 animate-spin text-gray-400"})]})}),e.jsx(g,{className:"p-0",children:z.length===0?e.jsxs("div",{className:"text-center py-10 text-gray-400",children:[e.jsx(M,{className:"w-8 h-8 mx-auto mb-2 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No sequences yet. They auto-start when projects are marked complete."})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsx("tr",{className:"border-b bg-gray-50/50",children:["Client","Project","Step","Status","Via","Next Fire",""].map(s=>e.jsx("th",{className:"px-3 py-2.5 text-left font-semibold text-gray-500",children:s},s))})}),e.jsx("tbody",{className:"divide-y",children:z.slice(0,50).map(s=>e.jsxs("tr",{className:"hover:bg-gray-50/50",children:[e.jsx("td",{className:"px-3 py-2.5 font-medium text-gray-800",children:s.clientName}),e.jsx("td",{className:"px-3 py-2.5 text-gray-500",children:s.projectType||"â"}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsxs(L,{className:"bg-[#2ab5a0]/10 text-[#2ab5a0] border-0 text-[10px]",children:["Step ",s.step??1,"/3"]})}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx(L,{className:`text-[10px] border-0 ${le[s.status]||"bg-gray-100 text-gray-500"}`,children:ce[s.status]||s.status})}),e.jsxs("td",{className:"px-3 py-2.5 text-gray-500 capitalize",children:[s.sentVia==="sms"?e.jsx(y,{className:"w-3.5 h-3.5 inline"}):e.jsx(E,{className:"w-3.5 h-3.5 inline"})," ",s.sentVia||"â",s.autoTriggered&&e.jsx("span",{className:"ml-1 text-[10px] text-teal-600 font-medium",children:"AUTO"})]}),e.jsx("td",{className:"px-3 py-2.5 text-gray-400",children:s.nextStepAt?new Date(s.nextStepAt).toLocaleDateString("en-US",{month:"short",day:"numeric"}):s.status==="sequence_complete"?"Done":"â"}),e.jsxs("td",{className:"px-3 py-2.5",children:[(s.status!=="reviewed"&&s.status!=="sequence_complete",null),s.status!=="reviewed"&&e.jsxs(m,{size:"sm",variant:"ghost",className:"h-6 px-2 text-[10px] text-green-600",onClick:()=>U.mutate(s.id),disabled:U.isPending,"data-testid":`button-mark-reviewed-${s.id}`,children:[e.jsx(I,{className:"w-3 h-3 mr-1"}),"Reviewed"]})]})]},s.id))})]})})})]})]})}export{Re as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.