import{Q as h,r as _,p as i,l as w,a0 as b,a as x,c as $,g as k,o as y,d as u,b as C,w as L,t as N}from"./app-fEKA3BkQ.js";import{e as I}from"./echoServiceComposable-DxEMrh9X.js";const M={key:0,class:"fixed bottom-12 right-12"},B={class:"relative flex h-12 w-12 items-center justify-center rounded-full dark:bg-slate-700"},U={class:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full bg-red-500 text-xs font-normal text-white"},A={__name:"NotificationRing",props:{module:{type:String,default:"whatsapp"}},setup(f){var p,m;const n=((m=(p=h().props.authUser)==null?void 0:p.active_workspace)==null?void 0:m.owner_id)??null,s=f,t=I.connect(),o=_([]),c=i(()=>o.value.length);w(()=>{if(!n)return console.log("Owner id not found");t==null||t.private(`live-chat.${s.module}.${n}`).subscribed(()=>console.log("Live chat counter activated successfully")).listen("LiveChatNotifyEvent",e=>{console.log(`New event received for: ${s.module}`,e),s.module=="whatsapp"&&d({platform_id:e.platform_id,conversation_id:e.conversation_id,message_id:e.message_id}),s.module=="whatsapp-web"&&e.event=="messages.upsert"&&d({sessionId:e.sessionId})}).error(e=>console.error(e))});const d=e=>{o.value.push(e),v()};b(()=>{t==null||t.leave(`live-chat.${s.module}.${n}`),console.log("Live chat counter left successfully")});const v=()=>{let e="/assets/incoming-message-online-whatsapp.mp3";new Audio(e).play().catch(l=>console.warn("Audio playback error:",l))},a=i(()=>o.value[o.value.length-1]),g=i(()=>{if(s.module==="whatsapp")return`/user/${s.module}/platforms/${a.value.platform_id}/conversations/${a.value.conversation_id}`;if(s.module==="whatsapp-web")return`/user/whatsapp-web/platforms/${a.value.sessionId}`});return(e,r)=>{const l=x("Link");return c.value>0?(y(),$("div",M,[u("div",B,[C(l,{href:g.value},{default:L(()=>r[0]||(r[0]=[u("img",{src:"/assets/svg/alert-counter.gif",alt:""},null,-1)])),_:1,__:[0]},8,["href"]),u("span",U,N(c.value),1)])])):k("",!0)}}};export{A as _};
