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