1import{a as b,f as L}from"./chunk-XVEXVSHY.js";import{k as D}from"./chunk-LQAJVVFO.js";import{b as R,g as p,k as w,m as S,n as A,r as I,s as C,t as d,w as U,y,z as h}from"./chunk-FHRX5ITS.js";import{Cb as N,J as E,N as m,qa as v}from"./chunk-Y5LJR3O3.js";import{a as u,b as f,o as a}from"./chunk-2ULHPW3F.js";var l=function(n){return n.PENDING="pending",n.APPROVED="approved",n.REJECTED="rejected",n}(l||{});var O=(()=>{let o=class o{constructor(){this.firestore=m(R),this.authService=m(L),this.pendingCountSignal=v(0),this.pendingCount=this.pendingCountSignal.asReadonly(),this.hasUpdatesSignal=v(!1),this.hasUpdates=this.hasUpdatesSignal.asReadonly(),this.listeners=new Map,this.authEffectRef=null,this.setupAuthListener()}setupAuthListener(){this.authEffectRef=N(()=>{this.authService.currentUser()&&this.authService.hasMinimumRole(b.ADMIN)?this.setupPendingApplicationsListener():this.removeListener("pendingApplications")})}setupPendingApplicationsListener(){this.removeListener("pendingApplications");let t=p(this.firestore,"applications"),e=d(t,h("status","==",l.PENDING)),i=I(e,r=>{this.pendingCountSignal.set(r.size)},r=>{console.error("Error listening to pending applications:",r),this.pendingCountSignal.set(0)});this.listeners.set("pendingApplications",i)}removeListener(t){let e=this.listeners.get(t);e&&(e(),this.listeners.delete(t))}removeAllListeners(){this.listeners.forEach(t=>t()),this.listeners.clear()}ngOnDestroy(){this.removeAllListeners(),this.authEffectRef&&(this.authEffectRef.destroy(),this.authEffectRef=null)}createApplication(t){return a(this,null,function*(){try{let e=p(this.firestore,"applications"),i=w(e),r={id:i.id,userId:t.userId,status:l.PENDING,firstName:this.capitalize(t.firstName),lastName:this.capitalize(t.lastName),email:t.email,phone:t.phone,isBaptized:t.isBaptized,isCCCCMember:t.isCCCCMember,previousChurchName:t.previousChurchName,note:t.note,createdAt:new Date,updatedAt:new Date};return yield U(i,r),r}catch(e){throw console.error("Error creating application:",e),e}})}updateApplication(t,e){return a(this,null,function*(){try{let i=w(this.firestore,"applications",t),r=new Date;switch(e.type){case"REVIEW":{yield y(i,{status:e.status,reviewerId:e.reviewerId,reviewerName:e.reviewerName,reviewerAvatarUrl:e.reviewerAvatarUrl,reviewNote:e.reviewNote,reviewedAt:r,updatedAt:r});break}case"REVISE":{yield y(i,{status:l.PENDING,note:e.note,reviewerId:null,reviewerName:null,reviewerAvatarUrl:null,reviewNote:null,reviewedAt:null,updatedAt:r});break}}}catch(i){throw console.error("Error updating application:",i),i}})}getApplication(t){return a(this,null,function*(){var e;try{let i=w(this.firestore,"applications",t),r=yield S(i);if(!r.exists())throw new Error("Application not found");return f(u({},r.data()),{id:r.id,createdAt:r.data().createdAt.toDate(),updatedAt:r.data().updatedAt.toDate(),reviewedAt:(e=r.data().reviewedAt)==null?void 0:e.toDate()})}catch(i){throw console.error("Error getting application:",i),i}})}getApplicationByUserId(t){return a(this,null,function*(){var e;try{let i=p(this.firestore,"applications"),r=d(i,h("userId","==",t)),g=yield A(r);if(g.empty)return this.hasUpdatesSignal.set(!1),null;let s=g.docs[0],c=f(u({},s.data()),{id:s.id,createdAt:s.data().createdAt.toDate(),updatedAt:s.data().updatedAt.toDate(),reviewedAt:(e=s.data().reviewedAt)==null?void 0:e.toDate()}),P=yield this.getLastViewedTime(c.id),q=c.updatedAt>P;return this.hasUpdatesSignal.set(q),c}catch(i){throw console.error("Error getting application by user ID:",i),i}})}getAllApplications(t){return a(this,null,function*(){try{let e=p(this.firestore,"applications"),i=[];t&&i.push(h("status","==",t)),i.push(C("createdAt","desc"));let r=d(e,...i);return(yield A(r)).docs.map(s=>{var c;return f(u({},s.data()),{id:s.id,createdAt:s.data().createdAt.toDate(),updatedAt:s.data().updatedAt.toDate(),reviewedAt:(c=s.data().reviewedAt)==null?void 0:c.toDate()})})}catch(e){throw console.error("Error getting applications:",e),e}})}getPendingApplicationsCount(){return a(this,null,function*(){try{let t=p(this.firestore,"applications"),e=d(t,h("status","==",l.PENDING));return(yield A(e)).size}catch(t){throw console.error("Error getting pending applications count:",t),t}})}markApplicationViewed(t){return a(this,null,function*(){try{yield D.set({key:`application_${t}_last_viewed`,value:new Date().toISOString()}),this.hasUpdatesSignal.set(!1)}catch(e){console.error("Error marking application as viewed:",e)}})}getLastViewedTime(t){return a(this,null,function*(){try{let{value:e}=yield D.get({key:`application_${t}_last_viewed`});return e?new Date(e):new Date(0)}catch(e){return console.error("Error getting last viewed time:",e),new Date(0)}})}capitalize(t){return t.charAt(0).toUpperCase()+t.slice(1)}};o.\u0275fac=function(e){return new(e||o)}
1,o.\u0275prov=E({token:o,factory:o.\u0275fac,providedIn:"root"});let n=o;return n})();export{l as a,O as b};
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.