1import{c as J,r as t,J as g,j as e,B as j}from"./index-CNPsGjEa.js";import{s as h}from"./client-BomsTZso.js";import{I as A}from"./input-BVM4_asw.js";import{L as E}from"./label-Dfvf70ds.js";import{T as M}from"./textarea-DnF6y1xa.js";import{B as P}from"./badge-BxnKxkwB.js";import{C as N,a as S,b as _,c as b,d as T}from"./card-DfvhUNcI.js";import{S as B,a as R,b as O,c as V,d as F}from"./select-CzibfoQS.js";import{L as C}from"./loader-circle-B_Dgc8V5.js";import{R as U}from"./refresh-cw-CVnDAkP1.js";import{S as K}from"./search-tmSGKc_r.js";import"./index-D9eVhfiJ.js";import"./index-DKaulZXA.js";import"./check-CDGWkqi-.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const I=J("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]),$=[{value:"new",label:"New"},{value:"contacted",label:"Contacted"},{value:"demo_booked",label:"Demo booked"},{value:"won",label:"Won"},{value:"lost",label:"Lost"}],f=(s,i)=>{var r;const n=(r=s.metadata)==null?void 0:r[i];return typeof n=="string"&&n.trim().length>0?n:null},Q=s=>{var i;return((i=$.find(n=>n.value===s))==null?void 0:i.label)??s},X=s=>new Date(s).toLocaleString("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}),Y=()=>{const[s,i]=t.useState(""),[n,r]=t.useState(!1),[m,u]=t.useState(!1),o=async c=>{if(c.preventDefault(),!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s)){g.error("Please enter a valid work email address.");return}r(!0);const{error:x}=await h.auth.signInWithOtp({email:s.trim(),options:{emailRedirectTo:`${window.location.origin}/sales`}});if(r(!1),x){g.error(x.message);return}u(!0)};return e.jsx("div",{className:"mx-auto flex min-h-screen w-full max-w-md items-center px-4",children:e.jsxs(N,{className:"w-full",children:[e.jsxs(S,{children:[e.jsx(_,{children:"Sales dashboard"}),e.jsx(b,{children:m?"Check your inbox and open the sign in link on this device.":"Enter your work email and we will send you a sign in link."})]}),e.jsx(T,{children:m?e.jsx(j,{variant:"outline",className:"w-full",onClick:()=>u(!1),children:"Use a different email"}):e.jsxs("form",{onSubmit:o,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:"sales-email",children:"Work email"}),e.jsx(A,{id:"sales-email",type:"email",autoComplete:"email",value:s,onChange:c=>i(c.target.value),placeholder:"[email protected]",required:!0})]}),e.jsx(j,{type:"submit",className:"w-full",disabled:n,children:n?e.jsxs(e.Fragment,{children:[e.jsx(C,{className:"mr-2 h-4 w-4 animate-spin"})," Sending link"]}):"Send sign in link"})]})})]})})},Z=({enquiry:s,onSave:i})=>{const[n,r]=t.useState(s.follow_up_status),[m,u]=t.useState(s.follow_up_note??""),[o,c]=t.useState(!1);t.useEffect(()=>{r(s.follow_up_status),u(s.follow_up_note??"")},[s.follow_up_status,s.follow_up_note]);const x=n!==s.follow_up_status||m!==(s.follow_up_note??""),w=async()=>{c(!0),await i(s.id,n,m),c(!1)};return e.jsxs(N,{children:[e.jsxs(S,{className:"gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(_,{className:"text-lg",children:f(s,"name")??"No name given"}),e.jsx(b,{children:e.jsx("a",{href:`mailto:${s.email}`,className:"underline underline-offset-4",children:s.email})})]}),e.jsx(P,{variant:"secondary",children:Q(s.follow_up_status)})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Received ",X(s.created_at)," · ",s.source]})]}),e.jsxs(T,{className:"space-y-4",children:[e.jsxs("dl",{className:"grid gap-3 sm:grid-cols-4",children:[e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Package"}),e.jsx("dd",{className:"text-sm",children:f(s,"plan")??"Not chosen"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Company"}),e.jsx("dd",{className:"text-sm",children:f(s,"company")??"Not given"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Team size"}),e.jsx("dd",{className:"text-sm",children:f(s,"team_size")??"Not given"})]}),e.jsxs("div",{children:[e.jsx("dt",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Goal"}),e.jsx("dd",{className:"text-sm",children:f(s,"goal")??s.position??"Not given"})]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-[200px_1fr]",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:`status-${s.id}`,children:"Follow up status"}),e.jsxs(B,{value:n,onValueChange:r,children:[e.jsx(R,{id:`status-${s.id}`,children:e.jsx(O,{})}),e.jsx(V,{children:$.map(d=>e.jsx(F,{value:d.value,children:d.label},d.value))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(E,{htmlFor:`note-${s.id}`,children:"Follow up notes"}),e.jsx(M,{id:`note-${s.id}`,value:m,maxLength:5e3,rows:3,placeholder:"What was discussed, next step, owner",onChange:d=>u(d.target.value)})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(j,{onClick:w,disabled:!x||o,children:[o?e.jsx(C,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save"]})})]})]})},xe=()=>{const[s,i]=t.useState(null),[n,r]=t.useState(!0),[m,u]=t.useState(null),[o,c]=t.useState([]),[x,w]=t.useState(!1),[d,W]=t.useState("all"),[k,z]=t.useState("");t.useEffect(()=>{const{data:a}=h.auth.onAuthStateChange((l,p)=>{i(p)});return h.auth.getSession().then(({data:l})=>{i(l.session),r(!1)}),()=>a.subscription.unsubscribe()},[]);const y=t.useCallback(async()=>{w(!0);const{data:a,error:l}=await h.from("leads").select("id, email, source, position, created_at, follow_up_status, follow_up_note, metadata").order("created_at",{ascending:!1}).limit(500);if(w(!1),l){g.error("Could not load enquiries.");return}c(a??[])},[]);t.useEffect(()=>{if(!s){u(null),c([]);return}let a=!0;return h.rpc("has_role",{_user_id:s.user.id,_role:"admin"}).then(({data:l,error:p})=>{if(!a)return;const v=!p&&l===!0;u(v),v&&y()}),()=>{a=!1}},[s,y]);const G=async(a,l,p)=>{const{error:v}=await h.from("leads").update({follow_up_status:l,follow_up_note:p.trim()||null}).eq("id",a);if(v){g.error("Could not save this update.");return}c(H=>H.map(L=>L.id===a?{...L,follow_up_status:l,follow_up_note:p.trim()||null}:L)),g.success("Follow up saved.")},D=t.useMemo(()=>{const a=k.trim().toLowerCase();return o.filter(l=>d!=="all"&&l.follow_up_status!==d?!1:a?[l.email,f(l,"name"),f(l,"company"),f(l,"goal"),l.follow_up_note].filter(
6Boolean).join(" ").toLowerCase().includes(a):!0)},[o,k,d]);return n?e.jsx("div",{className:"flex min-h-screen items-center justify-center",children:e.jsx(C,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):s?m===!1?e.jsx("div",{className:"mx-auto flex min-h-screen w-full max-w-md items-center px-4",children:e.jsxs(N,{className:"w-full",children:[e.jsxs(S,{children:[e.jsx(_,{children:"No access"}),e.jsx(b,{children:"This account is not set up to view demo enquiries. Ask an administrator to grant access."})]}),e.jsx(T,{children:e.jsxs(j,{variant:"outline",onClick:()=>h.auth.signOut(),children:[e.jsx(I,{className:"mr-2 h-4 w-4"})," Sign out"]})})]})}):e.jsx("main",{className:"min-h-screen bg-background px-4 py-10 sm:px-6 lg:px-10",children:e.jsxs("div",{className:"mx-auto w-full max-w-5xl space-y-6",children:[e.jsxs("header",{className:"flex flex-wrap items-end justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold sm:text-3xl",children:"Demo enquiries"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[o.length," enquir",o.length===1?"y":"ies"," · signed in as"," ",s.user.email]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(j,{variant:"outline",onClick:()=>void y(),disabled:x,children:[e.jsx(U,{className:`mr-2 h-4 w-4 ${x?"animate-spin":""}`})," Refresh"]}),e.jsxs(j,{variant:"ghost",onClick:()=>h.auth.signOut(),children:[e.jsx(I,{className:"mr-2 h-4 w-4"})," Sign out"]})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[1fr_200px]",children:[e.jsxs("div",{className:"relative",children:[e.jsx(K,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(A,{className:"pl-9",value:k,onChange:a=>z(a.target.value),placeholder:"Search name, company, email or notes","aria-label":"Search enquiries"})]}),e.jsxs(B,{value:d,onValueChange:W,children:[e.jsx(R,{"aria-label":"Filter by status",children:e.jsx(O,{})}),e.jsxs(V,{children:[e.jsx(F,{value:"all",children:"All statuses"}),$.map(a=>e.jsx(F,{value:a.value,children:a.label},a.value))]})]})]}),x&&o.length===0?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(C,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):D.length===0?e.jsx(N,{children:e.jsxs(S,{children:[e.jsx(_,{className:"text-lg",children:"Nothing to show"}),e.jsx(b,{children:"No enquiries match your search or filter just yet."})]})}):e.jsx("div",{className:"space-y-4",children:D.map(a=>e.jsx(Z,{enquiry:a,onSave:G},a.id))})]})}):e.jsx(Y,{})};export{xe 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.