1import{w as _,a1 as M,a2 as H,aT as Y,a3 as q,af as G,aU as $,a9 as z,aa as K,aO as Q,ad as J,r as n,j as e,c as W,t as A}from"./index-zHIJQHEM.js";import{l as X}from"./firebase-dashboard-DOHxQdyQ.js";import{c as Z}from"./firebase-visitors-BU80Ek-f.js";import{S as ee,a as se,b as ae,c as te,d as ne}from"./sheet-TglzMPV9.js";import{B as re}from"./badge-C9vBNQPF.js";import{MESSAGE_TYPES as y}from"./firebase-chat-DhDNQD80.js";import{g as ie,i as le,k as oe}from"./firebase-history-B5IUR5bp.js";import{f as ce}from"./visitor-meta-GsNgmn7p.js";import{c as S,C as de}from"./card-CDbECwhX.js";import{L as D}from"./loader-circle-BXo1LIey.js";import{E as me}from"./external-link-BbToABk1.js";import{B as I}from"./button-CF3fTBb6.js";import{I as xe}from"./input-D_VHSRb_.js";import{T as ue,a as pe,b as w,c as g,d as he,e as p}from"./table-pO-1fu8k.js";import{A as fe,a as je,b as ge,c as be,d as Ne,e as ve,f as ye,g as we,h as Se}from"./alert-dialog-BNfNvv6W.js";import{P as Ce,a as Be,b as Pe}from"./popover-DS7e2n5q.js";import{S as Ae}from"./search-CzBP5-_F.js";import{C as De}from"./chevrons-up-down-BGT7KHHb.js";import{f as Le}from"./format-UbsXkapy.js";import"./firebase-members-BiqOY63n.js";import"./firestore-utils-D5WDLgr6.js";import"./index-D3zZH8ng.js";import"./index-CfYrpjHA.js";import"./Combination-CvBMPJcf.js";import"./index-DKSXiZle.js";import"./globe-Cfqfe5ps.js";import"./index-DqkWgb9C.js";const Te=[["path",{d:"M9 14 4 9l5-5",key:"102s5s"}],["path",{d:"M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",key:"f3b9sd"}]],ke=_("undo-2",Te);async function Ee(a){if(!a)return[];const r=M(Y(),H("propertyId","==",a));return(await q(r)).docs.map(t=>({id:t.id,...t.data()}))}async function Ie(a){await G($(a)),await z(K(J,Q.visitors,a),{isBanned:!1})}function L(a){const r=[a.city,a.stateProv,a.countryName].filter(Boolean);return r.length>0?r.join(", "):"â"}function Oe(a){if(!a)return"â";const r=[a.city,a.stateProv,a.countryName].filter(Boolean);return r.length>0?r.join(", "):"â"}function Re({open:a,onOpenChange:r,entry:t}){const[i,x]=n.useState(!1),[l,j]=n.useState(null),[m,u]=n.useState(null),[b,h]=n.useState([]);return n.useEffect(()=>{if(!a||!t?.id){j(null),u(null),h([]);return}let c=!1;return x(!0),(async()=>{try{const N=await ie(t.id);if(c)return;j(N);const f=t.session??N?.session;if(f){const[C,B]=await Promise.all([le(t.id,f),oe(t.id,f)]);if(c)return;u(C),h([...B].reverse())}else u(null),h([])}catch{c||(j(null),u(null),h([]))}finally{c||x(!1)}})(),()=>{c=!0}},[a,t?.id,t?.session]),e.jsx(ee,{open:a,onOpenChange:r,children:e.jsxs(se,{side:"right",className:"w-full sm:max-w-xl p-0 flex flex-col",children:[e.jsxs(ae,{className:"p-5 border-b text-left",children:[e.jsx(te,{children:"Ban details"}),e.jsxs(ne,{children:[t?.name||"Visitor"," · ",t?.reason||"No reason provided"]})]}),i?e.jsxs("div",{className:"flex-1 flex items-center justify-center text-muted-foreground gap-2",children:[e.jsx(D,{className:"h-5 w-5 animate-spin"}),"Loading detailsâ¦"]}):e.jsxs("div",{className:"flex-1 overflow-y-auto p-5 space-y-6",children:[e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Visitor information"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsx(o,{label:"Name",value:l?.name||t?.name||"â"}),e.jsx(o,{label:"Email",value:l?.email||"â"}),e.jsx(o,{label:"Phone",value:l?.phone||l?.phoneNumber||"â"}),e.jsx(o,{label:"IP address",value:l?.ipAddress||t?.ipAddress||"â"}),e.jsx(o,{label:"Location",value:l?Oe(l):t?L(t):"â"}),e.jsx(o,{label:"Banned by",value:t?.bannedByName||"â"})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Session"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsx(o,{label:"Landing page",value:m?.landingPage?e.jsxs("a",{href:String(m.landingPage),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary underline-offset-2 hover:underline break-all",children:[String(m.landingPage),e.jsx(me,{className:"h-3 w-3 shrink-0"})]}):"â"}),e.jsx(o,{label:"Medium",value:m?.utmMedium||"â"}),e.jsx(o,{label:"Campaign",value:m?.utmCampaign||"â"}),e.jsx(o,{label:"Source",value:m?.utmSource||"â"}),e.jsx(o,{label:"Browser / OS",value:[l?.platform,l?.os].filter(
1Boolean).join(" · ")||"â"}),e.jsx(o,{label:"Device",value:l?.device||"â"})]})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Chat transcript"}),e.jsxs(re,{variant:"secondary",children:[b.length," messages"]})]}),b.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:"No messages found for this session."}):e.jsx("div",{className:"space-y-2 max-h-[40vh] overflow-y-auto rounded-lg border p-3 bg-muted/20",children:b.map(c=>e.jsx(Ue,{activity:c},c.id))})]})]})]})})}function o({label:a,value:r}){return e.jsxs("div",{className:"space-y-0.5 min-w-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:a}),e.jsx("div",{className:"font-medium break-words",children:r})]})}function Ue({activity:a}){const r=a.type??y.chat,t=typeof a.body=="string"&&a.body||(typeof a.message=="string"?a.message:"")||"",i=ce(a.created_at);if(r===y.navigation)return e.jsxs("div",{className:"text-center text-xs text-muted-foreground py-1",children:["Navigated to ",t||"â",i?` · ${i}`:""]});if(r===y.activity||r===y.log)return e.jsxs("div",{className:"text-center text-xs text-muted-foreground italic py-1",children:[t||"System event",i?` · ${i}`:""]});const x=!a.isVisitor;return e.jsx("div",{className:S("flex",x?"justify-end":"justify-start"),children:e.jsxs("div",{className:S("max-w-[85%] rounded-2xl px-3 py-2 text-sm whitespace-pre-wrap",x?"bg-primary text-primary-foreground rounded-br-sm":"bg-card border rounded-bl-sm"),children:[t||"â",i?e.jsx("p",{className:S("text-[10px] mt-1",x?"text-primary-foreground/70 text-right":"text-muted-foreground"),children:i}):null]})})}const O="voochat-banlist-property-id";function ms(){const a=W(s=>s.user),[r,t]=n.useState([]),[i,x]=n.useState(""),[l,j]=n.useState(!1),[m,u]=n.useState([]),[b,h]=n.useState(!1),[c,N]=n.useState(null),[f,C]=n.useState(""),[B,T]=n.useState(!1),[R,U]=n.useState(null),k=r.find(s=>s.id===i),P=n.useCallback(async()=>{if(!i){u([]);return}h(!0);try{const s=await Ee(i);u(s)}catch{A.error("Failed to load ban list"),u([])}finally{h(!1)}},[i]);n.useEffect(()=>{a&&X(a).then(s=>{if(t(s),s.length===0)return;const d=localStorage.getItem(O),v=s.find(F=>F.id===d);x(v?.id??s[0].id)})},[a]),n.useEffect(()=>{i&&localStorage.setItem(O,i)},[i]),n.useEffect(()=>{P()},[P]);const E=n.useMemo(()=>{const s=f.trim().toLowerCase();return s?m.filter(d=>[d.name,d.ipAddress,d.reason,L(d),d.countryName].filter(Boolean).join(" ").toLowerCase().includes(s)):m},[m,f]),V=async s=>{N(s);try{await Ie(s),u(d=>d.filter(v=>v.id!==s)),A.success("Visitor unbanned")}catch{A.error("Failed to unban visitor"),await P()}finally{N(null)}};return e.jsxs(de,{className:"rounded-lg overflow-hidden",children:[e.jsx("div",{className:"p-4 border-b space-y-3",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"font-semibold",children:"Ban list"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Visitors banned from chatting on the selected property."})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Ae,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(xe,{placeholder:"Searchâ¦",className:"pl-8 w-[200px]",value:f,onChange:s=>C(s.target.value)})]}),e.jsxs(Ce,{open:l,onOpenChange:j,children:[e.jsx(Be,{asChild:!0,children:e.jsxs(I,{variant:"outline",className:"min-w-[220px] justify-between",children:[e.jsxs("span",{className:"flex items-center gap-2 truncate",children:[e.jsx("span",{className:"h-6 w-6 rounded-md bg-primary/10 text-primary text-xs font-semibold flex items-center justify-center shrink-0",children:k?.name?.slice(0,1)??"?"}),e.jsx("span",{className:"truncate",children:k?.name??"Select property"})]}),e.jsx(De,{className:"h-4 w-4 opacity-60 shrink-0"})]})}),e.jsx(Pe,{align:"end",className:"w-[300px] p-1",children:r.map(s=>e.jsxs("button",{type:"button",className:S("w-full flex items-center gap-2 rounded-md px-2 py-2 text-sm hover:bg-accent text-left",s.id===i&&"bg-accent"),onClick:()=>{x(s.id),j(!1)},children:[e.jsx("span",{className:"h-6 w-6 rounded-md bg-primary/10 text-primary text-xs font-semibold flex items-center justify-center",children:s.name?.slice(0,1)??"?"}),e.jsx("span",{className:"truncate",children:s.name})]},s.id))})]})]})]})}),e.jsxs(ue,{children:[e.jsx(pe,{children:e.jsxs(w,{children:[e.jsx(g,{children:"Name"}),e.jsx(g,{children:"IP address"}),e.jsx(g,{children:"Reason"}),e.jsx(g,{children:"Location"}),e.jsx(g,{children:"Banned on"}),e.jsx(g,{className:"text-right",children:"Actions"})]})}),e.jsx(he,{children:b?e.jsx(w,{children:e.jsxs(p,{colSpan:6,className:"text-center py-10 text-muted-foreground",children:[e.jsx(D,{className:"h-5 w-5 animate-spin inline-block mr-2"}),"Loading ban listâ¦"]})}):E.length===0?e.jsx(w,{children:e.jsx(p,{colSpan:6,className:"text-center py-10 text-muted-foreground",children:i?"No banned visitors for this property.":"Select a property."})}):E.map(s=>e.jsxs(w,{className:"cursor-pointer",onClick:()=>{U(s),T(!0)},children:[e.jsx(p,{className:"font-medium",children:s.name||"â"}),e.jsx(p,{className:"font-mono text-sm",children:s.ipAddress||"â"}),e.jsx(p,{className:"text-muted-foreground max-w-xs truncate",children:s.reason||"â"}),e.jsx(p,{children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[L(s),s.countryCode&&e.jsx("span",{title:s.countryName??void 0,children:Z(s.countryCode)}
1)]})}),e.jsx(p,{children:s.createdAt?.toDate?Le(s.createdAt.toDate(),"PP"):"â"}),e.jsx(p,{className:"text-right",onClick:d=>d.stopPropagation(),children:e.jsxs(fe,{children:[e.jsx(je,{asChild:!0,children:e.jsxs(I,{variant:"outline",size:"sm",disabled:c===s.id,children:[c===s.id?e.jsx(D,{className:"h-3.5 w-3.5 mr-1 animate-spin"}):e.jsx(ke,{className:"h-3.5 w-3.5 mr-1"}),"Unban"]})}),e.jsxs(ge,{children:[e.jsxs(be,{children:[e.jsx(Ne,{children:"Unban visitor?"}),e.jsxs(ve,{children:[s.name||"This visitor"," will be able to chat again on this property."]})]}),e.jsxs(ye,{children:[e.jsx(we,{children:"Cancel"}),e.jsx(Se,{onClick:()=>V(s.id),children:"Unban"})]})]})]})})]},s.id))})]}),e.jsx(Re,{open:B,onOpenChange:T,entry:R})]})}export{ms 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.