UNPKG

@veltdev/sdk

Version:

Velt is an SDK to add collaborative features to your product within minutes. Example: Comments like Figma, Frame.io, Google docs or sheets, Recording like Loom, Huddles like Slack and much more.

3 lines 50.7 kB
import{a as Re,c as qe,d as We}from"./chunk-BDHZZGJO.js";import{a as mt}from"./chunk-6YXU2Y3T.js";import{t as at}from"./chunk-BACKCNIG.js";import"./chunk-JFNRCHYR.js";import"./chunk-U4YN7DB7.js";import{a as dt}from"./chunk-ZATQYC4Y.js";import"./chunk-3HGEDPEP.js";import{a as rt}from"./chunk-JDLRIKAZ.js";import"./chunk-3J52NZMN.js";import"./chunk-4ACOV475.js";import{b as ot,d as st}from"./chunk-WTYACTR5.js";import{a as lt}from"./chunk-6E3N35RF.js";import{a as ct}from"./chunk-KEM6PWSD.js";import{a as Pe}from"./chunk-UJRDSNTY.js";import{A as ze,G as $e,H as Ne,I as Le,ca as it,ea as nt}from"./chunk-KU45CEXD.js";import{$ as xe,Bf as he,E as A,Ed as Fe,Ee as O,Fa as h,Fc as ke,Ga as re,Gc as le,Ib as se,Ii as tt,J as ie,Kb as ae,L as J,M as Ie,Nb as E,Nh as Ye,Ob as H,Pa as I,Pb as R,Pc as Te,Rb as Ae,Rf as Ke,S as Ce,T as S,Ta as Oe,Td as Me,Ua as Z,Ud as je,Va as Be,W as De,Y as pe,_a as z,_h as Qe,a as m,aa as _e,ac as Ue,b as y,bi as de,ca as T,di as D,ei as Ze,g as q,ha as P,ia as F,ja as Y,jh as He,ka as Q,kc as U,l as $,lb as x,lc as k,lh as we,li as me,mb as v,mi as Xe,nb as w,ne as Ge,ni as fe,ob as M,pc as ce,qa as ne,r as V,sb as W,si as N,tb as G,ti as et,ua as Ee,v as f,vb as K,vh as ye,w as X,wa as oe,xb as j,yh as Je,yi as ue,zb as _}from"./chunk-GR3NESUB.js";var L=(()=>{let c=class c{constructor(e,t,n,i,o,a,d,s,u,g){this.afAuth=e,this.authService=t,this.configService=n,this.databaseService=i,this.docService=o,this.commonDbService=a,this.iamService=d,this.loggingService=s,this.userPermissionService=u,this.serviceBook=g,this.documentPaths=null,this.views$=new $({}),this.commentViews$=new $({}),this.documentViews$=new $({}),this.locationViews$=new $({}),this.commentViewsByOrganizationIdAndDocumentId$=new $({}),this.documentViewsByOrganizationIdAndDocumentId$=new $({}),this.locationViewsByOrganizationIdAndLocationId$=new $({}),this.documentViewsEnabled$=new $(!1),this.documentViewsSetByDocumentId={},this.notificationService=null,this.loggingService.log("%c[WB] Creating CLASS: ViewsService","color: blue;");try{this.serviceBook.observe(Ye).subscribe(p=>{this.commentService=p??void 0}),this.serviceBook.observe(Je).subscribe(p=>{this.notificationService=p??null}),this.databaseService.getDb().pipe(A(p=>!!p),ie(1)).subscribe(p=>{p&&(this.subscribeViewsData().subscribe(),this.getNotificationFeatureViews$().subscribe(C=>{this.notificationService?.setNotificationViews(C)}),this.authService.getUser$().pipe(A(C=>!!C),S(C=>this.documentViewsEnabled$.pipe(A(b=>b),f(()=>C))),S(C=>this.docService.getDocumentPaths$().pipe(Ce(null),Ie(),f(([b,B])=>(b?.documentId!==B?.documentId&&this.views$.next({}),B)),f(b=>(this.documentPaths=b,this.setDocumentAsRead({documentId:this.documentPaths?.documentId??"",clientDocumentId:this.documentPaths?.clientDocumentId??""}),{_user:C,_documentPaths:b})),S(b=>this.docService.getDocumentIds$().pipe(S(B=>(B?.length&&(B.find(te=>te.documentId===this.documentPaths?.documentId)||B.push({documentId:this.documentPaths?.documentId??"",clientDocumentId:this.documentPaths?.clientDocumentId??""}),B.forEach(te=>{this.setDocumentAsRead({documentId:te.documentId,clientDocumentId:te.clientDocumentId})})),V(b))))))),S(C=>this.docService.getDocumentMetadata$().pipe(A(b=>!!b),f(b=>y(m({},C),{_documentMetadata:b}))))).subscribe(),this.authService.getUser$().pipe(A(C=>!!C),S(C=>this.documentViewsEnabled$.pipe(A(b=>b),f(()=>C))),S(C=>this.docService.getLocation$().pipe(A(b=>!!b))),S(C=>this.docService.getDocumentIds$().pipe(S(b=>(b.find(B=>B.documentId===this.documentPaths?.documentId)||b.push({documentId:this.documentPaths?.documentId??"",clientDocumentId:this.documentPaths?.clientDocumentId??""}),b.forEach(B=>{this.setLocationAsRead({documentId:B.documentId,clientDocumentId:B.clientDocumentId})}),V(C)))))).subscribe())},p=>{this.loggingService.catch("Error in ViewsService getDb subscription: ",p)})}catch(p){this.loggingService.catch("Error in ViewsService constructor: ",p)}}clearCache(){this.loggingService.log("%c[WB] Calling FUNCTION: clearCache in ViewsService","color: green;");try{this.documentPaths=null,this.documentViews$.next({}),this.views$.next({}),this.commentViews$.next({}),this.locationViews$.next({}),this.commentViewsByOrganizationIdAndDocumentId$.next({}),this.documentViewsByOrganizationIdAndDocumentId$.next({}),this.locationViewsByOrganizationIdAndLocationId$.next({})}catch(e){this.loggingService.catch("Error in ViewsService clearCache: ",e)}}subscribeViewsData(e,t){this.loggingService.log("%c[WB] Calling FUNCTION: subscribeViewsData","color: green;");let n,i;try{if(e&&(i=he(e)),t&&typeof t=="object"){let o=Ke(t);n=he(JSON.stringify(o))}}catch(o){this.loggingService.catch("Error in ViewsService subscribeViewsData: ",o)}return this.authService.getAuthState$().pipe(A(o=>!!o),S(o=>this.isFeatureAllowed({firebaseUser:o})),S(o=>o.featureAllowed?this.iamService.isUserAllowed$().pipe(f(a=>(o.featureAllowed=a,o))):V(o)),S(o=>o.featureAllowed?V(o).pipe(S(a=>this.docService.getDocumentPaths$().pipe(f(d=>(this.documentPaths=d,a.documentPaths=d,a)))),S(a=>i?this.getDataFromDocumentIds([i]):this.docService.getDocumentIds$().pipe(S(d=>{let s=d?.length>0?d.map(u=>u.documentId):[this.documentPaths?.documentId??""];return this.getDataFromDocumentIds(s)})))):V([])))}isFeatureAllowed(e){return this.configService.getConfig$().pipe(A(t=>!!t),f(t=>y(m({},e),{config:t})),S(t=>this.authService.getUser$().pipe(f(n=>y(m({},t),{user:n})))),S(t=>t.user?V(y(m({},t),{featureAllowed:!0})):V(y(m({},t),{featureAllowed:!1}))),J((t,n)=>t?.featureAllowed===n?.featureAllowed))}getDataFromDocumentIds(e,t){return this.getDataFromDocuments({documentIds:e,filters:t})}getCommentViewsById(e){try{return this.commentViews$.value?.[e]?this.commentViews$.value?.[e]:void 0}catch(t){this.loggingService.catch("Error in ViewsService getCommentViewsById: ",t);return}}getDocumentViewsById(e){try{return this.documentViews$.value?.[e]}catch(t){this.loggingService.catch("Error in ViewsService getDocumentViewsById: ",t);return}}getLocationViewsById(e){try{return this.locationViews$.value?.[e]}catch(t){this.loggingService.catch("Error in ViewsService getLocationViewsById: ",t);return}}getDataFromDocuments(e){if(this.configService?.getApiKey()){let{documentIds:t,filters:n}=e;return t?.some(i=>!i)||!this.documentPaths?V([]):this.documentViewsEnabled$.pipe(S(i=>i?X([this.getCommentViewsDataFromDocuments(),this.getDocumentViewsDataFromDocuments(t),this.getLocationViewsDataFromDocuments(t)]):X([this.getCommentViewsDataFromDocuments()])))}else return V(null)}getCommentViews(e){try{let t={};Object.entries(e??{}).forEach(([n,i])=>{let o=i.metadata?.documentId,a=i.views;!o||!a||(t[o]||(t[o]={}),t[o][i.annotationId]=a)}),Object.entries(t??{}).forEach(([n,i])=>{this.setCommentViewsByOrganizationIdAndDocumentId({organizationId:this.documentPaths?.organizationId,documentId:n,commentViews:i})})}catch(t){this.loggingService.catch("Error in ViewsService getCommentViews: ",t)}}getCommentViewsDataFromDocuments(){try{return this.commentService?this.commentService?.getAllCommentAnnotations({detectGhostComments:!0,addFilterCommentsOnDomCheck:!0,fromCommentSidebar:!0,skipPositionCalculation:!0,analytics:{enabled:!0,properties:{source:"internal",sourceId:"commentsContainer"}}}).pipe(A(e=>!!e),De(e=>{this.getCommentViews(e)})):V([])}catch(e){return this.loggingService.catch("Error in ViewsService getCommentViewsDataFromDocuments: ",e),V([])}}getDocumentViewsDataFromDocuments(e){let t=this.docService.getDocumentPaths()?.veltFolderId,n=V([]),i={useCollectionGroup:!0,isCollection:!0,useQuery:!0};this.commonDbService.shouldUseFirestore()||(i.documentId=e?.length?e[0]:void 0,i.organizationId=this.documentPaths?.organizationId);let o=[];for(let a=0;a<(e?.length??0);a+=O.LISTENER_BATCH_SIZE)o.push(e?.slice(a,a+O.LISTENER_BATCH_SIZE)??[]);return n=X(o.map(a=>this.commonDbService.dbListener({feature:"allDocumentViews",properties:y(m({},i),{firestoreQuery:[fe(N("metadata.apiKey","==",this.configService?.getApiKey()),N("metadata.documentId","in",a),N("metadata.organizationId","==",this.documentPaths?.organizationId),...t?[N("metadata.veltFolderId","==",t)]:[])]})}).pipe(pe()))).pipe(f(a=>we(a))),n.pipe(f(a=>({data:a?.data,operation:a?.operation})),f(({data:a,operation:d})=>{let s={};return e?(Object.entries(a??{}).forEach(([u,g])=>{let p=g.metadata?.documentId;p&&(s[p]||(s[p]={}),s[p][u]=g)}),{data:a,documentMap:s,operation:d}):{data:a,documentMap:s,operation:d}}),f(({data:a,documentMap:d,operation:s})=>{if(s?.type==="removed"){if(s?.ids?.length){let u=this.documentViews$.value;s?.ids?.forEach(g=>{delete u?.[g]}),this.documentViews$.next(u)}}else Object.entries(d??{}).forEach(([u,g])=>{this.setDocumentViewsByOrganizationIdAndDocumentId({organizationId:this.documentPaths?.organizationId,documentId:u,documentViews:g})})}))}getLocationViewsDataFromDocuments(e){let t=this.docService.getDocumentPaths()?.veltFolderId,n=V([]),i={useCollectionGroup:!0,isCollection:!0,useQuery:!0};this.commonDbService.shouldUseFirestore()||(i.documentId=e?.length?e[0]:void 0,i.organizationId=this.documentPaths?.organizationId);let o=[];for(let a=0;a<(e?.length??0);a+=O.LISTENER_BATCH_SIZE)o.push(e?.slice(a,a+O.LISTENER_BATCH_SIZE)??[]);return n=X(o.map(a=>this.commonDbService.dbListener({feature:"allLocationViews",properties:y(m({},i),{firestoreQuery:[fe(N("metadata.apiKey","==",this.configService?.getApiKey()),N("metadata.documentId","in",a),N("metadata.organizationId","==",this.documentPaths?.organizationId),...t?[N("metadata.veltFolderId","==",t)]:[])]})}).pipe(pe()))).pipe(f(a=>we(a))),n.pipe(f(a=>({data:a?.data,operation:a?.operation})),f(({data:a,operation:d})=>{let s={};return e?(Object.entries(a??{}).forEach(([u,g])=>{let p=g.metadata?.documentId;p&&(s[p]||(s[p]={}),s[p][u]=g)}),{data:a,documentMap:s,operation:d}):{data:a,documentMap:s,operation:d}}),f(({data:a,documentMap:d,operation:s})=>{if(s?.type==="removed"){if(s?.ids?.length){let u=this.locationViews$.value;s?.ids?.forEach(g=>{delete u?.[g]}),this.locationViews$.next(u)}}else Object.entries(d??{}).forEach(([u,g])=>{this.setLocationViewsByOrganizationIdAndDocumentId({organizationId:this.documentPaths?.organizationId,documentId:u,locationViews:g})})}))}setViewsData(e){try{this.views$.next(m(m({},this.views$.getValue()),e||{}))}catch(t){this.loggingService.catch("Error in ViewsService setViewsData:",t)}}setCommentViewsByOrganizationIdAndDocumentId({organizationId:e,documentId:t,commentViews:n,queryHash:i}){try{if(n||(n={}),t){e||(e=O.NO_ORGANIZATION_ID),i||(i=O.DEFAULT_QUERY_HASH);let o=m(m({},this.commentViews$.value),n);this.commentViews$.next(o),this.commentViewsByOrganizationIdAndDocumentId$.next(y(m({},this.commentViewsByOrganizationIdAndDocumentId$.value),{[e]:y(m({},this.commentViewsByOrganizationIdAndDocumentId$.value[e]),{[t]:y(m({},this.commentViewsByOrganizationIdAndDocumentId$.value[e]?.[t]),{[i]:n})})}))}}catch(o){this.loggingService.catch("Error in CommentService setCommentAnnotationsByOrganizationIdAndDocumentId:",o)}}setDocumentViewsByOrganizationIdAndDocumentId({organizationId:e,documentId:t,documentViews:n,queryHash:i}){try{if(n||(n={}),t){e||(e=O.NO_ORGANIZATION_ID),i||(i=O.DEFAULT_QUERY_HASH);let o=m(m({},this.documentViews$.value),n);this.documentViews$.next(o),this.documentViewsByOrganizationIdAndDocumentId$.next(y(m({},this.documentViewsByOrganizationIdAndDocumentId$.value),{[e]:y(m({},this.documentViewsByOrganizationIdAndDocumentId$.value[e]),{[t]:y(m({},this.documentViewsByOrganizationIdAndDocumentId$.value[e]?.[t]),{[i]:n})})}))}}catch(o){this.loggingService.catch("Error in CommentService setCommentAnnotationsByOrganizationIdAndDocumentId:",o)}}setLocationViewsByOrganizationIdAndDocumentId({organizationId:e,documentId:t,locationViews:n,queryHash:i}){try{if(n||(n={}),t){e||(e=O.NO_ORGANIZATION_ID),i||(i=O.DEFAULT_QUERY_HASH);let o=m(m({},this.locationViews$.value),n);this.locationViews$.next(o),this.locationViewsByOrganizationIdAndLocationId$.next(y(m({},this.locationViewsByOrganizationIdAndLocationId$.value),{[e]:y(m({},this.locationViewsByOrganizationIdAndLocationId$.value[e]),{[t]:y(m({},this.locationViewsByOrganizationIdAndLocationId$.value[e]?.[t]),{[i]:n})})}))}}catch(o){this.loggingService.catch("Error in CommentService setCommentAnnotationsByOrganizationIdAndDocumentId:",o)}}getCommentFeatureViews$(){return this.commentViews$.pipe(J((e,t)=>JSON.stringify(e||{})===JSON.stringify(t||{})))}setCommentAnnotationAsRead(e){return q(this,null,function*(){try{if(this.authService.getUser()&&e?.annotationId){if(e.annotationId.startsWith("TEMP_COMPOSER_"))return;this.updateCommentAnnotationViews(e);let n=e?.metadata?.organizationId??this.documentPaths?.organizationId??"",i=e?.metadata?.documentId??this.documentPaths?.documentId??"";if(e?.isDraft)return;yield this.commonDbService.setData({feature:"comment",properties:{id:e.annotationId,documentId:i,organizationId:n,metadata:{apiKey:this.configService.getApiKey(),organizationId:n,veltFolderId:e?.metadata?.veltFolderId,documentId:i}},data:JSON.parse(JSON.stringify(e))})}}catch(t){this.loggingService.catch("Error in ViewsService setCommentAnnotationAsRead:",t)}})}setCommentAnnotationAsUnread(e){return q(this,null,function*(){try{if(this.authService.getUser()&&e?.annotationId){if(e.annotationId.startsWith("TEMP_COMPOSER_"))return;this.removeCommentAnnotationViews(e);let n=e?.metadata?.organizationId??this.documentPaths?.organizationId??"",i=e?.metadata?.documentId??this.documentPaths?.documentId??"";if(e?.isDraft)return;yield this.commonDbService.setData({feature:"comment",properties:{id:e.annotationId,documentId:i,organizationId:n,metadata:{apiKey:this.configService.getApiKey(),organizationId:n,veltFolderId:e?.metadata?.veltFolderId,documentId:i}},data:JSON.parse(JSON.stringify(e))})}}catch(t){this.loggingService.catch("Error in ViewsService setCommentAnnotationAsRead:",t)}})}updateCommentAnnotationViews(e){try{let t=this.authService.getUser(),n={views:{},comments:{}};if(t){let i={},o=e?.views?.comments||{},a=new Date().getTime()+this.commonDbService.getOffset();e.comments?.forEach(s=>{o[s.commentId]||(o[s.commentId]={views:{}}),o[s.commentId].views||(o[s.commentId].views={}),o[s.commentId].views[t.userSnippylyId]||(o[s.commentId].views[t.userSnippylyId]={timestamp:a})});let d=new Set(e.comments?.map(s=>s.commentId+""));if(Object.keys(o??{}).forEach(s=>{d.has(s)||delete o[s]}),e.comments?.length){let s=o[e.comments[0].commentId]?.views||{},u=Object.keys(s??{}).filter(g=>e.comments?.every(p=>o[p.commentId]?.views?.[g]));u.forEach(g=>{i[g]={timestamp:s[g].timestamp}}),e.viewedByUserIds=u}n.views=i,n.comments=o,e.views=n}return n}catch(t){return this.loggingService.catch("Error in ViewsService updateCommentAnnotationViews:",t),{views:{},comments:{}}}}removeCommentAnnotationViews(e){try{let t=this.authService.getUser(),n={views:{},comments:{}};if(t){let i={},o=e?.views?.comments||{};e.comments?.forEach(d=>{o[d.commentId]?.views?.[t.userSnippylyId]&&delete o[d.commentId].views[t.userSnippylyId]});let a=new Set(e.comments?.map(d=>d.commentId+""));if(Object.keys(o??{}).forEach(d=>{a.has(d)||delete o[d]}),e.comments?.length){let d=o[e.comments[0].commentId]?.views||{},s=Object.keys(d??{}).filter(u=>e.comments?.every(g=>o[g.commentId]?.views?.[u]));s.forEach(u=>{i[u]={timestamp:d[u].timestamp}}),e.viewedByUserIds=s}else e.viewedByUserIds=[];n.views=i,n.comments=o,e.views=n}return n}catch(t){return this.loggingService.catch("Error in ViewsService removeCommentAnnotationViews:",t),{views:{},comments:{}}}}getNotificationFeatureViews$(){return this.views$.pipe(J((e,t)=>JSON.stringify(e?.notification||{})===JSON.stringify(t?.notification||{})))}setNotificationsAsRead(e){try{let t=this.authService.getUser();if(t){let n=new Date().getTime()+this.commonDbService.getOffset();e.forEach(i=>{this.commonDbService.updateData({feature:"notificationViewsTimestamp",properties:{id:i,user:t.userSnippylyId,documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??""},data:{timestamp:n}})})}}catch(t){this.loggingService.catch("Error in ViewsService setNotificationAsRead:",t)}}getDocumentViews$(){return this.views$.pipe(J((e,t)=>JSON.stringify(e?.documentViews||{})===JSON.stringify(t?.documentViews||{})))}getUniqueViewsByUser(e){try{return this.enableDocumentViews(),this.docService.getDocumentPaths$().pipe(S(t=>(this.documentPaths=t,e?this.locationViews$.pipe(f(n=>{let i=Object.keys(n||{}).find(o=>n?.[o]?.location?.id===e);return i?n?.[i]?.users||{}:{}})):this.documentViews$.pipe(f(n=>{let i=this.documentPaths?.documentId;return i?n?.[i]?.users||{}:{}})))),J(He))}catch(t){return this.loggingService.catch("Error in ViewsService getUniqueViewsByUser:",t),V({})}}getUniqueViewsByDate(e){try{return this.enableDocumentViews(),this.docService.getDocumentPaths$().pipe(S(t=>(this.documentPaths=t,e?this.locationViews$.pipe(f(n=>{let i=Object.keys(n||{}).find(o=>n?.[o]?.location?.id===e);return i?n?.[i]?.day||{}:{}})):this.documentViews$.pipe(f(n=>{let i=this.documentPaths?.documentId;return i?n?.[i]?.day||{}:{}})))))}catch(t){return this.loggingService.catch("Error in ViewsService getUniqueViewsByDate:",t),V({})}}enableDocumentViews(){try{if(this.documentViewsEnabled$.value===!0)return;this.documentViewsEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in ViewsService enableDocumentViews:",e)}}disableDocumentViews(){try{if(this.documentViewsEnabled$.value===!1)return;this.documentViewsEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in ViewsService disableDocumentViews:",e)}}setDocumentAsRead(n){return q(this,arguments,function*({documentId:e,clientDocumentId:t}){try{let i=this.authService.getUser();if(i&&e&&this.userPermissionService?.hasEditAccess({documentId:e??"",folderId:this.documentPaths?.allDocuments&&this.documentPaths?.veltFolderId?this.documentPaths?.veltFolderId:void 0})){if(this.documentViewsSetByDocumentId[e])return;this.documentViewsSetByDocumentId[e]=!0;let o=new Date().getTime()+this.commonDbService.getOffset(),a=new Date().toISOString().split("T")[0],d=this.getDocumentViewsById(e);if(d){let s=new Date().toISOString().split("T")[0];d?.users[i.userSnippylyId]||(d.users[i.userSnippylyId]={}),d.users[i.userSnippylyId][s]={timestamp:this.timestamp},d?.day[s]||(d.day[s]={}),d.day[s][i.userSnippylyId]={timestamp:this.timestamp},d.metadata=this.docService.getBaseMetadata("documentViews",{clientDocumentId:t}),this.commonDbService.updateData({feature:"documentViews",properties:{id:e,date:s,user:i.userSnippylyId,documentId:e,organizationId:this.documentPaths?.organizationId??""},data:d})}else this.commonDbService.updateData({feature:"documentDayViews",properties:{id:e,date:a,user:i.userSnippylyId,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:{timestamp:o}}),this.commonDbService.updateData({feature:"documentUsersViews",properties:{id:e,user:i.userSnippylyId,date:a,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:{timestamp:o}}),this.commonDbService.updateData({feature:"documentMetadataViews",properties:{id:e,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:this.docService.getBaseMetadata("documentViews",{clientDocumentId:t})}),this.docService.getDocumentMetadata$(e).pipe(A(s=>s!==null),ie(1)).subscribe(()=>{let s={day:{[a]:{[i.userSnippylyId]:{timestamp:o}}},users:{[i.userSnippylyId]:{[a]:{timestamp:o}}},metadata:this.docService.getBaseMetadata("documentViews",{clientDocumentId:t})};this.commonDbService.updateData({feature:"documentViews",properties:{id:e,date:a,user:i.userSnippylyId,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipRtdb:!0},data:s})});this.checkAndTriggerNotification(i)}}catch(i){this.loggingService.catch("Error in ViewsService setDocumentAsRead:",i)}})}checkAndTriggerNotification(e){try{this.getUniqueViewsByUser().pipe(ie(1)).subscribe(t=>{if(Object.keys(t??{}).length===2){let n=this.docService.getDocumentMetadata();if(n?.creator?.email&&n?.creator?.email!==e.email){let i=[n.creator.email];this.updateNotificationsDatabase(Ge.FIRST_VIEWED,{documentViews:{emails:i}})}}})}catch(t){this.loggingService.catch("Error in checkAndTriggerNotification:",t)}}setLocationAsRead(n){return q(this,arguments,function*({documentId:e,clientDocumentId:t}){try{let i=this.authService.getUser(),o=this.docService.getLocation(),a=o?.locationId,d=o?.location;if(i&&a&&d){let s=new Date().getTime()+this.commonDbService.getOffset(),u=new Date().toISOString().split("T")[0],g=this.getLocationViewsById(a);if(g){let p=new Date().toISOString().split("T")[0];g?.users[i.userSnippylyId]||(g.users[i.userSnippylyId]={}),g.users[i.userSnippylyId][p]={timestamp:this.timestamp},g?.day[p]||(g.day[p]={}),g.day[p][i.userSnippylyId]={timestamp:this.timestamp},g.metadata=this.docService.getBaseMetadata("locationViews",{clientDocumentId:t}),this.commonDbService.updateData({feature:"location",data:g,properties:{id:a,documentId:e,organizationId:this.documentPaths?.organizationId??""}})}else{this.commonDbService.updateData({feature:"locationViews",data:d,properties:{id:a,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0}}),this.commonDbService.updateData({feature:"locationUsersViews",properties:{id:a,user:i.userSnippylyId,date:u,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:{timestamp:s}}),this.commonDbService.updateData({feature:"locationDayViews",properties:{id:a,date:u,user:i.userSnippylyId,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:{timestamp:s}}),this.commonDbService.updateData({feature:"locationMetadataViews",properties:{id:a,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:this.docService.getBaseMetadata("locationViews",{clientDocumentId:t})});let p={day:{[u]:{[i.userSnippylyId]:{timestamp:s}}},users:{[i.userSnippylyId]:{[u]:{timestamp:s}}},metadata:this.docService.getBaseMetadata("locationViews",{clientDocumentId:t}),location:d};this.commonDbService.updateData({feature:"location",data:p,properties:{id:a,documentId:e,organizationId:this.documentPaths?.organizationId??"",skipRtdb:!0}})}}}catch(i){this.loggingService.catch("Error in ViewsService setLocationAsRead:",i)}})}updateNotificationsDatabase(e,t={}){try{let n=m({actionType:e,notificationSource:"documentViews"},t);this.notificationService?.updateNotificationDatabase(n)}catch(n){this.loggingService.catch("Error in CommentService updateNotificationsDatabase: ",n)}}get timestamp(){return this.commonDbService.getServerTimestamp()}};c.\u0275fac=function(t){return new(t||c)(T(Fe),T(Xe),T(Ze),T(et),T(ue),T(tt),T(ct),T(D),T(dt),T(de))},c.\u0275prov=xe({token:c,factory:c.\u0275fac,providedIn:"root"});let l=c;return l})();function wt(l,c){if(l&1&&(W(0),v(1,"div",21)(2,"div",22),M(3,"snippyly-user-avatar",23),w(),v(4,"div",24)(5,"div",25),E(6),U(7,"translate"),w()(),v(8,"div",26),E(9),U(10,"timeAgo"),w()(),G()),l&2){let r=c.$implicit;h(3),x("user",r==null?null:r.user)("size",32),h(3),R(" ",k(7,4,(r==null||r.user==null?null:r.user.name)||(r==null||r.user==null?null:r.user.email))," "),h(3),R(" ",k(10,6,r==null?null:r.timestamp)," ")}}function yt(l,c){if(l&1&&(v(0,"div",19),z(1,wt,11,8,"ng-container",20),w()),l&2){let r=_(2).ngIf;h(),x("ngForOf",r.userViews)}}function ft(l,c){if(l&1){let r=K();W(0),v(1,"div",4)(2,"button",5),j("click",function(){P(r);let t=_(2);return F(t.closeTrendDialog())}),Y(),v(3,"svg",6),M(4,"path",7),w(),Q(),v(5,"span"),E(6),U(7,"translate"),w()()(),v(8,"div",8)(9,"div",9)(10,"div",10),E(11),w(),v(12,"div",11),Y(),v(13,"svg",12),M(14,"path",13)(15,"path",14),w(),Q(),v(16,"span"),E(17),U(18,"translate"),w()()(),v(19,"div",15)(20,"div",16),E(21),w(),v(22,"div",17)(23,"span"),E(24),U(25,"translate"),w()()()(),z(26,yt,2,1,"div",18),G()}if(l&2){let r=_().ngIf;h(6),H(k(7,6,"Go Back")),h(5),R(" ",r.totalUniqueViewsCount," "),h(6),H(k(18,8,"Total Views")),h(4),R(" ",r.todayViewsCount," "),h(3),H(k(25,10,"Views Today")),h(2),x("ngIf",r.userViews==null?null:r.userViews.length)}}function St(l,c){if(l&1&&(W(0),v(1,"div",21)(2,"div",22),M(3,"snippyly-user-avatar",23),w(),v(4,"div",24)(5,"div",25),E(6),U(7,"translate"),w(),v(8,"div",26),E(9),U(10,"timeAgo"),w()()(),G()),l&2){let r=c.$implicit;h(3),x("user",r==null?null:r.user)("size",32),h(3),R(" ",k(7,4,(r==null||r.user==null?null:r.user.name)||(r==null||r.user==null?null:r.user.email))," "),h(3),R(" ",k(10,6,r==null?null:r.timestamp)," ")}}function bt(l,c){if(l&1&&(v(0,"div",29)(1,"div",19),z(2,St,11,8,"ng-container",20),w()()),l&2){let r=_(2).ngIf;h(2),x("ngForOf",r.userViews)}}function Vt(l,c){if(l&1&&(v(0,"div",27)(1,"div",9)(2,"div",10),E(3),w(),v(4,"div",11),Y(),v(5,"svg",12),M(6,"path",13)(7,"path",14),w(),Q(),v(8,"span"),E(9),U(10,"translate"),w()()(),v(11,"div",15),E(12),U(13,"translate"),U(14,"translate"),U(15,"translate"),w()(),z(16,bt,3,1,"div",28)),l&2){let r=_().ngIf;h(3),R(" ",r.totalUniqueViewsCount," "),h(6),H(k(10,6,"Total Views")),h(3),Ae(" ",r.todayViewsCount," ",r.todayViewsCount===1?k(13,8,"View"):k(14,10,"Views")," ",k(15,12,"Today")," "),h(4),x("ngIf",r.userViews==null?null:r.userViews.length)}}function It(l,c){if(l&1){let r=K();W(0),v(1,"div",2),j("clickOutside",function(){P(r);let t=_();return F(t.closeTrendDialog())}),z(2,ft,27,12,"ng-container",3)(3,Vt,17,14,"ng-template",null,0,ce),w(),G()}if(l&2){let r=c.ngIf,e=se(4);h(),ae("bottom-sheet",r.bottomSheetMode),h(),x("ngIf",r.bottomSheetMode)("ngIfElse",e)}}var ee=(()=>{let c=class c{constructor(e,t,n,i,o,a,d){this.contactService=e,this.loggingService=t,this.viewsService=n,this.themeService=i,this.elementRef=o,this.domService=a,this.bottomSheetData=d,this.close=new re,this.componentConfigSignal=ne({today:new Date().toISOString().split("T")[0],todayViews:{},todayViewsCount:0,totalUniqueViews:{},totalUniqueViewsCount:0,views:{},usersMap:{},userViews:[],bottomSheetMode:!1}),this.subscriptions=[];try{d&&(this.componentConfigSignal.update(s=>(s=y(m({},s),{bottomSheetMode:!0}),s)),this.clientLocationId=d.clientLocationId,this.closeBottomSheetFn=d.closeBottomSheetFn),this.subscriptions.push(this.contactService.getUsersMap$().subscribe(s=>{this.componentConfigSignal.update(u=>(u=y(m({},u),{usersMap:s||{}}),u)),this.setLatestViewsByUsers()},s=>{this.loggingService.catch("Error in ViewAnalyticsDialogComponent getUsersMap$ subscription: ",s)})),this.subscriptions.push(this.themeService.getDarkMode$().subscribe(s=>{s?this.elementRef.nativeElement.setAttribute("dark",""):this.elementRef.nativeElement.removeAttribute("dark")}))}catch(s){this.loggingService.catch("Error in ViewAnalyticsDialogComponent constructor: ",s)}}ngOnInit(){this.getDocumentViews()}ngAfterViewInit(){try{this.subscriptions.push(this.domService.subscribeInjectCustomCss(this.elementRef))}catch(e){this.loggingService.catch("Error in ViewAnalyticsDialogComponent ngAfterViewInit: ",e)}}trackByUserIdAndTimestamp(e,t){return`${t?.user?.userSnippylyId}-${t.timestamp}`}getDocumentViews(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getDocumentViews","color: green;"),this.uniqueViewsByUserSubscription&&(this.componentConfigSignal.update(e=>(e=y(m({},e),{totalUniqueViews:{},totalUniqueViewsCount:0}),e)),this.uniqueViewsByUserSubscription.unsubscribe()),this.uniqueViewsByDateSubscription&&(this.componentConfigSignal.update(e=>(e=y(m({},e),{todayViews:{},todayViewsCount:0}),e)),this.uniqueViewsByDateSubscription.unsubscribe()),this.uniqueViewsByUserSubscription=this.viewsService.getUniqueViewsByUser(this.clientLocationId).subscribe(e=>{this.componentConfigSignal.update(t=>(t=y(m({},t),{totalUniqueViews:e||{},totalUniqueViewsCount:Object.keys(e||{})?.length||0}),t)),this.setLatestViewsByUsers()},e=>{this.loggingService.catch("Error in ViewAnalyticsDialogComponent getUniqueViewsByUser subscription: ",e)}),this.uniqueViewsByDateSubscription=this.viewsService.getUniqueViewsByDate(this.clientLocationId).subscribe(e=>{this.componentConfigSignal.update(t=>(t=m({},t),t.todayViews=e&&e[t.today]?e[t.today]:{},t.todayViewsCount=Object.keys(t.todayViews||{})?.length||0,t)),this.setLatestViewsByUsers()},e=>{this.loggingService.catch("Error in ViewAnalyticsDialogComponent getUniqueViewsByDate subscription: ",e)})}catch(e){this.loggingService.catch("Error in ViewAnalyticsDialogComponent getDocumentViews: ",e)}}setLatestViewsByUsers(){try{this.loggingService.log("%c[WB] Calling FUNCTION: setLatestViewsByUsers","color: green;"),Object.keys(this.componentConfigSignal().todayViews||{}).forEach(e=>{let t=this.componentConfigSignal().usersMap[e],n=this.componentConfigSignal().todayViews[e]?.timestamp;t&&n&&(this.componentConfigSignal().userViews.find(o=>o.user.userSnippylyId===e)||this.componentConfigSignal.update(o=>(o=y(m({},o),{userViews:[...o.userViews,{user:t,timestamp:n}]}),o)))}),this.componentConfigSignal.update(e=>(e=m({},e),e.userViews.sort((t,n)=>n.timestamp-t.timestamp),e.userViews=e.userViews.slice(0,3),e))}catch(e){this.loggingService.catch("Error in ViewAnalyticsDialogComponent setLatestViewsByUsers: ",e)}}closeTrendDialog(){try{this.close.emit(),this.closeBottomSheetFn&&this.closeBottomSheetFn?.()}catch(e){this.loggingService.catch("Error in ViewAnalyticsDialogComponent onClose: ",e)}}ngOnDestroy(){try{this.subscriptions.forEach(e=>{e.unsubscribe()}),this.uniqueViewsByDateSubscription?.unsubscribe(),this.uniqueViewsByUserSubscription?.unsubscribe()}catch(e){this.loggingService.catch("Error in ViewAnalyticsDialogComponent ngOnDestroy: ",e)}}};c.\u0275fac=function(t){return new(t||c)(I(it),I(D),I(L),I(nt),I(oe),I(me),I(Re,8))},c.\u0275cmp=Z({type:c,selectors:[["velt-view-analytics-dialog"]],inputs:{clientLocationId:"clientLocationId"},outputs:{close:"close"},standalone:!1,decls:1,vars:1,consts:[["defaultDialogRef",""],[4,"ngIf"],["snippylyClickOutside","",1,"v-view-analytics-dialog-container",3,"clickOutside"],[4,"ngIf","ngIfElse"],[1,"v-back-btn-container"],[1,"v-back-btn",3,"click"],["width","16","height","16","viewBox","0 0 16 16","fill","none","xmlns","http://www.w3.org/2000/svg"],["d","M9.99988 4L5.99988 8L9.99988 12","stroke","currentColor","stroke-width","1.33333","stroke-linecap","round","stroke-linejoin","round"],[1,"v-view-analytics-count-container"],[1,"v-total-views-container"],[1,"v-total-views-count"],[1,"v-total-views-text"],["width","18","height","18","viewBox","0 0 18 18","fill","none","xmlns","http://www.w3.org/2000/svg"],["d","M7.5 9C7.5 9.39782 7.65804 9.77936 7.93934 10.0607C8.22064 10.342 8.60218 10.5 9 10.5C9.39782 10.5 9.77936 10.342 10.0607 10.0607C10.342 9.77936 10.5 9.39782 10.5 9C10.5 8.60218 10.342 8.22064 10.0607 7.93934C9.77936 7.65804 9.39782 7.5 9 7.5C8.60218 7.5 8.22064 7.65804 7.93934 7.93934C7.65804 8.22064 7.5 8.60218 7.5 9Z","stroke","#625DF5","stroke-width","1.25","stroke-linecap","round","stroke-linejoin","round"],["d","M15.75 9C13.95 12 11.7 13.5 9 13.5C6.3 13.5 4.05 12 2.25 9C4.05 6 6.3 4.5 9 4.5C11.7 4.5 13.95 6 15.75 9Z","stroke","#625DF5","stroke-width","1.25","stroke-linecap","round","stroke-linejoin","round"],[1,"v-today-views-container"],[1,"v-today-views-count"],[1,"v-today-views-text"],["class","v-users-container",4,"ngIf"],[1,"v-users-container"],[4,"ngFor","ngForOf"],[1,"v-user"],[1,"v-user-image"],[3,"user","size"],[1,"v-user-view-details"],[1,"v-user-name"],[1,"v-user-view-time"],[1,"v-document-viewer-tread-left"],["class","v-document-viewer-tread-right",4,"ngIf"],[1,"v-document-viewer-tread-right"]],template:function(t,n){t&1&&z(0,It,5,4,"ng-container",1),t&2&&x("ngIf",n.componentConfigSignal())},dependencies:[ke,le,rt,st,ot,mt],styles:[`.v-view-analytics-dialog-container{border-radius:var(--legacy-velt-view-analytics-dialog-border-radius);border:var(--legacy-velt-view-analytics-dialog-border);background:var(--legacy-velt-view-analytics-dialog-bg-color);box-shadow:var(--legacy-velt-view-analytics-dialog-box-shadow);padding:var(--legacy-velt-view-analytics-dialog-padding);display:flex;gap:16px}.v-view-analytics-dialog-container .v-document-viewer-tread-left{display:flex;flex-direction:column;gap:4px}.v-view-analytics-dialog-container .v-document-viewer-tread-left .v-total-views-container{width:140px;height:110px;flex-shrink:0;border-radius:8px;background:var(--legacy-velt-view-analytics-dialog-views-container-bg-color);box-sizing:border-box;display:flex;flex-direction:column;justify-content:center;align-items:center;gap:10px}.v-view-analytics-dialog-container .v-document-viewer-tread-left .v-total-views-container .v-total-views-count{color:var(--legacy-velt-view-analytics-dialog-total-views-count-color);font-size:32px;font-style:normal;font-weight:600;line-height:100%}.v-view-analytics-dialog-container .v-document-viewer-tread-left .v-total-views-container .v-total-views-text{color:var(--legacy-velt-view-analytics-dialog-total-views-text-color);font-size:12px;font-style:normal;font-weight:500;line-height:100%;text-transform:uppercase;display:flex;gap:4px;align-items:center}.v-view-analytics-dialog-container .v-document-viewer-tread-left .v-today-views-container{display:flex;width:140px;padding:8px 4px;justify-content:center;align-items:center;gap:4px;border-radius:8px;background:var(--legacy-velt-view-analytics-dialog-views-container-bg-color);box-sizing:border-box;color:var(--legacy-velt-view-analytics-dialog-today-views-text-color);font-size:12px;font-style:normal;font-weight:500;line-height:100%;text-transform:uppercase}.v-view-analytics-dialog-container .v-document-viewer-tread-right{padding:8px 0}.v-view-analytics-dialog-container .v-document-viewer-tread-right .v-users-container{display:inline-flex;flex-direction:column;align-items:flex-start;gap:16px;margin-right:16px}.v-view-analytics-dialog-container .v-document-viewer-tread-right .v-users-container .v-user{display:flex;align-items:center;gap:12px}.v-view-analytics-dialog-container .v-document-viewer-tread-right .v-users-container .v-user snippyly-user-avatar{display:flex}.v-view-analytics-dialog-container .v-document-viewer-tread-right .v-users-container .v-user .v-user-view-details{display:flex;flex-direction:column;gap:8px}.v-view-analytics-dialog-container .v-document-viewer-tread-right .v-users-container .v-user .v-user-view-details .v-user-name{color:var(--legacy-velt-view-analytics-dialog-user-name-color);font-size:12px;font-style:normal;font-weight:500;line-height:100%}.v-view-analytics-dialog-container .v-document-viewer-tread-right .v-users-container .v-user .v-user-view-details .v-user-view-time{color:var(--legacy-velt-view-analytics-dialog-user-timestamp-color);font-size:10px;font-style:normal;font-weight:500;line-height:100%;text-transform:uppercase}.v-view-analytics-dialog-container.bottom-sheet{display:flex;flex-direction:column;border-bottom-left-radius:0;border-bottom-right-radius:0}.v-view-analytics-dialog-container.bottom-sheet .v-back-btn-container{display:flex;padding:8px 8px 0}.v-view-analytics-dialog-container.bottom-sheet .v-back-btn-container .v-back-btn{background:transparent;border:0;outline:0;display:flex;align-items:center;gap:8px;color:var(--legacy-velt-view-analytics-dialog-back-btn-color);cursor:pointer;font-size:16px;font-style:normal;font-weight:400;line-height:normal}.v-view-analytics-dialog-container.bottom-sheet .v-view-analytics-count-container{display:flex;flex:1;gap:10px}.v-view-analytics-dialog-container.bottom-sheet .v-view-analytics-count-container .v-total-views-container{display:flex;padding:25px 20px;flex-direction:column;justify-content:center;align-items:center;gap:10px;flex:1 0 0;border-radius:8px;background:var(--legacy-velt-view-analytics-dialog-views-container-bg-color)}.v-view-analytics-dialog-container.bottom-sheet .v-view-analytics-count-container .v-total-views-container .v-total-views-count{color:var(--legacy-velt-view-analytics-dialog-total-views-count-color);font-size:32px;font-style:normal;font-weight:600;line-height:100%}.v-view-analytics-dialog-container.bottom-sheet .v-view-analytics-count-container .v-total-views-container .v-total-views-text{color:var(--legacy-velt-view-analytics-dialog-total-views-text-color);font-size:12px;font-style:normal;font-weight:500;line-height:100%;text-transform:uppercase;display:flex;gap:4px;align-items:center}.v-view-analytics-dialog-container.bottom-sheet .v-view-analytics-count-container .v-today-views-container{display:flex;padding:25px 20px;flex-direction:column;justify-content:center;align-items:center;gap:10px;flex:1 0 0;border-radius:8px;background:var(--legacy-velt-view-analytics-dialog-views-container-bg-color)}.v-view-analytics-dialog-container.bottom-sheet .v-view-analytics-count-container .v-today-views-container .v-today-views-count{color:var(--legacy-velt-view-analytics-dialog-today-views-text-color);font-size:32px;font-style:normal;font-weight:600;line-height:100%}.v-view-analytics-dialog-container.bottom-sheet .v-view-analytics-count-container .v-today-views-container .v-today-views-text{color:var(--legacy-velt-view-analytics-dialog-today-views-text-color);font-size:12px;font-style:normal;font-weight:500;line-height:100%;text-transform:uppercase;display:flex;gap:4px;align-items:center}.v-view-analytics-dialog-container.bottom-sheet .v-users-container{display:inline-flex;flex-direction:column;align-items:flex-start;gap:16px;margin-right:16px}.v-view-analytics-dialog-container.bottom-sheet .v-users-container .v-user{display:flex;align-items:center;gap:12px;width:100%}.v-view-analytics-dialog-container.bottom-sheet .v-users-container .v-user snippyly-user-avatar{display:flex}.v-view-analytics-dialog-container.bottom-sheet .v-users-container .v-user .v-user-view-details{display:flex;flex-direction:column;gap:8px;flex:1}.v-view-analytics-dialog-container.bottom-sheet .v-users-container .v-user .v-user-view-details .v-user-name{color:var(--legacy-velt-view-analytics-dialog-user-name-color);font-size:12px;font-style:normal;font-weight:500;line-height:100%}.v-view-analytics-dialog-container.bottom-sheet .v-users-container .v-user .v-user-view-time{color:var(--legacy-velt-view-analytics-dialog-user-timestamp-color);font-size:10px;font-style:normal;font-weight:500;line-height:100%;text-transform:uppercase} `],encapsulation:3,changeDetection:0});let l=c;return l})();var be=(()=>{let c=class c{constructor(e,t){this.bottomSheet=e,this.loggingService=t,this.close=new re,this.subscriptions=[]}ngOnInit(){}ngAfterViewInit(){this.openBottomSheet()}openBottomSheet(){return q(this,null,function*(){try{this.bottomSheetRef=this.bottomSheet.open(ee,{data:{clientLocationId:this.clientLocationId,closeBottomSheetFn:()=>{this.onClose(),this.bottomSheetRef?.dismiss()}},panelClass:["v-view-analytics-bottom-sheet-container","velt-mat-bottom-sheet-container"]}),this.subscriptions.push(this.bottomSheetRef.backdropClick().subscribe(()=>{this.onClose()},e=>{this.loggingService.catch("Error in ViewAnalyticsBottomSheetComponent backdropClick subscription: ",e)}))}catch(e){this.loggingService.catch("Error in ViewAnalyticsBottomSheetComponent openBottomSheet: ",e)}})}onClose(){try{this.close.emit()}catch(e){this.loggingService.catch("Error in ViewAnalyticsBottomSheetComponent onClose: ",e)}}ngOnDestroy(){try{this.subscriptions.forEach(e=>{e.unsubscribe()})}catch(e){this.loggingService.catch("Error in ViewAnalyticsBottomSheetComponent ngOnDestroy: ",e)}}};c.\u0275fac=function(t){return new(t||c)(I(qe),I(D))},c.\u0275cmp=Z({type:c,selectors:[["velt-view-analytics-bottom-sheet-internal"]],inputs:{clientLocationId:"clientLocationId"},outputs:{close:"close"},standalone:!1,decls:0,vars:0,template:function(t,n){},styles:[".velt-mat-bottom-sheet-container.v-view-analytics-bottom-sheet-container{padding:0!important} .velt-mat-bottom-sheet-container.v-view-analytics-bottom-sheet-container .mat-bottom-sheet-container{padding:0!important}"],changeDetection:0});let l=c;return l})();var xt=()=>["snippyly-overlay-panel","v-view-analytics-overlay-panel","velt-overlay-panel"];function _t(l,c){if(l&1){let r=K();v(0,"velt-view-analytics-dialog",11),j("close",function(){P(r);let t=_(2);return F(t.toggleTrends())}),w()}if(l&2){let r=_(2);x("clientLocationId",r.clientLocationId)}}function Et(l,c){if(l&1){let r=K();v(0,"velt-view-analytics-bottom-sheet-internal",11),j("close",function(){P(r);let t=_(2);return F(t.closeTrends())}),w()}if(l&2){let r=_(2);x("clientLocationId",r.clientLocationId)}}function Ot(l,c){if(l&1){let r=K();W(0),v(1,"div",3,0),j("click",function(t){return P(r),_().toggleTrends(),F(t.stopPropagation())}),v(3,"slot",4),j("slotchange",function(){P(r);let t=_();return F(t.onButtonSlotChange())}),v(4,"div",5),Y(),v(5,"svg",6),M(6,"path",7),w(),Q(),v(7,"span",8),E(8),w()()()(),z(9,_t,1,1,"ng-template",9,1,ce)(11,Et,1,1,"velt-view-analytics-bottom-sheet-internal",10),G()}if(l&2){let r=c.ngIf,e=se(2),t=_();h(4),ae("active",r.treadsVisible),h(4),H(r.totalUniqueViewsCount),h(),x("cdkConnectedOverlayOrigin",e)("cdkConnectedOverlayOpen",!r.isPhone&&r.treadsVisible)("cdkConnectedOverlayPanelClass",Ue(11,xt))("cdkConnectedOverlayBackdropClass","snippyly-overlay-backdrop")("cdkConnectedOverlayGrowAfterOpen",!0)("cdkConnectedOverlayPositions",t.positions)("cdkConnectedOverlayDisableClose",!0),h(2),x("ngIf",r.isPhone&&r.treadsVisible)}}var Ve=(()=>{let c=class c{constructor(e,t,n,i,o,a){this.breakpointObserver=e,this.docService=t,this.loggingService=n,this.viewsService=i,this.elementRef=o,this.domService=a,this.type="document",this.componentConfigSignal=ne({today:new Date().toISOString().split("T")[0],todayViews:{},todayViewsCount:0,totalUniqueViews:{},totalUniqueViewsCount:0,treadsVisible:!1,customButtonAdded:!1,isPhone:!1,componentId:Math.random().toString(36).substring(2)}),this.positions=O.OVERLAY_POSITIONS.map(d=>new ze({originX:d.originX,originY:d.originY},{overlayX:d.overlayX,overlayY:d.overlayY})),this.subscriptions=[]}ngOnInit(){try{this.getUniqueViewsByUser(),this.subscriptions.push(this.breakpointObserver.observe(je.XSmall).subscribe(e=>{this.componentConfigSignal.update(t=>(t=m({},t),t.isPhone=!!e.matches,t))},e=>{this.loggingService.catch("Error in ViewAnalyticsComponent breakpointObserver subscription: ",e)})),this.subscriptions.push(this.docService.getLocation$().subscribe(e=>{e?.location?.id&&(this.clientLocationId=e?.location?.id,this.getUniqueViewsByUser())}))}catch(e){this.loggingService.catch("Error in ViewAnalyticsComponent ngOnInit: ",e)}}ngOnChanges(e){try{(e.type||e.clientLocationId)&&this.getUniqueViewsByUser()}catch(t){this.loggingService.catch("Error in ViewAnalyticsComponent ngOnChanges: ",t)}}ngAfterViewInit(){try{this.subscriptions.push(this.domService.subscribeInjectCustomCss(this.elementRef))}catch(e){this.loggingService.catch("Error in ViewAnalyticsComponent ngAfterViewInit: ",e)}}getUniqueViewsByUser(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getDocumentViews","color: green;"),this.uniqueViewsByUserSubscription&&(this.componentConfigSignal.update(t=>(t=m({},t),t.totalUniqueViews={},t.totalUniqueViewsCount=0,t)),this.uniqueViewsByUserSubscription.unsubscribe());let e=this.type==="location"&&this.clientLocationId?this.clientLocationId:void 0;this.uniqueViewsByUserSubscription=this.viewsService.getUniqueViewsByUser(e).subscribe(t=>{this.componentConfigSignal.update(n=>(n=m({},n),n.totalUniqueViews=t||{},n.totalUniqueViewsCount=Object.keys(n.totalUniqueViews||{})?.length||0,n))},t=>{this.loggingService.catch("Error in ViewAnalyticsComponent getUniqueViewsByUser subscription: ",t)})}catch(e){this.loggingService.catch("Error in ViewAnalyticsComponent getDocumentViews: ",e)}}toggleTrends(){try{this.loggingService.log("%c[WB] Calling FUNCTION: toggleTrends","color: green;"),this.componentConfigSignal.update(e=>(e=m({},e),e.treadsVisible=!e.treadsVisible,e))}catch(e){this.loggingService.catch("Error in ViewAnalyticsComponent toggleTrends: ",e)}}openTrends(){try{this.loggingService.log("%c[WB] Calling FUNCTION: openTrends","color: green;"),this.componentConfigSignal.update(e=>(e=m({},e),e.treadsVisible=!0,e))}catch(e){this.loggingService.catch("Error in ViewAnalyticsComponent openTrends: ",e)}}closeTrends(){try{this.loggingService.log("%c[WB] Calling FUNCTION: closeTrends","color: green;"),this.componentConfigSignal.update(e=>(e=m({},e),e.treadsVisible=!1,e))}catch(e){this.loggingService.catch("Error in ViewAnalyticsComponent closeTrends: ",e)}}onButtonSlotChange(){this.componentConfigSignal.update(e=>(e=m({},e),e.customButtonAdded=!0,e))}unsubscribe(){this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribe","color: green;");try{this.subscriptions.map(e=>{e.unsubscribe()}),this.subscriptions=[],this.uniqueViewsByUserSubscription&&this.uniqueViewsByUserSubscription.unsubscribe()}catch(e){this.loggingService.catch("Error in ViewAnalyticsComponent unsubscribe: ",e)}}ngOnDestroy(){try{this.unsubscribe()}catch(e){this.loggingService.catch("Error in ViewAnalyticsComponent ngOnDestroy: ",e)}}};c.\u0275fac=function(t){return new(t||c)(I(Me),I(ue),I(D),I(L),I(oe),I(me))},c.\u0275cmp=Z({type:c,selectors:[["velt-view-analytics-internal"]],inputs:{type:"type",clientLocationId:[0,"locationId","clientLocationId"]},standalone:!1,features:[Ee],decls:1,vars:1,consts:[["trigger","cdkOverlayOrigin"],["overlay","cdkConnectedOverlay"],[4,"ngIf"],["part","container","cdkOverlayOrigin","",1,"v-document-viewer-tread-container",3,"click"],["name","button",3,"slotchange"],["part","button-container",1,"action-btn"],["part","button-icon","width","24","height","24","viewBox","0 0 24 24","fill","none","xmlns","http://www.w3.org/2000/svg",1,"action-btn-icon"],["d","M4.5 16.1667L9.5 11.1667L12.8333 14.5L19.5 7.83334M19.5 7.83334H13.6667M19.5 7.83334V13.6667","stroke","currentColor","stroke-width","1.5","stroke-linecap","round","stroke-linejoin","round"],["part","button-label",1,"action-btn-label"],["cdkConnectedOverlay","",3,"cdkConnectedOverlayOrigin","cdkConnectedOverlayOpen","cdkConnectedOverlayPanelClass","cdkConnectedOverlayBackdropClass","cdkConnectedOverlayGrowAfterOpen","cdkConnectedOverlayPositions","cdkConnectedOverlayDisableClose"],[3,"clientLocationId","close",4,"ngIf"],[3,"close","clientLocationId"]],template:function(t,n){t&1&&z(0,Ot,12,12,"ng-container",2),t&2&&x("ngIf",n.componentConfigSignal())},dependencies:[le,Ne,$e,ee,be],styles:[`html{--velt-base-rem-unit: 1}*[data-snippyly-element=true],*[data-velt-element=true]{font-family:var(--velt-default-font-family)}velt-wireframe{display:none!important}body.velt-pin-dragging iframe{pointer-events:none!important}*{box-sizing:border-box;-webkit-tap-highlight-color:rgba(255,255,255,0);outline:none;margin:0;padding:0;height:unset;width:unset;text-align:left;line-height:1.5;font-size:calc((1rem + 0px) * var(--velt-base-rem-unit))}*:empty{display:revert}.v-document-viewer-tread-container{display:inline-block}.action-btn{display:inline-flex;justify-content:center;align-items:center;padding:6px;border-radius:var(--legacy-velt-tool-border-radius);border:var(--legacy-velt-tool-border);background-color:var(--legacy-velt-tool-bg-color);color:var(--legacy-velt-tool-icon-color);cursor:pointer}.action-btn .action-btn-label{font-size:calc((.9rem + 0px) * var(--velt-base-rem-unit));padding:0 12px 0 4px;font-weight:700;color:currentColor}.action-btn .action-btn-icon{width:calc((var(--legacy-velt-tool-icon-size) + 0px) * var(--velt-base-rem-unit));height:calc((var(--legacy-velt-tool-icon-size) + 0px) * var(--velt-base-rem-unit));color:currentColor;padding-left:8px;box-sizing:content-box}.action-btn .toolbar-icon-dropdown-arrow{width:16px;height:16px;color:currentColor}.action-btn:focus{border-radius:var(--legacy-velt-tool-focus-border-radius);border:var(--legacy-velt-tool-focus-border);background-color:var(--legacy-velt-tool-focus-bg-color);color:var(--legacy-velt-tool-focus-icon-color)}.action-btn:focus .action-btn-icon{width:calc((var(--legacy-velt-tool-focus-icon-size) + 0px) * var(--velt-base-rem-unit));height:calc((var(--legacy-velt-tool-focus-icon-size) + 0px) * var(--velt-base-rem-unit))}.action-btn:focus .toolbar-icon-dropdown-arrow{color:var(--legacy-velt-tool-focus-icon-color)}.action-btn:hover{border-radius:var(--legacy-velt-tool-hover-border-radius);border:var(--legacy-velt-tool-hover-border);background-color:var(--legacy-velt-tool-hover-bg-color);color:var(--legacy-velt-tool-hover-icon-color)}.action-btn:hover .action-btn-icon{width:calc((var(--legacy-velt-tool-hover-icon-size) + 0px) * var(--velt-base-rem-unit));height:calc((var(--legacy-velt-tool-hover-icon-size) + 0px) * var(--velt-base-rem-unit))}.action-btn:hover .toolbar-icon-dropdown-arrow{color:var(--legacy-velt-tool-hover-icon-color)}.action-btn:active,.action-btn.active{border-radius:var(--legacy-velt-tool-active-border-radius);border:var(--legacy-velt-tool-active-border);background-color:var(--legacy-velt-tool-active-bg-color);color:var(--legacy-velt-tool-active-icon-color)}.action-btn:active .action-btn-icon,.action-btn.active .action-btn-icon{width:calc((var(--legacy-velt-tool-active-icon-size) + 0px) * var(--velt-base-rem-unit));height:calc((var(--legacy-velt-tool-active-icon-size) + 0px) * var(--velt-base-rem-unit))}.action-btn:active .toolbar-icon-dropdown-arrow,.action-btn.active .toolbar-icon-dropdown-arrow{color:var(--legacy-velt-tool-active-icon-color)} `],encapsulation:3,changeDetection:0});let l=c;return l})();var ve=class extends lt{constructor(c){super(c),this.getService(D).log("%c[WB] Creating CLASS: ViewsElement","color: blue;"),this.getUniqueViewsByUser=this._getUniqueViewsByUser,this.getUniqueViewsByDate=this._getUniqueViewsByDate}_getUniqueViewsByUser(c){this.getService(D).log("%c[WB] Calling FUNCTION: _getUniqueViewsByUser","color: green;");try{return this.trackEvent(ye.Events.Views.GET_UNIQUE_VIEWS_BY_USER_TRIGGERED,{payload:{clientLocationId:c}}),this.getService(L).getUniqueViewsByUser(c)}catch(r){return this.getService(D).catch("Error in getUniqueViewsByUser: ",r),V({})}}_getUniqueViewsByDate(c){this.getService(D).log("%c[WB] Calling FUNCTION: _getUniq