import{d as R,P as E,E as M,c as n,a,t as x,e as w,b as N,v as V,F as B,n as F,r as c,g as $,a2 as o,i as A,o as i,f as m}from"./index-B4jeNr7A.js";const I={class:"h-full overflow-y-auto p-6"},L={key:0,class:"text-sm text-slate-400"},O={key:1,class:"text-sm text-rose-300"},P={key:2,class:"space-y-4 rounded-lg border border-slate-800 bg-slate-900/70 p-4"},T={key:0,class:"text-sm text-rose-300"},j={class:"block"},q={class:"space-y-2 rounded-md border border-slate-800 bg-slate-950/60 p-3"},z={class:"space-y-1"},G=["id","checked","onChange"],H=["for"],J={class:"block truncate text-sm text-slate-100"},K={class:"block truncate text-xs text-slate-400"},Q={key:0,class:"text-xs text-slate-400"},W={class:"flex items-center gap-2 border-t border-slate-800 pt-3"},X=["disabled"],Y=["disabled"],te=R({__name:"DirectMessageCreateView",setup(Z){const p=E(),_=A(),f=c(!1),u=c(!1),v=c(null),d=c(null),g=c([]),h=c(""),l=c([]),y=c(null),k=$(()=>g.value.filter(e=>o(e)!==y.value));function C(e,t){if(t){l.value.includes(e)||(l.value=[...l.value,e]);return}l.value=l.value.filter(s=>s!==e)}async function S(){f.value=!0,v.value=null;try{const e=await p.homeClient.getCurrentUser();y.value=o(e);const t=await Promise.allSettled(p.allServerDomains().map(r=>p.clientForServer(r).getUsers())),s=new Map;for(const r of t)if(r.status==="fulfilled")for(const b of r.value.users)s.set(o(b),b);g.value=[...s.values()].sort((r,b)=>o(r).localeCompare(o(b)))}catch(e){g.value=[],v.value=e instanceof Error?e.message:String(e)}finally{f.value=!1}}async function U(){if(!u.value){if(l.value.length===0){d.value="Select at least one member.";return}u.value=!0,d.value=null;try{const e=await p.homeClient.createDirectMessageRoom({name:h.value.trim(),memberlist:l.value.map(t=>{const s=t.indexOf("@");return{username:t.slice(0,s),homeServer:t.slice(s+1)}})});_.push({name:"direct-message-room",params:{roomId:e.id}})}catch(e){d.value=e instanceof Error?e.message:String(e)}finally{u.value=!1}}}function D(){_.push({name:"direct-messages"})}return M(()=>{S()}),(e,t)=>(i(),n("section",I,[t[4]||(t[4]=a("header",{class:"mb-4"},[a("p",{class:"text-xs uppercase tracking-wide text-slate-400"},"Direct messages"),a("h1",{class:"mt-1 text-2xl font-semibold text-slate-100"},"Create conversation")],-1)),f.value?(i(),n("p",L,"Loading users...")):v.value?(i(),n("p",O,x(v.value),1)):(i(),n("div",P,[d.value?(i(),n("p",T,x(d.value),1)):w("",!0),a("label",j,[t[2]||(t[2]=a("span",{class:"mb-1 block text-xs uppercase tracking-wide text-slate-400"},"Room name",-1)),N(a("input",{"onUpdate:modelValue":t[0]||(t[0]=s=>h.value=s),type:"text",class:"w-full rounded-md border border-slate-700 bg-slate-950 px-3 py-2 text-sm text-slate-100 outline-none focus:border-blue-400",placeholder:"Optional room name"},null,512),[[V,h.value]])]),a("div",q,[t[3]||(t[3]=a("p",{class:"text-xs uppercase tracking-wide text-slate-400"},"Members",-1)),a("ul",z,[(i(!0),n(B,null,F(k.value,s=>(i(),n("li",{key:m(o)(s),class:"flex items-center gap-2 rounded px-2 py-1.5 hover:bg-slate-900"},[a("input",{id:`dm-member-${m(o)(s)}`,type:"checkbox",class:"h-4 w-4 cursor-pointer rounded border-slate-700 bg-slate-900 text-blue-500",checked:l.value.includes(m(o)(s)),onChange:r=>C(m(o)(s),r.target.checked)},null,40,G),a("label",{for:`dm-member-${m(o)(s)}`,class:"min-w-0 cursor-pointer"},[a("span",J,x(s.username),1),a("span",K,x(s.homeServer),1)],8,H)]))),128)),k.value.length===0?(i(),n("li",Q,"No users available.")):w("",!0)])]),a("div",W,[a("button",{type:"button",class:"rounded-md border border-blue-400/50 bg-blue-500/20 px-3 py-2 text-sm text-blue-100 transition hover:bg-blue-500/30 disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",disabled:u.value,onClick:t[1]||(t[1]=s=>{U()})}," Create ",8,X),a("button",{type:"button",class:"rounded-md border border-slate-700 px-3 py-2 text-sm text-slate-200 transition hover:bg-slate-800 disabled:cursor-not-allowed disabled:opacity-50 cursor-pointer",disabled:u.value,onClick:D}," Cancel ",8,Y)])]))]))}});export{te as default};
//# sourceMappingURL=DirectMessageCreateView-BdgFCs9k.js.map
