import{r as i,cA as E,j as s,gF as I,au as T,u as R,M as F,a as _,w as v,fG as S,hH as N,az as M,hX as y,aL as A,fd as B,h as D,hY as O}from"./index-CXyQ5sGC.js";import{e as Y,R as G}from"./lodash-CQGrF3PQ.js";const P=({notification:a,onOpen:u,onRemove:d})=>{const[c,m]=E(!1),n=(l=!1)=>{l?u(a,l):(c||u(a,!a.content),a.content&&m())},f=l=>{l.stopPropagation(),d(a)};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"notification-new-item",onClick:()=>n(!!a.href),"data-status":a.visited?"read":"unread",children:[s.jsx("i",{className:"notification-new-item-icon bc-i-notification"}),s.jsx("span",{className:"notification-new-item-info",children:a.title}),s.jsx("i",{className:"bc-i-close-remove",onClick:f})]}),c&&s.jsx("div",{onClick:()=>n(!0),children:s.jsx(I,{props:{content:a.content,html:!0}})})]})},$=i.memo(P),j="whats_new_notifications",w="dateFull",z=(a,u)=>a.reduce((d,c)=>{if(u[c.id]!==1){const m=B.getTimestamp(c.date),n=D.unix(m).format(O[w].join(" "));d[n]||(d[n]={date:m,groupId:n,notifications:[]}),d[n].notifications.push({...c,groupId:n,visited:u[c.id]===2})}return d},{}),H=({show:a})=>{const u=T(),d=R(),{language:c}=F(),{isLoggedIn:m}=_(),n=i.useRef(v.getItem(j)||{}),[f,l]=i.useState({});i.useEffect(()=>{S.getNotifications("whats_new",c).then(e=>{u.current&&e&&l(z(e,n.current))}).catch(()=>l({}))},[u,c]);const x=i.useMemo(()=>Object.values(f).reduce((e,o)=>{const t=o.notifications.filter(r=>!r.visited&&N(r.showTo,m));return e+t.length},0),[f,m]);i.useEffect(()=>{M.dispatchEvent("setComponentNotificationsCount",{component:y.Notifications,value:x})},[x]);const h=i.useCallback(()=>{v.setItem(j,n.current)},[]),C=i.useCallback((e,o)=>{if((!o||!e.content)&&(n.current[e.id]=2,h(),l(t=>{const r=e.groupId,p=t[r].notifications.map(g=>g.id===e.id?{...g,visited:!0}:g);return{...t,[r]:{...t[r],notifications:p}}})),o){const t=e.url??e.href,r=e.linktarget??e.target;t&&(r==="_blank"?window.open(t,"_blank"):window.location.href=t)}},[h]),b=i.useCallback(e=>{const o=f[e].notifications.map(t=>t.id);l(t=>{const{[e]:r,...p}=t;return p}),o.forEach(t=>{n.current[t]=1}),h()},[f,h]),k=i.useCallback(e=>{l(o=>{const t=e.groupId,r=o[t].notifications.filter(p=>p.id!==e.id);if(r.length>0)return{...o,[t]:{...o[t],notifications:r}};{const{[t]:p,...g}=o;return g}}),n.current[e.id]=1,h()},[h]);return a?s.jsx(s.Fragment,{children:Y(f)?s.jsx("p",{className:"empty-b-text-v-bc",children:d("You have no new notifications")}):G(["date"],["desc"],Object.values(f)).map(e=>{const o=e.notifications.filter(t=>N(t.showTo,m));return s.jsxs("div",{className:"notification-new-container",children:[o.length>0&&s.jsxs("div",{className:"notification-new-header",children:[s.jsx(A,{seconds:e.date,preset:w}),s.jsx("span",{onClick:()=>b(e.groupId),children:d("Clear")})]}),o.map(t=>s.jsx($,{notification:t,onOpen:C,onRemove:k},t.id))]},e.date)})}):null},X=i.memo(H);export{X as default};