1var __IMPORT_META_ENV={};var __PROCESS_ENV={NODE_ENV:"production"}; 2import{a as yt}from"/chunks/chunk-RFL6KDMF.js";import{a as Qe}from"/chunks/chunk-O22CGXVZ.js";import{a as Nt}from"/chunks/chunk-HBBVZBLG.js";import{b as Xe}from"/chunks/chunk-EHGBO557.js";import{a as Ee,b as qe,c as Ke,d as De,e as bt,f as Pe,g as R}from"/chunks/chunk-RWIOG2RP.js";import{g as vt}from"/chunks/chunk-4M22FVJL.js";import{d as ht}from"/chunks/chunk-F2O4WAZZ.js";import"/chunks/chunk-AD6DUYMF.js";import{a as xt}from"/chunks/chunk-BHPEHDWW.js";import{c as gt}from"/chunks/chunk-OBUH64IE.js";import{b as _e}from"/chunks/chunk-6RM77LG4.js";import{b as C}from"/chunks/chunk-DP67E3KD.js";import"/chunks/chunk-64B44DNV.js";import"/chunks/chunk-ZSQ2II6E.js";import{a as F}from"/chunks/chunk-A6NSEO7N.js";import"/chunks/chunk-5LKAQM72.js";import"/chunks/chunk-YQIDYBH5.js";import{Ak as at,Da as rt,Gt as ut,Kp as lt,Nq as Ve,Ye as Ge,ZA as We,af as nt,ba as st,bz as ft,co as it,cu as et,da as Fe,eC as Te,gg as Oe,gr as dt,it as $e,kD as ee,mj as ot,nw as fe,rw as mt,sC as pt,wt as ct}from"/chunks/chunk-62QHDT2Z.js";import{a as tt}from"/chunks/chunk-DKSMBCPM.js";import"/chunks/chunk-Z2TP6DSD.js";import"/chunks/chunk-GQOIBJBD.js";import{h as Ze}from"/chunks/chunk-NJAFOOP7.js";import"/chunks/chunk-PE5MZRD7.js";import{a as me}from"/chunks/chunk-2F2XG2RD.js";import{d as D}from"/chunks/chunk-43M3N6VY.js";var h=D(me());var i=D(me());var wt=D(me());var we=D(F());function V({name:t,icon:s,size:p="md",color:v}){let[N,u]=(0,wt.useState)(!1),l=p==="sm"?"w-7 h-7 text-[10px]":p==="lg"?"w-11 h-11 text-sm":"w-9 h-9 text-xs",m=v??"#6366f1",g=!!s&&(s.startsWith("http")||s.startsWith("data:image")),a=Nt(N?null:g?s:null,N||g?null:s,t);if(a.type==="image")return(0,we.jsx)("img",{src:a.value,alt:t,className:C("rounded-full object-cover shrink-0",l),onError:()=>u(!0)});if(a.type==="lucide"){let{Icon:b}=a,k=p==="sm"?"w-3.5 h-3.5":p==="lg"?"w-5 h-5":"w-4 h-4";return(0,we.jsx)("div",{className:C("rounded-full flex items-center justify-center shrink-0 text-white",l),style:{background:m},children:(0,we.jsx)(b,{className:k})})}return a.type==="emoji"?(0,we.jsx)("div",{className:C("rounded-full flex items-center justify-center shrink-0 font-semibold",l),style:{background:m+"22",color:m},children:a.value}):(0,we.jsx)("div",{className:C("rounded-full flex items-center justify-center shrink-0 font-semibold text-white",l),style:{background:m},children:a.value})}var je=D(me());var x=D(F());function Dt(t,s,p,v){let N=!s||s===p||!t,[u,l]=(0,je.useState)(t),[m,g]=(0,je.useState)(!1),a=v.join("||");return(0,je.useEffect)(()=>{if(N){l(t),g(!1);return}let b=!1;return g(!0),gt(t,p,"auto",v).then(k=>{b||(l(k),g(!1))}),()=>{b=!0}},[t,s,p,N,a]),{text:u,loading:m}}function Pt({isRead:t}){return(0,x.jsxs)("svg",{width:"15",height:"10",viewBox:"0 0 15 10",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"inline-block shrink-0 select-none transition-colors duration-300",style:{color:t?"#22c55e":"hsl(var(--muted-foreground) / 0.35)"},title:t?"Vu":"Envoy\xE9","aria-label":t?"Vu":"Envoy\xE9",children:[(0,x.jsx)("path",{d:"M1 5.5L3.8 8.5L8.5 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),(0,x.jsx)("path",{d:"M5 5.5L7.8 8.5L13 2",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",style:{opacity:t?1:.4}})]})}function jt({msg:t,isMe:s,showSender:p,senderName:v,senderAvatar:N,primaryColor:u,lang:l,onDelete:m,isRead:g,context:a=[]}){let b=_e(),k=t.id.startsWith("__optimistic_"),P=Ke(t.ts,l),E=t.type!=="text"&&t.fileData,z=t.type==="image",{text:U,loading:T}=Dt(t.text??"",s?l:t.lang,l,a);async function d(){await b({message:"Supprimer ce message ?",confirmLabel:"Supprimer",danger:!0})&&m?.()}return(0,x.jsxs)("div",{className:C("flex gap-2 mb-0.5 group transition-opacity duration-300",s?"justify-end":"justify-start",k&&"opacity-60"),children:[!s&&(0,x.jsx)("div",{className:"w-6 shrink-0 self-end",children:p&&(0,x.jsx)(V,{name:v,icon:N,size:"sm",color:u})}),(0,x.jsxs)("div",{className:C("max-w-[75%] flex flex-col",s?"items-end":"items-start"),children:[p&&!s&&(0,x.jsx)("span",{className:"text-[10px] font-medium text-muted-foreground ml-1 mb-0.5",children:v}),t.type==="audio"&&t.fileData&&(0,x.jsx)("div",{className:C("mb-1 px-2 py-1.5 rounded-2xl",s?"rounded-br-sm":"bg-muted/60 rounded-bl-sm"),style:s?{background:u}:void 0,children:(0,x.jsx)("audio",{controls:!0,src:t.fileData,className:"max-w-[200px] h-8",style:{accentColor:s?"#fff":u}})}),E&&z&&(0,x.jsx)("a",{href:t.fileData,target:"_blank",rel:"noopener noreferrer",className:"mb-1 block",children:(0,x.jsx)("img",{src:t.fileData,alt:"",className:"max-w-[220px] max-h-52 object-cover rounded-2xl shadow-sm hover:opacity-90 transition-opacity",loading:"lazy"})}),E&&!z&&(0,x.jsxs)("a",{href:t.fileData,download:!0,className:C("flex items-center gap-2.5 px-3 py-2.5 rounded-2xl text-xs font-medium mb-1 hover:opacity-90 transition-opacity",s?"text-white":"bg-muted/70 text-foreground"),style:s?{background:u}:void 0,children:[(0,x.jsx)("div",{className:C("w-7 h-7 rounded-lg flex items-center justify-center shrink-0",s?"bg-white/20":"bg-background/60"),children:(0,x.jsx)(at,{className:"w-3.5 h-3.5"})}),(0,x.jsxs)("div",{className:"min-w-0",children:[(0,x.jsx)("p",{className:"truncate max-w-[140px]",children:t.fileName??"Fichier"}),(0,x.jsx)("p",{className:C("text-[9px] mt-0.5",s?"text-white/60":"text-muted-foreground"),children:"T\xE9l\xE9charger"})]}),(0,x.jsx)($e,{className:"w-3 h-3 shrink-0 opacity-50"})]}),t.text&&(0,x.jsx)("div",{className:C("px-3.5 py-2 rounded-2xl text-sm leading-relaxed whitespace-pre-wrap break-words transition-opacity",s?"rounded-br-sm text-white":"bg-muted/60 text-foreground rounded-bl-sm",T&&"opacity-60"),style:s?{background:u}:void 0,children:T?(0,x.jsxs)("span",{className:"flex flex-col gap-1.5",children:[(0,x.jsx)("span",{className:"block h-3 w-32 rounded bg-current opacity-10 animate-pulse"}),(0,x.jsx)("span",{className:"block h-3 w-20 rounded bg-current opacity-10 animate-pulse"})]}):U}),(0,x.jsxs)("div",{className:C("flex items-center gap-1 mt-0.5",s?"flex-row-reverse":"flex-row"),children:[(0,x.jsx)("span",{className:C("text-[9px] text-muted-foreground
2/40 transition-opacity duration-200",s?"text-right":"text-left"),children:P}),s&&m&&(0,x.jsx)("button",{onClick:d,className:"opacity-0 group-hover:opacity-100 transition-opacity duration-150 p-0.5 rounded-md text-muted-foreground/30 hover:text-destructive hover:bg-destructive/10",title:"Supprimer",children:(0,x.jsx)(We,{className:"w-2.5 h-2.5"})}),s&&!k&&(0,x.jsx)(Pt,{isRead:!!g})]})]})]})}function kt({messages:t,myNodeId:s,conv:p,userMap:v,lang:N,primaryColor:u,onDeleteMsg:l}){let m=(()=>{let a=p.members.filter(k=>k!==s);return a.length===0?"":a.map(k=>p.readBy?.[k]||"").filter(Boolean).sort()[0]||""})(),g=[];for(let a of t){let b=new Date(a.ts).toLocaleDateString(N,{weekday:"long",day:"numeric",month:"long"}),k=g[g.length-1];!k||k.date!==b?g.push({date:b,msgs:[a]}):k.msgs.push(a)}return(0,x.jsx)(x.Fragment,{children:g.map(a=>(0,x.jsxs)("div",{children:[(0,x.jsxs)("div",{className:"flex items-center gap-2 my-3",children:[(0,x.jsx)("div",{className:"flex-1 h-px bg-border/30"}),(0,x.jsx)("span",{className:"text-[9px] text-muted-foreground/50 uppercase tracking-wider shrink-0",children:a.date}),(0,x.jsx)("div",{className:"flex-1 h-px bg-border/30"})]}),a.msgs.map((b,k)=>{let P=b.sender===s,E=a.msgs[k-1],z=!P&&p.type==="group"&&(!E||E.sender!==b.sender),U=P&&m!==""&&m>=b.ts,T=[];if(!P){let d=0;for(let c=k-1;c>=0&&d<3;c--){let M=a.msgs[c];M.sender===b.sender&&M.text&&M.text.trim().length>3&&(T.unshift(M.text),d++)}}return(0,x.jsx)(jt,{msg:b,isMe:P,showSender:z,senderName:v[b.sender]?.name??"Inconnu",senderAvatar:v[b.sender]?.avatar??"",primaryColor:u,lang:N,onDelete:P&&l?()=>l(b.id):void 0,isRead:U,context:T},b.id)})]},a.date))})}var ke=D(me());var I=D(F());function Ct({conv:t,accessibleContacts:s,primaryColor:p,onSave:v,onClose:N}){let[u,l]=(0,ke.useState)(t.name),[m,g]=(0,ke.useState)(t.avatar),[a,b]=(0,ke.useState)(t.members),[k,P]=(0,ke.useState)(!1),[E,z]=(0,ke.useState)(""),U=s.filter(d=>!E||d.name.toLowerCase().includes(E.toLowerCase())),T=d=>{d!==t.owner&&b(c=>c.includes(d)?c.filter(M=>M!==d):[...c,d])};return(0,I.jsx)("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50 backdrop-blur-sm animate-in fade-in-0 duration-150",children:(0,I.jsxs)("div",{className:"w-full max-w-sm bg-card rounded-t-2xl sm:rounded-2xl shadow-2xl flex flex-col max-h-[82vh] animate-in slide-in-from-bottom-4 sm:zoom-in-95 duration-200",children:[(0,I.jsx)("div",{className:"flex justify-center pt-2.5 pb-0 sm:hidden shrink-0",children:(0,I.jsx)("div",{className:"w-8 h-1 rounded-full bg-muted-foreground/20"})}),(0,I.jsxs)("div",{className:"flex items-center justify-between px-4 pt-3 pb-3 shrink-0",children:[(0,I.jsx)("h2",{className:"text-sm font-semibold",children:"Modifier le groupe"}),(0,I.jsx)("button",{onClick:N,className:"p-1.5 rounded-lg hover:bg-accent transition-colors",children:(0,I.jsx)(ee,{className:"w-4 h-4"})})]}),(0,I.jsxs)("div",{className:"px-4 pb-3 shrink-0 space-y-2.5",children:[(0,I.jsxs)("div",{className:"flex items-center gap-3",children:[(0,I.jsx)("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-xl shrink-0",style:{background:p+"20",color:p},children:m}),(0,I.jsx)("input",{value:u,onChange:d=>l(d.target.value),placeholder:"Nom du groupe",className:"flex-1 px-3 py-2 text-xs rounded-xl bg-muted/40 border border-transparent focus:border-border/50 focus:bg-muted/60 focus:outline-none transition-all"})]}),(0,I.jsx)("div",{className:"flex gap-1.5 flex-wrap",children:Pe.map(d=>(0,I.jsx)("button",{onClick:()=>g(d),className:C("w-8 h-8 rounded-lg text-base flex items-center justify-center transition-all",m===d?"ring-2 bg-muted":"hover:bg-muted/60"),children:d},d))}),(0,I.jsx)("input",{value:E,onChange:d=>z(d.target.value),placeholder:"Filtrer les membres\u2026",className:"w-full px-3 py-2 text-xs rounded-xl bg-muted/40 border border-transparent focus:border-border/50 focus:bg-muted/60 focus:outline-none transition-all"}),(0,I.jsxs)("p",{className:"text-[10px] text-muted-foreground/60",children:[a.length," membre",a.length!==1?"s":""]})]}),(0,I.jsx)("div",{className:"overflow-y-auto flex-1 px-2 pb-2",children:U.map(d=>{let c=a.includes(d.nodeId),M=d.nodeId===t.owner;return(0,I.jsxs)("button",{onClick:()=>T(d.nodeId),disabled:M,className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-accent/50 disabled:opacity-60 active:bg-accent/70 transition-colors text-left",children:[(0,I.jsx)(V,{name:d.name,icon:d.avatar,size:"sm",color:p}),(0,I.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,I.jsx)("p",{className:"text-xs font-medium truncate",children:d.name}
2),M?(0,I.jsx)("p",{className:"text-[9px] text-muted-foreground/60",children:"Propri\xE9taire"}):(0,I.jsx)("p",{className:"text-[9px] text-muted-foreground/50 capitalize",children:d.role.replace("role-","")})]}),(0,I.jsx)("div",{className:C("w-5 h-5 rounded-full border-2 flex items-center justify-center shrink-0 transition-all",c?"border-transparent":"border-border/60"),style:c?{background:p}:void 0,children:c&&(0,I.jsx)(Ge,{className:"w-3 h-3 text-white"})})]},d.nodeId)})}),(0,I.jsx)("div",{className:"px-4 py-3 shrink-0 border-t border-border/30",children:(0,I.jsx)("button",{onClick:async()=>{P(!0),await v({name:u,avatar:m,members:a}),P(!1)},disabled:k||!u.trim(),className:"w-full py-2.5 rounded-xl text-xs font-semibold text-white disabled:opacity-35 hover:opacity-90 active:scale-[0.98] transition-all",style:{background:p},children:k?"Sauvegarde\u2026":"Enregistrer les modifications"})})]})})}var r=D(F());function Mt({conv:t,messages:s,myNodeId:p,userMap:v,lang:N,primaryColor:u,loading:l,sending:m,onBack:g,onSend:a,onUpdateGroup:b,onArchive:k,onDelete:P,onDeleteMsg:E,isOwner:z,accessibleContacts:U,hasProfileModule:T=!1,manageStatusActive:d=!1}){let c=_e(),[M,G]=(0,i.useState)(null),$=t.type==="direct"?t.members.find(o=>o!==p)??null:null,[j,Ce]=(0,i.useState)(""),[te,pe]=(0,i.useState)(),[Me,ge]=(0,i.useState)(),[Ae,xe]=(0,i.useState)(""),[W,Se]=(0,i.useState)(!1),[ie,be]=(0,i.useState)(0),Y=(0,i.useRef)(null),J=(0,i.useRef)([]),_=(0,i.useRef)(null),[le,q]=(0,i.useState)(!1),[Je,he]=(0,i.useState)(!1),[K,X]=(0,i.useState)(0),[y,H]=(0,i.useState)(!0),O=(0,i.useRef)(null),ve=(0,i.useRef)(null),se=(0,i.useRef)(null),Ie=(0,i.useRef)(null),Le=(0,i.useRef)(null),ye=(0,i.useRef)(s.length),de=(0,i.useRef)(t.id),Z=(0,i.useRef)(!0),re=Ee(t,p,v),Q=qe(t,p,v),Ne=Xe(),ne=(0,i.useMemo)(()=>{if(t.type!=="direct"||!$)return null;let o=v[$];return o?De(o.lastHeartbeat??"",o.statusCustom??"",Ne,d,o.lastLogin??"",o.lastLogout??""):null},[t.type,$,v,Ne,d]),ze=(0,i.useMemo)(()=>t.type!=="group"?0:t.members.filter(o=>{let f=v[o];return f?De(f.lastHeartbeat??"",f.statusCustom??"",Ne,d,f.lastLogin??"",f.lastLogout??"").status==="online":!1}).length,[t.type,t.members,v,Ne,d]),Re=(0,i.useCallback)((o="smooth")=>{let f=ve.current;if(f){f.scrollIntoView({behavior:o,block:"end"});return}let w=O.current;w&&w.scrollTo({top:w.scrollHeight,behavior:o})},[]),ce=(0,i.useCallback)(()=>{let o=()=>{let f=ve.current,w=O.current;f?f.scrollIntoView({behavior:"instant",block:"end"}):w&&(w.scrollTop=w.scrollHeight)};requestAnimationFrame(()=>requestAnimationFrame(o))},[]),Ue=(0,i.useCallback)(()=>{let o=O.current;return o?o.scrollHeight-o.scrollTop-o.clientHeight<80:!0},[]);(0,i.useLayoutEffect)(()=>{t.id!==de.current&&(de.current=t.id,ye.current=0,X(0),H(!0),Z.current=!0)},[t.id]),(0,i.useLayoutEffect)(()=>{!l&&s.length>0&&(ce(),ye.current=s.length,X(0),Z.current=!0)},[l]),(0,i.useLayoutEffect)(()=>{if(l)return;let o=ye.current,f=s.length;if(ye.current=f,f===0)return;let w=f-o;if(w<=0)return;s[s.length-1]?.sender===p?(ce(),X(0)):Z.current?(Re("smooth"),X(0)):X(Et=>Et+w)},[s.length,l,p,Re,ce]),(0,i.useEffect)(()=>{let o=O.current;if(!o)return;let f=()=>{let w=Ue();Z.current=w,H(w),w&&X(0)};return o.addEventListener("scroll",f,{passive:!0}),()=>o.removeEventListener("scroll",f)},[Ue]),(0,i.useEffect)(()=>{let o=se.current;o&&("fieldSizing"in o.style||(o.style.height="auto",o.style.height=Math.min(o.scrollHeight,96)+"px"))},[j]),(0,i.useEffect)(()=>{let o=window.visualViewport;if(!o)return;let f=o.height,w=()=>{let ue=o.height;ue<f&&Z.current&&requestAnimationFrame(()=>ce()),f=ue};return o.addEventListener("resize",w,{passive:!0}),()=>o.removeEventListener("resize",w)},[ce]);let He=(0,i.useCallback)(async()=>{try{let o=await navigator.mediaDevices.getUserMedia({audio:!0});J.current=[];let f=new MediaRecorder(o);Y.current=f,f.ondataavailable=w=>{w.data.size>0&&J.current.push(w.data)},f.onstop=()=>{o.getTracks().forEach(Be=>Be.stop());let w=new Blob(J.current,{type:"audio/webm"}),ue=new FileReader;ue.onload=()=>{let Be=ue.result;a("",Be,"audio")},ue.readAsDataURL(w),J.current=[]},f.start(),Se(!0),be(0),_.current=setInterval(()=>{be(w=>w>=119?(e(),0):w+1)},1e3)}catch{}},[a]),e=(0,i.useCallback)(()=>{_.current&&(clearInterval(_.current),_.current=null),Y.current?.stop(),Se(!1),be(0)},[]),S=(0,i.useCallback)(()=>{_.current&&(clearInterval(_.current),_.current=null),Y.current&&(Y.current.onstop=()=>{}
2,Y.current.stop(),Y.current.stream?.getTracks().forEach(o=>o.stop())),Se(!1),be(0)},[]);(0,i.useEffect)(()=>()=>{_.current&&clearInterval(_.current),Y.current?.stream?.getTracks().forEach(o=>o.stop())},[]);let B=o=>`${Math.floor(o/60)}:${String(o%60).padStart(2,"0")}`,oe=(0,i.useCallback)(async()=>{let o=j.trim();!o&&!te||m||(Ce(""),pe(void 0),ge(void 0),xe(""),se.current&&!("fieldSizing"in se.current.style)&&(se.current.style.height="auto"),await a(o,te,Me))},[j,te,Me,m,a]),It=o=>{o.key==="Enter"&&!o.shiftKey&&(o.preventDefault(),oe())},Lt=o=>{let f=o.target.files?.[0];if(!f)return;xe(f.name);let w=new FileReader;w.onload=()=>{pe(w.result),ge(f.type.startsWith("image/")?"image":"file")},w.readAsDataURL(f),o.target.value=""},Rt=o=>{let f=o.target.files?.[0];if(!f)return;xe(f.name);let w=new FileReader;w.onload=()=>{pe(w.result),ge(f.type.startsWith("image/")?"image":"file")},w.readAsDataURL(f),o.target.value=""},Tt=t.members.map(o=>v[o]?.name??"Inconnu").join(", ");return(0,r.jsxs)("div",{className:"flex flex-col flex-1 min-h-0 overflow-hidden",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2.5 border-b border-border/30 shrink-0 bg-card/80 backdrop-blur-sm",children:[(0,r.jsx)("button",{onClick:g,className:"p-1.5 rounded-lg hover:bg-accent transition-colors md:hidden shrink-0",children:(0,r.jsx)(rt,{className:"w-4 h-4"})}),t.type==="group"?(0,r.jsx)("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-base shrink-0",style:{background:u+"20",color:u},children:Q}):(0,r.jsx)(V,{name:re,icon:Q,size:"sm",color:u}),(0,r.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,r.jsx)("p",{className:"text-sm font-semibold truncate",children:re}),t.type==="direct"&&ne&&(0,r.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,r.jsxs)("span",{className:"relative flex items-center justify-center w-2 h-2 shrink-0",children:[(0,r.jsx)("span",{className:"absolute inset-0 rounded-full",style:{background:ne.color}}),ne.status==="online"&&(0,r.jsx)("span",{className:"absolute inset-0 rounded-full animate-ping opacity-50",style:{background:ne.color}})]}),(0,r.jsx)("p",{className:"text-[10px] font-medium",style:{color:ne.color},children:ne.label})]}),t.type==="group"&&(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsx)(Te,{className:"w-2.5 h-2.5 text-muted-foreground/50"}),(0,r.jsxs)("p",{className:"text-[10px] text-muted-foreground/70 truncate",children:[Tt,ze>0&&(0,r.jsxs)("span",{className:"ml-1 text-[#22c55e]",children:["\xB7 ",ze," en ligne"]})]})]})]}),T&&t.type==="direct"&&$&&(0,r.jsx)("button",{onClick:()=>G($),className:"p-1.5 rounded-lg hover:bg-accent text-muted-foreground hover:text-brand transition-all shrink-0",title:`Voir le profil de ${re}`,children:(0,r.jsx)(Oe,{className:"w-4 h-4"})}),(0,r.jsxs)("div",{className:"relative shrink-0",children:[(0,r.jsx)("button",{onClick:()=>q(o=>!o),className:C("p-1.5 rounded-lg hover:bg-accent transition-colors",le&&"bg-accent"),children:(0,r.jsx)(ot,{className:"w-4 h-4 text-muted-foreground"})}),le&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"fixed inset-0 z-10",onClick:()=>q(!1)}),(0,r.jsxs)("div",{className:"absolute right-0 top-9 w-44 bg-card border border-border/50 rounded-xl shadow-2xl z-20 py-1.5 overflow-hidden",children:[t.type==="group"&&z&&(0,r.jsxs)("button",{onClick:()=>{he(!0),q(!1)},className:"w-full flex items-center gap-2.5 px-3 py-2 text-xs hover:bg-accent transition-colors text-left",children:[(0,r.jsx)(ct,{className:"w-3.5 h-3.5 text-muted-foreground"})," Modifier le groupe"]}),(0,r.jsxs)("button",{onClick:()=>{k(!t.archived),q(!1)},className:"w-full flex items-center gap-2.5 px-3 py-2 text-xs hover:bg-accent transition-colors text-left",children:[(0,r.jsx)(Fe,{className:"w-3.5 h-3.5 text-muted-foreground"}),t.archived?"D\xE9sarchiver":"Archiver"]}),z&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"h-px bg-border/40 my-1 mx-2"}),(0,r.jsxs)("button",{onClick:async()=>{await c({message:"Supprimer cette conversation ? Cette action est irr\xE9versible.",confirmLabel:"Supprimer",danger:!0})&&(P(),q(!1))},className:"w-full flex items-center gap-2.5 px-3 py-2 text-xs hover:bg-destructive/10 text-destructive transition-colors text-left",children:[(0,r.jsx)(We,{className:"w-3.5 h-3.5"})," Supprimer"]})]})]})]})]})]}),(0,r.jsxs)("div",{className:"relative flex-1 min-h-0 overflow-hidden",children:[(0,r.jsxs)("div",{ref:O,className:"h-full overflow-y-auto px-3 py-3 space-y-0.5 overscroll-contain",style:{scrollbarWidth:"thin",scrollbarColor:"hsl(var(--border)/0.4) transparent"},children:[l?(0,r.jsx)("div",{className:"flex flex-col gap-3 py-4",children:[70,50,85,55,65].map((o,f)=>(0,r.jsxs)("div",{className:C("flex gap-2",f%2===0?"justify-start":"justify-end"),children:[f%2===0&&(0,r.jsx)("div",{className:"w-6 h-6 rounded-full bg-muted/50 shrink-0 self-end animate-pulse"}),(0,r.jsx)("div",{className:"h-9 rounded-2xl bg-muted/40 animate-pulse",style:{width:`${o}%`,maxWidth:"220px"}})]},f))}):s.length===0?(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3 py-16 text-center",children:[(0,r.jsx)("div",{className:"w-14 h-14 roun
2ded-2xl flex items-center justify-center text-2xl",style:{background:u+"15"},children:t.type==="group"?t.avatar:"\u{1F4AC}"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("p",{className:"text-sm font-medium",children:t.type==="group"?t.name:re}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground/50 mt-0.5",children:"Aucun message \u2014 dites bonjour !"})]})]}):(0,r.jsx)(kt,{messages:s,myNodeId:p,conv:t,userMap:v,lang:N,primaryColor:u,onDeleteMsg:E}),(0,r.jsx)("div",{ref:ve,className:"h-1 shrink-0"})]}),K>0&&!y&&(0,r.jsxs)("button",{onClick:()=>{Re("smooth"),X(0)},className:"absolute bottom-3 left-1/2 -translate-x-1/2 flex items-center gap-1.5 px-3 py-1.5 rounded-full text-white text-xs font-semibold shadow-lg animate-in fade-in-0 slide-in-from-bottom-2 duration-150 z-10 hover:opacity-90 transition-opacity",style:{background:u},children:[(0,r.jsx)(nt,{className:"w-3.5 h-3.5"}),K," nouveau",K>1?"x":""," message",K>1?"s":""]})]}),te&&(0,r.jsxs)("div",{className:"flex items-center gap-2.5 mx-3 mb-1 px-3 py-2 bg-muted/40 rounded-xl border border-border/30 shrink-0 animate-in fade-in-0 slide-in-from-bottom-1 duration-150",children:[Me==="image"?(0,r.jsx)("img",{src:te,alt:"",className:"w-10 h-10 rounded-lg object-cover shrink-0 shadow-sm"}):(0,r.jsx)("div",{className:"w-10 h-10 rounded-lg bg-background/60 border border-border/30 flex items-center justify-center shrink-0",children:(0,r.jsx)($e,{className:"w-4 h-4 text-muted-foreground"})}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground flex-1 truncate",children:Ae||"Fichier"}),(0,r.jsx)("button",{onClick:()=>{pe(void 0),xe(""),ge(void 0)},className:"p-1 hover:bg-muted/60 rounded-lg transition-colors",children:(0,r.jsx)(ee,{className:"w-3.5 h-3.5 text-muted-foreground"})})]}),(0,r.jsxs)("div",{className:"shrink-0 bg-card border-t border-border/30",style:{paddingBottom:"max(env(safe-area-inset-bottom, 0px), 8px)"},children:[(0,r.jsx)("input",{ref:Ie,type:"file",className:"hidden",onChange:Lt,accept:"image/*,.pdf,.doc,.docx,.xls,.xlsx,.zip"}),(0,r.jsx)("input",{ref:Le,type:"file",className:"hidden",onChange:Rt,accept:"image/*,video/*,.pdf,.doc,.docx,.xls,.xlsx,.zip"}),(0,r.jsxs)("div",{className:"flex items-end gap-2 px-3 pt-2.5 pb-1",children:[W?(0,r.jsxs)("div",{className:"flex items-center gap-1.5 shrink-0 self-end mb-0.5",children:[(0,r.jsx)("button",{onClick:S,className:"p-2 rounded-xl text-muted-foreground hover:bg-muted/40 transition-all",title:"Annuler",children:(0,r.jsx)(ee,{className:"w-4 h-4"})}),(0,r.jsx)("span",{className:"text-xs font-mono text-red-500 min-w-[36px]",children:B(ie)}),(0,r.jsx)("button",{onClick:e,className:"p-2 rounded-xl text-red-500 bg-red-500/10 animate-pulse transition-all",title:"Envoyer le vocal",children:(0,r.jsx)(ft,{className:"w-4 h-4 fill-red-500"})})]}):(0,r.jsx)("button",{onClick:He,className:"p-2 rounded-xl text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-all shrink-0 self-end mb-0.5",title:"Message vocal",children:(0,r.jsx)(dt,{className:"w-4 h-4"})}),(0,r.jsx)("textarea",{ref:se,value:j,onChange:o=>Ce(o.target.value),onKeyDown:It,placeholder:W?"\u{1F3A4} Enregistrement\u2026":"Message\u2026",disabled:W,rows:1,className:"flex-1 resize-none px-3.5 py-2 rounded-2xl border border-border/60 bg-muted/20 text-sm outline-none focus:border-border focus:bg-muted/30 transition-all leading-5 placeholder:text-muted-foreground/40 disabled:opacity-50",style:{fieldSizing:"content",minHeight:"38px",maxHeight:"96px",overflowY:"auto"}}),(0,r.jsx)("button",{onClick:oe,disabled:m||!j.trim()&&!te||W,className:"p-2 rounded-xl text-white transition-all disabled:opacity-25 shrink-0 self-end mb-0.5 active:scale-90 hover:opacity-90",style:{background:u},title:"Envoyer",children:m?(0,r.jsx)("div",{className:"w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"}):(0,r.jsx)(mt,{className:"w-4 h-4"})})]}),(0,r.jsxs)("div",{className:"flex items-center px-4 pb-1 pt-0.5 gap-1",children:[(0,r.jsxs)("button",{onClick:()=>Le.current?.click(),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-muted-foreground hover:bg-muted/40 hover:text-foreground transition-all text-xs",title:"Partager un m\xE9dia",children:[(0,r.jsx)(it,{className:"w-3.5 h-3.5"}),(0,r.jsx)("span",{children:"M\xE9dia"})]}),(0,r.jsx)("div",{className:"w-px h-3.5 bg-border/40 mx-1"}),(0,r.jsxs)("button",{disabled:!0,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-muted-foreground
2/30 cursor-not-allowed text-xs",title:"Bient\xF4t disponible",children:[(0,r.jsx)(ut,{className:"w-3.5 h-3.5"}),(0,r.jsx)("span",{children:"Appel"})]}),(0,r.jsx)("div",{className:"w-px h-3.5 bg-border/40 mx-1"}),(0,r.jsxs)("button",{disabled:!0,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-muted-foreground/30 cursor-not-allowed text-xs",title:"Bient\xF4t disponible",children:[(0,r.jsx)(pt,{className:"w-3.5 h-3.5"}),(0,r.jsx)("span",{children:"Vid\xE9o"})]})]})]}),(0,r.jsx)("div",{className:"shrink-0 md:hidden",style:{height:"env(safe-area-inset-bottom, 0px)",background:"hsl(var(--card))"}}),Je&&(0,r.jsx)(Ct,{conv:t,accessibleContacts:U,primaryColor:u,onSave:async o=>{await b(o),he(!1)},onClose:()=>he(!1)}),M&&$&&(0,r.jsx)(Qe,{targetNodeId:M,targetName:re,targetAvatar:v[M]?.avatar,onClose:()=>G(null)})]})}var Ye=D(me());var L=D(F());function At({contacts:t,myNodeId:s,existingConvs:p,primaryColor:v,onSelect:N,onClose:u}){let[l,m]=(0,Ye.useState)(""),g=(0,Ye.useMemo)(()=>{if(!l.trim())return t;let a=l.toLowerCase();return t.filter(b=>b.name.toLowerCase().includes(a))},[t,l]);return(0,L.jsx)("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50 backdrop-blur-sm animate-in fade-in-0 duration-150",children:(0,L.jsxs)("div",{className:"w-full max-w-sm bg-card rounded-t-2xl sm:rounded-2xl shadow-2xl flex flex-col max-h-[72vh] animate-in slide-in-from-bottom-4 sm:zoom-in-95 duration-200",children:[(0,L.jsx)("div",{className:"flex justify-center pt-2.5 pb-0 sm:hidden shrink-0",children:(0,L.jsx)("div",{className:"w-8 h-1 rounded-full bg-muted-foreground/20"})}),(0,L.jsxs)("div",{className:"flex items-center justify-between px-4 pt-3 pb-3 shrink-0",children:[(0,L.jsxs)("div",{children:[(0,L.jsx)("h2",{className:"text-sm font-semibold",children:"Nouveau message"}),(0,L.jsxs)("p",{className:"text-[10px] text-muted-foreground mt-0.5",children:[t.length," contact",t.length!==1?"s":""," disponible",t.length!==1?"s":""]})]}),(0,L.jsx)("button",{onClick:u,className:"p-1.5 rounded-lg hover:bg-accent transition-colors",children:(0,L.jsx)(ee,{className:"w-4 h-4"})})]}),(0,L.jsx)("div",{className:"px-4 pb-3 shrink-0",children:(0,L.jsxs)("div",{className:"relative",children:[(0,L.jsx)(fe,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground/40 pointer-events-none"}),(0,L.jsx)("input",{autoFocus:!0,value:l,onChange:a=>m(a.target.value),placeholder:"Rechercher un contact\u2026",className:"w-full pl-8 pr-3 py-2 text-xs rounded-xl bg-muted/40 border border-transparent focus:border-border/50 focus:bg-muted/60 focus:outline-none transition-all"})]})}),(0,L.jsx)("div",{className:"overflow-y-auto flex-1 px-2 pb-4",children:g.length===0?(0,L.jsxs)("div",{className:"flex flex-col items-center gap-2 py-10 text-center",children:[(0,L.jsx)(fe,{className:"w-6 h-6 text-muted-foreground/20"}),(0,L.jsx)("p",{className:"text-xs text-muted-foreground/50",children:"Aucun contact trouv\xE9"})]}):g.map(a=>{let b=p.some(k=>k.type==="direct"&&k.members.includes(a.nodeId)&&k.members.includes(s));return(0,L.jsxs)("button",{onClick:()=>N(a.nodeId),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-accent/50 active:bg-accent/70 transition-colors text-left",children:[(0,L.jsx)(V,{name:a.name,icon:a.avatar,size:"md",color:v}),(0,L.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,L.jsx)("p",{className:"text-xs font-medium truncate",children:a.name}),(0,L.jsx)("p",{className:"text-[10px] text-muted-foreground/70 capitalize",children:a.role.replace("role-","")})]}),b&&(0,L.jsx)("span",{className:"text-[9px] text-muted-foreground/50 shrink-0 px-1.5 py-0.5 rounded-md bg-muted/50",children:"Existant"})]},a.nodeId)})})]})})}var ae=D(me());var A=D(F());function St({contacts:t,primaryColor:s,onCreate:p,onClose:v}){let[N,u]=(0,ae.useState)(""),[l,m]=(0,ae.useState)(""),[g,a]=(0,ae.useState)([]),[b,k]=(0,ae.useState)(Pe[0]),[P,E]=(0,ae.useState)(!1),z=(0,ae.useMemo)(()=>{if(!l.trim())return t;let c=l.toLowerCase();return t.filter(M=>M.name.toLowerCase().includes(c))},[t,l]),U=c=>a(M=>M.includes(c)?M.filter(G=>G!==c):[...M,c]),T=N.trim().length>=2&&g.length>=1,d=async()=>
2{if(T){E(!0);try{await p(N.trim(),g,b)}finally{E(!1)}}};return(0,A.jsx)("div",{className:"fixed inset-0 z-50 flex items-end sm:items-center justify-center bg-black/50 backdrop-blur-sm animate-in fade-in-0 duration-150",children:(0,A.jsxs)("div",{className:"w-full max-w-sm bg-card rounded-t-2xl sm:rounded-2xl shadow-2xl flex flex-col max-h-[82vh] animate-in slide-in-from-bottom-4 sm:zoom-in-95 duration-200",children:[(0,A.jsx)("div",{className:"flex justify-center pt-2.5 pb-0 sm:hidden shrink-0",children:(0,A.jsx)("div",{className:"w-8 h-1 rounded-full bg-muted-foreground/20"})}),(0,A.jsxs)("div",{className:"flex items-center justify-between px-4 pt-3 pb-3 shrink-0",children:[(0,A.jsx)("h2",{className:"text-sm font-semibold",children:"Nouveau groupe"}),(0,A.jsx)("button",{onClick:v,className:"p-1.5 rounded-lg hover:bg-accent transition-colors",children:(0,A.jsx)(ee,{className:"w-4 h-4"})})]}),(0,A.jsxs)("div",{className:"px-4 pb-3 shrink-0 space-y-2.5",children:[(0,A.jsxs)("div",{className:"flex items-center gap-3 mb-1",children:[(0,A.jsx)("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-xl shrink-0",style:{background:s+"20",color:s},children:b}),(0,A.jsx)("input",{autoFocus:!0,value:N,onChange:c=>u(c.target.value),placeholder:"Nom du groupe\u2026",className:"flex-1 px-3 py-2 text-xs rounded-xl bg-muted/40 border border-transparent focus:border-border/50 focus:bg-muted/60 focus:outline-none transition-all"})]}),(0,A.jsx)("div",{className:"flex gap-1.5 flex-wrap",children:Pe.map(c=>(0,A.jsx)("button",{onClick:()=>k(c),className:C("w-8 h-8 rounded-lg text-base flex items-center justify-center transition-all",b===c?"bg-muted ring-2 ring-offset-1":"hover:bg-muted/60"),style:b===c?{ringColor:s}:void 0,children:c},c))}),(0,A.jsxs)("div",{className:"relative",children:[(0,A.jsx)(fe,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-muted-foreground/40 pointer-events-none"}),(0,A.jsx)("input",{value:l,onChange:c=>m(c.target.value),placeholder:"Rechercher des membres\u2026",className:"w-full pl-8 pr-3 py-2 text-xs rounded-xl bg-muted/40 border border-transparent focus:border-border/50 focus:bg-muted/60 focus:outline-none transition-all"})]}),g.length>0&&(0,A.jsxs)("p",{className:"text-[10px] text-muted-foreground/70 font-medium",children:[g.length," membre",g.length!==1?"s":""," s\xE9lectionn\xE9",g.length!==1?"s":""]})]}),(0,A.jsx)("div",{className:"overflow-y-auto flex-1 px-2 pb-2",children:z.map(c=>{let M=g.includes(c.nodeId);return(0,A.jsxs)("button",{onClick:()=>U(c.nodeId),className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-xl hover:bg-accent/50 active:bg-accent/70 transition-colors text-left",children:[(0,A.jsx)(V,{name:c.name,icon:c.avatar,size:"md",color:s}),(0,A.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,A.jsx)("p",{className:"text-xs font-medium truncate",children:c.name}),(0,A.jsx)("p",{className:"text-[10px] text-muted-foreground/70 capitalize",children:c.role.replace("role-","")})]}),(0,A.jsx)("div",{className:C("w-5 h-5 rounded-full border-2 flex items-center justify-center transition-all shrink-0",M?"border-transparent":"border-border/60"),style:M?{background:s}:void 0,children:M&&(0,A.jsx)(Ge,{className:"w-3 h-3 text-white"})})]},c.nodeId)})}),(0,A.jsx)("div",{className:"px-4 py-3 shrink-0 border-t border-border/30",children:(0,A.jsx)("button",{onClick:d,disabled:!T||P,className:"w-full py-2.5 rounded-xl text-xs font-semibold text-white transition-all disabled:opacity-35 hover:opacity-90 active:scale-[0.98]",style:{background:s},children:P?"Cr\xE9ation\u2026":`Cr\xE9er le groupe${g.length>0?` (${g.length+1})`:""}`})})]})})}var n=D(F());function zt(t){return t?t.role==="superadmin"?!0:(t.modulesAccess??"").split(",").map(s=>s.trim()).includes("messages"):!1}var Ut=(0,h.memo)(function({conv:s,isActive:p,myNodeId:v,userMap:N,primaryColor:u,notifColor:l,lang:m,unread:g,onClick:a,hasProfileModule:b,onlineThresholdMin:k,manageStatusActive:P}){let E=Ee(s,v,N),z=qe(s,v,N),U=s.updatedAt?Ke(s.updatedAt,m):"",T=g>0&&!p,[d,c]=(0,h.useState)(null),M=s.type==="direct"?s.members.find(j=>j!==v)??null:null,G=(0,h.useMemo)(()=>
2{if(s.type!=="direct"||!M)return null;let j=N[M];return j?De(j.lastHeartbeat,j.statusCustom,k,P,j.lastLogin,j.lastLogout):null},[s.type,M,N,k,P]),$=s.lastMessage?s.lastMessage.length>42?s.lastMessage.slice(0,42)+"\u2026":s.lastMessage:s.type==="group"?`${s.members.length} membre${s.members.length!==1?"s":""}`:s.archived?"Archiv\xE9":"D\xE9marrer la conversation";return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:C("w-full flex items-center gap-3 px-3 py-2.5 rounded-xl transition-all",p?"bg-accent/80":T?"hover:bg-accent/50 bg-accent/25":"hover:bg-accent/40"),children:[(0,n.jsxs)("button",{onClick:a,className:"relative shrink-0",children:[s.type==="group"?(0,n.jsx)("div",{className:"w-9 h-9 rounded-full flex items-center justify-center text-base",style:{background:u+"20",color:u},children:z}):(0,n.jsx)(V,{name:E,icon:z,size:"md",color:u}),G&&!T&&(0,n.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full border-2 border-card",style:{background:G.color},title:G.label,children:G.status==="online"&&(0,n.jsx)("span",{className:"absolute inset-0 rounded-full animate-ping opacity-60",style:{background:G.color}})}),T&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 min-w-[18px] h-[18px] px-1 rounded-full text-[9px] font-bold text-white flex items-center justify-center shadow-md ring-2 ring-card",style:{background:l},children:g>99?"99+":g})]}),(0,n.jsxs)("button",{onClick:a,className:"flex-1 min-w-0 text-left",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-1.5",children:[(0,n.jsx)("p",{className:C("text-xs truncate",T?"font-bold text-foreground":"font-semibold"),children:E}),U&&(0,n.jsx)("span",{className:C("text-[9px] shrink-0",T?"font-semibold":"text-muted-foreground/50"),style:T?{color:l}:void 0,children:U})]}),(0,n.jsx)("p",{className:C("text-[10px] truncate mt-0.5",T?"text-foreground/70 font-medium":"text-muted-foreground/55"),children:$})]}),b&&s.type==="direct"&&M&&(0,n.jsx)("button",{onClick:j=>{j.stopPropagation(),c(M)},className:"shrink-0 p-1.5 rounded-lg text-muted-foreground/40 hover:text-brand hover:bg-brand/10 transition-all",title:`Voir le profil de ${E}`,children:(0,n.jsx)(Oe,{className:"w-4 h-4"})})]}),d&&(0,n.jsx)(Qe,{targetNodeId:d,targetName:E,targetAvatar:N[d]?.avatar,onClose:()=>c(null)})]})},(t,s)=>{let p=(v,N,u)=>{if(v.type==="direct"){let l=v.members.find(g=>g!==u),m=N[l];return l?`${m?.lastHeartbeat}|${m?.statusCustom}|${m?.lastLogin}|${m?.lastLogout}`:""}return v.members.map(l=>{let m=N[l];return`${m?.lastHeartbeat}|${m?.statusCustom}|${m?.lastLogin}|${m?.lastLogout}`}).join("||")};return t.conv.id===s.conv.id&&t.isActive===s.isActive&&t.unread===s.unread&&t.conv.updatedAt===s.conv.updatedAt&&t.conv.lastMessage===s.conv.lastMessage&&t.primaryColor===s.primaryColor&&t.notifColor===s.notifColor&&t.hasProfileModule===s.hasProfileModule&&t.onClick===s.onClick&&p(t.conv,t.userMap,t.myNodeId)===p(s.conv,s.userMap,s.myNodeId)});function Ht(){let t=tt(e=>e.user),s=Ze(e=>e.primaryColor),v=Ze(e=>e.notifColor)??"#ef4444",N=xt(e=>e.lang),u=R(e=>e.conversations),l=R(e=>e.messages),m=R(e=>e.users),g=R(e=>e.teamNodeMap),a=R(e=>e.activeConvId),b=R(e=>e.loading),k=R(e=>e.msgsLoading),P=R(e=>e.sending),E=R(e=>e.unreadPerConv),z=R(e=>e.init),U=R(e=>e.loadConversations),T=R(e=>e.openConversation),d=R(e=>e.closeConversation),c=R(e=>e.pollMessages),M=R(e=>e.backgroundPollUnread),G=R(e=>e.markConvRead),$=R(e=>e.sendMessage),j=R(e=>e.openOrCreateDirect),Ce=R(e=>e.createGroup),te=R(e=>e.updateGroup),pe=R(e=>e.archiveConv),Me=R(e=>e.deleteConv),ge=R(e=>e.deleteMessage),Ae=R(e=>e.reloadUsers),xe=Xe(),[W,Se]=(0,h.useState)(""),[ie,be]=(0,h.useState)(!1),[Y,J]=(0,h.useState)(!1),[_,le]=(0,h.useState)(!1),[q,Je]=(0,h.useState)("all"),[he,K]=(0,h.useState)(!1),X=(0,h.useRef)(!0),y=t?.nodeId??"",H=zt(t),O=ht(),ve=vt();(0,h.useEffect)(()=>{y&&H&&z(y)},[y,H]),(0,h.useEffect)(()=>{let e=()=>{X.current=document.visibilityState==="visible"};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[]);let se=(0,h.useRef)(0),Ie=(0,h.useRef)(null),Le=(0,h.useRef)(a);(0,h.useEffect)(()=>{Le.current=a},[a]);let ye=(0,h.useRef)(O);(0,h.useEffect)(()=>{ye.current=O},[O]),(0,h.useEffect)(()=>
2{if(!H||!y||(U(),Ae(),ve))return;let e=y,S=()=>{if(!X.current)return;se.current+=1;let B=se.current;B%2===0&&(U(),M(e));let oe=Le.current;oe&&c(oe),B%2===0&&Ae()};return Ie.current=setInterval(S,1e4),()=>{Ie.current&&clearInterval(Ie.current)}},[H,y,ve]),(0,h.useEffect)(()=>{a&&H&&c(a)},[a]),(0,h.useEffect)(()=>{if(!H)return;let e=()=>{Ae()};return window.addEventListener("user-status-changed",e),()=>window.removeEventListener("user-status-changed",e)},[H]),(0,h.useEffect)(()=>{a&&G(a)},[a,l.length,G]);let de=(0,h.useMemo)(()=>{let e={};for(let S of m)e[S.nodeId]={name:S.name,avatar:S.avatar,role:S.role,lastHeartbeat:S.lastHeartbeat??"",statusCustom:S.statusCustom??"",lastLogin:S.lastLogin??"",lastLogout:S.lastLogout??""};return!O&&y&&e[y]&&(e[y]={...e[y],lastLogin:new Date().toISOString()}),e},[m,y,O]),Z=(0,h.useMemo)(()=>{if(!t||!H)return[];let e=t.teamId?g[t.teamId]??[]:[],S=[];for(let B of u)B.type==="group"&&B.members.includes(y)&&B.members.forEach(oe=>{oe!==y&&S.push(oe)});return bt({currentUser:{nodeId:y,role:t.role??"",teamId:t.teamId??"",assignedUsers:t.assignedUsers??"",managerOf:t.managerOf??""},allUsers:m,teamMembers:e,groupMembers:S})},[t,m,g,u,y,H]),re=(0,h.useMemo)(()=>{if(!H)return[];let e=u.filter(S=>S.members.includes(y));if(ie||(e=e.filter(S=>!S.archived)),q==="direct"&&(e=e.filter(S=>S.type==="direct")),q==="group"&&(e=e.filter(S=>S.type==="group")),W.trim()){let S=W.toLowerCase();e=e.filter(B=>Ee(B,y,de).toLowerCase().includes(S))}return e},[u,y,ie,q,W,de,H]),Q=u.find(e=>e.id===a)??null,Ne=(0,h.useCallback)(async e=>{await T(e,y),K(!0)},[T,y]),ne=(0,h.useCallback)(()=>{d(),K(!1)},[d]),ze=(0,h.useCallback)(async(e,S,B)=>{if(!(!a||!y)){try{window.__presenceBeat?.()}catch{}await $({convId:a,senderNodeId:y,text:e,lang:N,fileData:S,fileType:B})}},[a,y,N,$]),Re=(0,h.useCallback)(async e=>{J(!1),await j(y,e),K(!0)},[y,j]),ce=(0,h.useCallback)(async(e,S,B)=>{le(!1),await Ce(y,e,S,B),K(!0)},[y,Ce]),Ue=Q?Q.owner===y:!1,He=(0,h.useMemo)(()=>(t?.modulesAccess??"").split(",").map(e=>e.trim()).includes("profile")||t?.role==="superadmin",[t?.modulesAccess,t?.role]);return H?(0,n.jsxs)("div",{className:"h-full flex flex-row overflow-hidden bg-card/50",children:[(0,n.jsxs)("aside",{className:C("flex flex-col border-r border-border/30 bg-card/80 w-full md:w-72 shrink-0",he?"hidden md:flex":"flex"),children:[(0,n.jsxs)("div",{className:"px-3 pt-3 pb-2 shrink-0 space-y-2.5",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(Ve,{className:"w-4 h-4",style:{color:s}}),(0,n.jsx)("h2",{className:"text-sm font-bold",children:"Messages"}),y&&(0,n.jsx)(yt,{nodeId:y})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{onClick:()=>be(e=>!e),className:C("p-1.5 rounded-lg transition-colors text-muted-foreground",ie?"bg-accent text-foreground":"hover:bg-accent/50"),children:ie?(0,n.jsx)(st,{className:"w-3.5 h-3.5"}):(0,n.jsx)(Fe,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>le(!0),className:"p-1.5 rounded-lg hover:bg-accent/50 transition-colors text-muted-foreground",children:(0,n.jsx)(Te,{className:"w-3.5 h-3.5"})}),(0,n.jsx)("button",{onClick:()=>J(!0),className:"p-1.5 rounded-lg transition-colors text-white",style:{background:s},children:(0,n.jsx)(et,{className:"w-3.5 h-3.5"})})]})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(fe,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground/40 pointer-events-none"}),(0,n.jsx)("input",{value:W,onChange:e=>Se(e.target.value),placeholder:"Rechercher\u2026",className:"w-full pl-7 pr-3 py-1.5 text-xs rounded-lg bg-muted/30 border border-transparent focus:border-border/40 focus:outline-none transition-colors"})]}),(0,n.jsx)("div",{className:"flex gap-1 bg-muted/30 rounded-lg p-0.5",children:["all","direct","group"].map(e=>(0,n.jsx)("button",{onClick:()=>Je(e),className:C("flex-1 text-[10px] py-1 rounded-md font-medium transition-all",q===e?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:e==="all"?"Tous":e==="direct"?"Direct":"Groupes"},e))})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-2 pb-3 space-y-0.5",children:b&&u.length===0?(0,n.jsx)("div",{className:"space-y-1 px-1 pt-1",children:[1,2,3].map(e=>(0,n.jsxs)("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-xl",children:[(0,n.jsx)("div",{className:"w-9 h-9 rounded-full bg-muted/50 shrink-0 animate-pulse"}),(0,n.jsxs)("div",{className:"flex-1 space-y-1.5",children:[(0,n.jsx)("div",{className:"h-2.5 w-24 bg-muted/50 rounded animate-pulse"}),(0,n.jsx)("div",{className:"h-2 w-36 bg-muted/35 rounded animate-pulse"})]})]},e))}):re.length===0?(0,n.jsxs)("div",{className:"flex flex-col items-center gap-3 py-12 text-center px-4",children:[(0,n.jsx)("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center",style:{background:s+"15"},children:(0,n.jsx)(Ve,{className:"w-5 h-5",style:{color:s+"80"}})}
2),(0,n.jsx)("p",{className:"text-[11px] text-muted-foreground/50 leading-relaxed",children:W?`Aucun r\xE9sultat pour \xAB ${W} \xBB`:ie?"Aucune conversation archiv\xE9e":`Aucune conversation 3Appuyez sur + pour commencer`})]}):re.map(e=>(0,n.jsx)(Ut,{conv:e,isActive:e.id===a,myNodeId:y,userMap:de,primaryColor:s,notifColor:v,lang:N,unread:E[e.id]??0,onClick:()=>Ne(e.id),hasProfileModule:He,onlineThresholdMin:xe,manageStatusActive:O},e.id))})]}),(0,n.jsx)("main",{className:C("flex-1 min-w-0 min-h-0 flex flex-col overflow-hidden",he?"flex":"hidden md:flex"),children:Q?(0,n.jsx)(Mt,{conv:Q,messages:l,myNodeId:y,userMap:de,lang:N,primaryColor:s,loading:k,sending:P,onBack:ne,onSend:ze,onUpdateGroup:async e=>te(Q.id,e),onArchive:e=>pe(Q.id,e),onDelete:async()=>{await Me(Q.id),K(!1)},onDeleteMsg:e=>ge(e),isOwner:Ue,accessibleContacts:Z,hasProfileModule:He,manageStatusActive:O}):(0,n.jsxs)("div",{className:"hidden md:flex flex-col items-center justify-center h-full gap-4 text-center px-8",children:[(0,n.jsx)("div",{className:"w-16 h-16 rounded-2xl flex items-center justify-center",style:{background:s+"18"},children:(0,n.jsx)(Ve,{className:"w-7 h-7",style:{color:s}})}),(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)("p",{className:"text-sm font-semibold",children:"S\xE9lectionnez une conversation"}),(0,n.jsxs)("p",{className:"text-xs text-muted-foreground/50",children:["Ou appuyez sur ",(0,n.jsx)("span",{className:"font-medium",children:"+"})," pour d\xE9marrer"]})]}),(0,n.jsxs)("div",{className:"flex gap-2 mt-2",children:[(0,n.jsxs)("button",{onClick:()=>J(!0),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-xs font-medium text-white hover:opacity-90 transition-opacity",style:{background:s},children:[(0,n.jsx)(et,{className:"w-3.5 h-3.5"})," Message direct"]}),(0,n.jsxs)("button",{onClick:()=>le(!0),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-xs font-medium border border-border hover:bg-accent transition-colors",children:[(0,n.jsx)(Te,{className:"w-3.5 h-3.5"})," Groupe"]})]})]})}),Y&&(0,n.jsx)(At,{contacts:Z,myNodeId:y,existingConvs:u,primaryColor:s,onSelect:Re,onClose:()=>J(!1)}),_&&(0,n.jsx)(St,{contacts:Z,myNodeId:y,primaryColor:s,onCreate:ce,onClose:()=>le(!1)})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-[70vh] gap-4 text-center px-6",children:[(0,n.jsx)("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center",style:{background:s+"18"},children:(0,n.jsx)(lt,{className:"w-6 h-6",style:{color:s}})}),(0,n.jsx)("p",{className:"text-sm font-semibold",children:"Module messagerie non activ\xE9"}),(0,n.jsx)("p",{className:"text-xs text-muted-foreground max-w-xs",children:"Contactez votre administrateur pour activer ce module."})]})}export{Ht as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.