1import{j as e}from"./vendor-ui-Bjd3vdCN.js";import{h as W,r as o}from"./vendor-react-DINOD1j6.js";import{f as V,s as A,W as X,N as Z,ca as q,w as d,x as v,y as N,z as m,T as H,g as K,h as z,i as Y,F as $,b2 as C,_ as G,v as D,ci as ee,H as se,B as c,av as te,bg as ae,cj as F,c as ie,C as re,d as ne,be as u}from"./index-CDorQKP_.js";import{f as le}from"./exhibitorSession-CgXXe8aL.js";import{a as ce,u as oe,b as de,c as me}from"./vendor-data-CUC8xDaI.js";import{f as he}from"./formatDistanceToNow-CCmuBq8I.js";import"./vendor-charts-CpgP9Wyz.js";import"./vendor-editor-XsA6J37k.js";import"./vendor-dnd-D5C-TQg0.js";import"./differenceInMonths-BSuqMKZ1.js";const p=10,Ie=()=>{const _=W(),{toast:f}=V(),y=ce(),[t,R]=o.useState({}),[S,P]=o.useState(A),[r,j]=o.useState(1),[n,B]=o.useState("active");o.useEffect(()=>{(async()=>{const a=sessionStorage.getItem("impersonation_token"),i=sessionStorage.getItem("impersonation_refresh");let x=A;a&&i&&(x=me("https://pmrpbngnsgoqjhiicyim.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InBtcnBibmduc2dvcWpoaWljeWltIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc1OTk0MDUsImV4cCI6MjA4MzE3NTQwNX0.AQaY3MOSf9U2Jc2C3POfLs-dhfcBDSZDt08PxfeSUs8",{auth:{storage:{getItem:()=>null,setItem:()=>{},removeItem:()=>{}},persistSession:!1,autoRefreshToken:!0}}),await x.auth.setSession({access_token:a,refresh_token:i}),P(x));const{data:{session:I}}=await x.auth.getSession();if(!I){_("/exhibitor-portal/login");return}const{data:T,error:M}=await le(x,I.user.id,"id, name, booth_number, logo_url");if(M){console.error("Error fetching exhibitor:",M),f({title:"Error",description:"Failed to load exhibitor data",variant:"destructive"});return}if(!T){console.error("No exhibitor found for user:",I.user.id),f({title:"Error",description:"No exhibitor profile found. Please contact support.",variant:"destructive"});return}R(T)})()},[_]);const{data:b=[],isLoading:U}=oe({queryKey:["exhibitor-inquiries",t.id],queryFn:async()=>{if(!t.id)return[];const{data:s,error:a}=await S.from("exhibitor_inquiries").select("*").eq("exhibitor_id",t.id).not("status","in",'("pending","rejected")').order("created_at",{ascending:!1});if(a)throw a;return s},enabled:!!t.id}),g=de({mutationFn:async({id:s,status:a})=>{const{error:i}=await S.from("exhibitor_inquiries").update({status:a}).eq("id",s);if(i)throw i},onSuccess:()=>{y.invalidateQueries({queryKey:["exhibitor-inquiries"]}),y.invalidateQueries({queryKey:["exhibitor-new-inquiries"]}),f({title:"Status Updated",description:"Inquiry status has been updated"})},onError:s=>{const a=s instanceof Error?s.message:"Failed to update status";f({title:"Error",description:a,variant:"destructive"})}}),J=s=>{switch(s){case"new":return e.jsx(u,{variant:"default",children:"New"});case"read":return e.jsx(u,{variant:"secondary",children:"Read"});case"responded":return e.jsx(u,{variant:"outline",className:"border-green-600 text-green-600",children:"Responded"});case"archived":return e.jsx(u,{variant:"outline",className:"border-muted-foreground text-muted-foreground",children:"Archived"});default:return e.jsx(u,{children:s})}},w=b.filter(s=>s.status!=="archived"),L=w.filter(s=>s.status==="new").length,k=w.length,E=b.filter(s=>s.status==="archived").length,h=n==="active"?w:b.filter(s=>s.status==="archived"),l=Math.ceil(h.length/p),Q=h.slice((r-1)*p,r*p);o.useEffect(()=>{j(1)},[n]);const O=()=>U?e.jsx(d,{children:e.jsx(m,{className:"py-12 text-center text-muted-foreground",children:"Loading inquiries..."})}):h.length===0?e.jsx(d,{children:e.jsxs(m,{className:"py-12 text-center",children:[e.jsx(C,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:n==="archived"?"No Archived Inquiries":"No Active Inquiries"}),e.jsx("p",{className:"text-muted-foreground",children:n==="archived"?"Archived inquiries will appear here":"When visitors contact you through your exhibitor listing, inquiries will appear here"})]})}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-4",children:Q.map(s=>e.jsxs(d,{className:s.status==="new"?"border-primary":"",children:[e.jsx(v,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(N,{className:"text-lg",children:s.visitor_name}),e.jsxs(G,{className:"flex items-center gap-4 flex-wrap",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(C,{className:"h-3 w-3"}),e.jsx("a",{href:`mailto:${s.visitor_email}`,className:"hover:underline",children:s.visitor_email})]}),s.visitor_company&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(D,{className:"h-3 w-3"}),s.visitor_company]}),s.visitor_phone&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ee,{className:"h-3 w-3"}),e.jsx("a",{href:`tel:${s.visitor_phone}`,className:"hover:underline",children:s.visitor_phone})]})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:J(s.status)})]})}),e.jsxs(m,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium mb-2",children:"Message:"}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:s.message})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1",children:[e.jsx(se,{className:"h-3 w-3"}),"Received ",he(new Date(s.created_at),{addSuffix:!0})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[n==="active"&&e.jsxs(e.Fragment,{children:[s.status==="new"&&e.jsxs(c,{size:"sm",variant:"outline",onClick:()=>g.mutate({id:s.id,status:"read"}),children:[e.jsx(te,{className:"h-4 w-4 mr-2"}),"Mark as Read"]}),s.status!=="responded"&&e.jsxs(c,{size:"sm",onClick:()=>g.mutate({id:s.id,status:"responded"}),children:[e.jsx(ae,{className:"h-4 w-4 mr-2"}),"Mark as Responded"]}),e.jsxs(c,{size:"sm",variant:"outline",onClick:()=>g.mutate({id:s.id,status:"archived"}),children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"Archive"]})]}),n==="archived"&&e.jsxs(c,{size:"sm",variant:"outline",onClick:()=>g.mutate({id:s.id,status:"read"}),children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),"Unarchive"]}),e.jsx(ie,{styleType:"button1",className:"text-sm h-9 px-3",asChild:!0,children:e.jsxs("a",{href:`mailto:${s.visitor_email}`,children:[e.jsx(C,{className:"h-4 w-4 mr-2"}),"Reply"]})})]})]})]})]},s.id))}),l>1&&e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-4 pt-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Showing ",(r-1)*p+1," to ",Math.min(r*p,h.length)," of ",h.length," inquiries"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>j(s=>Math.max(1,s-1)),disabled:r===1,children:[e.jsx(re,{className:"h-4 w-4 mr-1"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-1",children:Array.from({length:Math.min(l,5)},(s,a)=>{let i;return l<=5||r<=3?i=a+1:r>=l-2?i=l-4+a:i=r-2+a,e.jsx(c,{variant:r===i?"default":"outline",size:"sm",onClick:()=>j(i),className:"w-10",children:i},i)})}),e.jsxs(c,{variant:"outline",size:"sm",onClick:()=>j(s=>Math.min(l,s+1)),disabled:r===l,children:["Next",e.jsx(ne,{className:"h-4 w-4 ml-1"})]})]})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(X,{children:e.jsx("title",{children:"Inquiries - Exhibitor Portal"})}),e.jsxs("div",{className:"min-h-screen flex flex-col",children:[e.jsx(Z,{}),e.jsx("main",{className:"flex-1 pt-page pb-12",children:e.jsx("div",{className:"container mx-auto px-6",children:e.jsxs("div",{className:"flex gap-8 mt-[60px]",children:[e.jsx("aside",{className:"w-64 flex-shrink-0 sticky top-24 h-fit hidden lg:block",children:e.jsx(q,{exhibitorName:t==null?void 0:t.name,standNumber:t==null?void 0:t.booth_number,logoUrl:t==null?void 0:t.logo_url,renderTrigger:!1,alwaysVisible:!0})}),e.jsx("div",{className:"lg:hidden fixed top-20 left-4 z-50",children:e.jsx(q,{exhibitorName:t==null?void 0:t.name,standNumber:t==null?void 0:t.booth_number,logoUrl:t==null?void 0:t.logo_url,renderTrigger:!0})}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold mb-2",children:"Contact Inquiries"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage and respond to inquiries from visitors interested in your products"})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs(d,{children:[e.jsx(v,{className:"pb-3",children:e.jsx(N,{className:"text-sm font-medium",children:"Total Inquiries"})}),e.jsx(m,{children:e.jsx("div",{className:"text-3xl font-bold",children:k})})]}),e.jsxs(d,{children:[e.jsx(v,{className:"pb-3",children:e.jsx(N,{className:"text-sm font-medium",children:"New Inquiries"})}),e.jsx(m,{children:e.jsx("div",{className:"text-3xl font-bold text-primary",children:L})})]}),e.jsxs(d,{children:[e.jsx(v,{className:"pb-3",children:e.jsx(N,{className:"text-sm font-medium",children:"Archived"})}),e.jsx(m,{children:e.jsx("div",{className:"text-3xl font-bold text-muted-foreground",children:E})})]})]}),e.jsxs(H,{value:n,onValueChange:s=>B(s),className:"w-full",children:[e.jsxs(K,{className:"grid w-full max-w-md grid-cols-2",children:[e.jsxs(z,{value:"active",children:["Active (",k,")"]}),e.jsxs(z,{value:"archived",children:["Archived (",E,")"]})]}),e.jsx(Y,{value:n,className:"mt-6",children:O()})]})]})]})})}),e.jsx($,{})]})]})};export{Ie 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.