PageSourceSearch

https://restaurant-app-production.web.app/assets/InternalCrmInbox-CbyXKwYV.js

js restaurant-app-production.web.app collected 2026-10-03 12:36:35 UTC 35,450 bytes, 1 lines download raw bytes

1import{r as ot}from"./rolldown-runtime-b3L32Ng1.js";import{Ct as ct,F as be,Ht as dt,Xt as he,_ as fe,g as $,h as u,j as J,l as $e,nr as ut,rn as ge,u as p,v as B,y as L}from"./module-B8BOkXXh.js";import{n as mt}from"./PremiumShell-B_wt6ND8.js";var r=ot(ut(),1),M=[{key:"new",label:"New",sortOrder:0},{key:"contacted",label:"Contacted",sortOrder:1},{key:"demo-scheduled",label:"Demo Scheduled",sortOrder:2},{key:"demo-done",label:"Demo Done",sortOrder:3},{key:"proposal-sent",label:"Proposal Sent",sortOrder:4},{key:"closed-won",label:"Closed Won",sortOrder:5},{key:"closed-lost",label:"Closed Lost",sortOrder:6}],xt=M.map(s=>s.key),It=xt.filter(s=>s!=="closed-won"&&s!=="closed-lost"),Z=[{key:"landing-page",label:"Landing Page"},{key:"referral",label:"Referral"},{key:"outbound",label:"Outbound"},{key:"demo-request",label:"Demo Request"},{key:"trade-show",label:"Trade Show"},{key:"content-marketing",label:"Content Marketing"},{key:"partner-referral",label:"Partner Referral"},{key:"other",label:"Other"}],Dt=Z.map(s=>s.key),je=[{key:"restaurant",label:"Restaurant"},{key:"home_services",label:"Home Services"},{key:"unknown",label:"Unknown"}],Ut=je.map(s=>s.key),pt=[{key:"price",label:"Price Too High"},{key:"competitor",label:"Chose Competitor"},{key:"timing",label:"Bad Timing"},{key:"no-need",label:"No Need / Not Ready"},{key:"no-response",label:"No Response"},{key:"other",label:"Other"}],Ft=pt.map(s=>s.key),bt=[{key:"onboarding",label:"Onboarding"},{key:"live",label:"Live"},{key:"paused",label:"Paused"},{key:"churned",label:"Churned"}],Yt=bt.map(s=>s.key),ht=[{key:"account-created",label:"Account Created",sortOrder:0,autoDetect:!0},{key:"owner-invited",label:"Owner Invited",sortOrder:1,autoDetect:!0},{key:"owner-accepted",label:"Owner Accepted",sortOrder:2,autoDetect:!0},{key:"pos-connected",label:"POS Connected",sortOrder:3,autoDetect:!0},{key:"team-invited",label:"Team Invited",sortOrder:4,autoDetect:!0},{key:"menu-loaded",label:"Menu & Recipes Loaded",sortOrder:5,autoDetect:!0},{key:"vendors-added",label:"Vendors Added",sortOrder:6,autoDetect:!0},{key:"accounting-connected",label:"Accounting Connected",sortOrder:7,autoDetect:!0},{key:"training-complete",label:"Training Complete",sortOrder:8,autoDetect:!1},{key:"live",label:"Live",sortOrder:9,autoDetect:!1}],$t=ht.map(s=>s.key),ft=[{key:"launch-blocker",label:"Launch Blocker"},{key:"follow-up",label:"Follow-Up"},{key:"support",label:"Support"},{key:"internal",label:"Internal"}],Bt=ft.map(s=>s.key),gt=[{key:"high",label:"High"},{key:"medium",label:"Medium"},{key:"low",label:"Low"}],Kt=gt.map(s=>s.key),vt=[{key:"open",label:"Open"},{key:"in-progress",label:"In Progress"},{key:"done",label:"Done"}],qt=vt.map(s=>s.key),jt=[{key:"note",label:"Note"},{key:"call",label:"Call"},{key:"email",label:"Email"},{key:"stage-change",label:"Stage Change"},{key:"task-completed",label:"Task Completed"},{key:"system",label:"System"}],Gt=jt.map(s=>s.key),Nt=[{key:"pro",label:"Pro",mrr:dt.restaurant},{key:"elite",label:"Elite",mrr:699},{key:"custom",label:"Custom",mrr:null}],Vt=Nt.map(s=>s.key),yt=[{key:"toast",label:"Toast"},{key:"square",label:"Square"},{key:"clover",label:"Clover"},{key:"other",label:"Other"}],Ht=yt.map(s=>s.key),wt=[{key:"quickbooks",label:"QuickBooks"},{key:"xero",label:"Xero"},{key:"other",label:"Other"}],Xt=wt.map(s=>s.key),e=ct(),kt=[{key:"unprocessed",label:"Unprocessed",enabled:!0,tone:"active"},{key:"promoted",label:"Promoted",enabled:!1,tone:"pending"},{key:"all",label:"All",enabled:!1,tone:"pending"}],zt=3e4,St=4e3,m="pipeline",R="inbox",Be=Object.fromEntries(Z.map(s=>[s.key,s.label])),Ke=Object.fromEntries(je.map(s=>[s.key,s.label])),ve={restaurantName:"",contactName:"",source:"outbound",vertical:"restaurant",email:"",phone:"",notes:""},qe={restaurant:"border-emerald-200 bg-emerald-50 text-emerald-700",home_services:"border-sky-200 bg-sky-50 text-sky-700",unknown:"border-zinc-200 bg-zinc-50 text-zinc-600"};function Q(s){const n=Number(s||0);return!Number.isFinite(n)||n<=0?"$0":n.toLocaleString(void 0,{style:"currency",currency:"USD",maximumFractionDigits:0})}function q(s){if(!s)return 0;if(typeof s=="number")return Number.isFinite(s)?s:0;if(typeof s?.toMillis=="function"){const i=s.toMillis();return Number.isFinite(i)?i:0}if(typeof s?.toDate=="function"){const i=s.toDate().getTime();return Number.isFinite(i)?i:0}if(typeof s=="object"&&typeof s.seconds=="number")return s.seconds*1e3;const n=new Date(s).getTime();return Number.isFinite(n)?n:0}function Ct(s=[]){const n=new Map;for(const i of s)i?.id&&n.set(i.id,q(i.updatedAt||i.createdAt));return n}function W(s){if(!s)return"—";try{const n=q(s);
1return!Number.isFinite(n)||n<=0?"—":new Date(n).toLocaleString(void 0,{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}catch{return"—"}}function Ge(s){const n=q(s);return!Number.isFinite(n)||n<=0?"":new Date(n).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function Rt(s){return M.find(n=>n.key===s)||M[0]}function Lt(s){const n=q(s.stageUpdatedAt||s.updatedAt||s.createdAt);if(!n)return"No activity yet";const i=Math.max(0,Math.floor((Date.now()-n)/864e5));return i===0?"Moved today":i===1?"1 day in stage":`${i} days in stage`}function At(s,n){return!(n.owner!=="all"&&(s.assignedRepUid||"")!==n.owner||n.stage!=="all"&&(s.stage||"new")!==n.stage||n.source!=="all"&&(s.source||"")!==n.source||n.utm&&![s.utmSource,s.utmMedium,s.utmCampaign,s.sourcePageUrl,s.referrer].filter(Boolean).join(" ").toLowerCase().includes(n.utm.toLowerCase()))}function Et(s=[]){return M.map(n=>{const i=s.filter(o=>(o.stage||"new")===n.key),b=i.reduce((o,P)=>o+Number(P.estimatedMrr||0),0);return{...n,rows:i,totalMrr:b}})}function K(s){return String(s||"").trim()}function Tt(s){const n={restaurantName:K(s.restaurantName),contactName:K(s.
1contactName),source:K(s.source),vertical:K(s.vertical)};for(const i of["email","phone","notes"]){const b=K(s[i]);b&&(n[i]=b)}return n}function x({label:s,value:n,helper:i=null}){return(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:s}),(0,e.jsx)("p",{className:"mt-1 break-words text-sm text-zinc-900",children:n||(0,e.jsx)("span",{className:"text-zinc-400",children:"—"})}),i?(0,e.jsx)("p",{className:"mt-0.5 text-xs text-zinc-500",children:i}):null]})}function O({label:s,placeholder:n}){return(0,e.jsxs)("div",{className:"rounded-xl border border-dashed border-zinc-300 bg-zinc-50 p-3",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:s}),(0,e.jsx)("p",{className:"mt-1 text-sm italic text-zinc-500",children:n})]})}function _t(){return(0,e.jsxs)("li",{className:"flex flex-wrap items-center justify-between gap-3 p-4",children:[(0,e.jsxs)("div",{className:"min-w-0 flex-1 space-y-2",children:[(0,e.jsx)(L,{variant:"title",width:"60%"}),(0,e.jsx)(L,{variant:"text",width:"45%"}),(0,e.jsx)(L,{variant:"text",width:"30%"})]}),(0,e.jsx)(L,{variant:"text",width:"90px",height:"36px",className:"!h-9 !rounded-lg"})]})}function Jt({profile:s,isSuperAdmin:n,isSalesRep:i=!1}){const b=!!(n||i),[o,P]=(0,r.useState)(n?R:m),[v,Ne]=(0,r.useState)([]),[ye,ee]=(0,r.useState)(!0),[j,we]=(0,r.useState)(!1),[te,ke]=(0,r.useState)(""),[Ve,He]=(0,r.useState)("unprocessed"),[A,se]=(0,r.useState)(null),[N,ae]=(0,r.useState)([]),[Xe,ze]=(0,r.useState)(!1),[I,Se]=(0,r.useState)(!1),[ne,Ce]=(0,r.useState)(""),[Je,G]=(0,r.useState)(""),[D,V]=(0,r.useState)(null),[Qe,re]=(0,r.useState)(!1),[f,le]=(0,r.useState)(()=>({...ve})),[Re,U]=(0,r.useState)(""),[F,Le]=(0,r.useState)(!1),[h,E]=(0,r.useState)({owner:"all",stage:"all",source:"all",utm:""}),[T,We]=(0,r.useState)(null),[Y,Ae]=(0,r.useState)(null),[Ze,ie]=(0,r.useState)(""),[oe,Ee]=(0,r.useState)(""),[ce,Te]=(0,r.useState)(!1),[,et]=(0,r.useState)(0),de=(0,r.useRef)(new Map),_e=(0,r.useRef)(null),ue=(0,r.useRef)(null),H=(0,r.useRef)(new Set),y=(0,r.useRef)(null),Oe=(0,r.useMemo)(()=>ge(he,"crmListRawLeads"),[]),Me=(0,r.useMemo)(()=>ge(he,"crmListLeads"),[]),Pe=(0,r.useMemo)(()=>ge(he,"crmCreateLead"),[]),w=(0,r.useCallback)(async({isInitial:t=!1,isBackground:a=!1}={})=>{if(n){t?ee(!0):a||we(!0),ke("");try{const l=await Oe({}),c=Array.isArray(l?.data)?l.data:[],g=Ct(c),S=ue.current;if(S){const Fe=c.filter(C=>C?.id&&!S.has(C.id)),Ye=Fe.filter(C=>!H.current.has(C.id));if(Ye.length>0){Ye.forEach(it=>H.current.add(it.id));const C=Fe.length;Ee(`${C} new lead${C===1?"":"s"} added since you opened this view.`)}}else ue.current=g,H.current=new Set(g.keys());Ne(c),We(Date.now()),Te(!1),ie(c.length===0?"Inbox refreshed. No unprocessed leads.":`Inbox refreshed. ${c.length} unprocessed lead${c.length===1?"":"s"}.`)}catch(l){ke(be(l,"Could not load the raw leads inbox.")),t&&Ne([]),Te(!0),ie("Inbox refresh failed.")}finally{t?ee(!1):a||we(!1)}}},[n,Oe]),X=(0,r.useCallback)(async({isInitial:t=!1}={})=>{if(b){t?ze(!0):Se(!0),Ce("");try{const a=await Me({}),l=Array.isArray(a?.data)?a.data:[];ae(l),Ae(Date.now()),G(l.length===0?"Pipeline refreshed. No CRM leads found.":`Pipeline refreshed. ${l.length} CRM lead${l.length===1?"":"s"} loaded.`)}catch(a){Ce(be(a,"Could not load the CRM pipeline.")),t&&ae([]),G("Pipeline refresh failed.")}finally{t?ze(!1):Se(!1)}}},[b,Me]);(0,r.useEffect)(()=>{if(!n){ee(!1),ue.current=null,H.current=new Set;return}o===R&&w({isInitial:!0})},[o,n,w]),(0,r.useEffect)(()=>{!b||o!==m||X({isInitial:!0})},[o,b,X]),(0,r.useEffect)(()=>{!n&&o!==m&&P(m)},[o,n]),(0,r.useEffect)(()=>{if(!n||o!==R)return;const t=window.setInterval(()=>{w({isBackground:!0})},zt);return()=>window.clearInterval(t)},[o,n,w]),(0,r.useEffect)(()=>{if(oe)return y.current&&window.clearTimeout(y.current),y.current=window.setTimeout(()=>{Ee(""),y.current=null},St),()=>{y.current&&(window.clearTimeout(y.current),y.current=null)}},[oe]),(0,r.useEffect)(()=>{if(!T&&!Y)return;const t=setInterval(()=>et(a=>a+1),3e4);return()=>clearInterval(t)},[T,Y]);const k=(0,r.useMemo)(()=>v.find(t=>
1t.id===A)||null,[v,A]),_=(0,r.useMemo)(()=>N.filter(t=>At(t,h)),[N,h]),tt=(0,r.useMemo)(()=>Et(_),[_]),st=(0,r.useMemo)(()=>{const t=new Map;for(const a of N){const l=String(a.assignedRepUid||"").trim();l&&t.set(l,a.assignedRepName||l)}return[...t.entries()].map(([a,l])=>({uid:a,name:l}))},[N]),me=(0,r.useMemo)(()=>{const t=_.reduce((l,c)=>l+Number(c.estimatedMrr||0),0),a=_.filter(l=>!["closed-won","closed-lost"].includes(l.stage||"new")).length;return{total:_.length,activeCount:a,totalMrr:t}},[_]),d=(0,r.useMemo)(()=>N.find(t=>t.id===D)||null,[N,D]);(0,r.useEffect)(()=>{A&&(v.some(t=>t.id===A)||(se(null),ie("Selected lead no longer in the inbox. Detail closed.")))},[v,A]),(0,r.useEffect)(()=>{D&&(N.some(t=>t.id===D)||(V(null),G("Selected deal no longer matches this pipeline view. Detail closed.")))},[N,D]);const at=(0,r.useCallback)(t=>{_e.current=t,se(t)},[]),Ie=(0,r.useCallback)(()=>{se(null);const t=_e.current;t&&setTimeout(()=>{const a=de.current.get(t);a&&typeof a.focus=="function"&&a.focus()},0)},[]),nt=(0,r.useCallback)(()=>{U(""),re(!0)},[]),De=(0,r.useCallback)(()=>{F||(re(!1),le({...ve}),U(""))},[F]),z=(0,r.useCallback)((t,a)=>{le(l=>({...l,[t]:a}))},[]),rt=(0,r.useCallback)(async t=>{t?.preventDefault&&t.preventDefault();const a=Tt(f);if(!a.restaurantName||!a.contactName||!a.source||!a.vertical){U("Restaurant, contact, source, and vertical are required.");return}Le(!0),U("");try{const l=await Pe(a),c=Date.now(),g=l?.data?.id||`lead-${c}`;ae(S=>[{id:g,...a,stage:"new",stageUpdatedAt:c,createdAt:c,updatedAt:c,assignedRepUid:s?.uid||s?.id||s?.email||"",assignedRepName:s?.name||s?.email||""},...S]),E({owner:"all",stage:"all",source:"all",utm:""}),Ae(c),G(`${a.restaurantName} added to New.`),le({...ve}),re(!1)}catch(l){U(be(l,"Could not add lead. Try again."))}finally{Le(!1)}},[Pe,f,s]);if(!b)return(0,e.jsx)("div",{className:"mx-auto max-w-3xl p-6",children:(0,e.jsxs)("div",{className:"rounded-2xl border border-zinc-200 bg-white p-6 text-center",children:[(0,e.jsx)(u,{name:"Lock",size:32,className:"mx-auto text-zinc-400"}),(0,e.jsx)("h2",{className:"mt-3 text-lg font-semibold text-zinc-900",children:"Internal CRM access required"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-600",children:"Pipeline V2 is available to MarginGains super admins and sales reps only."})]})});const xe=T?`Last refreshed ${J(T)||"just now"}`:"",lt=ce?"Live updates paused":T?`Live · updated ${J(T)||"just now"}`:"Connecting…",Ue=Y?`Pipeline updated ${J(Y)||"just now"}`:"",pe=Xe||o===m&&!Y&&!ne;return(0,e.jsxs)("div",{className:"mx-auto max-w-5xl space-y-6 p-3 sm:p-5 lg:p-6",children:[(0,e.jsx)("div",{className:"sr-only",role:"status","aria-live":"polite",children:Ze}),(0,e.jsx)("div",{role:"status","aria-live":"polite",className:"sr-only",children:oe}),(0,e.jsx)(mt,{icon:"Inbox",eyebrow:"Internal Sales CRM",title:o===m?"CRM Pipeline":"Raw Leads Inbox",description:o===m?"Review active restaurant opportunities across stages with owner, source, and follow-up context.":"Review unprocessed landing-page leads and open each row for detail.",action:(0,e.jsxs)("div",{className:"flex flex-wrap justify-end gap-2",children:[o===m?(0,e.jsxs)(p,{type:"button",onClick:nt,disabled:pe,"aria-label":"Add Lead",children:[(0,e.jsx)(u,{name:"Plus",size:16}),"Add Lead"]}):null,(0,e.jsxs)(p,{type:"button",variant:"secondary",onClick:()=>o===m?X():w(),disabled:o===m?pe||I:ye||j,"aria-label":o===m?"Refresh pipeline":"Refresh inbox",children:[(0,e.jsx)(u,{name:"RefreshCw",size:16,className:(o===m?I:j)?"animate-spin":""}),(o===m?I:j)?"Refreshing…":"Refresh"]})]})}),(0,e.jsx)("div",{className:"rounded-xl border border-zinc-200 bg-white p-1",children:(0,e.jsxs)("div",{className:`grid gap-1 ${n?"sm:grid-cols-2":""}`,role:"tablist","aria-label":"Internal CRM views",children:[n?(0,e.jsxs)("button",{type:"button",role:"tab","aria-selected":o===R,onClick:()=>P(R),className:`inline-flex min-h-11 items-center justify-center gap-2 rounded-lg px-3 py-2 text-sm font-semibold transition ${o===R?"bg-zinc-950 text-white":"text-zinc-600 hover:bg-zinc-50 hover:text-zinc-950"}`,children:[(0,e.jsx)(u,{name:"Inbox",size:16}),"Raw Inbox"]}):null,(0,e.jsxs)("button",{type:"button",role:"tab","aria-selected":o===m,onClick:()=>P(m),className:`inline-flex min-h-11 items-center justify-center gap-2 rounded-lg px-3 py-2 text-sm font-semibold transition ${o===m?"bg-zinc-950 text-white":"text-zinc-600 hover:bg-zinc-50 hover:text-zinc-950"}`,children:[(0,e.jsx)(u,{name:"Columns3",size:16}),"Pipeline"]})]})}),o===R?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 px-4 py-3 text-sm text-amber-900",children:(0,e.jsxs)("div",{className:"flex items-start gap-2",children:[(0,e.jsx)(u,{name:"Info",size:16,className:"mt-0.5 shrink-0"}),(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"font-medium",children:"Read-only preview."}),(0,e.jsx)("p",{className:"mt-0.5 text-amber-800",children:"The write path (Promote to CRM) is disabled in this slice. A separate CTO-approved PR will enable it."})]})]})}),(0,e.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[(0,e.jsx)("nav",{"aria-label":"Status filters",className:"flex flex-wrap gap-2",children:kt.map(t=>{const a=t.key===Ve,l=t.enabled,c=t.key==="unprocessed"?v.length:null;return(0,e.jsxs)("button",{type:"button",disabled:!l,onClick:()=>l&&He(t.key),title:l?"":"Coming in the next slice",className:`inline-flex items-center gap-2 rounded-full border px-4 py-1.5 text-sm font-medium transition ${a?"border-brand-300 bg-brand-50 text-brand-700":l?"border-zinc-200 bg-white text-zinc-700 hover:border-zinc-300":"border-zinc-200 bg-zinc-50 text-zinc-400 cursor-not-allowed"}`,"aria-pressed":a,children:[(0,e.jsx)("span",{children:t.label}),c!==null?(0,e.jsx)("span",{className:`rounded-full px-2 py-0.5 text-xs ${a?"bg-brand-100 text-brand-700":"bg-zinc-100 text-zinc-600"}`,children:c}):null]},t.key)})}),(0,e.jsxs)("div",{className:`ml-0 inline-flex items-center gap-2 rounded-full border px-3 py-1.5 text-[12px] font-semibold sm:ml-auto ${ce?"border-red-200 bg-red-50 text-red-700":"border-emerald-200 bg-emerald-50 text-emerald-700"}`,"aria-live":"polite",children:[(0,e.jsx)("span",{className:`inline-block h-2 w-2 rounded-full ${ce?"bg-red-500":"bg-emerald-500 animate-pulse"}`,"aria-hidden":"true"}),(0,e.jsx)("span",{children:lt})]})]}),xe?(0,e.jsx)("p",{className:"text-xs text-zinc-500","aria-label":xe,children:xe}):null,te?(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3 rounded-2xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700",children:[(0,e.jsxs)("div",{className:"flex items-start gap-2",children:[(0,e.jsx)(u,{name:"AlertCircle",size:16,className:"mt-0.5 shrink-0"}),(0,e.jsx)("p",{children:te})]}),(0,e.jsxs)(p,{variant:"secondary",onClick:()=>w(),disabled:j,"aria-label":"Retry loading the inbox",children:[(0,e.jsx)(u,{name:"RefreshCw",size:14,className:j?"animate-spin":""}),"Retry"]})]}):null,ye?(0,e.jsx)("ul",{className:"divide-y divide-zinc-200 overflow-hidden rounded-2xl border border-zinc-200 bg-white","aria-busy":"true","aria-label":"Loading inbox",children:Array.from({length:4}).map((t,a)=>(0,e.jsx)(_t,{},a))}):v.length===0&&!te?(0,e.jsxs)("div",{className:"rounded-2xl border border-dashed border-zinc-300 bg-white p-10 text-center",children:[(0,e.jsx)(u,{name:"Inbox",size:36,className:"mx-auto text-zinc-400"}),(0,e.jsx)("h2",{className:"mt-3 text-base font-semibold text-zinc-900",children:"Nothing waiting"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-600",children:"No unprocessed landing-page leads right now."}),(0,e.jsx)("p",{className:"mt-3 text-xs text-zinc-500",children:"Leads land here when someone submits the landing-page form. They stay until a rep promotes them (coming in a later slice)."}),(0,e.jsx)("div",{className:"mt-4",children:(0,e.jsxs)(p,{variant:"secondary",onClick:()=>w(),disabled:j,children:[(0,e.jsx)(u,{name:"RefreshCw",size:14,className:j?"animate-spin":""}),j?"Refreshing…":"Check again"]})})]}):v.length>0?(0,e.jsx)("ul",{className:"divide-y divide-zinc-200 overflow-hidden rounded-2xl border border-zinc-200 bg-white",children:v.map(t=>{const a=t.id===A,l=t.updatedAt||t.createdAt,c=J(q(l));return(0,e.jsxs)("li",{className:`flex flex-wrap items-center justify-between gap-3 p-4 ${a?"bg-brand-50/40":""}`,children:[(0,e.jsxs)("button",{ref:g=>
1{g?de.current.set(t.id,g):de.current.delete(t.id)},type:"button",onClick:()=>at(t.id),className:"-m-1 min-w-0 flex-1 rounded-xl p-1 text-left transition hover:bg-zinc-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-300","aria-label":`View detail for ${t.restaurant||"unknown restaurant"}`,children:[(0,e.jsx)("p",{className:"truncate text-sm font-semibold text-zinc-950",children:t.restaurant||"Unknown restaurant"}),(0,e.jsx)("p",{className:"truncate text-sm text-zinc-600",children:t.email||"—"}),(0,e.jsxs)("p",{className:"mt-1 text-xs text-zinc-500",children:["Captured ",W(t.createdAt)]}),c?(0,e.jsxs)("p",{className:"mt-1 text-xs text-zinc-500",title:W(l),children:["Updated ",c]}):null]}),(0,e.jsxs)(p,{disabled:!0,title:"Promote ships in the next slice","aria-label":"Promote (disabled in read-only preview)",children:[(0,e.jsx)(u,{name:"ArrowRight",size:16}),"Promote"]})]},t.id)})}):null,(0,e.jsxs)("p",{className:"text-xs text-zinc-500",children:["Signed in as ",s?.name||s?.email||"super admin",". Raw lead review is view-only."]})]}):(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("div",{className:"sr-only",role:"status","aria-live":"polite",children:Je}),(0,e.jsxs)("section",{className:"grid gap-3 sm:grid-cols-3","aria-label":"Pipeline summary",children:[(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-white p-4",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Filtered leads"}),(0,e.jsx)("p",{className:"mt-1 text-2xl font-bold text-zinc-950",children:me.total})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-white p-4",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Active pipeline"}),(0,e.jsx)("p",{className:"mt-1 text-2xl font-bold text-zinc-950",children:me.activeCount})]}),(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-white p-4",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Estimated total value"}),(0,e.jsx)("p",{className:"mt-1 text-2xl font-bold text-zinc-950",children:Q(me.totalMrr)})]})]}),(0,e.jsxs)("section",{className:"rounded-xl border border-zinc-200 bg-white p-4","aria-label":"Pipeline filters",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-end gap-3",children:[n?(0,e.jsxs)("label",{className:"min-w-[180px] flex-1 text-sm font-medium text-zinc-700",children:["Owner",(0,e.jsxs)(B,{value:h.owner,onChange:t=>E(a=>({...a,owner:t.target.value})),className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",children:[(0,e.jsx)("option",{value:"all",children:"All reps"}),st.map(t=>(0,e.jsx)("option",{value:t.uid,children:t.name},t.uid))]})]}):null,(0,e.jsxs)("label",{className:"min-w-[180px] flex-1 text-sm font-medium text-zinc-700",children:["Stage",(0,e.jsxs)(B,{value:h.stage,onChange:t=>E(a=>({...a,stage:t.target.value})),className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",children:[(0,e.jsx)("option",{value:"all",children:"All stages"}),M.map(t=>(0,e.jsx)("option",{value:t.key,children:t.label},t.key))]})]}),(0,e.jsxs)("label",{className:"min-w-[180px] flex-1 text-sm font-medium text-zinc-700",children:["Source",(0,e.jsxs)(B,{value:h.source,onChange:t=>E(a=>({...a,source:t.target.value})),className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",children:[(0,e.jsx)("option",{value:"all",children:"All sources"}),Z.map(t=>(0,e.jsx)("option",{value:t.key,children:t.label},t.key))]})]}),(0,e.jsxs)("label",{className:"min-w-[220px] flex-1 text-sm font-medium text-zinc-700",children:["UTM / referrer",(0,e.jsx)($,{type:"search",value:h.utm,onChange:t=>E(a=>({...a,utm:t.target.value})),placeholder:"Campaign, source, URL",className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 placeholder:text-zinc-400 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100"})]}),(0,e.jsxs)(p,{variant:"secondary",onClick:()=>E({owner:"all",stage:"all",source:"all",utm:""}),disabled:h.owner==="all"&&h.stage==="all"&&h.source==="all"&&!h.utm,children:[(0,e.jsx)(u,{name:"RotateCcw",size:14}),"Reset"]})]}),Ue?(0,e.jsx)("p",{className:"mt-3 text-xs text-zinc-500",children:Ue}):null]}),ne?(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-3 rounded-xl border border-rose-200 bg-rose-50 px-4 py-3 text-sm text-rose-700",children:[(0,e.jsxs)("div",{className:"flex items-start gap-2",children:[(0,e.jsx)(u,{name:"AlertCircle",size:16,className:"mt-0.5 shrink-0"}),(0,e.jsx)("p",{children:ne})]}),(0,e.jsxs)(p,{variant:"secondary",onClick:()=>X(),disabled:I,"aria-label":"Retry loading the pipeline",children:[(0,e.jsx)(u,{name:"RefreshCw",size:14,className:I?"animate-spin":""}),"Retry"]})]}):null,pe?(0,e.jsx)("div",{className:"grid min-h-[420px] gap-3 overflow-x-auto pb-2 md:grid-cols-4 xl:grid-cols-7","aria-busy":"true","aria-label":"Loading pipeline",children:M.map(t=>(0,e.jsxs)("div",{className:"min-w-[260px] rounded-xl border border-zinc-200 bg-white p-3",children:[(0,e.jsx)(L,{variant:"title",width:"70%"}),(0,e.jsxs)("div",{className:"mt-4 space-y-3",children:[(0,e.jsx)(L,{variant:"text",height:"92px",className:"!h-24 !rounded-lg"}),(0,e.jsx)(L,{variant:"text",height:"92px",className:"!h-24 !rounded-lg"})]})]},t.key))}):(0,e.jsx)("section",{className:"overflow-x-auto pb-2","aria-label":"Read-only CRM pipeline kanban",children:(0,e.jsx)("div",{className:"grid min-w-[1180px] gap-3 lg:grid-cols-7",children:tt.map(t=>(0,e.jsxs)("div",{className:"flex min-h-[420px] flex-col rounded-xl border border-zinc-200 bg-zinc-50",children:[(0,e.jsx)("div",{className:"border-b border-zinc-200 bg-white p-3",children:(0,e.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,e.jsxs)("div",{children:[(0,e.jsx)("h2",{className:"text-sm font-semibold text-zinc-950",children:t.label}),(0,e.jsxs)("p",{className:"mt-0.5 text-xs text-zinc-500",children:[t.rows.length," lead",t.rows.length===1?"":"s"," · ",Q(t.totalMrr)]})]}),(0,e.jsx)("span",{className:"rounded-full bg-zinc-100 px-2 py-0.5 text-xs font-semibold text-zinc-600",children:t.sortOrder+1})]})}),(0,e.jsx)("div",{className:"flex-1 space-y-2 p-2",children:t.rows.length===0?(0,e.jsx)("div",{className:"rounded-lg border border-dashed border-zinc-300 bg-white p-4 text-center text-xs text-zinc-500",children:"No leads in this stage"}):t.rows.map(a=>{const l=a.restaurantName||a.restaurant||a.companyName||"Unnamed lead",c=a.vertical||"unknown",g=Be[a.source]||a.source||"Unknown source",S=Ge(a.nextFollowUp);return(0,e.jsxs)("button",{type:"button",onClick:()=>V(a.id),className:"w-full rounded-lg border border-zinc-200 bg-white p-3 text-left shadow-sm transition hover:-translate-y-0.5 hover:border-brand-300 hover:shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-brand-300","aria-label":`Open deal detail for ${l}`,children:[(0,e.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"truncate text-sm font-semibold text-zinc-950",children:l}),(0,e.jsx)("p",{className:"mt-0.5 truncate text-xs text-zinc-600",children:a.contactName||a.email||a.phone||"No contact yet"})]}),(0,e.jsx)("span",{className:"shrink-0 text-xs font-semibold text-zinc-700",children:Q(a.estimatedMrr)})]}),(0,e.jsxs)("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[(0,e.jsx)($e,{className:`${qe[c]||qe.unknown}`,children:Ke[c]||"Unknown"}),(0,e.jsx)($e,{className:"border-zinc-200 bg-zinc-50 text-zinc-600",children:g})]}),(0,e.jsxs)("div",{className:"mt-3 flex items-center justify-between gap-2 text-[11px] text-zinc-500",children:[(0,e.jsx)("span",{children:Lt(a)}),S?(0,e.jsxs)("span",{children:["Follow-up ",S]}):null]})]},a.id)})})]},t.key))})}),(0,e.jsxs)("p",{className:"text-xs text-zinc-500",children:["Signed in as ",s?.name||s?.email||(i?"sales rep":"super admin"),". New leads can be added; stage movement and edits ship later."]})]}),k?(0,e.jsx)(fe,{isOpen:!0,onClose:Ie,title:"Lead detail",variant:"light",size:"md",children:(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsxs)("div",{className:"rounded-2xl border border-zinc-200 bg-zinc-50 p-4",children:[(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Restaurant"}),(0,e.jsx)("p",{className:"mt-1 break-words text-lg font-semibold text-zinc-950",children:k.restaurant||"Unknown restaurant"})]}),(0,e.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-amber-200 bg-amber-50 px-3 py-1 text-xs font-medium text-amber-900",children:[(0,e.jsx)(u,{name:"Inbox",size:12}),"Unprocessed"]})]}),(0,e.jsx)("p",{className:"mt-2 truncate text-sm text-zinc-700",children:k.email||"—"})]}),(0,e.jsxs)("section",{className:"grid gap-4 sm:grid-cols-2",children:[(0,e.jsx)(x,{label:"Source",value:k.source==="landing-page"?"Landing page":k.source||"—"}),(0,e.jsx)(x,{label:"Captured",value:W(k.createdAt)}),(0,e.jsx)(x,{label:"Status",value:"Unprocessed",helper:"Filtered by CRM inbox permissions"}),(0,e.jsx)(x,{label:"Lead ID",value:k.id,helper:"mg_leads document ID"})]}),(0,e.jsxs)("section",{children:[(0,e.jsx)("p",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Promotion preview"}),(0,e.jsx)("p",{className:"mb-3 text-xs text-zinc-500",children:"These fields become live once the write path is enabled. They are not captured or saved today."}),(0,e.jsxs)("div",{className:"grid gap-2 sm:grid-cols-2",children:[(0,e.jsx)(O,{label:"Contact name",placeholder:"Rep fills at promotion"}),(0,e.jsx)(O,{label:"Phone",placeholder:"Rep fills at promotion"}),(0,e.jsx)(O,{label:"POS system",placeholder:"Rep selects at promotion"}),(0,e.jsx)(O,{label:"Estimated total value",placeholder:"Rep fills at promotion"}),(0,e.jsx)(O,{label:"Assigned rep",placeholder:"Promoter takes ownership"}),(0,e.jsx)(O,{label:"Pipeline stage",placeholder:"Starts at New"})]})]}),(0,e.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900",children:"Promote from this view is disabled in the read-only preview. Use the inbox list Promote button (also disabled) once the write path ships."}),(0,e.jsx)("div",{className:"flex justify-end gap-2 pt-1",children:(0,e.jsx)(p,{variant:"secondary",onClick:Ie,children:"Close"})})]})}):null,Qe?(0,e.jsx)(fe,{isOpen:!0,onClose:De,title:"Add lead",variant:"light",size:"md",children:(0,e.jsxs)("form",{className:"space-y-5","aria-label":"Add lead form",onSubmit:rt,children:[(0,e.jsxs)("div",{className:"rounded-xl border border-zinc-200 bg-zinc-50 p-4",children:[(0,e.jsx)("p",{className:"text-sm font-semibold text-zinc-950",children:"New pipeline lead"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-600",children:"Create a lead for the internal sales pipeline. It starts in New after the server saves it."})]}),(0,e.jsxs)("div",{className:"grid gap-4 sm:grid-cols-2",children:[(0,e.jsxs)("label",{className:"text-sm font-medium text-zinc-700",children:["Restaurant name",(0,e.jsx)($,{name:"restaurantName",value:f.restaurantName,onChange:t=>z("restaurantName",t.target.value),required:!0,autoFocus:!0,className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 placeholder:text-zinc-400 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",placeholder:"Acme Bistro"})]}),(0,e.jsxs)("label",{className:"text-sm font-medium text-zinc-700",children:["Contact name",(0,e.jsx)($,{name:"contactName",value:f.contactName,onChange:t=>z("contactName",t.target.value),required:!0,className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 placeholder:text-zinc-400 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",placeholder:"Jamie Owner"})]}),(0,e.jsxs)("label",{className:"text-sm font-medium text-zinc-700",children:["Source",(0,e.jsx)(B,{name:"source",value:f.source,onCh
1ange:t=>z("source",t.target.value),required:!0,className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",children:Z.map(t=>(0,e.jsx)("option",{value:t.key,children:t.label},t.key))})]}),(0,e.jsxs)("label",{className:"text-sm font-medium text-zinc-700",children:["Vertical",(0,e.jsx)(B,{name:"vertical",value:f.vertical,onChange:t=>z("vertical",t.target.value),required:!0,className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",children:je.map(t=>(0,e.jsx)("option",{value:t.key,children:t.label},t.key))})]}),(0,e.jsxs)("label",{className:"text-sm font-medium text-zinc-700",children:["Email",(0,e.jsx)($,{name:"email",type:"email",value:f.email,onChange:t=>z("email",t.target.value),className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 placeholder:text-zinc-400 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",placeholder:"[email protected]"})]}),(0,e.jsxs)("label",{className:"text-sm font-medium text-zinc-700",children:["Phone",(0,e.jsx)($,{name:"phone",value:f.phone,onChange:t=>z("phone",t.target.value),className:"mt-1 rounded-lg border-zinc-300 bg-white px-3 text-zinc-900 placeholder:text-zinc-400 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",placeholder:"555-0101"})]})]}),(0,e.jsxs)("label",{className:"block text-sm font-medium text-zinc-700",children:["Notes",(0,e.jsx)("textarea",{name:"notes",value:f.notes,onChange:t=>z("notes",t.target.value),rows:4,className:"mt-1 w-full rounded-lg border border-zinc-300 bg-white px-3 py-2 text-sm text-zinc-900 placeholder:text-zinc-400 focus:border-brand-400 focus:outline-none focus:ring-2 focus:ring-brand-100",placeholder:"Context from the first conversation"})]}),Re?(0,e.jsx)("div",{role:"alert",className:"rounded-xl border border-rose-200 bg-rose-50 px-3 py-2 text-sm text-rose-700",children:Re}):null,(0,e.jsxs)("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:[(0,e.jsx)(p,{type:"button",variant:"secondary",onClick:De,disabled:F,children:"Cancel"}),(0,e.jsxs)(p,{type:"submit",disabled:F,children:[(0,e.jsx)(u,{name:"Plus",size:16}),F?"Adding...":"Add lead"]})]})]})}):null,d?(0,e.jsx)(fe,{isOpen:!0,onClose:()=>V(null),title:"Deal detail",variant:"light",size:"md",children:(0,e.jsxs)("div",{className:"space-y-5",children:[(0,e.jsx)("div",{className:"rounded-xl border border-zinc-200 bg-zinc-50 p-4",children:(0,e.jsxs)("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Deal"}),(0,e.jsx)("p",{className:"mt-1 break-words text-lg font-semibold text-zinc-950",children:d.restaurantName||d.restaurant||"Unnamed lead"}),(0,e.jsx)("p",{className:"mt-1 text-sm text-zinc-600",children:d.contactName||d.email||d.phone||"No contact captured"})]}),(0,e.jsxs)("span",{className:"inline-flex items-center gap-1 rounded-full border border-zinc-200 bg-white px-3 py-1 text-xs font-medium text-zinc-700",children:[(0,e.jsx)(u,{name:"Columns3",size:12}),Rt(d.stage||"new").label]})]})}),(0,e.jsxs)("section",{className:"grid gap-4 sm:grid-cols-2",children:[(0,e.jsx)(x,{label:"Owner",value:d.assignedRepName||d.assignedRepUid||"—"}),(0,e.jsx)(x,{label:"Estimated total value",value:Q(d.estimatedMrr)}),(0,e.jsx)(x,{label:"Vertical",value:Ke[d.vertical]||"Unknown"}),(0,e.jsx)(x,{label:"Source",value:Be[d.source]||d.source||"—"}),(0,e.jsx)(x,{label:"Next follow-up",value:Ge(d.nextFollowUp)||"Not set"}),(0,e.jsx)(x,{label:"Updated",value:W(d.updatedAt||d.createdAt)})]}),(0,e.jsxs)("section",{className:"rounded-xl border border-zinc-200 bg-white p-4",children:[(0,e.jsx)("p",{className:"text-xs font-semibold uppercase tracking-wide text-zinc-500",children:"Enrichment"}),(0,e.jsxs)("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[(0,e.jsx)(x,{label:"UTM source",value:d.utmSource||"—"}),(0,e.jsx)(x,{label:"UTM medium",value:d.utmMedium||"—"}),(0,e.jsx)(x,{label:"UTM campaign",value:d.utmCampaign||"—"}),(0,e.jsx)(x,{label:"Referrer",value:d.referrer||"—"})]})]}),(0,e.jsx)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900",children:"Stage movement, editing, notes, and tasks are not available in this view yet."}),(0,e.jsx)("div",{className:"flex justify-end gap-2 pt-1",children:(0,e.jsx)(p,{variant:"secondary",onClick:()=>V(null),children:"Close"})})]})}):null]})}export{Jt 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.