import { Component, OnInit } from '@angular/core'; import { OpenCloseBudgetAPI } from '@core/typings/api/open-close-budget.typing'; import { FundingSource, FundingSourceDrilldownInfo } from '@core/typings/budget.typing'; import { ClientSettingsService } from '@features/client-settings/client-settings.service'; import { AnalyticsService, EventType } from '@yourcause/common/analytics'; import { I18nService } from '@yourcause/common/i18n'; import { YCModalComponent } from '@yourcause/common/modals'; @Component({ selector: 'yc-open-close-fs-modal', templateUrl: './open-close-fs-modal.component.html', styleUrls: ['./open-close-fs-modal.component.scss'] }) export class OpenCloseFSModalComponent extends YCModalComponent implements OnInit { context: 'open'|'close'|'bulk'; fundingSourceDetails: FundingSourceDrilldownInfo; fundingSource: FundingSource; OpenCloseBudgetAPI = OpenCloseBudgetAPI; showFSTable = false; primaryButtonText: string; modalHeader: string; modalSubHeader: string; modalReady = false; scenarioText: string; constructor ( private i18n: I18nService, private clientSettingsService: ClientSettingsService, private analyticsService: AnalyticsService ) { super(); } get canReserveFunds () { return this.clientSettingsService.get('clientSettings').reserveFunds; } ngOnInit () { this.setModalScenario(); this.setModalText(); this.showFSTable = (this.context !== 'bulk'); this.modalReady = true; } onCancel () { this.closeModal.emit(); } onSubmit () { this.closeModal.emit(this.fundingSource.id); this.analyticsService.emitEvent({ eventName: 'Open close funding source modal submit', eventType: EventType.Click, extras: null }); } setModalScenario () { switch (this.context) { case 'open': this.modalHeader = this.i18n.translate( 'BUDGET:textOpenFundingSource', {}, 'Open funding source' ); this.primaryButtonText = this.i18n.translate( 'BUDGET:textOpenFundingSource', {}, 'Open funding source' ); break; case 'close': this.modalHeader = this.i18n.translate( 'BUDGET:textCloseFundingSource', {}, 'Close funding source' ); this.primaryButtonText = this.i18n.translate( 'BUDGET:textCloseFundingSource', {}, 'Close funding source' ); break; } } setModalText () { this.modalSubHeader = this.fundingSource.name; if (this.fundingSourceDetails.fundingSourceBudgetDetailModels.length) { if (this.context === 'open') { this.scenarioText = this.i18n.translate( 'BUDGET:textOpenFSWithDetails', {}, 'The funding source is attached to the following budgets. If the funding source has unavailable funds allocated to the budget, they will now become available for use if the budget is open.' ); } else { this.scenarioText = this.i18n.translate( 'BUDGET:textCloseFSWithDetails', { fundingSourceName: this.fundingSource.name }, 'Closing the __fundingSourceName__ funding source will prevent it from being added to open budgets. If attached to a budget, any funds for this source that have not been used will be made unavailable for future payments. The following budgets will be impacted by closing this source.' ); } } else { if (this.context === 'open') { this.scenarioText = this.i18n.translate( 'BUDGET:textOpenFSWithoutDetails', {}, 'If the funding source has unavailable funds allocated to any budgets, they will now become available for use if the budgets are open.' ); } else { this.scenarioText = this.i18n.translate( 'BUDGET:textCloseFSWithoutDetails', { fundingSourceName: this.fundingSource.name }, 'Closing the __fundingSourceName__ funding source will prevent it from being added to open budgets. If attached to a budget, any funds for this source that have not been used will be made unavailable for future payments.' ); } } } }