1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[64767],{82345:function(e,t,a){a.d(t,{AP:function(){return f},Cj:function(){return p},Q$:function(){return d},aK:function(){return g},d8:function(){return m}});var i=a(39129),n=a(83464),o=a(43577),s=a(64131),r=a(99551);let l={backlinks:[],loading:!1,error:null,stats:{total:0,dofollow:0,nofollow:0,limit:0,target_domain:""},lastUpdated:null},d=(0,i.hg)("backlinks/fetchBacklinks",async(e,t)=>{var a,i,l,d,c,u,h,f,g,m,p,v;let{rejectWithValue:y}=t,w=null!==(a=null==e?void 0:e.page)&&void 0!==a?a:1,C=null!==(i=null==e?void 0:e.pageSize)&&void 0!==i?i:10;try{let e=s.default.get("login_access_token");if(!e)return y("Authentication required");let t=(await n.default.get("".concat(r.BASE_URL,"backlink-monitor/"),{headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"},params:{page:w,page_size:C}})).data,a=[],i=0,o=0,l=0,d=0,c="";return t.results&&Array.isArray(t.results)?(a=t.results,i=t.count||t.results.length):t.results&&t.results.data&&Array.isArray(t.results.data)?(a=t.results.data,i=t.results.total||t.count||t.results.data.length,o=t.results.dofollow||0,l=t.results.nofollow||0,d=t.results.limit||0,c=t.results.target_domain||""):Array.isArray(t)&&(a=t,i=t.length),{count:i,next:t.next||null,previous:t.previous||null,results:{data:a,total:i,dofollow:o,nofollow:l,limit:d,target_domain:c}}}catch(e){if((0,o.IZ)(e)){let t=null!==(v=null!==(p=null!==(m=null===(d=e.response)||void 0===d?void 0:null===(l=d.data)||void 0===l?void 0:l.message)&&void 0!==m?m:null===(u=e.response)||void 0===u?void 0:null===(c=u.data)||void 0===c?void 0:c.detail)&&void 0!==p?p:e.message)&&void 0!==v?v:"Unable to fetch backlinks",a=null===(h=e.response)||void 0===h?void 0:h.data;return console.error("Backlink API Error:",{status:null===(f=e.response)||void 0===f?void 0:f.status,statusText:null===(g=e.response)||void 0===g?void 0:g.statusText,data:a,url:"".concat(r.BASE_URL,"backlink-monitor/"),params:{page:w,page_size:C}}),y(t)}return y("Unable to fetch backlinks")}}),c=(0,i.oM)({name:"backlinks",initialState:l,reducers:{clearError:e=>{e.error=null},setTargetDomain:(e,t)=>{e.stats.target_domain=t.payload}},extraReducers:e=>{e.addCase(d.pending,e=>{e.loading=!0,e.error=null}).addCase(d.fulfilled,(e,t)=>{var a;e.loading=!1,e.backlinks=null!==(a=t.payload.results.data)&&void 0!==a?a:[],e.stats={total:t.payload.results.total,dofollow:t.payload.results.dofollow,nofollow:t.payload.results.nofollow,limit:t.payload.results.limit,target_domain:t.payload.results.target_domain},e.lastUpdated=new Date().toISOString()}).addCase(d.rejected,(e,t)=>{e.loading=!1,e.error=t.payload||t.error.message||"Failed to fetch backlinks"})}}),{clearError:u,setTargetDomain:h}=c.actions;t.ZP=c.reducer;let f=e=>{var t,a;return null!==(a=null===(t=e.backlinks)||void 0===t?void 0:t.backlinks)&&void 0!==a?a:[]},g=e=>{var t,a;return null!==(a=null===(t=e.backlinks)||void 0===t?void 0:t.loading)&&void 0!==a&&a},m=e=>{var t,a;return null!==(a=null===(t=e.backlinks)||void 0===t?void 0:t.error)&&void 0!==a?a:null},p=e=>{var t,a;return null!==(a=null===(t=e.backlinks)||void 0===t?void 0:t.stats)&&void 0!==a?a:l.stats}},8858:function(e,t,a){a.r(t),a.d(t,{database:function(){return d},getFirebaseDatabaseURL:function(){return m},initializeFirebase:function(){return h},messaging:function(){return l},onMessageListener:function(){return g},requestPermission:function(){return f}});var i=a(738),n=a(27012),o=a(17292),s=a(7444);let r=null,l=null,d=null,c=null,u=null,h=async()=>{if(r)return r;try{let e=await (0,s.dv)();if(!e)return null;if(c={apiKey:e.apiKey,authDomain:e.authDomain,projectId:e.projectId,storageBucket:e.storageBucket,messagingSenderId:e.messagingSenderId,appId:e.appId,measurementId:e.measurementId,...e.databaseURL&&{databaseURL:e.databaseURL}},u=e.vapidKey,r=(0,i.C6)().length?(0,i.C6)()[0]:(0,i.ZF)(c),"serviceWorker"in navigator)try{l=(0,n.getMessaging)(r)}catch(e){console.error("Firebase messaging initialization error:",e)}try{let t=e.databaseURL||c.databaseURL;t?d=(0,o.N8)(r,t):(d=(0,o.N8)(r),console.warn("â ï¸ Firebase Realtime Database initialized with DEFAULT URL (databaseURL not provided by backend)"),console.warn("â ï¸ This may cause connection issues. Please ensure backend returns databaseURL in config."))}catch(t){console.error("â Firebase database initialization error:",t),console.error("â Config received from backend:",{hasDatabaseURL:!!e.databaseURL,databaseURL:e.databaseURL||"MISSING",projectId:e.projectId})}return r}catch(e){return(null==e?void 0:e.message)&&!e.message.includes("Firebase config")&&console.error("â [Firebase] Error initializing Firebase:",e),null}},f=async()=>
1{if(r||await h(),!l)return console.error("Firebase messaging not initialized"),null;if(!u)return console.error("VAPID key not available from backend"),null;if("Notification"in window){let e=Notification.permission;if("denied"===e)return window.__notificationPermissionDeniedLogged||(console.warn("â ï¸ [Notifications] Notification permission denied. Browser notifications are disabled."),console.warn("\uD83D\uDCA1 [Notifications] To enable notifications:"),console.warn(" Chrome/Edge: Click the lock icon (\uD83D\uDD12) in the address bar â Site settings â Notifications â Allow"),console.warn(" Firefox: Click the lock icon â More Information â Permissions â Notifications â Allow"),console.warn(" Safari: Safari menu â Settings â Websites â Notifications â Allow"),console.warn(" Or go to: chrome://settings/content/notifications (Chrome) or about:preferences#privacy (Firefox)"),window.__notificationPermissionDeniedLogged=!0),null;if("granted"===e)try{return await (0,n.getToken)(l,{vapidKey:u})||null}catch(e){return console.error("An error occurred while retrieving token:",e),null}}try{let e=await Notification.requestPermission();if("granted"===e)return await (0,n.getToken)(l,{vapidKey:u})||null;if("denied"===e)return window.__notificationPermissionDeniedLogged=!0,null;return null}catch(e){return console.error("An error occurred while retrieving token:",e),null}},g=e=>l?(0,n.p)(l,t=>{e&&e(t)}):(console.error("Firebase messaging not initialized"),()=>{}),m=()=>(window.getFirebaseDatabaseURL=()=>{if(d)try{var e,t;null===(t=d.app)||void 0===t||null===(e=t.options)||void 0===e||e.databaseURL}catch(e){}return{databaseInitialized:!!d,configDatabaseURL:null==c?void 0:c.databaseURL,projectId:null==c?void 0:c.projectId}},{databaseInitialized:!!d,configDatabaseURL:null==c?void 0:c.databaseURL,projectId:null==c?void 0:c.projectId});m(),t.default=r},3845:function(e,t,a){a.d(t,{h:function(){return U}});var i=a(39129),n=a(60937),o=a(81803),s=a(99551);let r=e=>Date.now()-e>3e5,l=(0,i.hg)("metadata/fetchMetadata",async(e,t)=>{let{getState:a,rejectWithValue:i}=t;try{let{data:t,lastFetched:i}=a().metadata;if(t[e]&&i[e]&&!r(i[e]))return{slug:e,data:t[e],fromCache:!0};let n=e.replace(/^\/+|\/+$/g,"")||"home",o=await fetch("".concat(s.BASE_URL,"auth/page-details/?slug=").concat(n),{headers:{"Content-Type":"application/json"}});if(!o.ok)throw Error("HTTP error! status: ".concat(o.status));let l=await o.json();return{slug:e,data:l,fromCache:!1}}catch(e){return i(e.message||"Failed to fetch metadata")}},{condition:(e,t)=>{let{getState:a}=t,{loading:i,data:n,lastFetched:o}=a().metadata;return!i[e]&&(!n[e]||!o[e]||!!r(o[e]))}}),d=(0,i.hg)("metadata/fetchWebsiteData",async(e,t)=>{let{getState:a,rejectWithValue:i}=t;try{let{data:t,lastFetched:i}=a().metadata;if(t[e]&&i[e]&&!r(i[e]))return{slug:e,data:t[e],fromCache:!0};let n=await fetch("".concat(s.BASE_URL,"website-page/").concat(e,"/"));if(!n.ok)throw Error("Failed to fetch website data: ".concat(n.status));let o=await n.json();return{slug:e,data:o,fromCache:!1}}catch(e){return i(e.message||"Failed to fetch website data")}},{condition:(e,t)=>{let{getState:a}=t,{loading:i,data:n,lastFetched:o}=a().metadata;return!i[e]&&(!n[e]||!o[e]||!!r(o[e]))}}),c=(0,i.oM)({name:"metadata",initialState:{data:{},loading:{},error:{},lastFetched:{}},reducers:{clearMetadata:(e,t)=>{let a=t.payload;delete e.data[a],delete e.loading[a],delete e.error[a],delete e.lastFetched[a]},clearAllMetadata:e=>{e.data={},e.loading={},e.error={},e.lastFetched={}},updateMetadata:(e,t)=>{let{slug:a,data:i}=t.payload;e.data[a]=i,e.lastFetched[a]=Date.now()}},extraReducers:e=>{e.addCase(l.pending,(e,t)=>{let a=t.meta.arg;e.loading[a]||(e.loading[a]=!0),e.error[a]=null}).addCase(l.fulfilled,(e,t)=>{let{slug:a,data:i,fromCache:n}=t.payload;e.loading[a]=!1,n||(e.data[a]=i,e.lastFetched[a]=Date.now()),e.error[a]=null}).addCase(l.rejected,(e,t)=>{let a=t.meta.arg;e.loading[a]=!1,e.error[a]=t.payload}).addCase(d.pending,(e,t)=>{let a=t.meta.arg;e.loading[a]||(e.loading[a]=!0),e.error[a]=null}).addCase(d.fulfilled,(e,t)=>{let{slug:a,data:i,fromCache:n}=t.payload;e.loading[a]=!1,n||(e.data[a]=i,e.lastFetched[a]=Date.now()),e.error[a]=null}).addCase(d.rejected,(e,t)=>{let a=t.meta.arg;e.loading[a]=!1,e.error[a]=t.payload})}}),{clearMetadata:u,clearAllMetadata:h,updateMetadata:f}=c.actions;var g=c.reducer,m=a(8606),p=a(82345),v=a(49850),y=a(85210),w=a(18719),C=a(27788),b=a(93050),k=a(13409);let U=(0,i.xC)({reducer:{profile:n.ZP,agency:b.ZP,invitation:k.ZP,marketplaceProfile:o.ZP,metadata:g,commonDetails:m.ZP,backlinks:p.ZP,project:v.ZP,chat:y.ZP,notifications:w.default,chatNotifications:C.default},middleware:e=>e({serializableCheck:{ignoredActions:["persist/PERSIST"],ignoredPaths:["chat.rooms"]}})})},93050:function(e,t,a){a.d(t,{nt:function(){return r},rM:function(){return o}});var i=a(39129),n=a(10278);let o=(0,i.hg)("agency/fetchAgencyStatus",async(e,t)=>{var a,i,o,s,r,l,d;let{rejectWithValue:c}=t;try{let e=await (0,n.yF)();return{ownedAgencyStatus:null!==(a=null==e?void 0:e.agency_status)&&void 0!==a?a:null,agencyName:null!==(i=null==e?void 0:e.agency_name)&&void 0!==i?i:null,agencyLogo:null!==(o=null==e?void 0:e.agency_logo)&&void 0!==o?o:null,hasAgency:!0}}catch(e){if((null==e?void 0:null===(r=e.response)||void 0===r?void 0:null===(s=r.data)||void 0===s?void 0:s.error)==="No agency foun
1d.")return{ownedAgencyStatus:null,agencyName:null,agencyLogo:null,hasAgency:!1};return c((null==e?void 0:null===(d=e.response)||void 0===d?void 0:null===(l=d.data)||void 0===l?void 0:l.message)||"Failed to fetch agency status")}}),s=(0,i.oM)({name:"agency",initialState:{ownedAgencyStatus:null,agencyName:null,agencyLogo:null,hasAgency:!1,loading:!1,error:null},reducers:{clearAgency:e=>{e.ownedAgencyStatus=null,e.agencyName=null,e.agencyLogo=null,e.hasAgency=!1,e.error=null,e.loading=!1}},extraReducers:e=>{e.addCase(o.pending,e=>{e.loading=!0,e.error=null}).addCase(o.fulfilled,(e,t)=>{e.loading=!1,e.ownedAgencyStatus=t.payload.ownedAgencyStatus,e.agencyName=t.payload.agencyName,e.agencyLogo=t.payload.agencyLogo,e.hasAgency=t.payload.hasAgency,e.error=null}).addCase(o.rejected,(e,t)=>{e.loading=!1,e.error=t.payload})}}),{clearAgency:r}=s.actions;t.ZP=s.reducer},27788:function(e,t,a){a.r(t),a.d(t,{decrementChatNotifUnreadCount:function(){return o},markAllChatNotifReadLocally:function(){return c},markChatNotifReadLocally:function(){return d},prependChatNotification:function(){return r},resetChatNotifUnreadCount:function(){return s},setChatNotifLoading:function(){return u},setChatNotifUnreadCount:function(){return n},setChatNotifications:function(){return l}});let i=(0,a(39129).oM)({name:"chatNotifications",initialState:{unreadCount:0,notifications:[],isLoading:!1},reducers:{setChatNotifUnreadCount(e,t){e.unreadCount=t.payload},decrementChatNotifUnreadCount(e,t){e.unreadCount=Math.max(0,e.unreadCount-t.payload)},resetChatNotifUnreadCount(e){e.unreadCount=0},prependChatNotification(e,t){!e.notifications.some(e=>e.id===t.payload.id)&&(e.notifications.unshift(t.payload),e.notifications.length>50&&e.notifications.pop())},setChatNotifications(e,t){e.notifications=t.payload},markChatNotifReadLocally(e,t){let a=new Set(t.payload);e.notifications=e.notifications.map(e=>a.has(e.id)?{...e,is_read:!0}:e)},markAllChatNotifReadLocally(e){e.notifications=e.notifications.map(e=>({...e,is_read:!0})),e.unreadCount=0},setChatNotifLoading(e,t){e.isLoading=t.payload}}}),{setChatNotifUnreadCount:n,decrementChatNotifUnreadCount:o,resetChatNotifUnreadCount:s,prependChatNotification:r,setChatNotifications:l,markChatNotifReadLocally:d,markAllChatNotifReadLocally:c,setChatNotifLoading:u}=i.actions;t.default=i.reducer},18719:function(e,t,a){a.r(t),a.d(t,{decrementUnreadCount:function(){return o},markAllReadLocally:function(){return c},markReadLocally:function(){return d},prependNotification:function(){return r},resetUnreadCount:function(){return s},setLoading:function(){return u},setNotifications:function(){return l},setUnreadCount:function(){return n}});let i=(0,a(39129).oM)({name:"notifications",initialState:{unreadCount:0,notifications:[],isLoading:!1},reducers:{setUnreadCount(e,t){e.unreadCount=t.payload},decrementUnreadCount(e,t){e.unreadCount=Math.max(0,e.unreadCount-t.payload)},resetUnreadCount(e){e.unreadCount=0},prependNotification(e,t){!e.notifications.some(e=>e.id===t.payload.id)&&(e.notifications.unshift(t.payload),e.notifications.length>50&&e.notifications.pop())},setNotifications(e,t){e.notifications=t.payload},markReadLocally(e,t){let a=new Set(t.payload);e.notifications=e.notifications.map(e=>a.has(e.id)?{...e,is_read:!0}:e)},markAllReadLocally(e){e.notifications=e.notifications.map(e=>({...e,is_read:!0})),e.unreadCount=0}
1,setLoading(e,t){e.isLoading=t.payload}}}),{setUnreadCount:n,decrementUnreadCount:o,resetUnreadCount:s,prependNotification:r,setNotifications:l,markReadLocally:d,markAllReadLocally:c,setLoading:u}=i.actions;t.default=i.reducer},49850:function(e,t,a){a.d(t,{Ol:function(){return s},R0:function(){return o},sl:function(){return n}});let i=(0,a(39129).oM)({name:"project",initialState:{seoByDomain:{}},reducers:{setAffectedPagesForDomain(e,t){let{domain:a,data:i}=t.payload;e.seoByDomain[a]||(e.seoByDomain[a]={}),e.seoByDomain[a].affectedPages=i},setIssuesForDomain(e,t){let{domain:a,data:i}=t.payload;e.seoByDomain[a]||(e.seoByDomain[a]={}),e.seoByDomain[a].issues=i},setSummaryForDomain(e,t){let{domain:a,data:i}=t.payload;e.seoByDomain[a]||(e.seoByDomain[a]={}),e.seoByDomain[a].summary=i}}}),{setAffectedPagesForDomain:n,setIssuesForDomain:o,setSummaryForDomain:s}=i.actions;t.ZP=i.reducer},64767:function(e,t,a){a.r(t),a.d(t,{diagnoseFirebase:function(){return w},disconnectNotifications:function(){return v},getNotificationService:function(){return m},initializeNotifications:function(){return p},resetNotificationFcmToken:function(){return y}});var i=a(17292),n=a(8858),o=a(64131),s=a(83464),r=a(99551),l=a(3845),d=a(85210),c=a(19641);let u=()=>{try{return a(8858).database||null}catch(e){return null}},h=()=>{try{return a(8858).messaging||null}catch(e){return null}};class f{async initialize(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.isServiceInitialized){this.setCallbacks(t);return}if(this.isInitializing&&this.initializationPromise){await this.initializationPromise,this.setCallbacks(t);return}this.isInitializing=!0,this.initializationPromise=this._doInitialize(e,t);try{await this.initializationPromise}finally{this.isInitializing=!1,this.initializationPromise=null}}async _doInitialize(e,t){this.currentUserId=e,this.setCallbacks(t);try{try{await this.requestNotificationPermission()}catch(e){}try{await this.setupRealtimeListeners()}catch(e){}try{this.setupForegroundMessageListener()}catch(e){}this.isServiceInitialized=!0}catch(e){this.currentUserId&&Object.keys(this.callbacks).length>0?this.isServiceInitialized=!0:(this.isServiceInitialized=!1,this.isInitializing=!1,this.initializationPromise=null)}}isInitialized(){return this.isServiceInitialized}getCurrentUserId(){return this.currentUserId}async requestNotificationPermission(){if("Notification"in window)try{let e=await Notification.requestPermission();if("granted"===e){let{requestPermission:e}=await Promise.resolve().then(a.bind(a,8858)),t=await e();t&&(this.fcmToken=t,await this.registerFCMToken(t))}}catch(e){}}async registerFCMToken(e){if(this.fcmToken===e)return;let t=o.default.get("login_access_token");if(t)for(let n of["".concat(r.BASE_URL,"marketplace/firebase/fcm-token/"),"".concat(r.BASE_URL,"notifications/fcm-token/"),"".concat(r.BASE_URL,"auth/fcm-token/")])try{let a=await s.default.post(n,{token:e},{headers:{Authorization:"Bearer ".concat(t),"Content-Type":"application/json"},validateStatus:e=>e<500});if(a.status>=200&&a.status<300){this.fcmToken=e;return}if(a.status>=400&&a.status<500){a.status;continue}}catch(t){var a,i;let e=null==t?void 0:null===(a=t.response)||void 0===a?void 0:a.status;if(null==t||null===(i=t.response)||void 0===i||i.data,e>=500)break;if(404===e)continue}}async testDatabasePermissions(){let e=u();if(!e||!this.currentUserId)return!1;try{let t=(0,i.iH)(e,"chat_rooms/".concat(1,"/messages"));return new Promise(e=>{let a=!1,n=null;n=(0,i.jM)(t,()=>{!a&&n&&(a=!0,n(),e(!0))},t=>{a||(a=!0,n&&n(),e(!1))}),setTimeout(()=>{a||(a=!0,n&&n(),e(!1))},5e3)})}catch(e){return!1}}async setupRealtimeListeners(){let e=u();if(e&&this.currentUserId)try{let t=!1,a=0,n=(0,i.iH)(e,".info/connected"),o=(0,i.jM)(n,async e=>{let i=e.val();a++,i&&!t&&(t=!0,await this.testDatabasePermissions())},e=>{});setTimeout(()=>{o()},1e4)}catch(e){}}async initializeUnreadCounts(e){let t=e=>{if(!e)return;if(e.startsWith("http://")||e.startsWith("https://"))return e;let t=r.BASE_URL.replace(/\/api\/?$/,"").replace(/\/$/,""),a=e.startsWith("/")?e:"/".concat(e);return"".concat(t).concat(a)};
1e.forEach(e=>{let a=e.id||e.room_id,i=e.unread_count||0;if(a){var n,o,s,r,c,u,h,f,g,m,p,v,y;let w;this.unreadCounts.set(a,i),null===(n=(o=this.callbacks).onUnreadCountUpdate)||void 0===n||n.call(o,a,i);let C=a.toString(),b=C.startsWith("chat_")?C.replace(/^chat_/,"").split("_")[0]:C;(null===(s=e.last_message)||void 0===s?void 0:s.created_at)?w=e.last_message.created_at:e.last_message_at?w=e.last_message_at:e.updated_at&&(w=e.updated_at);try{let a={roomId:b,publisherId:(null===(c=e.other_user)||void 0===c?void 0:null===(r=c.id)||void 0===r?void 0:r.toString())||(null===(u=e.publisher_id)||void 0===u?void 0:u.toString())||(null===(h=e.user_id)||void 0===h?void 0:h.toString())||"",publisherName:(null===(f=e.other_user)||void 0===f?void 0:f.username)||e.publisher_name||(null===(g=e.user)||void 0===g?void 0:g.username)||"Unknown",publisherAvatar:t((null===(m=e.other_user)||void 0===m?void 0:m.profile_picture)||e.publisher_avatar||(null===(p=e.user)||void 0===p?void 0:p.profile_picture)||""),lastMessage:(null===(v=e.last_message)||void 0===v?void 0:v.message)||e.last_message_text||"",lastMessageTime:w,unreadCount:i,messages:[],roomType:e.room_type||"direct",taskId:e.task||e.task_id,taskTitle:e.task_title};l.h.dispatch((0,d.Fk)(a))}catch(t){try{l.h.dispatch((0,d.h3)({roomId:b,unreadCount:i,lastMessage:(null===(y=e.last_message)||void 0===y?void 0:y.message)||e.last_message_text,lastMessageTime:w}))}catch(e){}}}}),this.updateTotalUnreadCount()}async fetchUserChatRooms(){let e=o.default.get("login_access_token");if(!e)return[];if(this.isLoadingRooms)return await new Promise(e=>setTimeout(e,500)),[];try{return this.isLoadingRooms=!0,await c.l.request("chat-rooms-".concat(this.currentUserId),async()=>{var t;let a=await s.default.get("".concat(r.BASE_URL,"marketplace/chat/rooms/"),{headers:{Authorization:"Bearer ".concat(e),"Content-Type":"application/json"}}),i=(null===(t=a.data)||void 0===t?void 0:t.results)||a.data;if(Array.isArray(i))return i;if(i&&"object"==typeof i){let e=i.results||i.rooms||i.data||i.items||i.list;if(Array.isArray(e))return e;if(void 0!==i.count&&Array.isArray(i.results))return i.results;if(i.id)return[i];let t=Object.keys(i);if(t.length>0&&t.every(e=>!isNaN(Number(e))))return Object.values(i)}return[]},{useCache:!0,cacheTTL:5e3,dedupWindow:2e3})}catch(e){return[]}finally{this.isLoadingRooms=!1}}setupRoomListener(e){let t=u();if(t)try{let a=(0,i.iH)(t,"chat_rooms/".concat(e,"/messages"));this.processedMessageIds.has(e)||this.processedMessageIds.set(e,new Set),this.isInitialLoad.set(e,!0);let n=(0,i.jM)(a,t=>{if(t.exists()){let n=t.val(),o=Object.keys(n),s=this.processedMessageIds.get(e)||new Set,r=this.lastProcessedMessageId.get(e)||0,l=this.isInitialLoad.get(e)||!1;if(o.length>0){let t=r;for(let d of o.sort()){var a,i;
1let o=n[d],c="number"==typeof o.id?o.id:parseInt(o.id)||0;if(!c)continue;if(c>t&&(t=c),l){s.add(c),c>t&&(t=c);continue}if(s.has(c))continue;let u="number"==typeof(null===(a=o.sender)||void 0===a?void 0:a.id)?o.sender.id:parseInt(null===(i=o.sender)||void 0===i?void 0:i.id)||0;c>r&&u!==this.currentUserId?(s.add(c),this.handleNewMessage(e,o)):c>r&&s.add(c)}t>r&&this.lastProcessedMessageId.set(e,t),l&&this.isInitialLoad.set(e,!1)}}else this.isInitialLoad.set(e,!1)},e=>{});this.listeners.push(n),this.setupUnreadCountListener(e)}catch(e){}}setupUnreadCountListener(e){let t=u();if(t&&this.currentUserId)try{let a=(0,i.iH)(t,"chat_rooms/".concat(e,"/participants/").concat(this.currentUserId)),n=(0,i.iH)(t,"chat_rooms/".concat(e,"/messages")),o=(0,i.jM)(a,async t=>{var a,o,s,r;let c=await (0,i.U2)(n);if(!(c.exists()&&Object.keys(c.val()||{}).length>0)){this.unreadCounts.get(e);return}if(t.exists()){let i=t.val().last_read_message_id||0,n=await this.calculateUnreadCount(e,i);if(n!==this.unreadCounts.get(e)){this.unreadCounts.set(e,n),null===(a=(o=this.callbacks).onUnreadCountUpdate)||void 0===a||a.call(o,e,n),this.updateTotalUnreadCount();try{l.h.dispatch((0,d.h3)({roomId:e.toString(),unreadCount:n}))}catch(e){}}}else{let t=await this.calculateUnreadCount(e,0);if(t!==this.unreadCounts.get(e)){this.unreadCounts.set(e,t),null===(s=(r=this.callbacks).onUnreadCountUpdate)||void 0===s||s.call(r,e,t),this.updateTotalUnreadCount();try{l.h.dispatch((0,d.h3)({roomId:e.toString(),unreadCount:t}))}catch(e){}}}},e=>{}),s=(0,i.jM)(n,async t=>{t.exists()&&Object.keys(t.val()||{}).length>0&&this.recalculateUnreadCount(e)},e=>{});this.listeners.push(o),this.listeners.push(s)}catch(e){}}async recalculateUnreadCount(e){let t=u();if(t&&this.currentUserId)try{let o=(0,i.iH)(t,"chat_rooms/".concat(e,"/messages")),s=await (0,i.U2)(o);if(!(s.exists()&&Object.keys(s.val()||{}).length>0)){this.unreadCounts.get(e);return}let r=(0,i.iH)(t,"chat_rooms/".concat(e,"/participants/").concat(this.currentUserId)),l=await (0,i.U2)(r),d=(null==l?void 0:l.exists())&&l.val().last_read_message_id||0,c=await this.calculateUnreadCount(e,d);if(c!==this.unreadCounts.get(e)){var a,n;this.unreadCounts.set(e,c),null===(a=(n=this.callbacks).onUnreadCountUpdate)||void 0===a||a.call(n,e,c),this.updateTotalUnreadCount()}}catch(e){}}async calculateUnreadCount(e,t){let a=u();if(!a||!this.currentUserId)return 0;try{let n=(0,i.iH)(a,"chat_rooms/".concat(e,"/messages")),o=await (0,i.U2)(n);if(!o.exists())return 0;let s=o.val(),r=0;return Object.values(s).forEach(e=>{var a,i;let n="number"==typeof e.id?e.id:parseInt(e.id)||0,o="number"==typeof(null===(a=e.sender)||void 0===a?void 0:a.id)?e.sender.id:parseInt(null===(i=e.sender)||void 0===i?void 0:i.id)||0;n>t&&o!==this.currentUserId&&r++}),r}catch(e){return 0}}setupUserRoomsListener(){let e=u();if(e&&this.currentUserId)try{let t=(0,i.iH)(e,"user_rooms/".concat(this.currentUserId,"/rooms")),a=(0,i.jM)(t,e=>{if(e.exists()){let t=e.val();Object.keys(t).map(e=>
1parseInt(e)).forEach(e=>{this.listeners.some(()=>e==e)||this.setupRoomListener(e)})}},e=>{});this.listeners.push(a)}catch(e){}}handleNewMessage(e,t){var a,i,n,o;if(!this.currentUserId)return;let s="number"==typeof(null===(a=t.sender)||void 0===a?void 0:a.id)?t.sender.id:(null===(i=t.sender)||void 0===i?void 0:i.id)?parseInt(t.sender.id):null;if(null!==s&&s===this.currentUserId)return;let r=window.location.pathname,c=r.includes("/messages")||r.includes("/chat"),u=new URLSearchParams(window.location.search).get("room")===e.toString(),h=document.hasFocus(),f="visible"===document.visibilityState;c&&u&&h&&f&&f||this.showBrowserNotification(e,t);let g=(this.unreadCounts.get(e)||0)+1;this.unreadCounts.set(e,g),null===(n=(o=this.callbacks).onUnreadCountUpdate)||void 0===n||n.call(o,e,g),this.updateTotalUnreadCount();try{l.h.dispatch((0,d.h3)({roomId:e.toString(),unreadCount:g,lastMessage:t.message||"New message",lastMessageTime:t.created_at||new Date().toISOString()}))}catch(e){}let m={roomId:e,message:{id:t.id,sender:t.sender,message:t.message,created_at:t.created_at},unreadCount:g};if(this.callbacks.onNewMessage)try{this.callbacks.onNewMessage(m)}catch(e){}else this.queuedNotifications.push(m),this.queuedNotifications.length>50&&this.queuedNotifications.shift()}showBrowserNotification(e,t){if("Notification"in window&&"denied"!==Notification.permission){if("default"===Notification.permission){if(window.__notificationPermissionRequesting)return;window.__notificationPermissionRequesting=!0,Notification.requestPermission().then(a=>{window.__notificationPermissionRequesting=!1,"granted"===a?this.showBrowserNotification(e,t):"denied"===a&&(window.__notificationPermissionDeniedLogged=!0)}).catch(()=>{window.__notificationPermissionRequesting=!1});return}if("granted"===Notification.permission)try{var a,i,n,o,s;let r=(null===(a=t.sender)||void 0===a?void 0:a.username)||(null===(i=t.sender)||void 0===i?void 0:i.first_name)||"Someone",l=t.message||"You have a new message",d={body:l.length>100?l.substring(0,100)+"...":l,icon:(null===(n=t.sender)||void 0===n?void 0:n.profile_picture)||"/images/logo/vefogix.png",badge:"/images/logo/vefogix.png",tag:"chat_".concat(e),requireInteraction:!1,silent:!1,...(null===(o=t.sender)||void 0===o?void 0:o.profile_picture)&&{image:t.sender.profile_picture},data:{roomId:e.toString(),messageId:(null===(s=t.id)||void 0===s?void 0:s.toString())||"",url:"/messages/".concat(e),timestamp:Date.now()}};try{let t=new Notification("".concat(r," sent a message"),d);t.onclick=a=>{a.preventDefault(),t.close(),window.focus&&window.focus();{let t=new CustomEvent("notification-navigate",{detail:{url:"/messages/".concat(e),roomId:e}});window.dispatchEvent(t),setTimeout(()=>{window.location.pathname.startsWith("/messages/".concat(e))||(window.location.href="/messages/".concat(e))},100)}},t.onclose=()=>{},t.onerror=e=>{},setTimeout(()=>{try{t.close()}catch(e){}},5e3)}catch(e){}}catch(e){}}}setupForegroundMessageListener(){if(h())try{let e=(0,n.onMessageListener)(e=>{if(e.notification){var t,a,i;this.showBrowserNotification((null===(t=e.data)||void 0===t?void 0:t.roomId)?parseInt(e.data.roomId):0,{id:null===(a=e.data)||void 0===a?void 0:a.messageId,sender:{id:null===(i=e.data)||void 0===i?void 0:i.senderId,username:e.notification.title||"New Message"},message:e.notification.body||"",created_at:new Date().toISOString()})}});this.listeners.push(e)}catch(e){}}updateTotalUnreadCount(){let e=Array.from(this.unreadCounts.values()).reduce((e,t)=>e+t,0);this.callbacks.onTotalUnreadUpdate&&(this.callbacks.onTotalUnreadUpdate(e),setTimeout(()=>{var t,a;null===(t=(a=this.callbacks).onTotalUnreadUpdate)||void 0===t||t.call(a,e)},0)),this.updateBrowserBadge(e)}updateBrowserBadge(e){if("serviceWorker"in navigator&&"setAppBadge"in navigator)try{e>0?navigator.setAppBadge(e):navigator.clearAppBadge()}catch(e){}}getUnreadCount(e){return this.unreadCounts.get(e)||0}getTotalUnreadCount(){return Array.from(this.unreadCounts.values()).reduce((e,t)=>e+t,0)}setUnreadCountsFromRooms(e){e&&Array.isArray(e)&&(e.forEach(e=>{var t,a,i,n,o;let s=null!=e.roomId?Number(e.roomId):null!==(t=e.id)&&void 0!==t?t:e.room_id,r=null!==(i=null!==(a=e.unreadCount)&&void 0!==a?a:e.unread_count)&&void 0!==i?i:0;null==s||Number.isNaN(s)||(this.unreadCounts.set(s,r),null===(n=(o=this.callbacks).onUnreadCountUpdate)||void 0===n||n.call(o,s,r))}),this.updateTotalUnreadCount())}getCallbacks(){return{...this.callbacks}}setCallbacks(e){if(e.onNewMessage&&this.callbacks.onNewMessage){let t=this.callbacks.onNewMessage;if(t!==e.onNewMessage){let a=t.toString();if(a.includes("Combined callback triggered")||a.includes("InAppNotificationManager")){this.callbacks={...this.callbacks,...e,onNewMessage:t};return}}}this.callbacks={...this.callbacks,...e};let t=e.onNewMessage;t&&this.queuedNotifications.splice(0,this.queuedNotifications.length).forEac
1h(e=>{try{t(e)}catch(e){}})}async markRoomAsRead(e){var t,a;let i=o.default.get("login_access_token");if(i)try{await s.default.post("".concat(r.BASE_URL,"marketplace/chat/rooms/").concat(e,"/read/"),{},{headers:{Authorization:"Bearer ".concat(i),"Content-Type":"application/json"}})}catch(e){}this.unreadCounts.set(e,0),null===(t=(a=this.callbacks).onUnreadCountUpdate)||void 0===t||t.call(a,e,0),this.updateTotalUnreadCount();try{l.h.dispatch((0,d.h3)({roomId:e.toString(),unreadCount:0}))}catch(e){}}resetFcmToken(){this.fcmToken=null}getFcmToken(){return this.fcmToken}disconnect(){this.listeners.forEach(e=>e()),this.listeners=[],this.fcmToken=null,this.unreadCounts.clear(),this.processedMessageIds.clear(),this.lastProcessedMessageId.clear(),this.isInitialLoad.clear(),this.isServiceInitialized=!1,this.isInitializing=!1,this.initializationPromise=null}constructor(){this.callbacks={},this.listeners=[],this.currentUserId=null,this.isServiceInitialized=!1,this.isInitializing=!1,this.initializationPromise=null,this.unreadCounts=new Map,this.fcmToken=null,this.processedMessageIds=new Map,this.lastProcessedMessageId=new Map,this.isInitialLoad=new Map,this.isLoadingRooms=!1,this.queuedNotifications=[]}}let g=null,m=()=>(g||(g=new f),g),p=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=m();await a.initialize(e,t)},v=()=>{g&&g.disconnect()},y=()=>{g&&g.resetFcmToken()},w=async()=>{let e=u();if(!e){console.error("â Firebase database not initialized"),console.error("\uD83D\uDCA1 Make sure Firebase is initialized before calling this function");return}try{var t,a;null===(a=e.app)||void 0===a||null===(t=a.options)||void 0===t||t.databaseURL}catch(e){console.warn("â ï¸ Could not retrieve database URL")}let n=(0,i.iH)(e,".info/connected"),o=(0,i.jM)(n,e=>{e.val()},e=>{console.error("â Connection test error:",e)}),s=(0,i.iH)(e,"chat_rooms/1/messages"),r=(0,i.jM)(s,e=>{e.exists()},e=>{console.error("â Permission test FAILED"),console.error("\uD83D\uDCCB Error code:",null==e?void 0:e.code),console.error("\uD83D\uDCCB Error message:",null==e?void 0:e.message),console.error("\uD83D\uDCCB Error path:",null==e?void 0:e.path),(null==e?void 0:e.code)==="PERMISSION_DENIED"&&(console.error("\n\uD83D\uDEA8 PERMISSION_DENIED detected!"),console.error("\uD83D\uDCCB This means your security rules are blocking access"),console.error("\uD83D\uDCCB Check Firebase Console â Realtime Database â Rules tab"),console.error("\uD83D\uDCCB Make sure rules are PUBLISHED (not just saved)"))});setTimeout(()=>{o(),r()},5e3)};window.diagnoseFirebase=w,t.default=m}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.