import{f as N}from"./chunk-LJ6RXHCI.js";import{a as D}from"./chunk-D7GKLKEZ.js";import{a as O}from"./chunk-YXNSGUXN.js";import{k as P,l as E}from"./chunk-5KBO3I44.js";import{b as C}from"./chunk-7KBVBHHW.js";import{d as L}from"./chunk-Z4HIIQNW.js";import{a as I,b as T}from"./chunk-CFFHWVA5.js";import{b as M}from"./chunk-GH7I4V3C.js";import{A as v,e as R,i as g}from"./chunk-2YE7XEKS.js";import{$d as S,Vd as n,Wd as u,ba as f,ie as s,je as m,ka as c,pa as o,r as d,w as p,x as h}from"./chunk-UNHECMG2.js";var x=S({Email:s(n),Email2:s(n),PhoneBusiness:s(n),CompanyName:m(n),CompanyNameAddition:m(n),Firstname:s(n),Lastname:s(n),AddressLine1:m(n),AddressLine2:m(n),PostalCode:s(n),Location:s(n),Id:u});var _=(()=>{class i extends I{constructor(){let e=o(g),t=o(v);super(e,t,x,"ApprenticeshipManagers")}static{this.\u0275fac=function(t){return new(t||i)}}static{this.\u0275prov=c({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();var j=S({Email:s(n),Email2:s(n),PhoneBusiness:s(n),PhoneMobile:s(n),Firstname:s(n),Lastname:s(n),Id:u});var w=(()=>{class i extends I{constructor(){let e=o(g),t=o(v);super(e,t,j,"JobTrainers")}static{this.\u0275fac=function(t){return new(t||i)}}static{this.\u0275prov=c({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();function b(i,l){let e=+P(i)-+P(l);return e<0?-1:e>0?1:e}function G(i,l,e){let[t,r]=E(e?.in,i,l);return t.getFullYear()-r.getFullYear()}function X(i,l,e){let[t,r]=E(e?.in,i,l),a=b(t,r),A=Math.abs(G(t,r));t.setFullYear(1584),r.setFullYear(1584);let z=b(t,r)===-a,y=a*(A-+z);return y===0?0:y}var V=18;function Y(i){return X(new Date,i.Birthdate||new Date)>=V}var J="dossier-myself",H="dossier-student",B="dossier-legal-reps",$="dossier-apprenticeships",k="dossier-stay-permit",Ge=(()=>{class i{constructor(){this.studentsService=o(N),this.personsService=o(L),this.apprenticeshipManagersService=o(_),this.jobTrainersService=o(w),this.dropDownItemsService=o(D),this.loadingService=o(O),this.IGNORE_404_CONTEXT=new R().set(C,{disableErrorHandlingForStatus:[404]}),this.loadingStudent$=this.loadingService.loading(H),this.loadingMyself$=this.loadingService.loading(J),this.loadingLegalRepresentatives$=this.loadingService.loading(B),this.loadingApprenticeships$=this.loadingService.loading($),this.loadingStayPermit$=this.loadingService.loading(k)}getStudent(e){return this.loadingService.load(this.loadStudent(e).pipe(f(t=>t?d(t):this.loadPerson(e))),H)}getMyself(){return this.loadingService.load(this.personsService.getMyself({context:new R().set(C,{disableErrorHandlingForStatus:[403]})}),J)}getLegalRepresentatives(e){return this.loadingService.load(this.loadLegalRepresentatives(e).pipe(f(t=>this.loadLegalRepresentativePersons(t).pipe(p(r=>t.map(a=>this.findPerson(a.RepresentativeId,r)).filter(M))))),B)}getApprenticeships(e){return this.loadingService.load(this.loadApprenticeshipContracts(e).pipe(f(t=>h([this.loadApprenticeshipManagers(t),this.loadJobTrainers(t)]).pipe(p(([r,a])=>t.map(A=>this.createApprenticeshipCompany(A,r,a)))))),$)}getStayPermitValue(e){return this.loadingService.load(this.dropDownItemsService.getStayPermits().pipe(p(t=>t.find(r=>r.Key===e)?.Value||null)),k)}loadStudent(e){return this.studentsService.getWithClassRegistrations(e,{context:this.IGNORE_404_CONTEXT}).pipe(T())}loadPerson(e){return this.personsService.get(e,{context:this.IGNORE_404_CONTEXT}).pipe(p(t=>this.createStudentFromPerson(t)),T())}createStudentFromPerson(e){return{Id:e.Id,AddressLine1:e.AddressLine1,AddressLine2:e.AddressLine2,Birthdate:e.Birthdate,DisplayEmail:e.DisplayEmail,FirstName:e.FirstName??"",FullName:e.FullName??"",Gender:e.Gender??"X",LastName:e.LastName??"",Location:e.Location,PhoneMobile:e.PhoneMobile,PhonePrivate:e.PhonePrivate,PostalCode:e.Zip,ClassRegistrations:[]}}loadLegalRepresentatives(e){return this.studentsService.getLegalRepresentatives(e.Id).pipe(p(t=>{let r=Y(e);return t.filter(a=>!r||a.RepresentativeAfterMajority)}))}loadLegalRepresentativePersons(e){return e.length===0?d([]):this.personsService.getListForIds(e.map(t=>t.RepresentativeId))}loadApprenticeshipContracts(e){return this.studentsService.getCurrentApprenticeshipContracts(e,{context:this.IGNORE_404_CONTEXT}).pipe(T([]))}loadJobTrainers(e){let t=e.map(r=>r.JobTrainer).filter(r=>typeof r=="number");return t.length===0?d([]):h(t.map(r=>this.jobTrainersService.get(r)))}loadApprenticeshipManagers(e){let t=e.map(r=>r.ApprenticeshipManagerId);return t.length===0?d([]):h(t.map(r=>this.apprenticeshipManagersService.get(r)))}createApprenticeshipCompany(e,t,r){return{apprenticeshipContract:e,jobTrainer:this.findPerson(e.JobTrainer,r),apprenticeshipManager:this.findPerson(e.ApprenticeshipManagerId,t)}}findPerson(e,t){return e&&t.find(r=>r.Id===e)||null}static{this.\u0275fac=function(t){return new(t||i)}}static{this.\u0275prov=c({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();export{Ge as a};
