import { Component, Input, OnInit } from '@angular/core'; import { ClassificationService } from '@core/services/classification.service'; import { Affiliations, CompanyCompliance, NonprofitProfileData, YCCompliance } from '@core/typings/organization.typing'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { UserService } from '@features/users/user.service'; import { OrganizationEligibleForGivingStatus, SubsectionCodeMap } from '@yourcause/common'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; @Component({ selector: 'gc-due-dilligence-modal', templateUrl: 'due-diligence-modal.component.html', styleUrls: ['./due-diligence-modal.component.scss'] }) export class DueDiligenceModalComponent extends YCModalComponent implements OnInit { @Input() nonprofit: NonprofitProfileData; numberComplianceAccepted = 0; totalComplianceNumber = 0; affiliations: string[] = []; companyCompliance: CompanyCompliance[] = []; subsectionCodeMap = SubsectionCodeMap; classificationMap = this.classificationService.classificationMap; user = this.userService.get('user'); companyName = this.clientSettingsService.get('clientBranding').name; OrganizationEligibleForGivingStatus = OrganizationEligibleForGivingStatus; constructor ( private classificationService: ClassificationService, private clientSettingsService: ClientSettingsService, private userService: UserService, private i18n: I18nService ) { super(); } ngOnInit () { if ( this.nonprofit.dueDiligence && this.nonprofit.dueDiligence.ycCompliance ) { const ycCompliance = this.nonprofit.dueDiligence.ycCompliance; this.totalComplianceNumber = Object.keys(ycCompliance).length; Object.keys(ycCompliance).map(key => key as keyof YCCompliance) .forEach((key: keyof YCCompliance) => { if (ycCompliance[key]) { this.numberComplianceAccepted++; } }); } this.getAffiliationString(); this.formatCompanyCompliance(); } formatCompanyCompliance () { this.nonprofit.dueDiligence.companyCompliance?.forEach((company) => { if (this.user.affiliateId === parseInt(company.externalKey, 10)) { this.companyCompliance.push({ clientName: this.companyName, response: company.response }); } }); } getAffiliationString () { this.nonprofit.nonprofit.nonprofitAffiliationId?.forEach((affiliationId) => { switch (affiliationId) { case Affiliations.POLITICALLYAFFILIATED: this.affiliations.push(this.i18n.translate( 'nonprofits:textPoliticallyAffiliated', {}, 'Politically affiliated' )); break; case Affiliations.FRATERNAL: this.affiliations.push(this.i18n.translate( 'nonprofits:textFraternal', {}, 'Fraternal' )); break; case Affiliations.RELIGIOUS: this.affiliations.push(this.i18n.translate( 'nonprofits:textReligious', {}, 'Religious' )); break; case Affiliations.SECTARIAN: this.affiliations.push(this.i18n.translate( 'nonprofits:textSectarian', {}, 'Sectarian' )); break; case Affiliations.SERVICE: this.affiliations.push(this.i18n.translate( 'nonprofits:textService', {}, 'Service' )); break; case Affiliations.VETERANS: this.affiliations.push(this.i18n.translate( 'nonprofits:textVeterans', {}, 'Veterans' )); break; case Affiliations.NONEOFTHEABOVE: this.affiliations.push(this.i18n.translate( 'nonprofits:textNoneOfTheAbove', {}, 'None of the above' )); break; default: break; } }); } }