import{r as t,d as i,h as a,a as s}from"./p-a599f720.js";import{e,i as n}from"./p-9811c98c.js";import{c as r}from"./p-901c1d40.js";import{S as o}from"./p-af705ed1.js";var h=function(t,i,a,s){var e,n=arguments.length,r=n<3?i:null===s?s=Object.getOwnPropertyDescriptor(i,a):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,i,a,s);else for(var o=t.length-1;o>=0;o--)(e=t[o])&&(r=(n<3?e(r):n>3?e(i,a,r):e(i,a))||r);return n>3&&r&&Object.defineProperty(i,a,r),r};const c=class{constructor(a){t(this,a),this.stateUpdate=i(this,"rtkStateUpdate",7),this.unreadMessageCount=0,this.variant="button",this.iconPack=e,this.t=n(),this.chatActive=!1,this.canViewChat=!1,this.pageSize=11,this.onChatUpdate=({action:t,message:i})=>{var a;this.chatActive||"add"===t&&i.userId!==(null===(a=this.meeting)||void 0===a?void 0:a.self.userId)&&this.unreadMessageCount<=10&&(this.unreadMessageCount+=1)},this.toggleChat=()=>{const t=this.states;this.chatActive=!((null==t?void 0:t.activeSidebar)&&"chat"===(null==t?void 0:t.sidebar)),this.chatActive&&(this.unreadMessageCount=0),this.stateUpdate.emit({activeSidebar:this.chatActive,sidebar:this.chatActive?"chat":void 0,activeMoreMenu:!1})},this.updateCanView=()=>{this.canViewChat=r(this.meeting)}}connectedCallback(){this.meetingChanged(this.meeting),this.statesChanged(this.states)}disconnectedCallback(){var t,i,a,s,e,n;null===(i=null===(t=this.meeting)||void 0===t?void 0:t.chat)||void 0===i||i.removeListener("chatUpdate",this.onChatUpdate),null===(s=null===(a=this.meeting)||void 0===a?void 0:a.stage)||void 0===s||s.removeListener("stageStatusUpdate",this.updateCanView),null===(n=null===(e=this.meeting)||void 0===e?void 0:e.self)||void 0===n||n.permissions.removeListener("chatUpdate",this.updateCanView)}meetingChanged(t){var i,a,s;t&&(this.setUnreadMessageCount(),this.canViewChat=r(t),null===(i=t.chat)||void 0===i||i.addListener("chatUpdate",this.onChatUpdate),null===(a=null==t?void 0:t.stage)||void 0===a||a.on("stageStatusUpdate",this.updateCanView),null===(s=null==t?void 0:t.self)||void 0===s||s.permissions.on("chatUpdate",this.updateCanView))}statesChanged(t){null!=t&&(this.chatActive=!0===t.activeSidebar&&"chat"===t.sidebar)}async setUnreadMessageCount(){var t,i;const a=this.meeting.chat;if(!a)return;const s=null!==(i=null===(t=this.meeting.meta)||void 0===t?void 0:t.meetingStartedTimestamp.getTime())&&void 0!==i?i:0,e=await a.fetchPublicMessages({timestamp:s,limit:this.pageSize,direction:"after"});this.unreadMessageCount=e.length}handleChatActiveChange(){this.chatActive||this.states.activeSidebar||this.buttonEl.focus()}render(){return this.meeting?this.canViewChat?a(s,{title:this.t("chat")},0!==this.unreadMessageCount&&!this.chatActive&&a("div",{class:"unread-count",part:"unread-count"},a("span",null,this.unreadMessageCount<this.pageSize?this.unreadMessageCount:"10+")),a("rtk-controlbar-button",{ref:t=>this.buttonEl=t,part:"controlbar-button",size:this.size,iconPack:this.iconPack,class:{active:this.chatActive},onClick:this.toggleChat,icon:this.iconPack.chat,label:this.t("chat"),variant:this.variant})):a(s,{"data-hidden":!0}):null}static get watchers(){return{meeting:["meetingChanged"],states:["statesChanged"],chatActive:["handleChatActiveChange"]}}};h([o()],c.prototype,"meeting",void 0),h([o()],c.prototype,"states",void 0),h([o()],c.prototype,"iconPack",void 0),h([o()],c.prototype,"t",void 0),c.style=":host{line-height:initial;font-family:var(--rtk-font-family, sans-serif);font-feature-settings:normal;font-variation-settings:normal}p{margin:var(--rtk-space-0, 0px);padding:var(--rtk-space-0, 0px)}:host{position:relative;display:block}:host([data-hidden]){display:none}.unread-count{position:absolute;right:var(--rtk-space-4, 16px);box-sizing:border-box;padding:var(--rtk-space-0\\.5, 2px);-webkit-user-select:none;-moz-user-select:none;user-select:none;--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-brand-500, 33 96 253) / var(--tw-bg-opacity));font-size:12px;color:rgb(var(--rtk-colors-text-on-brand-1000, var(--rtk-colors-text-1000, 255 255 255)));display:flex;height:var(--rtk-space-5, 20px);min-width:var(--rtk-space-5, 20px);align-items:center;justify-content:center;border-radius:9999px;z-index:1}.unread-count-dot{position:absolute;right:var(--rtk-space-3, 12px);z-index:10;--tw-bg-opacity:1;background-color:rgba(var(--rtk-colors-brand-500, 33 96 253) / var(--tw-bg-opacity));border-radius:50%;display:flex;height:var(--rtk-space-4, 16px);width:var(--rtk-space-4, 16px);align-items:center;justify-content:center}:host([variant='horizontal']) .unread-count{right:var(--rtk-space-4, 16px);top:50%;transform:translateY(-50%)}";export{c as rtk_chat_toggle}