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