import { Component, Input, OnInit } from '@angular/core'; import { CurrencyService } from '@core/services/currency.service'; import { StatusService } from '@core/services/status.service'; import { FundingSourceTypes } from '@core/typings/budget.typing'; import { PaymentStatus } from '@core/typings/status.typing'; import { Award } from '@features/awards/typings/award.typing'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; @Component({ selector: 'gc-applicant-payments-modal', templateUrl: './applicant-payments-modal.component.html', styleUrls: ['./applicant-payments-modal.component.scss'] }) export class ApplicantPaymentsModalComponent extends YCModalComponent implements OnInit { @Input() award: Award; modalSubHeader = ''; total: string; PaymentStatus = PaymentStatus; paymentSubStatusMap = this.statusService.paymentSubStatusMap; cashString = this.i18n.translate('GLOBAL:textCash', {}, 'Cash'); inKindString = this.i18n.translate('GLOBAL:textInKind', {}, 'In-Kind'); loaded: boolean; FundingSourceTypes = FundingSourceTypes; popoverPlacement: 'right' = 'right'; constructor ( private i18n: I18nService, private currencyService: CurrencyService, private statusService: StatusService ) { super(); } async ngOnInit () { let awardAmount; if ( this.award.awardType === FundingSourceTypes.DOLLARS && this.award.currencyRequested && this.award.currencyRequestedAmountEquivalent ) { awardAmount = this.currencyService.formatMoney( this.award.currencyRequestedAmountEquivalent, this.award.currencyRequested ); } else { awardAmount = this.currencyService.formatMoney( this.award.amount ); } this.modalSubHeader = this.award.awardType === FundingSourceTypes.UNITS ? this.i18n.translate( 'GLOBAL:textNumberUnits', { number: this.award.inKindItems.reduce((acc, item) => { return acc + +item.count; }, 0) }, '__number__ units' ) : this.i18n.translate( 'GLOBAL:textAwardForAmount', { awardAmount }, 'Award amount: __awardAmount__' ); this.loaded = true; } onCancel () { this.closeModal.emit(); } }