import{C as e,D as t,E as n,G as r,H as i,L as a,Q as o,R as s,S as c,W as l,Y as u,Z as d,et as f,i as p,k as m,m as h,r as g,tt as _,v,w as y,x as b}from"./app-CAV_k0tk.js";import{t as x}from"./i18n-CNs07Srl.js";import{n as S,t as C}from"./AppLayout-DsKf8YtU.js";var w={class:`mx-auto max-w-[760px]`},T={class:`mb-5 flex items-center justify-between`},E={class:`text-2xl font-extrabold tracking-tight`},D={key:0,class:`mb-4 rounded-c border border-line bg-surface p-3`},O={key:0,class:`mb-2 flex flex-wrap gap-2`},k=[`onClick`,`aria-label`],A=[`placeholder`],j={key:1,class:`mt-2 divide-y divide-line/60`},M=[`onClick`],N={class:`text-sm font-semibold text-ink`},P={class:`ml-auto text-xs font-semibold text-primary`},F=[`placeholder`],I={class:`mt-3 flex items-center gap-2`},L=[`disabled`],R={class:`text-xs text-ink-muted`},z={class:`overflow-hidden rounded-c border border-line bg-surface`},B={class:`min-w-0 flex-1`},V={class:`flex items-center gap-2`},H={class:`truncate font-bold text-ink`},U={class:`ml-auto shrink-0 text-xs text-ink-muted`},W={key:0,class:`h-2.5 w-2.5 shrink-0 rounded-full bg-primary`},G={key:0,class:`px-4 py-16 text-center text-sm text-ink-muted`},K=m({__name:`Index`,props:{conversations:{}},setup(m){let K=u(!1),q=u(``),J=u([]),Y=u([]),X=u(``),Z=null;i(q,e=>{if(clearTimeout(Z),!e.trim()){J.value=[];return}Z=setTimeout(async()=>{try{let t=await fetch(`/users/search?q=${encodeURIComponent(e)}`,{headers:{Accept:`application/json`},credentials:`same-origin`});J.value=t.ok?await t.json():[]}catch{J.value=[]}},200)});function Q(e){Y.value.some(t=>t.uid===e.uid)||Y.value.push(e),q.value=``,J.value=[]}function $(e){Y.value=Y.value.filter(t=>t.uid!==e)}function ee(){Y.value.length&&_.post(`/messages`,{user_ids:Y.value.map(e=>e.uid),title:Y.value.length>1&&X.value.trim()||null},{preserveScroll:!0})}return(i,u)=>(a(),y(v,null,[t(d(g),{title:d(x)(`Messages`)},null,8,[`title`]),t(C,null,{default:l(()=>[b(`div`,w,[b(`div`,T,[b(`h1`,E,f(d(x)(`Messages`)),1),b(`button`,{type:`button`,class:`rounded-c bg-primary px-4 py-2 text-sm font-semibold text-white hover:bg-primary-600`,onClick:u[0]||=e=>K.value=!K.value},f(d(x)(`New message`)),1)]),K.value?(a(),y(`div`,D,[Y.value.length?(a(),y(`div`,O,[(a(!0),y(v,null,s(Y.value,e=>(a(),y(`span`,{key:e.uid,class:`inline-flex items-center gap-1.5 rounded-full bg-primary/15 py-1 pl-1 pr-2 text-sm font-semibold text-primary`},[t(S,{avatar:e,size:22},null,8,[`avatar`]),n(` `+f(e.name)+` `,1),b(`button`,{type:`button`,class:`ml-0.5 text-primary/70 hover:text-primary`,onClick:t=>$(e.uid),"aria-label":d(x)(`Remove`)},`✕`,8,k)]))),128))])):e(``,!0),r(b(`input`,{"onUpdate:modelValue":u[1]||=e=>q.value=e,type:`text`,placeholder:d(x)(`Add people by name…`),class:`w-full rounded-lg border-line bg-surface-2 text-ink placeholder:text-ink-muted focus:border-primary focus:ring-primary`},null,8,A),[[h,q.value]]),J.value.length?(a(),y(`div`,j,[(a(!0),y(v,null,s(J.value,e=>(a(),y(`button`,{key:e.uid,type:`button`,class:`flex w-full items-center gap-2.5 px-1 py-2 text-left hover:bg-surface-2`,onClick:t=>Q(e)},[t(S,{avatar:e,size:30},null,8,[`avatar`]),b(`span`,N,f(e.name),1),b(`span`,P,f(d(x)(`Add`)),1)],8,M))),128))])):e(``,!0),Y.value.length>1?r((a(),y(`input`,{key:2,"onUpdate:modelValue":u[2]||=e=>X.value=e,type:`text`,placeholder:d(x)(`Group name (optional)`),class:`mt-2 w-full rounded-lg border-line bg-surface-2 text-ink placeholder:text-ink-muted focus:border-primary focus:ring-primary`},null,8,F)),[[h,X.value]]):e(``,!0),b(`div`,I,[b(`button`,{type:`button`,disabled:!Y.value.length,onClick:ee,class:`rounded-c bg-primary px-4 py-2 text-sm font-semibold text-white hover:bg-primary-600 disabled:opacity-50`},f(Y.value.length>1?d(x)(`Start group ({n})`,{n:Y.value.length}):d(x)(`Start conversation`)),9,L),b(`span`,R,f(d(x)(`Add more than one person to start a group.`)),1)])])):e(``,!0),b(`div`,z,[(a(!0),y(v,null,s(m.conversations,n=>(a(),c(d(p),{key:n.id,href:`/messages/${n.id}`,class:`flex items-center gap-3 border-b border-line/60 px-4 py-3 last:border-0 hover:bg-surface-2`},{default:l(()=>[t(S,{avatar:n.avatar,size:44},null,8,[`avatar`]),b(`div`,B,[b(`div`,V,[b(`span`,H,f(n.title),1),b(`span`,U,f(n.time),1)]),b(`div`,{class:o([`truncate text-sm`,n.unread?`font-semibold text-ink`:`text-ink-muted`])},f(n.excerpt),3)]),n.unread?(a(),y(`span`,W)):e(``,!0)]),_:2},1032,[`href`]))),128)),m.conversations.length?e(``,!0):(a(),y(`p`,G,f(d(x)(`No conversations yet. Start one with “New message”.`)),1))])])]),_:1})],64))}});export{K as default};