import{J as p,b as d,d as b}from"./bootstrap-BsWQM_6D.js";import{_ as f,d as v}from"./currency-Dtag6qPd.js";import{n as _}from"./ns-prompt-popup-CwRKP6Ip.js";import{h as x}from"./components-DUSFgsKA.js";import{_ as k}from"./_plugin-vue_export-helper-DlAUqK2U.js";import{r as g,o as c,c as r,a as i,t as a,e as u,n as y,F as N,b as w,f as C}from"./runtime-core.esm-bundler-VrNrzzXC.js";import"./chart-CAYz1qzV.js";import"./ns-avatar-image-Pigdi04i.js";const E={name:"ns-notifications",data(){return{notifications:[],visible:!1,socketEnabled:!1,interval:null}},components:{nsCloseButton:x},mounted(){document.addEventListener("click",this.checkClickedItem),typeof Echo>"u"?this.interval=setInterval(()=>{this.loadNotifications()},15e3):(this.interval=setInterval(()=>{this.socketEnabled=Echo.connector.pusher.connection.state==="connected"},1e3),Echo.private(`App.User.${ns.user.attributes.user_id}`).listen("NotificationUpdatedEvent",e=>{this.pushNotificationIfNew(e.notification)}).listen("NotificationCreatedEvent",e=>{this.pushNotificationIfNew(e.notification)}).listen("NotificationDeletedEvent",e=>{this.deleteNotificationIfExists(e.notification)})),this.loadNotifications()},unmounted(){clearInterval(this.interval)},methods:{__:f,timespan:p,nsNumberAbbreviate:v,pushNotificationIfNew(e){this.notifications.filter(s=>s.id===e.id).length>0||this.notifications.unshift(e)},deleteNotificationIfExists(e){const t=this.notifications.filter(s=>s.id===e.id);if(t.length>0){const s=this.notifications.indexOf(t[0]);this.notifications.splice(s,1)}},deleteAll(){Popup.show(_,{title:f("Confirm Your Action"),message:f("Would you like to clear all the notifications ?"),onAction:e=>{e&&d.delete("/api/notifications/all").subscribe(t=>{b.success(t.message).subscribe()})}})},checkClickedItem(e){let t;document.getElementById("notification-center")?t=document.getElementById("notification-center").contains(e.srcElement):t=!1;const s=document.getElementById("notification-button").contains(e.srcElement);!t&&!s&&this.visible&&(this.visible=!1)},loadNotifications(){d.get("/api/notifications").subscribe(e=>{this.notifications=e})},triggerLink(e){if(e.url!=="url")return window.open(e.url,"_blank")},closeNotice(e,t){d.delete(`/api/notifications/${t.id}`).subscribe(s=>{this.socketEnabled||this.loadNotifications()}),e.stopPropagation()}}},I={id:"notificaton-wrapper"},B={key:0,class:"relative float-right"},A={class:"absolute -ml-6 -mt-8"},j={class:"bg-info-tertiary text-white w-8 h-8 rounded-full text-xs flex items-center justify-center"},L={key:0,class:"h-0 w-0",id:"notification-center"},P={class:"absolute left-0 top-0 sm:relative w-screen zoom-out-entrance anim-duration-300 h-5/7-screen sm:w-64 sm:h-108 flex flex-row-reverse"},V={class:"z-50 sm:rounded-lg shadow-lg h-full w-full md:mt-2 overflow-y-hidden flex flex-col"},z={class:"overflow-y-auto flex flex-col flex-auto"},D=["onClick"],F={class:"flex items-center justify-between"},S={class:"font-semibold"},U={class:"py-1 text-sm"},H={class:"flex justify-end"},J={class:"text-xs date"},O={key:0,class:"h-full w-full flex items-center justify-center"},W={class:"flex flex-col items-center"},Y={class:"text-secondary text-sm"},q={class:"cursor-pointer clear-all"};function G(e,t,s,K,o,l){const h=g("ns-close-button");return c(),r("div",I,[i("div",{id:"notification-button",onClick:t[0]||(t[0]=n=>o.visible=!o.visible),class:y([o.visible?"panel-visible border-0 shadow-lg":"border panel-hidden","hover:shadow-lg hover:border-opacity-0 rounded-full h-12 w-12 cursor-pointer font-bold text-2xl justify-center items-center flex"])},[o.notifications.length>0?(c(),r("div",B,[i("div",A,[i("div",j,a(l.nsNumberAbbreviate(o.notifications.length,"abbreviate")),1)])])):u("",!0),t[3]||(t[3]=i("i",{class:"las la-bell"},null,-1))],2),o.visible?(c(),r("div",L,[i("div",P,[i("div",V,[i("div",{onClick:t[1]||(t[1]=n=>o.visible=!1),class:"sm:hidden p-2 cursor-pointer flex items-center justify-center border-b border-gray-200"},t[4]||(t[4]=[i("h3",{class:"font-semibold hover:text-info-primary"},"Close",-1)])),i("div",z,[(c(!0),r(N,null,w(o.notifications,n=>(c(),r("div",{key:n.id,class:"notification-card notice border-b"},[i("div",{class:"p-2 cursor-pointer",onClick:m=>l.triggerLink(n)},[i("div",F,[i("h1",S,a(n.title),1),C(h,{onClick:m=>l.closeNotice(m,n)},null,8,["onClick"])]),i("p",U,a(n.description),1),i("div",H,[i("span",J,a(l.timespan(n.updated_at)),1)])],8,D)]))),128)),o.notifications.length===0?(c(),r("div",O,[i("div",W,[t[5]||(t[5]=i("i",{class:"las la-laugh-wink text-5xl text-primary"},null,-1)),i("p",Y,a(l.__("Nothing to care about !")),1)])])):u("",!0)]),i("div",q,[i("h3",{onClick:t[2]||(t[2]=n=>l.deleteAll()),class:"text-sm p-2 flex items-center justify-center w-full font-semibold"},a(l.__("Clear All")),1)])])])])):u("",!0)])}const et=k(E,[["render",G]]);export{et as default};
