import{Jb as O,K as T,La as n,Rb as p,Ri as A,Sa as J,Sb as m,V as b,Wl as x,Xa as M,Xh as U,Yb as F,_ as S,a as h,b as g,em as j,f as z,fb as y,gb as v,gl as q,gm as L,hl as w,hm as $,il as N,jc as P,kc as D,kl as R,na as C,ob as I,q as l,rm as k,s as _,t as a,ug as E,vm as W,wi as B}from"./chunk-J36AVOW5.js";var H=z(q());var G=["dash-user-job-handler",""],K="USERS",Q=1e3,V=5e3,X=(()=>{let t=class t extends ${constructor(e,i,r,u,d,f){super(i,r,u,d,f),this.usersService=e,this.jobService=i,this.changeDetectorRef=r,this.messagingService=u,this.toastrService=d,this.toastPackage=f,this.selectToastMessage=this.selectJobUpdates.pipe(a(o=>o.unsuccessful()||o.hasFailures()?this.failureMessage():this.progressMessage()),S(this.progressMessage())),this.selectShowDismissButton=this.selectJobUpdates.pipe(a(o=>o.unsuccessful())),this.selectSecondaryText=this.selectJobUpdates.pipe(a(o=>{if(o.job)return Y(o)}))}transformJob(e){return e.status===x.COMPLETED?this.fetchCompletedJobFromApiBecauseWebsocketUpdatesDoNotContainFullResult(e):l(e)}fetchCompletedJobFromApiBecauseWebsocketUpdatesDoNotContainFullResult(e){return this.usersService.getUserBatchJob(e.id).pipe(b({delay:Q}),a(i=>{if(i.type===A.TypeEnum.Completed)return g(h({},e),{result:i.result})}),E(),T(1),this.timeoutAndReturnOriginalJobIfCompletedJobCanNotBeFetchedFromApi(e))}timeoutAndReturnOriginalJobIfCompletedJobCanNotBeFetchedFromApi(e){return _({first:V,with:()=>l(e)})}performOnFinish(){this.succeeded()&&(this.jobData.onComplete?.(),setTimeout(()=>this.dismissToast(),L))}progressMessage(){return"Inviting users"}failureMessage(){return this.hasFailures()?`${this.numberOfFailures()} ${(0,H.default)("user",this.numberOfFailures())} could not be invited`:"There was a problem inviting the users"}};t.\u0275fac=function(i){return new(i||t)(n(U),n(j),n(F),n(R),n(N),n(w))},t.\u0275cmp=C({type:t,selectors:[["","dash-user-job-handler",""]],features:[O([D]),J],attrs:G,decls:5,vars:12,consts:[["spinnerMode","indeterminate",3,"dismiss","state","primaryText","secondaryText","showDismiss"]],template:function(i,r){i&1&&(y(0,"dash-job-progress-toast",0),p(1,"async"),p(2,"async"),p(3,"async"),p(4,"async"),I("dismiss",function(){return r.dismissToast()}),v()),i&2&&M("state",m(1,4,r.selectJobState))("primaryText",m(2,6,r.selectToastMessage))("secondaryText",m(3,8,r.selectSecondaryText))("showDismiss",m(4,10,r.selectShowDismissButton))},dependencies:[W,P],styles:[".handler__progress[_ngcontent-%COMP%]{display:flex;align-items:center}.handler__progress__spinner[_ngcontent-%COMP%]{margin-right:1rem}.handler__error[_ngcontent-%COMP%]{margin-bottom:.5rem}"],data:{animation:[k]},changeDetection:0});let s=t;return s})();function fe(s,t,c){s.showJobMessageForAllInProgressJobsOfType(K,X,t,c)}function Y(s){if(s.job?.progress){let[t,c]=s.job.progress.steps;return s.completed()?`Invited ${Object.keys(s.result().successes).length} of ${t.totalItems} users`:t.status!==B.StatusEnum.Completed?"Preparing...":`Processed ${c.completedItems} of ${t.totalItems} users`}else return}export{fe as a};
