PageSourceSearch

https://comms-crm-frontend-production.up.railway.app/_next/static/chunks/626-790ceb97e4941fbf.js

js comms-crm-frontend-production.up.railway.app collected 2026-10-03 12:12:25 UTC 63,453 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[626],{5597:function(e,t,a){a.d(t,{C:function(){return v},z:function(){return b}});var n=a(37821),l=a(59794),i=a(63410),r=a(77448),s=a(72572),o=a(20700),c=a(63492),d=a(32259),u=a(32189),m=a(87181),h=a(43013),x=a(46455),p=a(23086),g=a(85480);let f={cat:{Icon:l.Z,label:"Cat",bg:"#EADFF3",fg:"#6B4A8A"},dog:{Icon:i.Z,label:"Dog",bg:"#FBE3D2",fg:"#9A5A2B"},rabbit:{Icon:r.Z,label:"Rabbit",bg:"#F6DDE6",fg:"#96436A"},bird:{Icon:s.Z,label:"Bird",bg:"#D6E9F7",fg:"#2C6489"},fish:{Icon:o.Z,label:"Fish",bg:"#D2ECE9",fg:"#1F6E68"},squirrel:{Icon:c.Z,label:"Squirrel",bg:"#F9E1D6",fg:"#9E4B25"},turtle:{Icon:d.Z,label:"Turtle",bg:"#DDEEDC",fg:"#3B6E3D"},snail:{Icon:u.Z,label:"Snail",bg:"#F3E9D2",fg:"#7E6320"},shell:{Icon:m.Z,label:"Shell",bg:"#F5DFDD",fg:"#8E4038"},feather:{Icon:h.Z,label:"Feather",bg:"#E2E4F5",fg:"#4A4E8C"},paw:{Icon:x.Z,label:"Paw",bg:"#E9E3DA",fg:"#6B5D4A"},crane:{Icon:p.Z,label:"Crane",bg:"#DCE7F0",fg:"#3D5C74"}},b=g.sxs.map(e=>({id:e,...f[e]}));function v(e){let{roomId:t,icon:a,iconUrl:l,size:i=36,className:r=""}=e;if(l)return(0,n.jsx)("img",{src:l,alt:"",className:"rounded-full shrink-0 object-cover bg-white ring-1 ring-black/5 ".concat(r),style:{width:i,height:i}});let{Icon:s,label:o,bg:c,fg:d}=f[(0,g.Ai_)(t,a)];return(0,n.jsx)("span",{className:"rounded-full flex items-center justify-center shrink-0 ".concat(r),style:{background:c,color:d,width:i,height:i},"aria-label":o,title:o,children:(0,n.jsx)(s,{size:Math.round(.55*i)})})}},50035:function(e,t,a){a.d(t,{Q:function(){return d}});var n=a(37821),l=a(58078),i=a(55118),r=a(68156),s=a(3116),o=a(5597),c=a(64790);function d(e){let{roomId:t,icon:a,iconUrl:d,canEdit:m,size:h=22,onChanged:x}=e,[p,g]=(0,l.useState)(!1),[f,b]=(0,l.useState)(null),[v,y]=(0,l.useState)(null),k=(0,l.useRef)(null),w=(0,l.useRef)(null);if((0,l.useEffect)(()=>{if(!p)return;let e=e=>{k.current&&!k.current.contains(e.target)&&g(!1)},t=e=>{"Escape"===e.key&&(e.stopPropagation(),g(!1))};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[p]),!m)return(0,n.jsx)(o.C,{roomId:t,icon:a,iconUrl:d,size:h+6});let j=async e=>{b(e),y(null);try{await (0,c.api)("/api/team-chat/rooms/".concat(t,"/icon"),{method:"PATCH",body:JSON.stringify({icon:e})}),g(!1),null==x||x()}catch(e){y(e.message||"Could not change the icon")}finally{b(null)}},N=async e=>{b("photo"),y(null);try{let a=await u(e,256),n=await (0,c.api)("/api/team-chat/upload",{method:"POST",body:JSON.stringify({filename:e.name,contentType:"image/png",dataBase64:a})});await (0,c.api)("/api/team-chat/rooms/".concat(t,"/icon-image"),{method:"PATCH",body:JSON.stringify({ref:n.ref})}),g(!1),null==x||x()}catch(e){y(e.message||"Could not upload that photo")}finally{b(null)}},_=async()=>{b("clear"),y(null);try{await (0,c.api)("/api/team-chat/rooms/".concat(t,"/icon-image"),{method:"PATCH",body:JSON.stringify({ref:null})}),g(!1),null==x||x()}catch(e){y(e.message||"Could not remove the photo")}finally{b(null)}};return(0,n.jsxs)("div",{ref:k,className:"relative shrink-0",children:[(0,n.jsx)("button",{type:"button",onClick:()=>g(e=>!e),"aria-expanded":p,title:"Change this group's icon","aria-label":"Change this group's icon",className:"rounded-full ring-offset-1 hover:ring-2 hover:ring-clay-300 focus-visible:ring-2 focus-visible:ring-clay-400 transition-shadow",children:(0,n.jsx)(o.C,{roomId:t,icon:a,iconUrl:d,size:h+6})}),p&&(0,n.jsxs)("div",{className:"absolute left-0 top-full mt-1.5 z-30 w-[212px] rounded-xl border border-cream-200 dark:border-white/10 bg-white dark:bg-[rgb(var(--surface-2))] shadow-xl p-2",children:[(0,n.jsx)("div",{className:"text-[10px] uppercase tracking-wide text-ink-400 px-1 pb-1.5",children:"Group icon"}),(0,n.jsx)("div",{className:"grid grid-cols-4 gap-1",children:o.z.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>void j(e.id),disabled:!!f,title:e.label,"aria-label":e.label,className:"h-11 rounded-lg flex items-center justify-center hover:bg-cream-100 dar
1k:hover:bg-white/[0.06] disabled:opacity-50",children:f===e.id?(0,n.jsx)(i.Z,{size:16,className:"animate-spin text-ink-400"}):(0,n.jsx)(o.C,{roomId:t,icon:e.id,size:30})},e.id))}),(0,n.jsxs)("div",{className:"border-t border-cream-200 dark:border-white/10 mt-2 pt-2 flex items-center gap-1",children:[(0,n.jsx)("input",{ref:w,type:"file",accept:"image/*",className:"hidden",onChange:e=>{var t;let a=null===(t=e.target.files)||void 0===t?void 0:t[0];a&&N(a),e.target.value=""}}),(0,n.jsxs)("button",{type:"button",onClick:()=>{var e;return null===(e=w.current)||void 0===e?void 0:e.click()},disabled:!!f,className:"flex-1 flex items-center gap-1.5 px-1.5 py-1.5 rounded-lg text-[12px] text-ink-700 dark:text-white/80 hover:bg-cream-100 dark:hover:bg-white/[0.06] disabled:opacity-50",children:["photo"===f?(0,n.jsx)(i.Z,{size:14,className:"animate-spin text-ink-400"}):(0,n.jsx)(r.Z,{size:14,className:"text-ink-400"}),"Upload a photo"]}),d&&(0,n.jsx)("button",{type:"button",onClick:()=>void _(),disabled:!!f,title:"Remove the photo","aria-label":"Remove the photo",className:"p-1.5 rounded-lg text-ink-400 hover:text-clay-600 hover:bg-cream-100 dark:hover:bg-white/[0.06] disabled:opacity-50",children:"clear"===f?(0,n.jsx)(i.Z,{size:14,className:"animate-spin"}):(0,n.jsx)(s.Z,{size:14})})]}),v&&(0,n.jsx)("div",{className:"text-[11px] text-clay-600 px-1 pt-1.5 leading-tight",children:v})]})]})}async function u(e,t){var a;let n=await createImageBitmap(e,{imageOrientation:"from-image"}),l=Math.min(1,t/Math.max(n.width,n.height)),i=document.createElement("canvas");return i.width=Math.round(n.width*l),i.height=Math.round(n.height*l),i.getContext("2d").drawImage(n,0,0,i.width,i.height),null!==(a=i.toDataURL("image/png").split(",")[1])&&void 0!==a?a:""}},41749:function(e,t,a){a.d(t,{M2:function(){return G},_H:function(){return B},aw:function(){return H},gq:function(){return K},iu:function(){return Y},jv:function(){return V},mt:function(){return U},qE:function(){return I},rX:function(){return q}});var n=a(37821),l=a(58078),i=a(5597),r=a(88620),s=a(12304),o=a(26490),c=a(80555),d=a(48149),u=a(67092),m=a(84928),h=a(97838),x=a(36868),p=a(79044),g=a(55118),f=a(5189),b=a(62870),v=a(76515),y=a(15818),k=a(98791),w=a(26764),j=a(3116),N=a(80961),_=a(68156),C=a(96258),S=a(17737),E=a(42942),D=a(65675),z=a(85480),Z=a(66330),A=a(72952),T=a(65094),M=a(40450),R=a(24605),O=a(96311),P=a(46552),F=a(69549);function I(e){let{name:t,size:a=36,avatarUrl:i}=e,[r,s]=(0,l.useState)(!1);return i&&!r?(0,n.jsx)("img",{src:i,alt:t,width:a,height:a,onError:()=>s(!0),referrerPolicy:"no-referrer",className:"rounded-full object-cover shrink-0",style:{width:a,height:a}}):(0,n.jsx)("div",{className:"rounded-full bg-clay-100 text-clay-700 dark:bg-white/10 dark:text-white flex items-center justify-center font-semibold shrink-0",style:{width:a,height:a,fontSize:.4*a},children:t.slice(0,1).toUpperCase()})}function L(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function U(e){let{onlineIds:t,activeId:a}=e,g=(0,D.pA)(),{agent:f}=(0,A.Z)(),[b,v]=(0,l.useState)(null),[y,k]=(0,l.useState)(""),[w,j]=(0,l.useState)(!1),[N,_]=(0,l.useState)(null),[C,S]=(0,l.useState)(null);(0,l.useEffect)(()=>{if(!N)return;let e=()=>_(null),t=t=>{"Escape"===t.key&&e()};return window.addEventListener("click",e),window.addEventListener("keydown",t),()=>{window.removeEventListener("click",e),window.removeEventListener("keydown",t)}},[N]);let E=g.rooms.filter(e=>!!e.archived===g.showArchived),z=g.rooms.filter(e=>e.archived).length;return 0===g.rooms.length?(0,n.jsx)("div",{className:"p-8 text-center text-sm text-ink-500",children:"No chats yet. Start a message with a teammate."}):(0,n.jsxs)(n.Fragment,{children:[g.showArchived&&(0,n.jsxs)("button",{onClick:()=>g.setShowArchived(!1),className:"w-full flex items-center gap-2 px-4 py-2 text-xs text-ink-500 hover:text-ink-900 border-b border-cream-100 dark:border-white/5",children:[(0,n.jsx)(r.Z,{size:13})," Back to your chats"]}),0===E.length&&(0,n.jsx)("div",{className:"p-8 text-center text-sm text-ink-500",children:g.showArchived?"Nothing archived.":"No chats yet. Start a message with a teammate."}),C&&(0,n.jsx)("div",{className:"mx-4 my-2 px-3 py-2 rounded-lg bg-clay-50 dark:bg-clay-500/10 border border-clay-200 dark:border-clay-500/20 text-xs text-clay-700 dark:text-clay-300",children:C}),E.map(e=>{var l,r,b;let y="dm"===e.kind?e.members.find(e=>e.id!==(null==f?void 0:f.id)):null,w=!!y&&t.has(y.id);return(0,n.jsxs)("div",{className:(0,F.cn)("group/room relative border-b border-cream-50 dark:border-white/5",e.id===a?"bg-cream-100 dar
1k:bg-white/[0.06]":"hover:bg-cream-50 dark:hover:bg-white/[0.03]"),children:[(0,n.jsxs)("button",{onClick:()=>g.openRoom(e.id),className:"w-full flex items-center gap-3 px-4 py-3 text-left",children:[(0,n.jsxs)("div",{className:"relative",children:["group"===e.kind?(0,n.jsx)(i.C,{roomId:e.id,icon:e.icon,iconUrl:e.icon_url,size:36}):(0,n.jsx)(I,{name:e.name,avatarUrl:null==y?void 0:y.avatarUrl}),"dm"===e.kind&&w&&(0,n.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full bg-sage-500 border-2 border-white dark:border-[rgb(var(--surface))]"})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:(0,F.cn)("font-medium text-ink-900 truncate",e.unread>0&&"font-semibold"),children:e.name}),e.last_message&&(0,n.jsx)("span",{className:"text-[11px] text-ink-400 ml-auto shrink-0",children:(0,R.Gf)(e.last_message.created_at)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:(0,F.cn)("text-xs truncate",e.unread>0?"text-ink-700":"text-ink-500"),children:e.last_message?"".concat(e.last_message.from_me?"You: ":"").concat(e.last_message.body):"No messages yet"}),e.unread>0&&(()=>{var t,a,l,i;let r=null!==(t=e.notify_level)&&void 0!==t?t:"all",s="all"===r||"mentions"===r&&(null!==(a=e.unread_mentions)&&void 0!==a?a:0)>0,o="mentions"===r&&(null!==(l=e.unread_mentions)&&void 0!==l?l:0)>0?e.unread_mentions:e.unread;return(0,n.jsx)("span",{title:"all"===r?void 0:"none"===r?"".concat(e.unread," unread — this chat is muted"):"".concat(e.unread," unread, ").concat(null!==(i=e.unread_mentions)&&void 0!==i?i:0," tagging you"),className:(0,F.cn)("ml-auto shrink-0 min-w-[18px] h-[18px] px-1 rounded-full text-[10px] font-semibold flex items-center justify-center",s?"bg-clay-500 text-white":"bg-transparent border border-cream-300 dark:border-white/15 text-ink-400"),children:o})})(),(null!==(l=e.notify_level)&&void 0!==l?l:"all")!=="all"&&(0,n.jsx)("span",{className:"shrink-0 text-ink-300",title:"none"===e.notify_level?"Muted":"Only notifies when you are tagged",children:"none"===e.notify_level?(0,n.jsx)(s.Z,{size:12}):(0,n.jsx)(o.Z,{size:12})})]})]})]}),(0,n.jsxs)("div",{className:(0,F.cn)("absolute right-2 top-2 flex items-center gap-0.5 group-hover/room:opacity-100 focus-within:opacity-100 transition-opacity",N===e.id?"opacity-100":"opacity-0"),children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),S(null),_(N===e.id?null:e.id)},title:(null!==(r=e.notify_level)&&void 0!==r?r:"all")==="none"?"Muted — nothing from this chat notifies you":"mentions"===e.notify_level?"Only notifies you when someone tags you":"Notifications: every message. Click to mute or switch to tagged-only.","aria-label":"Notification settings for this chat","aria-haspopup":"menu","aria-expanded":N===e.id,className:"p-1.5 rounded-lg bg-white/90 dark:bg-[rgb(var(--surface-2))] border border-cream-200 dark:border-white/10 text-ink-500 hover:text-ink-900",children:(null!==(b=e.notify_level)&&void 0!==b?b:"all")==="none"?(0,n.jsx)(s.Z,{size:13}):"mentions"===e.notify_level?(0,n.jsx)(o.Z,{size:13}):(0,n.jsx)(c.Z,{size:13})}),N===e.id&&(0,n.jsxs)("div",{role:"menu",onClick:e=>e.stopPropagation(),className:"absolute right-0 top-full mt-1 z-30 w-60 rounded-xl bg-white dark:bg-[rgb(var(--surface-2))] border border-cream-200 dark:border-white/10 shadow-lg py-1",children:[[{level:"all",icon:(0,n.jsx)(c.Z,{size:13}),label:"All messages",hint:"Chime and notify every time"},{level:"mentions",icon:(0,n.jsx)(o.Z,{size:13}),label:"Only when tagged",hint:"Silent unless someone @s you"},{level:"none",icon:(0,n.jsx)(s.Z,{size:13}),label:"Mute",hint:"Nothing from this chat notifies you"}].map(t=>{var a,l;return(0,n.jsxs)("button",{role:"menuitemradio","aria-checked":(null!==(a=e.notify_level)&&void 0!==a?a:"all")===t.level,onClick:async()=>{_(null),S(null);try{await g.setRoomNotify(e.id,t.level)}catch(e){S("Could not change notifications. Try again.")}},className:"w-full flex items-start gap-2.5 px-3 py-2 text-left hover:bg-cream-50 dark:hover:bg-white/5",children:[(0,n.jsx)("span",{className:"mt-0.5 text-ink-500",children:t.icon}),(0,n.jsxs)("span",{className:"flex-1 min-w-0",children:[(0,n.jsx)("span",{className:"block text-xs font-medium text-ink-900",children:t.label}),(0,n.jsx)("span",{className:"block text-[11px] text-ink-400",children:t.hint})]}),(null!==(l=e.notify_level)&&void 0!==l?l:"all")===t.level&&(0,n.jsx)(d.Z,{size:13,className:"mt-0.5 text-sage-600"})]},t.level)}),(0,n.jsx)("p",{className:"px-3 pt-1.5 pb-1 text-[10px] text-ink-300 border-t border-cream-100 dar
1k:border-white/5",children:"Only changes it for you."})]})]}),(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),g.setRoomPinned(e.id,!e.pinned)},title:e.pinned?"Unpin — it goes back to sitting in date order":"Pin to the top of your list. Only you see this.","aria-label":e.pinned?"Unpin this chat":"Pin this chat to the top",className:"p-1.5 rounded-lg bg-white/90 dark:bg-[rgb(var(--surface-2))] border border-cream-200 dark:border-white/10 text-ink-500 hover:text-ink-900",children:e.pinned?(0,n.jsx)(u.Z,{size:13}):(0,n.jsx)(m.Z,{size:13})}),(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),g.setArchived(e.id,!e.archived)},title:e.archived?"Put this back in your chats":"Archive — hides it from your list only. A new message brings it back.","aria-label":e.archived?"Unarchive this chat":"Archive this chat",className:"p-1.5 rounded-lg bg-white/90 dark:bg-[rgb(var(--surface-2))] border border-cream-200 dark:border-white/10 text-ink-500 hover:text-ink-900",children:e.archived?(0,n.jsx)(h.Z,{size:13}):(0,n.jsx)(x.Z,{size:13})}),e.can_delete&&(0,n.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),v(e),k("")},title:"Delete this group for everyone — this cannot be undone","aria-label":"Delete this group for everyone",className:"p-1.5 rounded-lg bg-white/90 dark:bg-[rgb(var(--surface-2))] border border-cream-200 dark:border-white/10 text-ink-500 hover:text-clay-600",children:(0,n.jsx)(p.Z,{size:13})})]})]},e.id)}),!g.showArchived&&z>0&&(0,n.jsxs)("button",{onClick:()=>g.setShowArchived(!0),className:"w-full flex items-center gap-2 px-4 py-3 text-xs text-ink-500 hover:text-ink-900 hover:bg-cream-50 dark:hover:bg-white/[0.03]",children:[(0,n.jsx)(x.Z,{size:13})," Archived ",(0,n.jsxs)("span",{className:"text-ink-400",children:["(",z,")"]})]}),b&&(0,n.jsx)(J,{room:b,value:y,onChange:k,busy:w,onCancel:()=>{v(null),k("")},onConfirm:async()=>{j(!0);try{await g.deleteRoom(b.id),v(null),k("")}catch(e){alert(e.message)}finally{j(!1)}}})]})}function J(e){let{room:t,value:a,onChange:l,busy:i,onCancel:r,onConfirm:s}=e,o=a.trim()===t.name.trim();return(0,n.jsx)("div",{className:"fixed inset-0 z-[95] flex items-center justify-center bg-ink-900/40 p-4",onClick:r,children:(0,n.jsxs)("div",{className:"w-full max-w-sm rounded-2xl bg-white dark:bg-[rgb(var(--surface))] border border-cream-200 dark:border-white/10 p-5 shadow-2xl",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("h3",{className:"font-display font-semibold text-ink-900 mb-1",children:["Delete “",t.name,"”?"]}),(0,n.jsxs)("p",{className:"text-sm text-ink-500 mb-1",children:["This deletes the group and every message in it ",(0,n.jsxs)("strong",{className:"text-ink-700",children:["for all ",t.members.length," people"]}),", not just you."]}),(0,n.jsx)("p",{className:"text-sm text-ink-500 mb-4",children:"It cannot be undone. To just remove it from your own list, archive it instead."}),(0,n.jsxs)("label",{className:"block text-xs text-ink-500 mb-1",children:["Type ",(0,n.jsx)("span",{className:"font-semibold text-ink-700",children:t.name})," to confirm"]}),(0,n.jsx)("input",{autoFocus:!0,value:a,disabled:i,onChange:e=>l(e.target.value),onKeyDown:e=>{"Enter"===e.key&&o&&!i&&s(),"Escape"===e.key&&r()},className:"input w-full mb-4","aria-label":"Type the group name to confirm deletion"}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:r,disabled:i,className:"btn-ghost flex-1",children:"Cancel"}),(0,n.jsx)("button",{onClick:s,disabled:!o||i,className:(0,F.cn)("flex-1 rounded-xl px-3 py-2 text-sm font-medium transition-colors",o&&!i?"bg-clay-600 text-white hover:bg-clay-700":"bg-cream-200 text-ink-400 cursor-default"),children:i?(0,n.jsx)(g.Z,{size:15,className:"animate-spin mx-auto"}):"Delete for everyone"})]})]})})}function B(){let e=(0,D.pA)(),{agent:t}=(0,A.Z)(),a=(null==t?void 0:t.role)==="owner"||(null==t?void 0:t.role)==="admin"||(null==t?void 0:t.role)==="manager";return(0,n.jsxs)("div",{className:"p-2 flex gap-2 border-b border-cream-100 dark:border-white/5",children:[(0,n.jsxs)("button",{onClick:()=>{e.loadDirectory(),e.setView("new-dm")},className:"btn-secondary text-sm flex-1",children:[(0,n.jsx)(f.Z,{size:14})," New message"]}),a&&(0,n.jsxs)("button",{onClick:()=>{e.loadDirectory(),e.setView("new-group")},className:"btn-ghost text-sm",children:[(0,n.jsx)(b.Z,{size:14})," Group"]})]})}function H(e){var t,a,i,r,s,o,c;let{wide:d=!1}=e,u=(0,D.pA)(),{agent:m}=(0,A.Z)(),[h,x]=(0,l.useState)(""),[f,b]=(0,l.useState)(!1),[E,T]=(0,l.useState)(!1),[U,J]=(0,l.useState)(null),[B,H]=(0,l.useState)({}),[q,V]=(0,l.useState)(null),[G,Y]=(0,l.useState)(0),K=(0,l.useRef)(null),Q=(0,l.useRef)(null),$=(0,l.useRef)(null),X=(0,l.useRef)(null),[ee,et]=(0,l.useState)(null),[ea,en]=(0,l.useState)(null),el=(0,l.useRef)(!0),ei=(0,l.useCallback)(()=>{el.current&&requestAnimationFrame(()=>{requestAnimationFrame(()=>{let e=K.current;e&&el.current&&(e.scrollTop=e.scrollHeight)})})},[]),er=(0,l.useCallback)(()=>{let e=K.current;e&&(el.current=e.scrollHeight-e.scrollTop-e.clientHeight<120)},[]),es=(0,l.useCallback)(async()=>{let e=K.current,t=e?e.scrollHeight-e.scrollTop:0;el.current=!1,await u.loadOlder(),requestAnimationFrame(()=>{let e=K.current;e&&(e.scrollTop=e.scrollHeight-t)})},[u]);(0,l.useEffect)(()=>{el.current=!0,ei()},[u.activeId,ei]),(0,l.useEffect)(()=>{ei()},[u.messagesLoading,u.messages,ei]),(0,l.useEffect)(()=>{let e=K.current;if(!e||"undefined"==typeof ResizeObserver)return;let t=new ResizeObserver(()=>{ei()});return t.observe(e),e.firstElementChild&&t.observe(e.firstElementChild),()=>t.disconnect()},[u.activeId,ei]),(0,l.useEffect)(()=>{J(null)},[u.activeId]),(0,l.useEffect)(()=>{let e=Q.current;e&&(e.style.height="auto",e.style.height="".concat(Math.min(e.scrollHeight,d?240:200),"px"))},[h,d]);let eo=(null!==(s=null===(t=u.activeRoom)||void 0===t?void 0:t.members)&&void 0!==s?s:[]).filter(e=>e.id!==(null==m?void 0:m.id)),ec=(()=>{var e,t,a;let n=u.activeRoom;if(!n)return"Message the team…";if("dm"===n.kind){let e=null===(a=eo[0])||void 0===a?void 0:null===(t=a.name)||void 0===t?void 0:t.trim();return e?"Message ".concat(e.split(" ")[0],"…"):"Message…"}return(null===(e=n.name)||void 0===e?void 0:e.trim())?"Message ".concat(n.name.trim(),"…"):"Message the group…"})(),ed=null!==(o=null==q?void 0:q.query.toLowerCase())&&void 0!==o?o:"",eu=(null===(a=u.activeRoom)||void 0===a?void 0:a.kind)==="group"&&D.Uz.some(e=>e.startsWith(ed)),em=q?eo.filter(e=>""===ed||e.name.toLowerCase().includes(ed)||e.email.toLowerCase().includes(ed)).slice(0,6):[],eh=q?[...eu?[{kind:"everyone"}]:[],...em.map(e=>({kind:"member",m:e}))]:[],ex=eh.length?Math.min(G,eh.length-1):0,ep=e=>{requestAnimationFrame(()=>{let t=Q.current;t&&(t.focus(),t.setSelectionRange(e,e))})},eg=(e,t)=>{let a=e.slice(0,t),n=a.lastIndexOf("@");if(-1===n){V(null);return}let l=0===n?" ":a[n-1];if(0!==n&&!/\s/.test(l)){V(null);return}let i=a.slice(n+1);if(/[\s@]/.test(i)){V(null);return}V({query:i,start:n}),Y(0)},ef=e=>{if(!q)return;let t=h.slice(0,q.start),a=h.slice(q.start+1+q.query.length),n="@".concat(e.name," ");x(t+n+a),H(t=>
1({...t,[e.id]:e.name})),V(null),ep((t+n).length)},eb=()=>{if(!q)return;let e=h.slice(0,q.start),t=h.slice(q.start+1+q.query.length),a="@everyone ";x(e+a+t),V(null),ep((e+a).length)},ev=e=>{"everyone"===e.kind?eb():ef(e.m)},ey=async()=>{var e,t;let a=h.trim();if(!a||f)return;b(!0);let n=Object.entries(B).filter(e=>{let[,t]=e;return(0,D.fR)(a,t)}).map(e=>{let[t]=e;return t}),l=null!==(t=null===(e=u.replyingTo)||void 0===e?void 0:e.id)&&void 0!==t?t:null;x(""),H({}),V(null),u.setReplyingTo(null);try{await u.send(a,n,void 0,l)}catch(e){x(a)}finally{b(!1)}},ek=async e=>{if(E)return;T(!0);let t=h.trim(),a=Object.entries(B).filter(e=>{let[,a]=e;return(0,D.fR)(t,a)}).map(e=>{let[t]=e;return t});try{var n,l;let i=await u.uploadImage(e);x(""),H({}),V(null),await u.send(t,a,i,null!==(l=null===(n=u.replyingTo)||void 0===n?void 0:n.id)&&void 0!==l?l:null),u.setReplyingTo(null)}catch(e){}finally{T(!1)}},ew=async e=>{if(E)return;T(!0);let t=h.trim(),a=Object.entries(B).filter(e=>{let[,a]=e;return(0,D.fR)(t,a)}).map(e=>{let[t]=e;return t});try{var n,l;let i=await u.uploadFile(e);x(""),H({}),V(null),await u.send(t,a,void 0,null!==(l=null===(n=u.replyingTo)||void 0===n?void 0:n.id)&&void 0!==l?l:null,i),u.setReplyingTo(null)}catch(e){en(e instanceof Error?e.message:"That file could not be attached")}finally{T(!1)}},ej=(0,P._)(x),eN=(null===(i=u.activeRoom)||void 0===i?void 0:i.kind)==="group",e_=null!==(c=null===(r=u.activeRoom)||void 0===r?void 0:r.members)&&void 0!==c?c:[];return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{ref:K,onScroll:er,className:(0,F.cn)("flex-1 overflow-y-auto overscroll-contain py-3",d?"px-3 md:px-6":"px-4"),children:(0,n.jsxs)("div",{className:(0,F.cn)("flex flex-col gap-2",d&&"mx-auto w-full max-w-[820px]"),children:[u.messagesLoading&&(0,n.jsx)("div",{className:"text-center text-sm text-ink-400 py-8",role:"status",children:"Loading…"}),!u.messagesLoading&&0===u.messages.length&&(0,n.jsx)("div",{className:"text-center text-sm text-ink-400 py-8",children:"No messages yet. Say hello."}),!u.messagesLoading&&u.hasOlder&&(0,n.jsx)("div",{className:"text-center py-3",children:(0,n.jsx)("button",{type:"button",onClick:()=>{es()},disabled:u.loadingOlder,className:"btn-secondary text-xs",children:u.loadingOlder?"Loading…":"Load earlier messages"})}),u.messages.map((e,t)=>{var a,i,r,s,o,c;let h;if(null===e.sender_id)return(0,n.jsx)("div",{className:"text-center text-[11px] text-ink-400 py-1.5 px-4",children:e.body},e.id);let x=e.sender_id===(null==m?void 0:m.id),g=u.messages[t-1],f=(null==g?void 0:g.sender_id)!==e.sender_id,b=!g||new Date(g.created_at).toDateString()!==new Date(e.created_at).toDateString(),j=!x&&eN&&f,N=!x&&eN,_=(null!==(i=e.mentions)&&void 0!==i?i:[]).flatMap(e=>{let t=e_.find(t=>t.id===e);return t?[t.name,t.name.split(" ")[0]]:[]});(0,D.db)(e.body)&&_.push(...D.Uz);let C=U===e.id;return(0,n.jsxs)(l.Fragment,{children:[b&&(0,n.jsxs)("div",{className:"flex items-center gap-3 py-2 px-1 select-none",children:[(0,n.jsx)("span",{className:"h-px flex-1 bg-cream-200 dark:bg-white/10"}),(0,n.jsx)("span",{className:"text-[10.5px] font-medium text-ink-400 whitespace-nowrap",children:(0,R.tm)(e.created_at)}),(0,n.jsx)("span",{className:"h-px flex-1 bg-cream-200 dark:bg-white/10"})]}),(0,n.jsxs)("div",{className:(0,F.cn)("flex flex-col",x?"items-end":"items-start"),children:[j&&(0,n.jsx)("span",{className:(0,F.cn)("text-[11px] text-ink-500 mb-0.5",N?"ml-[38px]":"ml-1"),children:e.sender_name}),(0,n.jsxs)("div",{className:(0,F.cn)("flex items-end gap-2",x?"flex-row-reverse":"flex-row",d?"max-w-[85%] md:max-w-[68%]":"max-w-[85%]"),children:[N&&(f?(0,n.jsx)(I,{name:e.sender_name,size:28,avatarUrl:e.sender_avatar_url}):(0,n.jsx)("span",{className:"w-7 shrink-0","aria-hidden":!0})),(0,n.jsxs)("div",{className:"group flex items-center gap-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex flex-col gap-1 min-w-0",children:[!e.deleted_at&&e.image_url&&(0,n.jsx)("a",{href:e.image_url,target:"_blank",rel:"noreferrer",className:(0,F.cn)("block",x?"self-end":"self-start"),children:(0,n.jsx)("img",{src:e.image_url,alt:"Shared image",className:"rounded-xl object-contain max-w-[240px] max-h-[280px] border border-cream-200 dark:border-white/10"})}),!e.deleted_at&&e.file_url&&(0,n.jsxs)("a",{href:e.file_url,target:"_blank",rel:"noreferrer",download:null!==(r=e.file_name)&&void 0!==r?r:void 0,className:(0,F.cn)("group flex items-center gap-2.5 rounded-xl border px-3 py-2 max-w-[280px] transition-colors","border-cream-200 bg-cream-50 hover:bg-cream-100 dar
1k:border-white/10 dark:bg-white/[0.04] dark:hover:bg-white/[0.07]",x?"self-end":"self-start"),children:[(0,n.jsx)(v.Z,{size:18,className:"shrink-0 text-ink-500 dark:text-white/50"}),(0,n.jsxs)("span",{className:"min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"block truncate text-[13px] font-medium text-ink-900 dark:text-white/90",children:null!==(s=e.file_name)&&void 0!==s?s:"Attachment"}),(0,n.jsx)("span",{className:"block text-[11px] text-ink-400 dark:text-white/40",children:(0,z.sSd)(e.file_size)})]}),(0,n.jsx)(y.Z,{size:15,className:"shrink-0 text-ink-400 opacity-0 group-hover:opacity-100 transition-opacity dark:text-white/40"})]}),e.reply_to&&(0,n.jsxs)("div",{className:(0,F.cn)("flex items-stretch gap-1.5 text-[11px] max-w-full",x?"self-end":"self-start"),children:[(0,n.jsx)("span",{className:(0,F.cn)("w-0.5 rounded-full shrink-0",x?"bg-clay-300":"bg-cream-300 dark:bg-white/20")}),(0,n.jsxs)("span",{className:"min-w-0 py-0.5",children:[(0,n.jsx)("span",{className:"font-medium text-ink-600 dark:text-white/70",children:e.reply_to.sender_name}),(0,n.jsx)("span",{className:"text-ink-400 dark:text-white/40",children:" \xb7 "}),(0,n.jsx)("span",{className:"text-ink-400 dark:text-white/40 line-clamp-1 break-words [overflow-wrap:anywhere]",children:e.reply_to.body})]})]}),e.deleted_at?(0,n.jsxs)("div",{className:"text-xs italic text-ink-400 py-1 self-start",children:["Message deleted by ",x?"you":e.sender_name||"the author"]}):C?(0,n.jsx)(W,{initial:e.body,onCancel:()=>J(null),onSave:async t=>{await u.editMessage(e.id,t),J(null)}}):e.body.trim()&&(0,n.jsx)("div",{className:(0,F.cn)("rounded-2xl px-3 py-1.5 text-sm whitespace-pre-wrap break-words [overflow-wrap:anywhere]",x?"bg-clay-500 dark:bg-clay-400 text-white rounded-br-sm self-end":"bg-cream-100 dark:bg-white/[0.06] text-ink-900 rounded-bl-sm self-start"),children:(c=e.body,h=0,(0,O.Bc)(c,{linkClassName:(0,F.cn)("underline underline-offset-2 break-all hover:opacity-80",x?"text-white decoration-white/50":"text-tsblue-500 dark:text-tsblue-300"),renderText:e=>(function(e,t,a,l){let i;let r=Array.from(new Set(t.filter(Boolean))).sort((e,t)=>t.length-e.length);if(0===r.length)return[e];let s=RegExp("@(?:".concat(r.map(L).join("|"),")(?![\\p{L}\\p{N}])"),"giu"),o=[],c=0;for(;null!==(i=s.exec(e));)i.index>c&&o.push(e.slice(c,i.index)),o.push((0,n.jsx)("span",{className:(0,F.cn)("rounded px-1 font-medium",a?"bg-white/25 text-white":"bg-clay-100 text-clay-700 dark:bg-clay-500/25 dark:text-clay-100"),children:i[0]},"m".concat(l()))),c=i.index+i[0].length,s.lastIndex===i.index&&s.lastIndex++;return c<e.length&&o.push(e.slice(c)),o})(e,_,x,()=>h++)}))})]}),!C&&!e.deleted_at&&(0,n.jsxs)("div",{className:"flex opacity-100 md:opacity-0 md:group-hover:opacity-100 focus-within:opacity-100 transition-opacity items-center gap-0.5 shrink-0",children:[x&&e.body.trim()&&(0,n.jsx)("button",{type:"button",onClick:()=>J(e.id),title:"Edit this message","aria-label":"Edit this message",className:"p-1 rounded-full text-ink-400 hover:text-ink-700 hover:bg-cream-100 dark:hover:bg-white/[0.06]",children:(0,n.jsx)(k.Z,{size:14})}),x&&(0,n.jsx)("button",{type:"button",onClick:()=>{window.confirm("Delete this message? Everyone will see that you deleted it.")&&u.deleteMessage(e.id)},title:"Delete this message","aria-label":"Delete this message",className:"p-1 rounded-full text-ink-400 hover:text-clay-600 hover:bg-cream-100 dark:hover:bg-white/[0.06]",children:(0,n.jsx)(p.Z,{size:14})}),(0,n.jsx)("button",{type:"button",onClick:()=>u.setReplyingTo(e),title:"Reply to this message","aria-label":"Reply to this message",className:"p-1 rounded-full text-ink-400 hover:text-ink-700 hover:bg-cream-100 dark:hover:bg-white/[0.06]",children:(0,n.jsx)(w.Z,{size:14})}),(0,n.jsx)(M.LG,{onPick:t=>u.react(e.id,t),closeOnPick:!0,align:x?"right":"left",direction:"up",iconSize:15,title:"React",className:"p-1 rounded-full text-ink-400 hover:text-ink-700 hover:bg-cream-100 dark:hover:bg-white/[0.06]"})]})]})]}),(null!==(o=null===(a=e.reactions)||void 0===a?void 0:a.length)&&void 0!==o?o:0)>0&&(0,n.jsx)("div",{className:(0,F.cn)("flex flex-wrap gap-1 mt-1",x?"justify-end":"justify-start"),children:e.reactions.map(t=>{let a=!!u.myId&&t.agent_ids.includes(u.myId),l=t.agent_ids.map(e=>{var t;return e===u.myId?"You":null===(t=e_.find(t=>
1t.id===e))||void 0===t?void 0:t.name}).filter(Boolean),i=l.length?"".concat(l.join(", ")," reacted ").concat(t.emoji).concat(a?" — click to remove yours":""):a?"Remove your reaction":"React";return(0,n.jsxs)("button",{type:"button",onClick:()=>u.react(e.id,t.emoji),className:(0,F.cn)("inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-xs transition-colors",a?"border-clay-300 bg-clay-50 text-clay-700 dark:border-clay-500/40 dark:bg-clay-500/15 dark:text-clay-200":"border-cream-200 bg-white text-ink-600 hover:bg-cream-50 dark:border-white/10 dark:bg-white/[0.04] dark:text-white/70"),title:i,children:[(0,n.jsx)("span",{className:"text-sm leading-none",children:t.emoji}),(0,n.jsx)("span",{className:"tabular-nums",children:t.count})]},t.emoji)})}),(0,n.jsxs)("span",{className:(0,F.cn)("text-[10px] text-ink-400 mt-0.5 px-1",N&&"ml-[36px]"),title:(0,R.CQ)(e.created_at),children:[(0,R.i1)(e.created_at),e.edited_at&&(0,n.jsx)("span",{className:"italic",children:" \xb7 edited"})]})]})]},e.id)})]})}),(0,n.jsxs)("div",{className:(0,F.cn)("relative border-t border-cream-200 dark:border-white/10",d?"px-6 pt-3 pb-5":"px-3 pt-2 pb-4"),children:[u.replyingTo&&(0,n.jsxs)("div",{className:(0,F.cn)("flex items-start gap-2 mb-1.5 rounded-xl border border-cream-200 dark:border-white/10 bg-cream-100/70 dark:bg-white/[0.05] px-3 py-2",d&&"mx-auto max-w-[820px]"),children:[(0,n.jsx)(w.Z,{size:13,className:"text-ink-400 mt-0.5 shrink-0"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1 text-[11.5px] leading-snug",children:[(0,n.jsx)("span",{className:"text-ink-500",children:"Replying to "}),(0,n.jsx)("span",{className:"font-medium text-ink-700 dark:text-white/80",children:u.replyingTo.sender_name}),(0,n.jsx)("div",{className:"text-ink-400 dark:text-white/40 line-clamp-2 break-words [overflow-wrap:anywhere]",children:u.replyingTo.body.trim()||(u.replyingTo.image_url?"\uD83D\uDCF7 Photo":u.replyingTo.file_name?"\uD83D\uDCCE ".concat(u.replyingTo.file_name):"")})]}),(0,n.jsx)("button",{type:"button",onClick:()=>u.setReplyingTo(null),className:"p-0.5 rounded text-ink-400 hover:text-ink-700 shrink-0","aria-label":"Stop replying to that message",title:"Stop replying",children:(0,n.jsx)(j.Z,{size:13})})]}),(0,n.jsx)("div",{className:(0,F.cn)(d&&"mx-auto w-full max-w-[820px]"),children:(0,n.jsx)(Z.E,{value:ee,busy:E||f,hint:h.trim()?"Your text will go with it as the caption":"Add a caption below, or just send it",onCancel:()=>et(null),onSend:()=>{let e=null==ee?void 0:ee.file;et(null),e&&ek(e)}})}),ea&&(0,n.jsxs)("div",{className:(0,F.cn)("mb-1.5 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-300 flex items-start gap-2",d&&"mx-auto w-full max-w-[820px]"),children:[(0,n.jsx)("span",{className:"flex-1 min-w-0",children:ea}),(0,n.jsx)("button",{type:"button",onClick:()=>en(null),className:"shrink-0 underline",children:"Dismiss"})]}),(0,n.jsxs)("div",{className:(0,F.cn)("relative flex items-end gap-1.5 w-full rounded-2xl border border-cream-200 dark:border-white/10 bg-cream-50 dark:bg-white/[0.03] px-2 py-1.5 focus-within:border-clay-300 dark:focus-within:border-white/20 transition-colors",d&&"mx-auto max-w-[820px]"),children:[q&&eh.length>0&&(0,n.jsx)("div",{className:"absolute left-2 right-2 bottom-full mb-2 rounded-xl border border-cream-200 dark:border-white/10 bg-white dark:bg-[rgb(var(--surface-2))] shadow-xl overflow-hidden z-10",children:eh.map((e,t)=>{var a,l;return(0,n.jsx)("button",{type:"button",onMouseDown:t=>{t.preventDefault(),ev(e)},onMouseEnter:()=>Y(t),className:(0,F.cn)("w-full flex items-center gap-2 px-3 py-2 text-left",t===ex?"bg-cream-100 dark:bg-white/[0.06]":"hover:bg-cream-50 dark:hover:bg-white/[0.03]"),children:"everyone"===e.kind?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"w-[26px] h-[26px] rounded-full bg-clay-100 dark:bg-white/10 text-clay-700 dark:text-white flex items-center justify-center shrink-0",children:(0,n.jsx)(N.Z,{size:13})}),(0,n.jsx)("span",{className:"text-sm text-ink-900",children:"everyone"}),(0,n.jsxs)("span",{className:"text-xs text-ink-400 ml-auto",children:["notifies all ",null!==(l=null===(a=u.activeRoom)||void 0===a?void 0:a.members.length)&&void 0!==l?l:1," people"]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(I,{name:e.m.name,size:26,avatarUrl:e.m.avatarUrl}),(0,n.jsx)("span",{className:"text-sm text-ink-900 truncate",children:e.m.name}),(0,n.jsx)("span",{className:"text-xs text-ink-400 truncate ml-auto",children:e.m.email})]})},"everyone"===e.kind?"@everyone":e.m.id)})}),(0,n.jsx)(M.LG,{onPick:e=>{var t,a;let n=Q.current,l=null!==(t=null==n?void 0:n.selectionStart)&&void 0!==t?t:h.length,i=null!==(a=null==n?void 0:n.selectionEnd)&&void 0!==a?a:l;x(h.slice(0,l)+e+h.slice(i)),ep(l+e.length)},align:"left",direction:"up"}),(0,n.jsx)("input",{ref:$,type:"file",accept:"image/*",className:"hidden",onChange:e=>{var t;let a=null===(t=e.target.files)||void 0===t?void 0:t[0];a&&et((0,Z.n)(a)),e.target.value=""}}),(0,n.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=$.current)||void 0===e?void 0:e.click()},disabled:E||f,className:"btn-secondary shrink-0 px-2.5",title:"Attach an image","aria-label":"Attach an image",children:E?(0,n.jsx)(g.Z,{size:16,className:"animate-spin"}):(0,n.jsx)(_.Z,{size:16})}),(0,n.jsx)("input",{ref:X,type:"file",accept:z.Jj6,className:"hidden",onChange:e=>{var t;let a=null===(t=e.target.files)||void 0===t?void 0:t[0];en(null),a&&ew(a),e.target.value=""}}),(0,n.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=X.current)||void 0===e?void 0:e.click()},disabled:E||f,className:"btn-secondary shrink-0 px-2.5",title:"Attach a file (PDF, Word, Excel, CSV)","aria-label":"Attach a file",children:(0,n.jsx)(C.Z,{size:16})}),(0,n.jsx)("textarea",{ref:Q,value:h,onChange:e=>{var t;let a=e.target.value;x(a),eg(a,null!==(t=e.target.selectionStart)&&void 0!==t?t:a.length)},onKeyDown:e=>{if(q&&eh.length){if("ArrowDown"===e.key){e.preventDefault(),Y(e=>Math.min(e+1,eh.length-1));return}if("ArrowUp"===e.key){e.preventDefault(),Y(e=>Math.max(e-1,0));return}if("Enter"===e.key||"Tab"===e.key){e.preventDefault(),ev(eh[ex]);return}if("Escape"===e.key){e.preventDefault(),V(null);return}}"Enter"!==e.key||e.shiftKey||(e.preventDefault(),ey())},onPaste:e=>{let t=[...e.clipboardData.items].find(e=>e.type.startsWith("image/"));if(!t){ej(e);return}e.preventDefault();let a=t.getAsFile();a&&et((0,Z.n)(a))},rows:1,placeholder:ec,className:(0,F.cn)("resize-none overflow-y-auto flex-1 leading-relaxed bg-transparent border-0 outline-none px-2 py-1.5 text-ink-900 placeholder:text-ink-400","text-[16px] md:text-sm",d?"min-h-[36px] max-h-[240px]":"min-h-[36px] max-h-[200px]")}),(0,n.jsx)("button",{onClick:ey,disabled:!h.trim()||f,className:(0,F.cn)("shrink-0 rounded-full w-9 h-9 flex items-center justify-center transition-colors",h.trim()&&!f?"bg-clay-500 text-white hover:bg-clay-600":"bg-cream-200 text-ink-400 dark:bg-white/10 dark:text-white/40 cursor-default"),"aria-label":"Send",children:f?(0,n.jsx)(g.Z,{size:16,className:"animate-spin"}):(0,n.jsx)(S.Z,{size:16})})]})]})]})}function W(e){let{initial:t,onSave:a,onCancel:i}=e,[r,s]=(0,l.useState)(t),[o,c]=(0,l.useState)(!1),[u,m]=(0,l.useState)(null),h=(0,l.useRef)(null);(0,l.useEffect)(()=>{let e=h.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},[]),(0,l.useEffect)(()=>{let e=h.current;e&&(e.style.height="auto",e.style.height="".concat(Math.min(e.scrollHeight,160),"px"))},[r]);let x=async()=>{let e=r.trim();if(!o){if(!e||e===t.trim()){i();return}c(!0),m(null);try{await a(e)}catch(e){m("Couldn’t save that. Try again."),c(!1)}}};return(0,n.jsxs)("div",{className:"flex flex-col gap-1 self-end min-w-[200px]",children:[(0,n.jsx)("textarea",{ref:h,value:r,disabled:o,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),x()),"Escape"===e.key&&(e.preventDefault(),i())},rows:1,"aria-label":"Edit message",className:"w-full resize-none rounded-2xl border border-clay-500 bg-white dark:bg-[rgb(var(--surface-2))] px-3 py-1.5 text-[16px] md:text-sm text-ink-900 outline-none disabled:opacity-50 leading-relaxed"}),(0,n.jsxs)("div",{className:"flex items-center gap-2 px-1",children:[u?(0,n.jsx)("span",{className:"text-[10.5px] text-clay-600",children:u}):(0,n.jsxs)("span",{className:"text-[10.5px] text-ink-400",children:[(0,n.jsx)("b",{className:"font-semibold text-ink-700",children:"Enter"})," to save \xb7 ",(0,n.jsx)("b",{className:"font-semibold text-ink-700",children:"Esc"})," to cancel"]}),(0,n.jsx)("button",{type:"button",onClick:i,className:"ml-auto p-1 rounded text-ink-400 hover:text-ink-900","aria-label":"Cancel edit",children:(0,n.jsx)(j.Z,{size:13})}),(0,n.jsx)("button",{type:"button",onClick:x,disabled:o,className:"p-1 rounded text-ink-400 hover:text-ink-900","aria-label":"Save edit",children:o?(0,n.jsx)(g.Z,{size:13,className:"animate-spin"}):(0,n.jsx)(d.Z,{size:13})})]})]})}function q(e){let{onDone:t}=e,a=(0,D.pA)();return(0,n.jsxs)("div",{className:"w-[260px]",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-cream-200 dark:border-white/10 text-xs font-semibold text-ink-900",children:"When a teammate messages you"}),(0,n.jsx)("div",{role:"radiogroup","aria-label":"Chat sound",children:T.xM.map(e=>(0,n.jsxs)("button",{type:"button",role:"radio","aria-checked":a.sound===e.id,onClick:()=>{a.setSound(e.id),a.previewSound(e.id)},className:(0,F.cn)("w-full flex items-center gap-2.5 px-3 py-2 text-left text-sm hover:bg-cream-50 dark:hover:bg-white/[0.03]",a.sound===e.id&&"bg-cream-100 dar
1k:bg-white/[0.06]"),children:[(0,n.jsx)("span",{className:(0,F.cn)("w-3.5 h-3.5 rounded-full border shrink-0 flex items-center justify-center",a.sound===e.id?"border-clay-500":"border-ink-300"),children:a.sound===e.id&&(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-clay-500"})}),(0,n.jsx)("span",{className:"text-ink-900",children:e.label}),(0,n.jsx)("span",{className:"ml-auto text-[11px] text-ink-400",children:e.hint})]},e.id))}),(0,n.jsxs)("div",{className:"px-3 py-2.5 border-t border-cream-200 dark:border-white/10 flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-[11px] text-ink-500 shrink-0",children:"Volume"}),(0,n.jsx)("input",{type:"range",min:0,max:100,step:5,value:a.soundVolume,disabled:"off"===a.sound,onChange:e=>a.setSoundVolume(Number(e.target.value)),onMouseUp:()=>a.previewSound(),onTouchEnd:()=>a.previewSound(),"aria-label":"Chat sound volume",className:"flex-1 accent-clay-500 disabled:opacity-40"}),(0,n.jsxs)("span",{className:"text-[11px] text-ink-400 tabular-nums w-8 text-right",children:[a.soundVolume,"%"]})]}),t&&(0,n.jsx)("div",{className:"px-3 pb-2",children:(0,n.jsx)("button",{type:"button",onClick:t,className:"btn-ghost w-full text-xs",children:"Done"})})]})}function V(){let e=(0,D.pA)(),[t,a]=(0,l.useState)(""),[i,r]=(0,l.useState)(null),s=e.directory.filter(e=>(e.full_name||e.email).toLowerCase().includes(t.toLowerCase()));return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"p-3 border-b border-cream-100 dark:border-white/5",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(E.Z,{size:14,className:"absolute left-3 top-3 text-ink-400"}),(0,n.jsx)("input",{value:t,onChange:e=>a(e.target.value),placeholder:"Search teammates",className:"input pl-9",autoFocus:!0})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[s.map(t=>(0,n.jsxs)("button",{disabled:i===t.id,onClick:async()=>{r(t.id);try{await e.startDm(t.id)}finally{r(null)}},className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-cream-50 dark:hover:bg-white/[0.03] text-left",children:[(0,n.jsx)(I,{name:t.full_name||t.email,size:32,avatarUrl:t.avatar_url}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-ink-900 truncate",children:t.full_name||t.email.split("@")[0]}),(0,n.jsx)("div",{className:"text-xs text-ink-500 truncate",children:t.email})]}),i===t.id&&(0,n.jsx)(g.Z,{size:14,className:"animate-spin ml-auto text-ink-400"})]},t.id)),0===s.length&&(0,n.jsx)("div",{className:"p-6 text-center text-sm text-ink-400",children:"No teammates found."})]})]})}function G(){let e=(0,D.pA)(),[t,a]=(0,l.useState)(""),[i,r]=(0,l.useState)({}),[s,o]=(0,l.useState)(!1),c=Object.keys(i).filter(e=>i[e]),d=()=>{let t=e.directory.filter(e=>i[e.id]).map(e=>(e.full_name||e.email.split("@")[0]).split(" ")[0]);return(t.length<=3?t.join(", "):"".concat(t.slice(0,3).join(", ")," +").concat(t.length-3)).slice(0,80)},u=async()=>{if(0!==c.length&&!s){o(!0);try{await e.createGroup(t.trim()||d(),c)}catch(e){alert(e.message)}finally{o(!1)}}};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"p-3 space-y-2 border-b border-cream-100 dark:border-white/5",children:[(0,n.jsx)("input",{value:t,onChange:e=>a(e.target.value),placeholder:"Group name (optional)",className:"input",autoFocus:!0}),(0,n.jsxs)("div",{className:"text-xs text-ink-500",children:["Pick members (",c.length," selected)",!t.trim()&&c.length>0?' \xb7 will be named "'.concat(d(),'"'):""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:e.directory.map(e=>(0,n.jsxs)("label",{className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-cream-50 dark:hover:bg-white/[0.03] cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:!!i[e.id],onChange:t=>r(a=>({...a,[e.id]:t.target.checked}))}),(0,n.jsx)(I,{name:e.full_name||e.email,size:30,avatarUrl:e.avatar_url}),(0,n.jsx)("span",{className:"text-sm text-ink-900 truncate",children:e.full_name||e.email.split("@")[0]})]},e.id))}),(0,n.jsxs)("div",{className:"p-3 border-t border-cream-200 dark:border-white/10",children:[(0,n.jsxs)("button",{onClick:u,disabled:0===c.length||s,className:"btn-primary w-full",children:[s?(0,n.jsx)(g.Z,{size:14,className:"animate-spin"}):(0,n.jsx)(b.Z,{size:14})," Create group"]}),0===c.length&&(0,n.jsx)("div",{className:"mt-1.5 text-center text-[11px] text-ink-400",children:"Pick at least one person to create a group."})]})]})}function Y(e){var t,a;let{onlineIds:i}=e,r=(0,D.pA)(),{agent:s}=(0,A.Z)(),[o,c]=(0,l.useState)(null),d=null!==(a=null===(t=r.activeRoom)||void 0===t?void 0:t.members)&&void 0!==a?a:[],u=async e=>{let t=e.id===(null==s?void 0:s.id);if(!t||window.confirm("Leave this group? You’ll stop receiving its messages.")){c(e.id);try{await r.removeMember(e.id),t&&r.setView("list")}catch(e){alert(e.message)}finally{c(null)}}};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"p-2 border-b border-cream-100 dar
1k:border-white/5",children:(0,n.jsxs)("button",{onClick:()=>{r.loadDirectory(),r.setView("add-members")},className:"btn-secondary text-sm w-full",children:[(0,n.jsx)(N.Z,{size:14})," Add people"]})}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto",children:d.map(e=>{let t=e.id===(null==s?void 0:s.id),a="owner"===e.role,l=i.has(e.id);return(0,n.jsxs)("div",{className:"w-full flex items-center gap-3 px-4 py-2.5 border-b border-cream-50 dark:border-white/5",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(I,{name:e.name,size:34,avatarUrl:e.avatarUrl}),l&&(0,n.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full bg-sage-500 border-2 border-white dark:border-[rgb(var(--surface))]"})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"text-sm font-medium text-ink-900 truncate",children:[e.name,t&&(0,n.jsx)("span",{className:"text-ink-400 font-normal",children:" (you)"})]}),(0,n.jsx)("div",{className:"text-xs text-ink-500 truncate",children:e.email})]}),t?(0,n.jsx)("button",{onClick:()=>u(e),disabled:o===e.id,className:"btn-ghost p-1.5 text-ink-400 hover:text-clay-600",title:"Leave group","aria-label":"Leave group",children:o===e.id?(0,n.jsx)(g.Z,{size:15,className:"animate-spin"}):(0,n.jsx)(j.Z,{size:15})}):a?(0,n.jsx)("span",{className:"text-[11px] text-ink-400 shrink-0",children:"Creator"}):(0,n.jsx)("button",{onClick:()=>u(e),disabled:o===e.id,className:"btn-ghost p-1.5 text-ink-400 hover:text-clay-600",title:"Remove ".concat(e.name),"aria-label":"Remove ".concat(e.name),children:o===e.id?(0,n.jsx)(g.Z,{size:15,className:"animate-spin"}):(0,n.jsx)(j.Z,{size:15})})]},e.id)})})]})}function K(){var e,t;let a=(0,D.pA)(),[i,r]=(0,l.useState)(""),[s,o]=(0,l.useState)({}),[c,d]=(0,l.useState)(!1),u=new Set((null!==(t=null===(e=a.activeRoom)||void 0===e?void 0:e.members)&&void 0!==t?t:[]).map(e=>e.id)),m=a.directory.filter(e=>!u.has(e.id)&&(e.full_name||e.email).toLowerCase().includes(i.toLowerCase())),h=Object.keys(s).filter(e=>s[e]),x=async()=>{if(0!==h.length&&!c){d(!0);try{await a.addMembers(h),a.setView("members")}catch(e){alert(e.message)}finally{d(!1)}}};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"p-3 border-b border-cream-100 dark:border-white/5",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(E.Z,{size:14,className:"absolute left-3 top-3 text-ink-400"}),(0,n.jsx)("input",{value:i,onChange:e=>r(e.target.value),placeholder:"Search teammates",className:"input pl-9",autoFocus:!0})]})}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[m.map(e=>(0,n.jsxs)("label",{className:"w-full flex items-center gap-3 px-4 py-2.5 hover:bg-cream-50 dark:hover:bg-white/[0.03] cursor-pointer",children:[(0,n.jsx)("input",{type:"checkbox",checked:!!s[e.id],onChange:t=>o(a=>({...a,[e.id]:t.target.checked}))}),(0,n.jsx)(I,{name:e.full_name||e.email,size:30,avatarUrl:e.avatar_url}),(0,n.jsx)("span",{className:"text-sm text-ink-900 truncate",children:e.full_name||e.email.split("@")[0]})]},e.id)),0===m.length&&(0,n.jsx)("div",{className:"p-6 text-center text-sm text-ink-400",children:i?"No teammates found.":"Everyone’s already in this group."})]}),(0,n.jsxs)("div",{className:"p-3 border-t border-cream-200 dark:border-white/10",children:[(0,n.jsxs)("button",{onClick:x,disabled:0===h.length||c,className:"btn-primary w-full",children:[c?(0,n.jsx)(g.Z,{size:14,className:"animate-spin"}):(0,n.jsx)(N.Z,{size:14})," ",0===h.length?"Add people":"Add ".concat(h.length," ").concat(1===h.length?"person":"people")]}),(0,n.jsx)("div",{className:"mt-1.5 text-center text-[11px] text-ink-400",children:"They’ll see the group’s full history once added."})]})]})}},24605:function(e,t,a){a.d(t,{CN:function(){return r},CQ:function(){return c},Fz:function(){return s},Gf:function(){return o},H0:function(){return d},QA:function(){return h},i1:function(){return m},tm:function(){return x},x9:function(){return u}});var n=a(92109),l=a(68610),i=a(14781);function r(e){if(!e||e.startsWith("+0"))return"—";if(e.startsWith("+61")&&12===e.length){let t=e.slice(3);return t.startsWith("4")?"+61 ".concat(t.slice(0,3)," ").concat(t.slice(3,6)," ").concat(t.slice(6)):"+61 ".concat(t.slice(0,1)," ").concat(t.slice(1,5)," ").concat(t.slice(5))}return e}function s(e){return null==e?"$0":new Intl.NumberFormat("en-AU",{style:"currency",currency:"AUD",currencyDisplay:"narrowSymbol",maximumFractionDigits:e%1==0?0:2}).format(e)}function o(e){if(!e)return"";try{return(0,n.Q)(new Date(e),{addSuffix:!0})}catch(e){return""}}function c(e){if(!e)return"";try{return(0,l.WU)(new Date(e),"d MMM yyyy, HH:mm")}catch(e){return""}}function d(e){if(!e)return"";try{return(0,l.WU)(new Date(e),"dd-MMM-yy")}catch(e){return""}}function u(e){if(!e||e<1)return"0s";let t=Math.floor(e/60),a=Math.floor(e%60);return 0===t?"".concat(a,"s"):"".concat(t,"m ").concat(String(a).padStart(2,"0"),"s")}function m(e){if(!e)return"";try{return(0,l.WU)(new Date(e),"h:mm a").replace("AM","am").replace("PM","pm")}catch(e){return""}}function h(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Date;if(!e)return"";try{let a=new Date(e);if(Number.isNaN(a.getTime()))return"";let n=(0,l.WU)(a,"h:mm a").replace("AM","am").replace("PM","pm"),r=(0,i.B)(a,t,{addSuffix:!0});if(a.toDateString()===t.toDateString())return"".concat(n," \xb7 ").concat(r);let s=a.getFullYear()===t.getFullYear()?(0,l.WU)(a,"EEE d MMM"):(0,l.WU)(a,"EEE d MMM yyyy");return"".concat(s,", ").concat(n," \xb7 ").concat(r)}catch(e){return""}}function x(e){if(!e)return"";try{let t=new Date(e),a=new Date,n=new Date;n.setDate(n.getDate()-1);let i=(e,t)=>e.toDateString()===t.toDateString();if(i(t,a))return"Today";if(i(t,n))return"Yesterday";return(0,l.WU)(t,"EEEE d MMMM yyyy")}catch(e){return""}}},65675:function(e,t,a){a.d(t,{Uz:function(){return g}
1,oF:function(){return y},fR:function(){return p},db:function(){return f},Dm:function(){return x},pA:function(){return k}});var n=a(37821),l=a(58078),i=a(64790),r=a(10017),s=a(45142),o=a(72952),c=a(65094),d=a(23890),u=a(85480);let m="ts-chat-pinned",h="ts-chat-minimised";function x(e){let t=window.open("/team-chat/popout","ts-team-chat");if(t){try{t.focus()}catch(e){}null==e||e()}}function p(e,t){return!!t&&RegExp("@".concat(t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"(?![\\p{L}\\p{N}])"),"iu").test(e)}let g=["everyone","all"];function f(e){return g.some(t=>p(e,t))}function b(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if(f(e))return t.map(e=>e.id);let n=new Set;for(let l of t){let i=l.name.split(" ")[0],r=p(e,l.name),s=p(e,i);if(r||s){if(a.includes(l.id)||r){n.add(l.id);continue}1===t.filter(e=>e.name.split(" ")[0].toLowerCase()===i.toLowerCase()).length&&n.add(l.id)}}return[...n]}let v=(0,l.createContext)(null);function y(e){var t,a,x,p,g,f,y;let{children:k}=e,{agent:w,mutate:j}=(0,o.Z)(),[N,_]=(0,l.useState)(!1),[C,S]=(0,l.useState)(!1),[E,D]=(0,l.useState)(!1),[z,Z]=(0,l.useState)(!1),A=(0,l.useRef)([]),[T,M]=(0,l.useState)(!1),[R,O]=(0,l.useState)(!1),[P,F]=(0,l.useState)(!1),[I,L]=(0,l.useState)(!1),[U,J]=(0,l.useState)("list"),[B,H]=(0,l.useState)([]),[W,q]=(0,l.useState)(null),[V,G]=(0,l.useState)([]),[Y,K]=(0,l.useState)([]),[Q,$]=(0,l.useState)(null),X=(0,l.useRef)(null),ee=(0,l.useRef)(!1),et=(0,l.useRef)(null);X.current=W,A.current=V,ee.current=I;let ea=(0,l.useRef)(!1);et.current=null!==(t=null==w?void 0:w.id)&&void 0!==t?t:null;let en=(0,l.useRef)(new Map);en.current=new Map(B.map(e=>{var t;return[e.id,null!==(t=e.notify_level)&&void 0!==t?t:"all"]}));let el=null!==(a=null==w?void 0:w.chat_sound)&&void 0!==a?a:"knock",ei=null!==(x=null==w?void 0:w.chat_sound_volume)&&void 0!==x?x:45,[er,es]=(0,l.useState)(null),eo=null!==(p=null==er?void 0:er.sound)&&void 0!==p?p:el,ec=null!==(g=null==er?void 0:er.volume)&&void 0!==g?g:ei,ed=(0,l.useRef)({sound:eo,volume:ec});ed.current={sound:eo,volume:ec};let eu=(0,l.useCallback)((e,t)=>{(0,c.XG)(null!=e?e:ed.current.sound,null!=t?t:ed.current.volume)},[]),em=(0,l.useCallback)(async e=>{es(t=>{var a,n,l,i;return{sound:null!==(n=null!==(a=e.chat_sound)&&void 0!==a?a:null==t?void 0:t.sound)&&void 0!==n?n:ed.current.sound,volume:null!==(i=null!==(l=e.chat_sound_volume)&&void 0!==l?l:null==t?void 0:t.volume)&&void 0!==i?i:ed.current.volume}});try{await (0,i.api)("/api/agents/me/notifications",{method:"PATCH",body:JSON.stringify(e)}),null==j||j()}catch(e){}},[j]),eh=(0,l.useCallback)(e=>{em({chat_sound:e})},[em]),ex=(0,l.useCallback)(e=>{em({chat_sound_volume:Math.max(0,Math.min(100,Math.round(e)))})},[em]);(0,l.useEffect)(()=>{let e="1"===window.localStorage.getItem(m);S(e);try{D("1"===window.localStorage.getItem(h))}catch(e){}e&&(L(!0),J("list"))},[]);let ep=(0,l.useCallback)(()=>{S(e=>{let t=!e;return window.localStorage.setItem(m,t?"1":"0"),t})},[]);(0,l.useEffect)(()=>{let e=(0,s.getSupabaseBrowserClient)();e.auth.getSession().then(e=>{let{data:t}=e;return _(!!t.session)});let{data:t}=e.auth.onAuthStateChange((e,t)=>_(!!t));return()=>t.subscription.unsubscribe()},[]);let eg=(0,l.useCallback)(async()=>{if(N)try{let e=await (0,i.api)("/api/team-chat/rooms");H(e.rooms)}catch(e){}},[N]);(0,l.useEffect)(()=>{N&&eg()},[N,eg]),(0,l.useEffect)(()=>{if(!N)return;let e=setInterval(()=>{eg()},27e5);return()=>clearInterval(e)},[N,eg]),(0,l.useEffect)(()=>{if(!N)return;let e=()=>{"visible"===document.visibilityState&&eg()};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[N,eg]);let ef=(0,l.useCallback)(async e=>{try{await (0,i.api)("/api/team-chat/rooms/".concat(e,"/read"),{method:"POST"})}catch(e){}H(t=>t.map(t=>t.id===e?{...t,unread:0}:t))},[]);(0,l.useEffect)(()=>{if(!N)return;let e=(0,r.getSocket)(),t=e=>{var t,a;let{room_id:n,message:l}=e,i=(ee.current||ea.current)&&X.current===n,r=null===l.sender_id,s=l.sender_id===et.current,o=!!(et.current&&(null!==(t=l.mentions)&&void 0!==t?t:[]).includes(et.current)),m=(0,u.B_N)(null!==(a=en.current.get(n))&&void 0!==a?a:"all",o);if(!i&&!s&&!r&&m&&(0,d.C)("chat:".concat(l.id)))try{(0,c.XG)(ed.current.sound,ed.current.volume)}catch(e){}i&&(G(e=>e.some(e=>e.id===l.id)?e:[...e,l]),ef(n)),H(e=>{var t;let a=e.findIndex(e=>e.id===n);if(-1===a)return eg(),e;let r=e[a],s=i?0:r.unread+(l.sender_id?1:0),c=i?0:(null!==(t=r.unread_mentions)&&void 0!==t?t:0)+(l.sender_id&&o?1:0),d=l.body.trim()?l.body:l.image_url?"\uD83D\uDCF7 Photo":l.file_name?"\uD83D\uDCCE ".concat(l.file_name):l.body,u={...r,unread:s,unread_mentions:c,last_message:{body:d,created_at:l.created_at,from_me:!1},last_message_at:l.created_at},m=[...e];return m.splice(a,1),[u,...m]})},a=()=>{eg()},n=e=>{X.current===e.room_id&&G(t=>t.map(t=>
1t.id===e.message_id?{...t,reactions:e.reactions}:t))},l=e=>{X.current===e.room_id&&G(t=>t.map(t=>{var a;return t.id===e.message_id?{...t,body:e.body,mentions:null!==(a=e.mentions)&&void 0!==a?a:[],edited_at:e.edited_at}:t}))},i=e=>{H(t=>t.filter(t=>t.id!==e.room_id)),X.current===e.room_id&&(q(null),J("list"))},s=e=>{(null==e?void 0:e.room_id)&&H(t=>{let a=t.find(t=>t.id===e.room_id);return a&&0!==a.unread?t.map(t=>t.id===e.room_id?{...t,unread:0}:t):t})},o=e=>{(null==e?void 0:e.message_id)&&G(t=>t.map(t=>{var a;return t.id===e.message_id?{...t,body:"",image_url:null,file_url:null,file_name:null,mentions:[],deleted_at:null!==(a=e.deleted_at)&&void 0!==a?a:new Date().toISOString()}:t}))};return e.on("chat_message_deleted",o),e.on("chat_room_read",s),e.on("chat_room_deleted",i),e.on("chat_message",t),e.on("chat_room_updated",a),e.on("chat_reaction",n),e.on("chat_message_edited",l),()=>{e.off("chat_message",t),e.off("chat_room_updated",a),e.off("chat_reaction",n),e.off("chat_message_edited",l),e.off("chat_room_deleted",i),e.off("chat_room_read",s),e.off("chat_message_deleted",o)}},[N,eg,ef]);let eb=(0,l.useCallback)(e=>{D(e);try{window.localStorage.setItem(h,e?"1":"0")}catch(e){}},[]),ev=(0,l.useCallback)(async e=>{q(e),J("room"),L(!0),eb(!1),G([]),Z(!0);let[t]=await Promise.allSettled([(0,i.api)("/api/team-chat/rooms/".concat(e,"/messages")),ef(e)]),a="fulfilled"===t.status?t.value.messages:[];G(a),O(a.length>=50),Z(!1)},[ef]),ey=(0,l.useCallback)(async()=>{var e,t;let a=X.current;if(!a||T)return;let n=null===(e=A.current[0])||void 0===e?void 0:e.created_at;if(n){M(!0);try{let e=await (0,i.api)("/api/team-chat/rooms/".concat(a,"/messages?before=").concat(encodeURIComponent(n),"&limit=50")),l=null!==(t=e.messages)&&void 0!==t?t:[];O(l.length>=50),l.length&&G(e=>{let t=new Set(e.map(e=>e.id));return[...l.filter(e=>!t.has(e.id)),...e]})}catch(e){}finally{M(!1)}}},[T]),ek=(0,l.useCallback)(async(e,t,a,n,l)=>{var r;let s=X.current,o=e.trim();if(!s||!o&&!a&&!l)return;let c=B.find(e=>e.id===s),d=b(o,null!==(r=null==c?void 0:c.members)&&void 0!==r?r:[],null!=t?t:[]),u=await (0,i.api)("/api/team-chat/rooms/".concat(s,"/messages"),{method:"POST",body:JSON.stringify({body:o,image_url:a,file_url:null==l?void 0:l.url,file_name:null==l?void 0:l.name,file_type:null==l?void 0:l.type,file_size:null==l?void 0:l.size,mentions:d,reply_to_id:null!=n?n:void 0})});G(e=>e.some(e=>e.id===u.message.id)?e:[...e,u.message]),H(e=>{let t=e.findIndex(e=>e.id===s);if(-1===t)return e;let a=u.message.body.trim()?u.message.body:u.message.image_url?"\uD83D\uDCF7 Photo":u.message.file_name?"\uD83D\uDCCE ".concat(u.message.file_name):u.message.body,n={...e[t],last_message:{body:a,created_at:u.message.created_at,from_me:!0},last_message_at:u.message.created_at},l=[...e];return l.splice(t,1),[n,...l]})},[B]),ew=(0,l.useCallback)(async e=>{let t=X.current;if(!t)return;let a=await (0,i.api)("/api/team-chat/rooms/".concat(t,"/messages/").concat(e),{method:"DELETE"});G(e=>e.map(e=>e.id===a.message_id?{...e,body:"",image_url:null,file_url:null,file_name:null,mentions:[],deleted_at:a.deleted_at}:e)),H(e=>e.map(e=>e.id===t&&e.last_message&&e.last_message.from_me?{...e,last_message:{...e.last_message,body:"Message deleted"}}:e))},[]),ej=(0,l.useCallback)(async(e,t,a)=>{var n;let l=X.current,r=t.trim();if(!l)return;let s=B.find(e=>e.id===l),o=b(r,null!==(n=null==s?void 0:s.members)&&void 0!==n?n:[],null!=a?a:[]),c=await (0,i.api)("/api/team-chat/rooms/".concat(l,"/messages/").concat(e),{method:"PATCH",body:JSON.stringify({body:r,mentions:o})});G(e=>e.map(e=>{var t;return e.id===c.message_id?{...e,body:c.body,mentions:null!==(t=c.mentions)&&void 0!==t?t:[],edited_at:c.edited_at}:e})),H(e=>e.map(e=>e.id===l&&e.last_message&&e.last_message.from_me?{...e,last_message:{...e.last_message,body:c.body}
1}:e))},[B]),eN=(0,l.useCallback)(async(e,t)=>{let a=e=>[...e].sort((e,t)=>{var a,n;return!!e.pinned!=!!t.pinned?e.pinned?-1:1:new Date(null!==(a=t.last_message_at)&&void 0!==a?a:0).getTime()-new Date(null!==(n=e.last_message_at)&&void 0!==n?n:0).getTime()});H(n=>a(n.map(a=>a.id===e?{...a,pinned:t,archived:!t&&a.archived}:a)));try{await (0,i.api)("/api/team-chat/rooms/".concat(e,"/pin"),{method:"POST",body:JSON.stringify({pinned:t})})}catch(n){H(n=>a(n.map(a=>a.id===e?{...a,pinned:!t}:a)))}},[]),e_=(0,l.useCallback)(async(e,t)=>{let a="all";H(n=>n.map(n=>{var l;return n.id!==e?n:(a=null!==(l=n.notify_level)&&void 0!==l?l:"all",{...n,notify_level:t})}));try{await (0,i.api)("/api/team-chat/rooms/".concat(e,"/notify"),{method:"POST",body:JSON.stringify({level:t})})}catch(t){throw H(t=>t.map(t=>t.id===e?{...t,notify_level:a}:t)),Error("Could not change notifications for this chat")}},[]),eC=(0,l.useCallback)(async(e,t)=>{H(a=>a.map(a=>a.id===e?{...a,archived:t}:a)),t&&X.current===e&&(q(null),J("list"));try{await (0,i.api)("/api/team-chat/rooms/".concat(e,"/archive"),{method:"POST",body:JSON.stringify({archived:t})})}catch(a){H(a=>a.map(a=>a.id===e?{...a,archived:!t}:a))}},[]),eS=(0,l.useCallback)(async e=>{await (0,i.api)("/api/team-chat/rooms/".concat(e),{method:"DELETE"}),H(t=>t.filter(t=>t.id!==e)),X.current===e&&(q(null),J("list"))},[]),eE=e=>new Promise((t,a)=>{let n=new FileReader;n.onload=()=>{var e;return t(null!==(e=String(n.result).split(",")[1])&&void 0!==e?e:"")},n.onerror=a,n.readAsDataURL(e)}),eD=(0,l.useCallback)(async e=>{let t=await eE(e);return(await (0,i.api)("/api/team-chat/upload",{method:"POST",body:JSON.stringify({filename:e.name,contentType:e.type||"image/jpeg",dataBase64:t})})).url},[]),ez=(0,l.useCallback)(async e=>{var t;let a=await eE(e),n=await (0,i.api)("/api/team-chat/upload",{method:"POST",body:JSON.stringify({filename:e.name,contentType:e.type||"application/octet-stream",dataBase64:a})});return{url:n.url,name:e.name,type:e.type||"application/octet-stream",size:null!==(t=n.file_size)&&void 0!==t?t:e.size}},[]),eZ=(0,l.useCallback)(async(e,t)=>{let a=X.current;if(a)try{let n=await (0,i.api)("/api/team-chat/rooms/".concat(a,"/messages/").concat(e,"/react"),{method:"POST",body:JSON.stringify({emoji:t})});G(e=>e.map(e=>e.id===n.message_id?{...e,reactions:n.reactions}:e))}catch(e){}},[]),eA=(0,l.useCallback)(async e=>{let t=await (0,i.api)("/api/team-chat/rooms/dm",{method:"POST",body:JSON.stringify({agent_id:e})});await eg(),await ev(t.room_id)},[eg,ev]),eT=(0,l.useCallback)(async(e,t)=>{let a=await (0,i.api)("/api/team-chat/rooms/group",{method:"POST",body:JSON.stringify({name:e,member_ids:t})});await eg(),await ev(a.room_id)},[eg,ev]),eM=(0,l.useCallback)(async e=>{let t=X.current,a=e.trim();t&&a&&(await (0,i.api)("/api/team-chat/rooms/".concat(t),{method:"PATCH",body:JSON.stringify({name:a})}),await eg())},[eg]),eR=(0,l.useCallback)(async e=>{let t=X.current;t&&0!==e.length&&(await (0,i.api)("/api/team-chat/rooms/".concat(t,"/members"),{method:"POST",body:JSON.stringify({member_ids:e})}),await eg())},[eg]),eO=(0,l.useCallback)(async e=>{let t=X.current;t&&(await (0,i.api)("/api/team-chat/rooms/".concat(t,"/members/").concat(e),{method:"DELETE"}),await eg())},[eg]),eP=(0,l.useCallback)(async()=>{try{let e=await (0,i.api)("/api/team-chat/directory");K(e.agents)}catch(e){}},[]),eF=B.reduce((e,t)=>{var a,n;return e+(0,u.ZYt)(null!==(a=t.notify_level)&&void 0!==a?a:"all",t.unread,null!==(n=t.unread_mentions)&&void 0!==n?n:0)},0);(0,l.useEffect)(()=>{!function(e){if("undefined"==typeof navigator)return;let t=navigator;try{var a,n,l,i,r,s;e>0?null===(l=t.setAppBadge)||void 0===l||null===(n=l.call(t,e))||void 0===n||null===(a=n.catch)||void 0===a||a.call(n,()=>void 0):null===(s=t.clearAppBadge)||void 0===s||null===(r=s.call(t))||void 0===r||null===(i=r.catch)||void 0===i||i.call(r,()=>void 0)}catch(e){}}(eF)},[eF]);let eI=null!==(f=B.find(e=>e.id===W))&&void 0!==f?f:null,eL={open:I,view:U,rooms:B,unreadTotal:eF,activeId:W,activeRoom:eI,messages:V,directory:Y,setPageOpen:e=>{ea.current=e},openDrawer:()=>{L(!0),J("list"),eg()},closeDrawer:()=>L(!1),toggle:()=>L(e=>{let t=!e;return t&&(J("list"),eg()),t}
1),setView:J,openRoom:ev,send:ek,editMessage:ej,deleteMessage:ew,setArchived:eC,setRoomPinned:eN,setRoomNotify:e_,deleteRoom:eS,showArchived:P,setShowArchived:F,replyingTo:Q,setReplyingTo:$,uploadImage:eD,uploadFile:ez,react:eZ,myId:null!==(y=null==w?void 0:w.id)&&void 0!==y?y:null,startDm:eA,createGroup:eT,addMembers:eR,removeMember:eO,renameGroup:eM,loadDirectory:eP,refresh:eg,sound:eo,soundVolume:ec,setSound:eh,setSoundVolume:ex,previewSound:eu,pinned:C,togglePin:ep,minimised:E,setMinimised:eb,messagesLoading:z,loadingOlder:T,hasOlder:R,loadOlder:ey};return(0,n.jsx)(v.Provider,{value:eL,children:k})}function k(){let e=(0,l.useContext)(v);if(!e)throw Error("useTeamChat must be used within TeamChatProvider");return e}}}]);

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.