import { Component, Input, Output, EventEmitter } from '@angular/core'; import { FormGroup, FormControl } from '@angular/forms'; import { ICountry } from '../../signup/data/api/signupInfo/country.interface'; import { IState } from '../../signup/data/api/signupInfo/state.interface'; import { Constants } from '../../common/constants'; @Component({ selector: 'bh-payment', template: require('./payment.component.html'), styles: [require('./payment.component.css')] }) export class PaymentComponent { constants = new Constants(); @Input('group') paymentForm: FormGroup; @Input() showCopyApplicantButtons: boolean; @Input() cardholderCountries: ICountry[]; @Input() cardholderStates: IState[]; @Output() notifyApplicantCopyClicked: EventEmitter = new EventEmitter(); @Output() notifyCompanyCopyClicked: EventEmitter = new EventEmitter(); @Output() notifyCardholderCountrySelected: EventEmitter = new EventEmitter(); //@Output() setPaymentMethodType: EventEmitter = new EventEmitter(); setPaymentMethodType(type: string) { const ctrl: FormControl = (this.paymentForm).controls.paymentMethod.controls.type; ctrl.setValue(type); } paymentMethod_applicant_copyClicked() { this.notifyApplicantCopyClicked.emit('clicked'); } paymentMethod_company_copyClicked() { this.notifyCompanyCopyClicked.emit('clicked'); } paymentMethod_cardholder_countryOnSelect(val) { this.notifyCardholderCountrySelected.emit(val); } expiryMonth_onChange(val) { const pmCtrl = (this.paymentForm).controls.paymentMethod; const cardCtrl = pmCtrl.controls.card; let exp = cardCtrl.controls['expiryMonth'].value; if (exp.length > 2) cardCtrl.patchValue({ expiryMonth: exp.substring(0, 2) }); let expNum = Number(exp); if (expNum) { if (expNum > 12 || expNum <= 0) { cardCtrl.patchValue({ expiryMonth: '' }); } } else if (exp.length === 2) { cardCtrl.patchValue({ expiryMonth: '' }); } } expiryMonth_change(val) { const pmCtrl = (this.paymentForm).controls.paymentMethod; const cardCtrl = pmCtrl.controls.card; let exp = cardCtrl.controls['expiryMonth'].value; if (exp === '1') cardCtrl.patchValue({ expiryMonth: '01' }); if (exp === '2') cardCtrl.patchValue({ expiryMonth: '02' }); if (exp === '3') cardCtrl.patchValue({ expiryMonth: '03' }); if (exp === '4') cardCtrl.patchValue({ expiryMonth: '04' }); if (exp === '5') cardCtrl.patchValue({ expiryMonth: '05' }); if (exp === '6') cardCtrl.patchValue({ expiryMonth: '06' }); if (exp === '7') cardCtrl.patchValue({ expiryMonth: '07' }); if (exp === '8') cardCtrl.patchValue({ expiryMonth: '08' }); if (exp === '9') cardCtrl.patchValue({ expiryMonth: '09' }); } expiryYear_onChange(val) { const pmCtrl = (this.paymentForm).controls.paymentMethod; const cardCtrl = pmCtrl.controls.card; let exp = cardCtrl.controls['expiryYear'].value; if (exp.length > 2) cardCtrl.patchValue({ expiryYear: exp.substring(0, 2) }); let minYear: number = new Date().getFullYear() - 2000; let expNum = Number(exp); if (expNum && exp.length === 2) { if (minYear > expNum || expNum <= 0) { cardCtrl.patchValue({ expiryYear: '' }); } } else if (exp.length === 2) { cardCtrl.patchValue({ expiryYear: '' }); } } }