import{$ as e,C as t,D as n,E as r,I as i,J as a,L as o,O as s,S as c,U as l,V as u,W as d,X as f,Z as p,et as m,i as h,m as g,r as _,v,w as y,x as b}from"./app-hx74OzLv.js";import{t as x}from"./i18n-C6IJoid2.js";import{n as S,t as C}from"./AppLayout-BrHSGE2i.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=s({__name:`Index`,props:{conversations:{}},setup(s){let K=a(!1),q=a(``),J=a([]),Y=a([]),X=a(``),Z=null;u(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&&m.post(`/messages`,{user_ids:Y.value.map(e=>e.uid),title:Y.value.length>1&&X.value.trim()||null},{preserveScroll:!0})}return(a,u)=>(i(),y(v,null,[n(f(_),{title:f(x)(`Messages`)},null,8,[`title`]),n(C,null,{default:l(()=>[b(`div`,w,[b(`div`,T,[b(`h1`,E,e(f(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},e(f(x)(`New message`)),1)]),K.value?(i(),y(`div`,D,[Y.value.length?(i(),y(`div`,O,[(i(!0),y(v,null,o(Y.value,t=>(i(),y(`span`,{key:t.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`},[n(S,{avatar:t,size:22},null,8,[`avatar`]),r(` `+e(t.name)+` `,1),b(`button`,{type:`button`,class:`ml-0.5 text-primary/70 hover:text-primary`,onClick:e=>$(t.uid),"aria-label":f(x)(`Remove`)},`✕`,8,k)]))),128))])):t(``,!0),d(b(`input`,{"onUpdate:modelValue":u[1]||=e=>q.value=e,type:`text`,placeholder:f(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),[[g,q.value]]),J.value.length?(i(),y(`div`,j,[(i(!0),y(v,null,o(J.value,t=>(i(),y(`button`,{key:t.uid,type:`button`,class:`flex w-full items-center gap-2.5 px-1 py-2 text-left hover:bg-surface-2`,onClick:e=>Q(t)},[n(S,{avatar:t,size:30},null,8,[`avatar`]),b(`span`,N,e(t.name),1),b(`span`,P,e(f(x)(`Add`)),1)],8,M))),128))])):t(``,!0),Y.value.length>1?d((i(),y(`input`,{key:2,"onUpdate:modelValue":u[2]||=e=>X.value=e,type:`text`,placeholder:f(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)),[[g,X.value]]):t(``,!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`},e(Y.value.length>1?f(x)(`Start group ({n})`,{n:Y.value.length}):f(x)(`Start conversation`)),9,L),b(`span`,R,e(f(x)(`Add more than one person to start a group.`)),1)])])):t(``,!0),b(`div`,z,[(i(!0),y(v,null,o(s.conversations,r=>(i(),c(f(h),{key:r.id,href:`/messages/${r.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(()=>[n(S,{avatar:r.avatar,size:44},null,8,[`avatar`]),b(`div`,B,[b(`div`,V,[b(`span`,H,e(r.title),1),b(`span`,U,e(r.time),1)]),b(`div`,{class:p([`truncate text-sm`,r.unread?`font-semibold text-ink`:`text-ink-muted`])},e(r.excerpt),3)]),r.unread?(i(),y(`span`,W)):t(``,!0)]),_:2},1032,[`href`]))),128)),s.conversations.length?t(``,!0):(i(),y(`p`,G,e(f(x)(`No conversations yet. Start one with “New message”.`)),1))])])]),_:1})],64))}});export{K as default};