2026-02-12 01:15:11 +00:00
|
|
|
import{a as n,j as e}from"./vendor-react-Dkpvlwai.js";import{g as ee,D as ue,E as W,B as _,p as te,a as M,d as y,u as A,l as O,L as se,_ as re,h as me,i as H,C as q}from"./index-jE2AGx2y.js";import{u as ae,a as ne,b as V}from"./vendor-tanstack-BoI3DtL9.js";import{L as J,I as oe}from"./input-CpxrTzwP.js";import{S as he}from"./Select-Zbef75Fw.js";import{u as T}from"./chatStore-Dpim9vVR.js";import{D as F,ab as fe,L as xe,ac as pe,ad as ge,m as be,T as ye,ae as ve,af as Q,a1 as je,j as we,S as ie,X as $,ag as B,ah as Ne,ai as Ce,aj as Se,ak as ke,a as G}from"./vendor-icons-CbmLcMl-.js";import{D as _e,a as Ee,b as Re,c as Z,u as De}from"./useIsRateLimited-V6u_TMsM.js";import{C as X}from"./confirmation-dialog-oRC6nIEK.js";import{A as le}from"./avatar-DSgu46M3.js";import{F as ze,T as ce,G as Te}from"./vendor-CAoAb3tF.js";import"./vendor-router-4bycex72.js";import"./vendor-utils-CDFfoeXY.js";import"./dropdown-WuZUrg5z.js";function Le({open:t,onClose:l}){const[a,o]=n.useState(""),[m,c]=n.useState("public"),[d,s]=n.useState(!1),[i,u]=n.useState(null),[p,x]=n.useState(null),[r,v]=n.useState(0),g=n.useRef(null),w=ee(),{addConversation:E,setCurrentConversation:R}=T(),D=async()=>{if(u(null),x(null),!a.trim()){u("Room name is required");return}const N=a.trim(),f=m,j=async()=>{const k=await M.post("/conversations",{name:N,type:f}),C={id:k.data.id||k.data.conversation?.id,name:k.data.name||k.data.conversation?.name,type:k.data.type||k.data.conversation?.type||f,participants:k.data.participants||[],unread_count:0};E(C),R(C.id),w.success("Room created successfully"),o(""),c("public"),x(null),v(0),g.current=null,l()};g.current=j,s(!0);try{await j()}catch(k){const C=te(k);x(new Error(C.message))}finally{s(!1)}},P=async()=>{if(!(!g.current||r>=3)){v(N=>N+1),s(!0);try{await g.current()}catch{}finally{s(!1)}}};return e.jsx(ue,{open:t,onClose:l,title:"Create New Room",variant:"default",size:"md",children:e.jsxs("div",{className:"space-y-4",children:[p&&e.jsx(W,{error:p,variant:"banner",severity:"error",context:{action:"creating room",resource:"conversation"},onRetry:r<3?P:void 0,onDismiss:()=>{x(null),v(0),g.current=null}}),i&&e.jsx(W,{error:i,variant:"inline",severity:"error",size:"sm",dismissible:!1}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"room-name",children:"Room Name"}),e.jsx(oe,{id:"room-name",value:a,onChange:N=>{o(N.target.value),u(null)},placeholder:"Enter room name",maxLength:100})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(J,{htmlFor:"room-type",children:"Room Type"}),e.jsx(he,{options:[{value:"public",label:"Public"},{value:"private",label:"Private"}],value:m,onChange:N=>c(Array.isArray(N)?N[0]:N),name:"room-type"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(_,{variant:"outline",onClick:l,disabled:d,children:"Cancel"}),e.jsx(_,{onClick:D,disabled:d||!a.trim(),children:d?"Creating...":"Create Room"})]})]})})}function Me(t,l,a){const{data:o,isLoading:m,error:c}=ae({queryKey:["chatConversations",t],queryFn:async()=>{if(!t)return[];const s=(await M.get("/conversations")).data,i=Array.isArray(s)?s:s?.conversations??[];return Array.isArray(i)?i:[]},enabled:!!t});return n.useEffect(()=>{o&&o.forEach(d=>{a.some(s=>s.id===d.id)||l({id:d.id,name:d.name,type:d.type??"direct",participants:Array.isArray(d.participants)?d.participants:[],unread_count:0})})},[o,a,l]),{data:o??[],isLoading:m,error:c}}function Pe({count:t,className:l}){return e.jsx("div",{className:y("p-4 border-b border-white/5 bg-white/2 backdrop-blur-sm",l),children:e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("h2",{className:"text-sm font-bold text-foreground tracking-wide uppercase flex items-center gap-2",children:[e.jsx(F,{className:"w-4 h-4 text-muted-foreground"}),"Active Channels"]}),e.jsx("span",{className:"text-xs font-mono text-muted-foreground bg-muted px-1.5 py-0.5 rounded",children:t})]})})}function Ae({className:t}){return e.jsxs("div",{className:y("flex flex-col items-center gap-3 text-sm p-6 text-center border border-dashed border-border rounded-xl m-2 animate-e
|