import { __decorate, __metadata } from 'tslib';
import { ElementRef, Input, HostListener, Directive, ɵɵdefineInjectable, ɵɵinject, Injectable, ViewChild, Component, NgModule } from '@angular/core';
import { NG_VALIDATORS, NG_ASYNC_VALIDATORS, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { HttpParams, HttpHeaders, HttpClient, HttpClientModule } from '@angular/common/http';
import { CreateNewAutocompleteGroup, NgAutoCompleteComponent, NgAutoCompleteModule } from 'ng-auto-complete';
import { TextMaskModule } from 'angular2-text-mask';
import { BehaviorSubject } from 'rxjs';
import { number, expirationDate } from 'card-validator';
import createAutoCorrectedDatePipe from 'text-mask-addons/dist/createAutoCorrectedDatePipe';
import { map } from 'rxjs/operators';
import { validate } from 'email-validator';
import Phone from 'awesome-phonenumber';

import * as ɵngcc0 from '@angular/core';
import * as ɵngcc1 from '@angular/common/http';
import * as ɵngcc2 from 'ng-auto-complete';
let AfdResultDirective = 
// directive that sets an input to work as a result box for PCE, the afdResult attribute sets the relevant PCE field
class AfdResultDirective {
    constructor(el) {
        this.el = el;
    }
    afdLookupInitiate(e) {
        this.el.nativeElement.value = e.detail.body.Item[0][this.field];
    }
};
AfdResultDirective.ɵfac = function AfdResultDirective_Factory(t) { return new (t || AfdResultDirective)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdResultDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdResultDirective, selectors: [["", "afdResult", ""]], hostBindings: function AfdResultDirective_HostBindings(rf, ctx) { if (rf & 1) {
        ɵngcc0.ɵɵlistener("afdRetrieveComplete", function AfdResultDirective_afdRetrieveComplete_HostBindingHandler($event) { return ctx.afdLookupInitiate($event); }, false, ɵngcc0.ɵɵresolveDocument);
    } }, inputs: { field: ["afdResult", "field"] } });
AfdResultDirective.ctorParameters = () => [
    { type: ElementRef }
];
__decorate([
    Input('afdResult'),
    __metadata("design:type", String)
], AfdResultDirective.prototype, "field", void 0);
__decorate([
    HostListener('document:afdRetrieveComplete', ['$event']),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], AfdResultDirective.prototype, "afdLookupInitiate", null);
AfdResultDirective = __decorate([ __metadata("design:paramtypes", [ElementRef])
], AfdResultDirective);

let AfdPceService = class AfdPceService {
    constructor(http) {
        this.http = http;
        // Settings
        this.settings = {
            afdPceUrl: 'https://pce.afd.co.uk/afddata.pce',
            fieldSets: '',
            afdSerial: '',
            afdPassword: '',
            lookupType: '',
            maxResults: '',
            defaultCountry: null,
            messages: {
                phone: {
                    invalidRegex: 'Please input a valid phone number',
                    invalidPce: null,
                    required: 'Phone number is a required field'
                },
                card: {
                    invalidCardRegex: 'Please input a valid card number',
                    invalidExpiryRegex: 'Please input a valid expiry date',
                    invalidPce: 'Incorrect card number or expiry date',
                    required: 'Card Number is a required field',
                    expiryRequired: 'Expiry Date is  a required field'
                },
                account: {
                    invalidAccountRegex: 'Please input a valid account number',
                    invalidSortRegex: 'Please input a valid sort code',
                    invalidPce: null,
                    required: 'Account Number is a required field',
                    sortRequired: 'Sort Code is a required field'
                },
                email: {
                    invalidRegex: 'Please input a valid email address',
                    invalidPce: null,
                    required: 'Email is a required field'
                }
            }
        };
        this.uniqueId = Math.floor(Math.random() * 100000).toString();
        this.countries = [];
        this.resultList = [];
        this.selectedCountry = null;
        this.selectedLanguage = null;
        this.phoneCountry = null;
        // Email Info
        this.emailInfoDefaults = {
            pceValid: false,
            regexValid: false,
            pceValidationMessage: null,
            emailAddress: null
        };
        this.emailInfoSource = new BehaviorSubject(this.emailInfoDefaults);
        this.emailInfo = this.emailInfoSource.asObservable();
        // Phone Info
        this.phoneInfoDefaults = {
            pceValid: false,
            regexValid: false,
            country: {
                name: null,
                iso2: null,
                iso3: null
            },
            isMobile: false,
            isLandLine: false
        };
        this.phoneInfoSource = new BehaviorSubject(this.phoneInfoDefaults);
        this.phoneInfo = this.phoneInfoSource.asObservable();
        // Card Info
        this.cardInfoDefaults = {
            pceValid: false,
            cardRegexValid: false,
            expiryRegexValid: false,
            cardTypeNice: null,
            cardType: null,
            cardNumber: '',
            expiryDate: ''
        };
        this.cardInfoSource = new BehaviorSubject(this.cardInfoDefaults);
        this.cardInfo = this.cardInfoSource.asObservable();
        // Account Info
        this.accountInfoDefaults = {
            pceValid: false,
            accountRegexValid: false,
            sortRegexValid: false,
            iban: null,
            clearingSystem: null,
            rollNumber: null,
            accountType: null,
            accountNumber: '',
            sortCode: ''
        };
        this.accountInfoSource = new BehaviorSubject(this.accountInfoDefaults);
        this.accountInfo = this.accountInfoSource.asObservable();
        this.typeAheadString = '';
        this.listResult = null;
        this.lookupResults = {};
        this.typeAheadResults = [];
        this.retrieveResult = {};
        // Masks
        this.phoneMask = { mask: this.phoneMaskFunction, guide: false };
        this.cardMask = { mask: this.cardMaskFunction, guide: false };
        this.autoCorrectedDatePipe = createAutoCorrectedDatePipe('mm/yyyy');
        this.expiryMask = {
            mask: [/\d/, /\d/, '/', /\d/, /\d/, /\d/, /\d/],
            keepCharPositions: true,
            pipe: this.autoCorrectedDatePipe,
            guide: false
        };
        this.accountMask = { mask: [/\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/, /\d/], guide: false };
        this.sortMask = { mask: [/\d/, /\d/, '-', /\d/, /\d/, '-', /\d/, /\d/], guide: false };
    }
    // get the countries for WA control
    getCountries(defaultCountry = null) {
        let params = new HttpParams();
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', 'list');
        params = params.set('fields', 'standard');
        params = params.set('task', 'listcountries');
        params = params.set('format', 'json');
        const headers = new HttpHeaders({
            'Content-Type': 'text/plain'
        });
        return this.http.get(this.settings.afdPceUrl, {
            params: params,
            headers: headers,
            observe: 'response'
        });
    }
    // normal lookup
    pceLookup(lookup, data) {
        if (typeof data === 'undefined') {
            data = 'address';
        }
        let params = new HttpParams();
        params = params.set('lookup', lookup);
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', data);
        params = params.set('format', 'json');
        params = params.set('task', 'fastfindv4');
        params = params.set('fields', 'list');
        params = params.set('maxquantity', this.settings.maxResults);
        params = params.set('uniqueid', this.uniqueId);
        params = params.set('allpc', '1');
        if (this.selectedCountry) {
            params = params.set('countryiso', this.selectedCountry.iso);
        }
        if (this.selectedLanguage) {
            params = params.set('language', this.selectedLanguage);
        }
        const headers = new HttpHeaders({
            'Content-Type': 'text/plain'
        });
        return this.http.get(this.settings.afdPceUrl, {
            params: params,
            headers: headers,
            observe: 'response'
        });
    }
    // normal retrieve
    pceRetrieve(key, data) {
        if (typeof data === 'undefined') {
            data = 'address';
        }
        let params = new HttpParams();
        params = params.set('key', key);
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', data);
        params = params.set('format', 'json');
        params = params.set('task', 'retrieve');
        params = params.set('fields', this.settings.fieldSets);
        params = params.set('uniqueid', this.uniqueId);
        if (this.selectedCountry !== null) {
            params = params.set('fields', 'international');
            params = params.set('countryiso', this.selectedCountry.iso);
        }
        if (this.selectedLanguage) {
            params = params.set('language', this.selectedLanguage);
        }
        const headers = new HttpHeaders({
            'Content-Type': 'text/plain'
        });
        return this.http.get(this.settings.afdPceUrl, {
            params: params,
            observe: 'response',
            headers: headers
        });
    }
    //
    reverseGeocode(lat, lng) {
        let params = new HttpParams();
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', 'address');
        params = params.set('task', 'nearest');
        params = params.set('fields', 'list');
        params = params.set('latitude', lat);
        params = params.set('longitude', lng);
        params = params.set('format', 'json');
        const headers = new HttpHeaders({
            'Content-Type': 'text/plain'
        });
        const options = {
            params: params,
            responseType: 'text',
            headers: headers
        };
        return this.http.get(this.settings.afdPceUrl, options);
    }
    // email validation
    validateEmail(email) {
        let params = new HttpParams();
        params = params.set('email', email);
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', 'email');
        params = params.set('format', 'json');
        params = params.set('task', 'live');
        params = params.set('fields', 'standard');
        const options = {
            params: params,
            responseType: 'text'
        };
        return this.http.get(this.settings.afdPceUrl, options);
    }
    // phone validation
    validatePhone(phone) {
        let params = new HttpParams();
        params = params.set('phone', phone);
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', 'phone');
        params = params.set('format', 'json');
        params = params.set('task', 'full');
        params = params.set('fields', 'standard');
        params = params.set('uniqueid', this.uniqueId);
        params = params.set('countryiso', 'gbr');
        if (this.phoneCountry !== null) {
            params = params.set('countryiso', this.phoneCountry.iso3);
        }
        return this.http.get(this.settings.afdPceUrl, {
            params: params,
            observe: 'response'
        });
    }
    // get phone business information
    searchPhone(phone) {
        let params = new HttpParams();
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', 'address');
        params = params.set('task', 'fastfind');
        params = params.set('fields', 'standard');
        params = params.set('lookup', phone);
        params = params.set('format', 'json');
        params = params.set('uniqueid', this.uniqueId);
        return this.http.get(this.settings.afdPceUrl, {
            params: params,
            observe: 'response'
        });
    }
    // card validation
    validateCard(cardNumber, expiryDate) {
        let params = new HttpParams();
        params = params.set('cardNumber', cardNumber);
        params = params.set('expiryDate', expiryDate);
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', 'bank');
        params = params.set('format', 'json');
        params = params.set('task', 'card');
        params = params.set('fields', 'card');
        const options = {
            params: params,
            responseType: 'text'
        };
        return this.http.get(this.settings.afdPceUrl, options);
    }
    // card validation
    validateAccount(accountNumber, sortCode) {
        let params = new HttpParams();
        params = params.set('accountNumber', accountNumber);
        params = params.set('sortCode', sortCode);
        params = params.set('serial', this.settings.afdSerial);
        params = params.set('password', this.settings.afdPassword);
        params = params.set('data', 'bank');
        params = params.set('format', 'json');
        params = params.set('task', 'account');
        params = params.set('fields', 'account');
        const options = {
            params: params,
            responseType: 'text'
        };
        return this.http.get(this.settings.afdPceUrl, options);
    }
    typeAheadSelected(result, data) {
        if (typeof data === 'undefined') {
            data = 'address';
        }
        this.typeAheadString = '';
        this.pceRetrieve(result.Key, data).subscribe(res => {
            const event = new CustomEvent('afdRetrieveComplete', { detail: res });
            document.dispatchEvent(event);
            this.typeAheadResults = [];
        });
    }
    refreshUniqueId() {
        this.uniqueId = Math.floor(Math.random() * 100000).toString();
    }
    // waits to see if typing has stopped in typeahead for more than 10 seconds, if so a new uniqueid is generated
    manageUniqueId(value) {
        // if element is empty create new unique id
        if (value.length < 1) {
            this.refreshUniqueId();
        }
        // if user stops typing for 10 seconds create new unique id
        if (this.typeAheadTimer) {
            window.clearTimeout(this.typeAheadTimer);
        }
        this.typeAheadTimer = window.setTimeout(() => {
            this.typeAheadTimer = null;
            this.refreshUniqueId();
        }, 10000);
    }
    // Mask Functions
    phoneMaskFunction(input) {
        const output = [/[+/\d/]/];
        for (let i = 0; i < input.length; i++) {
            output.push(/\d/);
        }
        return output;
    }
    cardMaskFunction(input) {
        const cardValid = number(input);
        if (cardValid.card) {
            const totalLength = cardValid.card.lengths[cardValid.card.lengths.length - 1] + cardValid.card.gaps.length;
            const output = [];
            const actualPositions = [];
            for (let i = 0; i < cardValid.card.gaps.length; i++) {
                actualPositions.push(cardValid.card.gaps[i] + i);
            }
            for (let i = 0; i < totalLength; i++) {
                if (actualPositions.indexOf(output.length) > -1) {
                    output.push(' ');
                }
                else {
                    output.push(/\d/);
                }
            }
            return output;
        }
        else {
            const output = [];
            for (let i = 0; i < 16; i++) {
                output.push(/\d/);
            }
            return output;
        }
    }
};
AfdPceService.ɵfac = function AfdPceService_Factory(t) { return new (t || AfdPceService)(ɵngcc0.ɵɵinject(ɵngcc1.HttpClient)); };
AfdPceService.ctorParameters = () => [
    { type: HttpClient }
];
AfdPceService.ɵprov = ɵɵdefineInjectable({ factory: function AfdPceService_Factory() { return new AfdPceService(ɵɵinject(HttpClient)); }, token: AfdPceService, providedIn: "root" });
AfdPceService = __decorate([ __metadata("design:paramtypes", [HttpClient])
], AfdPceService);

var AfdEmailRegexValidDirective_1, AfdEmailPceValidDirective_1;
let AfdEmailRegexValidDirective = AfdEmailRegexValidDirective_1 = class AfdEmailRegexValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    validate(control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            // send useful information to the pce service
            this.afdPceService.emailInfoSource.next({
                pceValid: false,
                regexValid: validate(control.value),
                pceValidationMessage: null,
                emailAddress: control.value
            });
            // validate regex
            return validate(control.value) ? null : {
                afdEmailRegexValid: {
                    message: this.afdPceService.settings.messages.email.invalidRegex
                }
            };
        }
        else {
            // if there is nothing in the control
            return null;
        }
    }
};
AfdEmailRegexValidDirective.ɵfac = function AfdEmailRegexValidDirective_Factory(t) { return new (t || AfdEmailRegexValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdEmailRegexValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdEmailRegexValidDirective, selectors: [["", "afdEmailRegexValid", ""]], features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_VALIDATORS,
                useExisting: AfdEmailRegexValidDirective_1,
                multi: true
            }
        ])] });
AfdEmailRegexValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
AfdEmailRegexValidDirective = AfdEmailRegexValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdEmailRegexValidDirective);
let AfdEmailPceValidDirective = AfdEmailPceValidDirective_1 = class AfdEmailPceValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
        // check to see if the regex element exists
        this.hasRegexCheck = !!el.nativeElement.hasAttribute('afdEmailRegexValid');
        if (!this.hasRegexCheck) {
            console.warn('Warning, you are using the PCE email validation directive without the regex directive.  ' +
                'This means that you are querying PCE and are being charged for every keypress.  ' +
                'Please add the directive "afdEmailRegexValid" to the input element');
        }
    }
    validate(control) {
        if (control.value) {
            // validate
            return this.afdPceService.validateEmail(control.value).pipe(map(data => JSON.parse(data)), map(data => {
                // Check if valid
                if (data['Result'] === '1') {
                    // send useful information to the pce service
                    this.afdPceService.emailInfoSource.next({
                        pceValid: true,
                        regexValid: validate(control.value),
                        pceValidationMessage: data['Item'][0].Status,
                        emailAddress: control.value
                    });
                    return null;
                }
                else {
                    // send useful information to the pce service
                    this.afdPceService.emailInfoSource.next({
                        pceValid: false,
                        regexValid: validate(control.value),
                        pceValidationMessage: data.ErrorText,
                        emailAddress: control.value
                    });
                    return {
                        afdEmailPceValid: {
                            message: this.afdPceService.settings.messages.email.invalidPce ? this.afdPceService.settings.messages.email.invalidPce
                                : data['ErrorText']
                        }
                    };
                }
            }));
        }
        else {
            return new Promise((resolve => resolve(null)));
        }
    }
};
AfdEmailPceValidDirective.ɵfac = function AfdEmailPceValidDirective_Factory(t) { return new (t || AfdEmailPceValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdEmailPceValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdEmailPceValidDirective, selectors: [["", "afdEmailPceValid", ""]], features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_ASYNC_VALIDATORS,
                useExisting: AfdEmailPceValidDirective_1,
                multi: true
            }
        ])] });
AfdEmailPceValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
AfdEmailPceValidDirective = AfdEmailPceValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdEmailPceValidDirective);

const Countries = [
    {
        dial: 886,
        iso3: 'TWN',
        iso2: 'TW',
        name: 'Taiwan'
    },
    {
        dial: 93,
        iso3: 'AFG',
        iso2: 'AF',
        name: 'Afghanistan'
    },
    {
        dial: 355,
        iso3: 'ALB',
        iso2: 'AL',
        name: 'Albania'
    },
    {
        dial: 213,
        iso3: 'DZA',
        iso2: 'DZ',
        name: 'Algeria'
    },
    {
        dial: '1-684',
        iso3: 'ASM',
        iso2: 'AS',
        name: 'American Samoa'
    },
    {
        dial: 376,
        iso3: 'AND',
        iso2: 'AD',
        name: 'Andorra'
    },
    {
        dial: 244,
        iso3: 'AGO',
        iso2: 'AO',
        name: 'Angola'
    },
    {
        dial: '1-264',
        iso3: 'AIA',
        iso2: 'AI',
        name: 'Anguilla'
    },
    {
        dial: 672,
        iso3: 'ATA',
        iso2: 'AQ',
        name: 'Antarctica'
    },
    {
        dial: '1-268',
        iso3: 'ATG',
        iso2: 'AG',
        name: 'Antigua & Barbuda'
    },
    {
        dial: 54,
        iso3: 'ARG',
        iso2: 'AR',
        name: 'Argentina'
    },
    {
        dial: 374,
        iso3: 'ARM',
        iso2: 'AM',
        name: 'Armenia'
    },
    {
        dial: 297,
        iso3: 'ABW',
        iso2: 'AW',
        name: 'Aruba'
    },
    {
        dial: 61,
        iso3: 'AUS',
        iso2: 'AU',
        name: 'Australia'
    },
    {
        dial: 43,
        iso3: 'AUT',
        iso2: 'AT',
        name: 'Austria'
    },
    {
        dial: 994,
        iso3: 'AZE',
        iso2: 'AZ',
        name: 'Azerbaijan'
    },
    {
        dial: '1-242',
        iso3: 'BHS',
        iso2: 'BS',
        name: 'Bahamas'
    },
    {
        dial: 973,
        iso3: 'BHR',
        iso2: 'BH',
        name: 'Bahrain'
    },
    {
        dial: 880,
        iso3: 'BGD',
        iso2: 'BD',
        name: 'Bangladesh'
    },
    {
        dial: '1-246',
        iso3: 'BRB',
        iso2: 'BB',
        name: 'Barbados'
    },
    {
        dial: 375,
        iso3: 'BLR',
        iso2: 'BY',
        name: 'Belarus'
    },
    {
        dial: 32,
        iso3: 'BEL',
        iso2: 'BE',
        name: 'Belgium'
    },
    {
        dial: 501,
        iso3: 'BLZ',
        iso2: 'BZ',
        name: 'Belize'
    },
    {
        dial: 229,
        iso3: 'BEN',
        iso2: 'BJ',
        name: 'Benin'
    },
    {
        dial: '1-441',
        iso3: 'BMU',
        iso2: 'BM',
        name: 'Bermuda'
    },
    {
        dial: 975,
        iso3: 'BTN',
        iso2: 'BT',
        name: 'Bhutan'
    },
    {
        dial: 591,
        iso3: 'BOL',
        iso2: 'BO',
        name: 'Bolivia'
    },
    {
        dial: 599,
        iso3: 'BES',
        iso2: 'BQ',
        name: 'Caribbean Netherlands'
    },
    {
        dial: 387,
        iso3: 'BIH',
        iso2: 'BA',
        name: 'Bosnia'
    },
    {
        dial: 267,
        iso3: 'BWA',
        iso2: 'BW',
        name: 'Botswana'
    },
    {
        dial: 47,
        iso3: 'BVT',
        iso2: 'BV',
        name: 'Bouvet Island'
    },
    {
        dial: 55,
        iso3: 'BRA',
        iso2: 'BR',
        name: 'Brazil'
    },
    {
        dial: 246,
        iso3: 'IOT',
        iso2: 'IO',
        name: 'British Indian Ocean Territory'
    },
    {
        dial: '1-284',
        iso3: 'VGB',
        iso2: 'VG',
        name: 'British Virgin Islands'
    },
    {
        dial: 673,
        iso3: 'BRN',
        iso2: 'BN',
        name: 'Brunei'
    },
    {
        dial: 359,
        iso3: 'BGR',
        iso2: 'BG',
        name: 'Bulgaria'
    },
    {
        dial: 226,
        iso3: 'BFA',
        iso2: 'BF',
        name: 'Burkina Faso'
    },
    {
        dial: 257,
        iso3: 'BDI',
        iso2: 'BI',
        name: 'Burundi'
    },
    {
        dial: 238,
        iso3: 'CPV',
        iso2: 'CV',
        name: 'Cape Verde'
    },
    {
        dial: 855,
        iso3: 'KHM',
        iso2: 'KH',
        name: 'Cambodia'
    },
    {
        dial: 237,
        iso3: 'CMR',
        iso2: 'CM',
        name: 'Cameroon'
    },
    {
        dial: 1,
        iso3: 'CAN',
        iso2: 'CA',
        name: 'Canada'
    },
    {
        dial: '1-345',
        iso3: 'CYM',
        iso2: 'KY',
        name: 'Cayman Islands'
    },
    {
        dial: 236,
        iso3: 'CAF',
        iso2: 'CF',
        name: 'Central African Republic'
    },
    {
        dial: 235,
        iso3: 'TCD',
        iso2: 'TD',
        name: 'Chad'
    },
    {
        dial: 56,
        iso3: 'CHL',
        iso2: 'CL',
        name: 'Chile'
    },
    {
        dial: 86,
        iso3: 'CHN',
        iso2: 'CN',
        name: 'China'
    },
    {
        dial: 852,
        iso3: 'HKG',
        iso2: 'HK',
        name: 'Hong Kong'
    },
    {
        dial: 853,
        iso3: 'MAC',
        iso2: 'MO',
        name: 'Macau'
    },
    {
        dial: 61,
        iso3: 'CXR',
        iso2: 'CX',
        name: 'Christmas Island'
    },
    {
        dial: 61,
        iso3: 'CCK',
        iso2: 'CC',
        name: 'Cocos (Keeling) Islands'
    },
    {
        dial: 57,
        iso3: 'COL',
        iso2: 'CO',
        name: 'Colombia'
    },
    {
        dial: 269,
        iso3: 'COM',
        iso2: 'KM',
        name: 'Comoros'
    },
    {
        dial: 242,
        iso3: 'COG',
        iso2: 'CG',
        name: 'Congo - Brazzaville'
    },
    {
        dial: 682,
        iso3: 'COK',
        iso2: 'CK',
        name: 'Cook Islands'
    },
    {
        dial: 506,
        iso3: 'CRI',
        iso2: 'CR',
        name: 'Costa Rica'
    },
    {
        dial: 385,
        iso3: 'HRV',
        iso2: 'HR',
        name: 'Croatia'
    },
    {
        dial: 53,
        iso3: 'CUB',
        iso2: 'CU',
        name: 'Cuba'
    },
    {
        dial: 599,
        iso3: 'CUW',
        iso2: 'CW',
        name: 'Curaçao'
    },
    {
        dial: 357,
        iso3: 'CYP',
        iso2: 'CY',
        name: 'Cyprus'
    },
    {
        dial: 420,
        iso3: 'CZE',
        iso2: 'CZ',
        name: 'Czechia'
    },
    {
        dial: 225,
        iso3: 'CIV',
        iso2: 'CI',
        name: 'Côte d’Ivoire'
    },
    {
        dial: 850,
        iso3: 'PRK',
        iso2: 'KP',
        name: 'North Korea'
    },
    {
        dial: 243,
        iso3: 'COD',
        iso2: 'CD',
        name: 'Congo - Kinshasa'
    },
    {
        dial: 45,
        iso3: 'DNK',
        iso2: 'DK',
        name: 'Denmark'
    },
    {
        dial: 253,
        iso3: 'DJI',
        iso2: 'DJ',
        name: 'Djibouti'
    },
    {
        dial: '1-767',
        iso3: 'DMA',
        iso2: 'DM',
        name: 'Dominica'
    },
    {
        dial: '1-809,1-829,1-849',
        iso3: 'DOM',
        iso2: 'DO',
        name: 'Dominican Republic'
    },
    {
        dial: 593,
        iso3: 'ECU',
        iso2: 'EC',
        name: 'Ecuador'
    },
    {
        dial: 20,
        iso3: 'EGY',
        iso2: 'EG',
        name: 'Egypt'
    },
    {
        dial: 503,
        iso3: 'SLV',
        iso2: 'SV',
        name: 'El Salvador'
    },
    {
        dial: 240,
        iso3: 'GNQ',
        iso2: 'GQ',
        name: 'Equatorial Guinea'
    },
    {
        dial: 291,
        iso3: 'ERI',
        iso2: 'ER',
        name: 'Eritrea'
    },
    {
        dial: 372,
        iso3: 'EST',
        iso2: 'EE',
        name: 'Estonia'
    },
    {
        dial: 268,
        iso3: 'SWZ',
        iso2: 'SZ',
        name: 'Eswatini'
    },
    {
        dial: 251,
        iso3: 'ETH',
        iso2: 'ET',
        name: 'Ethiopia'
    },
    {
        dial: 500,
        iso3: 'FLK',
        iso2: 'FK',
        name: 'Falkland Islands'
    },
    {
        dial: 298,
        iso3: 'FRO',
        iso2: 'FO',
        name: 'Faroe Islands'
    },
    {
        dial: 679,
        iso3: 'FJI',
        iso2: 'FJ',
        name: 'Fiji'
    },
    {
        dial: 358,
        iso3: 'FIN',
        iso2: 'FI',
        name: 'Finland'
    },
    {
        dial: 33,
        iso3: 'FRA',
        iso2: 'FR',
        name: 'France'
    },
    {
        dial: 594,
        iso3: 'GUF',
        iso2: 'GF',
        name: 'French Guiana'
    },
    {
        dial: 689,
        iso3: 'PYF',
        iso2: 'PF',
        name: 'French Polynesia'
    },
    {
        dial: 262,
        iso3: 'ATF',
        iso2: 'TF',
        name: 'French Southern Territories'
    },
    {
        dial: 241,
        iso3: 'GAB',
        iso2: 'GA',
        name: 'Gabon'
    },
    {
        dial: 220,
        iso3: 'GMB',
        iso2: 'GM',
        name: 'Gambia'
    },
    {
        dial: 995,
        iso3: 'GEO',
        iso2: 'GE',
        name: 'Georgia'
    },
    {
        dial: 49,
        iso3: 'DEU',
        iso2: 'DE',
        name: 'Germany'
    },
    {
        dial: 233,
        iso3: 'GHA',
        iso2: 'GH',
        name: 'Ghana'
    },
    {
        dial: 350,
        iso3: 'GIB',
        iso2: 'GI',
        name: 'Gibraltar'
    },
    {
        dial: 30,
        iso3: 'GRC',
        iso2: 'GR',
        name: 'Greece'
    },
    {
        dial: 299,
        iso3: 'GRL',
        iso2: 'GL',
        name: 'Greenland'
    },
    {
        dial: '1-473',
        iso3: 'GRD',
        iso2: 'GD',
        name: 'Grenada'
    },
    {
        dial: 590,
        iso3: 'GLP',
        iso2: 'GP',
        name: 'Guadeloupe'
    },
    {
        dial: '1-671',
        iso3: 'GUM',
        iso2: 'GU',
        name: 'Guam'
    },
    {
        dial: 502,
        iso3: 'GTM',
        iso2: 'GT',
        name: 'Guatemala'
    },
    {
        dial: 44,
        iso3: 'GGY',
        iso2: 'GG',
        name: 'Guernsey'
    },
    {
        dial: 224,
        iso3: 'GIN',
        iso2: 'GN',
        name: 'Guinea'
    },
    {
        dial: 245,
        iso3: 'GNB',
        iso2: 'GW',
        name: 'Guinea-Bissau'
    },
    {
        dial: 592,
        iso3: 'GUY',
        iso2: 'GY',
        name: 'Guyana'
    },
    {
        dial: 509,
        iso3: 'HTI',
        iso2: 'HT',
        name: 'Haiti'
    },
    {
        dial: 672,
        iso3: 'HMD',
        iso2: 'HM',
        name: 'Heard & McDonald Islands'
    },
    {
        dial: '39-06',
        iso3: 'VAT',
        iso2: 'VA',
        name: 'Vatican City'
    },
    {
        dial: 504,
        iso3: 'HND',
        iso2: 'HN',
        name: 'Honduras'
    },
    {
        dial: 36,
        iso3: 'HUN',
        iso2: 'HU',
        name: 'Hungary'
    },
    {
        dial: 354,
        iso3: 'ISL',
        iso2: 'IS',
        name: 'Iceland'
    },
    {
        dial: 91,
        iso3: 'IND',
        iso2: 'IN',
        name: 'India'
    },
    {
        dial: 62,
        iso3: 'IDN',
        iso2: 'ID',
        name: 'Indonesia'
    },
    {
        dial: 98,
        iso3: 'IRN',
        iso2: 'IR',
        name: 'Iran'
    },
    {
        dial: 964,
        iso3: 'IRQ',
        iso2: 'IQ',
        name: 'Iraq'
    },
    {
        dial: 353,
        iso3: 'IRL',
        iso2: 'IE',
        name: 'Ireland'
    },
    {
        dial: 44,
        iso3: 'IMN',
        iso2: 'IM',
        name: 'Isle of Man'
    },
    {
        dial: 972,
        iso3: 'ISR',
        iso2: 'IL',
        name: 'Israel'
    },
    {
        dial: 39,
        iso3: 'ITA',
        iso2: 'IT',
        name: 'Italy'
    },
    {
        dial: '1-876',
        iso3: 'JAM',
        iso2: 'JM',
        name: 'Jamaica'
    },
    {
        dial: 81,
        iso3: 'JPN',
        iso2: 'JP',
        name: 'Japan'
    },
    {
        dial: 44,
        iso3: 'JEY',
        iso2: 'JE',
        name: 'Jersey'
    },
    {
        dial: 962,
        iso3: 'JOR',
        iso2: 'JO',
        name: 'Jordan'
    },
    {
        dial: 7,
        iso3: 'KAZ',
        iso2: 'KZ',
        name: 'Kazakhstan'
    },
    {
        dial: 254,
        iso3: 'KEN',
        iso2: 'KE',
        name: 'Kenya'
    },
    {
        dial: 686,
        iso3: 'KIR',
        iso2: 'KI',
        name: 'Kiribati'
    },
    {
        dial: 965,
        iso3: 'KWT',
        iso2: 'KW',
        name: 'Kuwait'
    },
    {
        dial: 996,
        iso3: 'KGZ',
        iso2: 'KG',
        name: 'Kyrgyzstan'
    },
    {
        dial: 856,
        iso3: 'LAO',
        iso2: 'LA',
        name: 'Laos'
    },
    {
        dial: 371,
        iso3: 'LVA',
        iso2: 'LV',
        name: 'Latvia'
    },
    {
        dial: 961,
        iso3: 'LBN',
        iso2: 'LB',
        name: 'Lebanon'
    },
    {
        dial: 266,
        iso3: 'LSO',
        iso2: 'LS',
        name: 'Lesotho'
    },
    {
        dial: 231,
        iso3: 'LBR',
        iso2: 'LR',
        name: 'Liberia'
    },
    {
        dial: 218,
        iso3: 'LBY',
        iso2: 'LY',
        name: 'Libya'
    },
    {
        dial: 423,
        iso3: 'LIE',
        iso2: 'LI',
        name: 'Liechtenstein'
    },
    {
        dial: 370,
        iso3: 'LTU',
        iso2: 'LT',
        name: 'Lithuania'
    },
    {
        dial: 352,
        iso3: 'LUX',
        iso2: 'LU',
        name: 'Luxembourg'
    },
    {
        dial: 261,
        iso3: 'MDG',
        iso2: 'MG',
        name: 'Madagascar'
    },
    {
        dial: 265,
        iso3: 'MWI',
        iso2: 'MW',
        name: 'Malawi'
    },
    {
        dial: 60,
        iso3: 'MYS',
        iso2: 'MY',
        name: 'Malaysia'
    },
    {
        dial: 960,
        iso3: 'MDV',
        iso2: 'MV',
        name: 'Maldives'
    },
    {
        dial: 223,
        iso3: 'MLI',
        iso2: 'ML',
        name: 'Mali'
    },
    {
        dial: 356,
        iso3: 'MLT',
        iso2: 'MT',
        name: 'Malta'
    },
    {
        dial: 692,
        iso3: 'MHL',
        iso2: 'MH',
        name: 'Marshall Islands'
    },
    {
        dial: 596,
        iso3: 'MTQ',
        iso2: 'MQ',
        name: 'Martinique'
    },
    {
        dial: 222,
        iso3: 'MRT',
        iso2: 'MR',
        name: 'Mauritania'
    },
    {
        dial: 230,
        iso3: 'MUS',
        iso2: 'MU',
        name: 'Mauritius'
    },
    {
        dial: 262,
        iso3: 'MYT',
        iso2: 'YT',
        name: 'Mayotte'
    },
    {
        dial: 52,
        iso3: 'MEX',
        iso2: 'MX',
        name: 'Mexico'
    },
    {
        dial: 691,
        iso3: 'FSM',
        iso2: 'FM',
        name: 'Micronesia'
    },
    {
        dial: 377,
        iso3: 'MCO',
        iso2: 'MC',
        name: 'Monaco'
    },
    {
        dial: 976,
        iso3: 'MNG',
        iso2: 'MN',
        name: 'Mongolia'
    },
    {
        dial: 382,
        iso3: 'MNE',
        iso2: 'ME',
        name: 'Montenegro'
    },
    {
        dial: '1-664',
        iso3: 'MSR',
        iso2: 'MS',
        name: 'Montserrat'
    },
    {
        dial: 212,
        iso3: 'MAR',
        iso2: 'MA',
        name: 'Morocco'
    },
    {
        dial: 258,
        iso3: 'MOZ',
        iso2: 'MZ',
        name: 'Mozambique'
    },
    {
        dial: 95,
        iso3: 'MMR',
        iso2: 'MM',
        name: 'Myanmar'
    },
    {
        dial: 264,
        iso3: 'NAM',
        iso2: 'NA',
        name: 'Namibia'
    },
    {
        dial: 674,
        iso3: 'NRU',
        iso2: 'NR',
        name: 'Nauru'
    },
    {
        dial: 977,
        iso3: 'NPL',
        iso2: 'NP',
        name: 'Nepal'
    },
    {
        dial: 31,
        iso3: 'NLD',
        iso2: 'NL',
        name: 'Netherlands'
    },
    {
        dial: 687,
        iso3: 'NCL',
        iso2: 'NC',
        name: 'New Caledonia'
    },
    {
        dial: 64,
        iso3: 'NZL',
        iso2: 'NZ',
        name: 'New Zealand'
    },
    {
        dial: 505,
        iso3: 'NIC',
        iso2: 'NI',
        name: 'Nicaragua'
    },
    {
        dial: 227,
        iso3: 'NER',
        iso2: 'NE',
        name: 'Niger'
    },
    {
        dial: 234,
        iso3: 'NGA',
        iso2: 'NG',
        name: 'Nigeria'
    },
    {
        dial: 683,
        iso3: 'NIU',
        iso2: 'NU',
        name: 'Niue'
    },
    {
        dial: 672,
        iso3: 'NFK',
        iso2: 'NF',
        name: 'Norfolk Island'
    },
    {
        dial: '1-670',
        iso3: 'MNP',
        iso2: 'MP',
        name: 'Northern Mariana Islands'
    },
    {
        dial: 47,
        iso3: 'NOR',
        iso2: 'NO',
        name: 'Norway'
    },
    {
        dial: 968,
        iso3: 'OMN',
        iso2: 'OM',
        name: 'Oman'
    },
    {
        dial: 92,
        iso3: 'PAK',
        iso2: 'PK',
        name: 'Pakistan'
    },
    {
        dial: 680,
        iso3: 'PLW',
        iso2: 'PW',
        name: 'Palau'
    },
    {
        dial: 507,
        iso3: 'PAN',
        iso2: 'PA',
        name: 'Panama'
    },
    {
        dial: 675,
        iso3: 'PNG',
        iso2: 'PG',
        name: 'Papua New Guinea'
    },
    {
        dial: 595,
        iso3: 'PRY',
        iso2: 'PY',
        name: 'Paraguay'
    },
    {
        dial: 51,
        iso3: 'PER',
        iso2: 'PE',
        name: 'Peru'
    },
    {
        dial: 63,
        iso3: 'PHL',
        iso2: 'PH',
        name: 'Philippines'
    },
    {
        dial: 870,
        iso3: 'PCN',
        iso2: 'PN',
        name: 'Pitcairn Islands'
    },
    {
        dial: 48,
        iso3: 'POL',
        iso2: 'PL',
        name: 'Poland'
    },
    {
        dial: 351,
        iso3: 'PRT',
        iso2: 'PT',
        name: 'Portugal'
    },
    {
        dial: 1,
        iso3: 'PRI',
        iso2: 'PR',
        name: 'Puerto Rico'
    },
    {
        dial: 974,
        iso3: 'QAT',
        iso2: 'QA',
        name: 'Qatar'
    },
    {
        dial: 82,
        iso3: 'KOR',
        iso2: 'KR',
        name: 'South Korea'
    },
    {
        dial: 373,
        iso3: 'MDA',
        iso2: 'MD',
        name: 'Moldova'
    },
    {
        dial: 40,
        iso3: 'ROU',
        iso2: 'RO',
        name: 'Romania'
    },
    {
        dial: 7,
        iso3: 'RUS',
        iso2: 'RU',
        name: 'Russia'
    },
    {
        dial: 250,
        iso3: 'RWA',
        iso2: 'RW',
        name: 'Rwanda'
    },
    {
        dial: 262,
        iso3: 'REU',
        iso2: 'RE',
        name: 'Réunion'
    },
    {
        dial: 590,
        iso3: 'BLM',
        iso2: 'BL',
        name: 'St. Barthélemy'
    },
    {
        dial: 290,
        iso3: 'SHN',
        iso2: 'SH',
        name: 'St. Helena'
    },
    {
        dial: '1-869',
        iso3: 'KNA',
        iso2: 'KN',
        name: 'St. Kitts & Nevis'
    },
    {
        dial: '1-758',
        iso3: 'LCA',
        iso2: 'LC',
        name: 'St. Lucia'
    },
    {
        dial: 590,
        iso3: 'MAF',
        iso2: 'MF',
        name: 'St. Martin'
    },
    {
        dial: 508,
        iso3: 'SPM',
        iso2: 'PM',
        name: 'St. Pierre & Miquelon'
    },
    {
        dial: '1-784',
        iso3: 'VCT',
        iso2: 'VC',
        name: 'St. Vincent & Grenadines'
    },
    {
        dial: 685,
        iso3: 'WSM',
        iso2: 'WS',
        name: 'Samoa'
    },
    {
        dial: 378,
        iso3: 'SMR',
        iso2: 'SM',
        name: 'San Marino'
    },
    {
        dial: 239,
        iso3: 'STP',
        iso2: 'ST',
        name: 'São Tomé & Príncipe'
    },
    {
        dial: '',
        iso3: '',
        iso2: '',
        name: ''
    },
    {
        dial: 966,
        iso3: 'SAU',
        iso2: 'SA',
        name: 'Saudi Arabia'
    },
    {
        dial: 221,
        iso3: 'SEN',
        iso2: 'SN',
        name: 'Senegal'
    },
    {
        dial: 381,
        iso3: 'SRB',
        iso2: 'RS',
        name: 'Serbia'
    },
    {
        dial: 248,
        iso3: 'SYC',
        iso2: 'SC',
        name: 'Seychelles'
    },
    {
        dial: 232,
        iso3: 'SLE',
        iso2: 'SL',
        name: 'Sierra Leone'
    },
    {
        dial: 65,
        iso3: 'SGP',
        iso2: 'SG',
        name: 'Singapore'
    },
    {
        dial: '1-721',
        iso3: 'SXM',
        iso2: 'SX',
        name: 'Sint Maarten'
    },
    {
        dial: 421,
        iso3: 'SVK',
        iso2: 'SK',
        name: 'Slovakia'
    },
    {
        dial: 386,
        iso3: 'SVN',
        iso2: 'SI',
        name: 'Slovenia'
    },
    {
        dial: 677,
        iso3: 'SLB',
        iso2: 'SB',
        name: 'Solomon Islands'
    },
    {
        dial: 252,
        iso3: 'SOM',
        iso2: 'SO',
        name: 'Somalia'
    },
    {
        dial: 27,
        iso3: 'ZAF',
        iso2: 'ZA',
        name: 'South Africa'
    },
    {
        dial: 500,
        iso3: 'SGS',
        iso2: 'GS',
        name: 'South Georgia & South Sandwich Islands'
    },
    {
        dial: 211,
        iso3: 'SSD',
        iso2: 'SS',
        name: 'South Sudan'
    },
    {
        dial: 34,
        iso3: 'ESP',
        iso2: 'ES',
        name: 'Spain'
    },
    {
        dial: 94,
        iso3: 'LKA',
        iso2: 'LK',
        name: 'Sri Lanka'
    },
    {
        dial: 970,
        iso3: 'PSE',
        iso2: 'PS',
        name: 'Palestine'
    },
    {
        dial: 249,
        iso3: 'SDN',
        iso2: 'SD',
        name: 'Sudan'
    },
    {
        dial: 597,
        iso3: 'SUR',
        iso2: 'SR',
        name: 'Suriname'
    },
    {
        dial: 47,
        iso3: 'SJM',
        iso2: 'SJ',
        name: 'Svalbard & Jan Mayen'
    },
    {
        dial: 46,
        iso3: 'SWE',
        iso2: 'SE',
        name: 'Sweden'
    },
    {
        dial: 41,
        iso3: 'CHE',
        iso2: 'CH',
        name: 'Switzerland'
    },
    {
        dial: 963,
        iso3: 'SYR',
        iso2: 'SY',
        name: 'Syria'
    },
    {
        dial: 992,
        iso3: 'TJK',
        iso2: 'TJ',
        name: 'Tajikistan'
    },
    {
        dial: 66,
        iso3: 'THA',
        iso2: 'TH',
        name: 'Thailand'
    },
    {
        dial: 389,
        iso3: 'MKD',
        iso2: 'MK',
        name: 'Macedonia'
    },
    {
        dial: 670,
        iso3: 'TLS',
        iso2: 'TL',
        name: 'Timor-Leste'
    },
    {
        dial: 228,
        iso3: 'TGO',
        iso2: 'TG',
        name: 'Togo'
    },
    {
        dial: 690,
        iso3: 'TKL',
        iso2: 'TK',
        name: 'Tokelau'
    },
    {
        dial: 676,
        iso3: 'TON',
        iso2: 'TO',
        name: 'Tonga'
    },
    {
        dial: '1-868',
        iso3: 'TTO',
        iso2: 'TT',
        name: 'Trinidad & Tobago'
    },
    {
        dial: 216,
        iso3: 'TUN',
        iso2: 'TN',
        name: 'Tunisia'
    },
    {
        dial: 90,
        iso3: 'TUR',
        iso2: 'TR',
        name: 'Turkey'
    },
    {
        dial: 993,
        iso3: 'TKM',
        iso2: 'TM',
        name: 'Turkmenistan'
    },
    {
        dial: '1-649',
        iso3: 'TCA',
        iso2: 'TC',
        name: 'Turks & Caicos Islands'
    },
    {
        dial: 688,
        iso3: 'TUV',
        iso2: 'TV',
        name: 'Tuvalu'
    },
    {
        dial: 256,
        iso3: 'UGA',
        iso2: 'UG',
        name: 'Uganda'
    },
    {
        dial: 380,
        iso3: 'UKR',
        iso2: 'UA',
        name: 'Ukraine'
    },
    {
        dial: 971,
        iso3: 'ARE',
        iso2: 'AE',
        name: 'United Arab Emirates'
    },
    {
        dial: 44,
        iso3: 'GBR',
        iso2: 'GB',
        name: 'UK'
    },
    {
        dial: 255,
        iso3: 'TZA',
        iso2: 'TZ',
        name: 'Tanzania'
    },
    {
        dial: '',
        iso3: 'UMI',
        iso2: 'UM',
        name: 'U.S. Outlying Islands'
    },
    {
        dial: '1-340',
        iso3: 'VIR',
        iso2: 'VI',
        name: 'U.S. Virgin Islands'
    },
    {
        dial: 1,
        iso3: 'USA',
        iso2: 'US',
        name: 'US'
    },
    {
        dial: 598,
        iso3: 'URY',
        iso2: 'UY',
        name: 'Uruguay'
    },
    {
        dial: 998,
        iso3: 'UZB',
        iso2: 'UZ',
        name: 'Uzbekistan'
    },
    {
        dial: 678,
        iso3: 'VUT',
        iso2: 'VU',
        name: 'Vanuatu'
    },
    {
        dial: 58,
        iso3: 'VEN',
        iso2: 'VE',
        name: 'Venezuela'
    },
    {
        dial: 84,
        iso3: 'VNM',
        iso2: 'VN',
        name: 'Vietnam'
    },
    {
        dial: 681,
        iso3: 'WLF',
        iso2: 'WF',
        name: 'Wallis & Futuna'
    },
    {
        dial: 212,
        iso3: 'ESH',
        iso2: 'EH',
        name: 'Western Sahara'
    },
    {
        dial: 967,
        iso3: 'YEM',
        iso2: 'YE',
        name: 'Yemen'
    },
    {
        dial: 260,
        iso3: 'ZMB',
        iso2: 'ZM',
        name: 'Zambia'
    },
    {
        dial: 263,
        iso3: 'ZWE',
        iso2: 'ZW',
        name: 'Zimbabwe'
    },
    {
        dial: 358,
        iso3: 'ALA',
        iso2: 'AX',
        name: 'Åland Islands'
    }
];

var AfdPhoneRegexValidDirective_1, AfdPhonePceValidDirective_1;
let AfdPhoneRegexValidDirective = AfdPhoneRegexValidDirective_1 = class AfdPhoneRegexValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    ngOnInit() {
        // Set the initial country
        this.afdPceService.phoneCountry = setInitialCountry(this.country);
    }
    // https://angular.io/guide/form-validation#custom-validators
    validate(control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            // https://www.npmjs.com/package/awesome-phonenumber
            // Get the phone number object
            const pn = getPhoneObject(control.value, this.country);
            // set the country in type AFD service
            this.afdPceService.phoneCountry = setCountry(pn.getRegionCode());
            // send useful information to the pce service
            this.afdPceService.phoneInfoSource.next({
                pceValid: false,
                regexValid: pn.isValid(),
                country: this.afdPceService.phoneCountry,
                isMobile: pn.isMobile(),
                isLandLine: pn.isFixedLine()
            });
            // reformat number
            if (pn.isValid()) {
                this.el.nativeElement.value = this.country === pn.getRegionCode() ? pn.getNumber('national')
                    : pn.getNumber('international');
                return null;
            }
            // validate regex
            return pn.isValid() ? null : { afdPhoneRegexValid: { message: this.afdPceService.settings.messages.phone.invalidRegex } };
        }
        else {
            // if there is nothing in the control
            return null;
        }
    }
};
AfdPhoneRegexValidDirective.ɵfac = function AfdPhoneRegexValidDirective_Factory(t) { return new (t || AfdPhoneRegexValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdPhoneRegexValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdPhoneRegexValidDirective, selectors: [["", "afdPhoneRegexValid", ""]], inputs: { country: "country" }, features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_VALIDATORS,
                useExisting: AfdPhoneRegexValidDirective_1,
                multi: true
            }
        ])] });
AfdPhoneRegexValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], AfdPhoneRegexValidDirective.prototype, "country", void 0);
AfdPhoneRegexValidDirective = AfdPhoneRegexValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdPhoneRegexValidDirective);
let AfdPhonePceValidDirective = AfdPhonePceValidDirective_1 = class AfdPhonePceValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
        // check to see if the regex element exists
        this.hasRegexCheck = !!el.nativeElement.hasAttribute('afdPhoneRegexValid');
        if (!this.hasRegexCheck) {
            console.warn('Warning, you are using the PCE phone validation directive without the regex directive.  ' +
                'This means that you are querying PCE and are being charged for every keypress.  ' +
                'Please add the directive "afdPhoneRegexValid" to the input element');
        }
    }
    ngOnInit() {
        // Set the initial country if there is no Regex directive on the lement
        if (!this.hasRegexCheck) {
            this.afdPceService.phoneCountry = setInitialCountry(this.country);
        }
    }
    validate(control) {
        let phoneNumber = '';
        let pn = getPhoneObject('', this.country);
        if (control.value) {
            // Get the phone number object
            pn = getPhoneObject(control.value, this.country);
            phoneNumber = pn.getNumber();
            if (!this.hasRegexCheck) {
                // set the country in type AFD service
                this.afdPceService.phoneCountry = setInitialCountry(pn.getRegionCode());
            }
            const countryCode = '+' + Phone.getCountryCodeForRegionCode(pn.getRegionCode());
            // validate
            return this.afdPceService.validatePhone(pn.getNumber().replace(countryCode, '0')).pipe(map(data => {
                // emit observable update with useful information
                this.afdPceService.phoneInfoSource.next({
                    pceValid: data.body['Result'] === '1',
                    regexValid: pn.isValid(),
                    country: this.afdPceService.phoneCountry,
                    isMobile: pn.isMobile(),
                    isLandLine: pn.isFixedLine()
                });
                const output = data;
                output['phone'] = pn.getNumber('national');
                const endEvent = new CustomEvent('afdPhonePceValidationComplete', { detail: output });
                document.dispatchEvent(endEvent);
                // Check if valid
                if (data.body['Result'] === '1') {
                    return null;
                }
                else {
                    return {
                        afdPhonePceValid: {
                            message: this.afdPceService.settings.messages.phone.invalidPce ? this.afdPceService.settings.messages.phone.invalidPce
                                : data.body['ErrorText']
                        }
                    };
                }
            }));
        }
        else {
            return new Promise((resolve => resolve(null)));
        }
    }
};
AfdPhonePceValidDirective.ɵfac = function AfdPhonePceValidDirective_Factory(t) { return new (t || AfdPhonePceValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdPhonePceValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdPhonePceValidDirective, selectors: [["", "afdPhonePceValid", ""]], inputs: { country: "country" }, features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_ASYNC_VALIDATORS,
                useExisting: AfdPhonePceValidDirective_1,
                multi: true
            }
        ])] });
AfdPhonePceValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], AfdPhonePceValidDirective.prototype, "country", void 0);
AfdPhonePceValidDirective = AfdPhonePceValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdPhonePceValidDirective);
let AfdSearchPhoneDirective = class AfdSearchPhoneDirective {
    constructor(afdPceService) {
        this.afdPceService = afdPceService;
    }
    onAfdPhonePceValidationComplete(e) {
        this.afdPceService.searchPhone(e.detail.phone).subscribe((res) => {
            const endEvent = new CustomEvent('afdPhoneSearchComplete', { detail: res });
            document.dispatchEvent(endEvent);
        });
    }
};
AfdSearchPhoneDirective.ɵfac = function AfdSearchPhoneDirective_Factory(t) { return new (t || AfdSearchPhoneDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService)); };
AfdSearchPhoneDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdSearchPhoneDirective, selectors: [["", "afdSearchPhone", ""]], hostBindings: function AfdSearchPhoneDirective_HostBindings(rf, ctx) { if (rf & 1) {
        ɵngcc0.ɵɵlistener("afdPhonePceValidationComplete", function AfdSearchPhoneDirective_afdPhonePceValidationComplete_HostBindingHandler($event) { return ctx.onAfdPhonePceValidationComplete($event); }, false, ɵngcc0.ɵɵresolveDocument);
    } } });
AfdSearchPhoneDirective.ctorParameters = () => [
    { type: AfdPceService }
];
__decorate([
    HostListener('document:afdPhonePceValidationComplete', ['$event']),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], AfdSearchPhoneDirective.prototype, "onAfdPhonePceValidationComplete", null);
AfdSearchPhoneDirective = __decorate([ __metadata("design:paramtypes", [AfdPceService])
], AfdSearchPhoneDirective);
let AfdPhoneCountriesDirective = class AfdPhoneCountriesDirective {
    constructor(el) {
        this.el = el;
        console.log(el);
    }
};
AfdPhoneCountriesDirective.ɵfac = function AfdPhoneCountriesDirective_Factory(t) { return new (t || AfdPhoneCountriesDirective)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdPhoneCountriesDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdPhoneCountriesDirective, selectors: [["", "afdPhoneCountries", ""]] });
AfdPhoneCountriesDirective.ctorParameters = () => [
    { type: ElementRef }
];
AfdPhoneCountriesDirective = __decorate([ __metadata("design:paramtypes", [ElementRef])
], AfdPhoneCountriesDirective);
function getPhoneObject(phoneNumber, country) {
    if (phoneNumber !== null) {
        // set the default dialing code
        let defaultCountryDialingCode;
        if (typeof country === 'undefined') {
            defaultCountryDialingCode = '+44';
        }
        else {
            defaultCountryDialingCode = '+' + Phone.getCountryCodeForRegionCode(country);
        }
        // If no dialing code is added to the front of the number, then add the default one
        if (phoneNumber.substr(0, 1) !== '+' && phoneNumber.substr(0, 2) !== '00') {
            phoneNumber = defaultCountryDialingCode + phoneNumber;
        }
        // create the Awesome phone object
        return new Phone(phoneNumber);
    }
    else {
        return null;
    }
}
function setInitialCountry(countryAttribute) {
    // default to GB if not set
    const initialCountry = typeof countryAttribute !== 'undefined' ? countryAttribute : 'GB';
    return setCountry(initialCountry);
}
function setCountry(newCountry) {
    let phoneCountry = {
        name: null,
        iso2: null,
        iso3: null
    };
    for (const country of Countries) {
        if (country.iso2 === newCountry) {
            phoneCountry = country;
        }
    }
    return phoneCountry;
}

var AfdCardRegexValidDirective_1, AfdExpiryRegexValidDirective_1, AfdCardPceValidDirective_1;
let AfdCardRegexValidDirective = AfdCardRegexValidDirective_1 = class AfdCardRegexValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    validate(control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            const regexValid = number(control.value);
            const currentInfo = this.afdPceService.cardInfoSource.value;
            currentInfo.cardRegexValid = regexValid.isValid;
            currentInfo.pceValid = false;
            currentInfo.cardTypeNice = regexValid.card ? regexValid.card.niceType : null;
            currentInfo.cardType = regexValid.card ? regexValid.card.type : null;
            currentInfo.cardNumber = control.value;
            // send useful information to the pce service
            this.afdPceService.cardInfoSource.next(currentInfo);
            // validate regex
            return regexValid.isValid ? null : { afdCardRegexValid: { message: this.afdPceService.settings.messages.card.invalidCardRegex } };
        }
        else {
            // if there is nothing in the control
            return null;
        }
    }
};
AfdCardRegexValidDirective.ɵfac = function AfdCardRegexValidDirective_Factory(t) { return new (t || AfdCardRegexValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdCardRegexValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdCardRegexValidDirective, selectors: [["", "afdCardRegexValid", ""]], features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_VALIDATORS,
                useExisting: AfdCardRegexValidDirective_1,
                multi: true
            }
        ])] });
AfdCardRegexValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
AfdCardRegexValidDirective = AfdCardRegexValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdCardRegexValidDirective);
let AfdExpiryRegexValidDirective = AfdExpiryRegexValidDirective_1 = class AfdExpiryRegexValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    validate(control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            const regexValid = expirationDate(control.value);
            const currentInfo = this.afdPceService.cardInfoSource.value;
            currentInfo.pceValid = false;
            currentInfo.expiryRegexValid = regexValid.isValid;
            currentInfo.expiryDate = control.value;
            // send useful information to the pce service
            this.afdPceService.cardInfoSource.next(currentInfo);
            // validate regex
            return regexValid.isValid ? null : { afdExpiryRegexValid: { message: this.afdPceService.settings.messages.card.invalidExpiryRegex } };
        }
        else {
            // if there is nothing in the control
            return null;
        }
    }
};
AfdExpiryRegexValidDirective.ɵfac = function AfdExpiryRegexValidDirective_Factory(t) { return new (t || AfdExpiryRegexValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdExpiryRegexValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdExpiryRegexValidDirective, selectors: [["", "afdExpiryRegexValid", ""]], inputs: { country: "country" }, features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_VALIDATORS,
                useExisting: AfdExpiryRegexValidDirective_1,
                multi: true
            }
        ])] });
AfdExpiryRegexValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], AfdExpiryRegexValidDirective.prototype, "country", void 0);
AfdExpiryRegexValidDirective = AfdExpiryRegexValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdExpiryRegexValidDirective);
let AfdCardPceValidDirective = AfdCardPceValidDirective_1 = class AfdCardPceValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    validate(control) {
        const currentInfo = this.afdPceService.cardInfoSource.value;
        const card = control.get('cardControl');
        const expiry = control.get('expiryControl');
        const cardTouched = control.touched && card.value.length > 0 && card.valid;
        const expiryTouched = control.touched && expiry.value.length > 0 && expiry.valid;
        console.log(cardTouched);
        console.log(expiryTouched);
        // check that both fields are regex valid
        if (cardTouched && expiryTouched) {
            // validate
            return this.afdPceService.validateCard(currentInfo.cardNumber, currentInfo.expiryDate).pipe(map(data => JSON.parse(data)), map(data => {
                // Check if valid
                if (data['Result'] === '1') {
                    // emit observable update with useful information
                    this.afdPceService.cardInfoSource.next({
                        pceValid: data.Result === '1',
                        cardRegexValid: true,
                        expiryRegexValid: true,
                        cardTypeNice: data.Item[0].CardType,
                        cardType: currentInfo.cardType,
                        cardNumber: currentInfo.cardNumber,
                        expiryDate: currentInfo.expiryDate
                    });
                    return null;
                }
                else {
                    return {
                        afdCardPceValid: {
                            message: this.afdPceService.settings.messages.card.invalidPce ? this.afdPceService.settings.messages.card.invalidPce
                                : data['ErrorText']
                        }
                    };
                }
            }));
        }
        else {
            return new Promise((resolve => resolve(null)));
        }
    }
};
AfdCardPceValidDirective.ɵfac = function AfdCardPceValidDirective_Factory(t) { return new (t || AfdCardPceValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdCardPceValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdCardPceValidDirective, selectors: [["", "afdCardPceValid", ""]], inputs: { country: "country" }, features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_ASYNC_VALIDATORS,
                useExisting: AfdCardPceValidDirective_1,
                multi: true
            }
        ])] });
AfdCardPceValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], AfdCardPceValidDirective.prototype, "country", void 0);
AfdCardPceValidDirective = AfdCardPceValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdCardPceValidDirective);

var AfdAccountRegexValidDirective_1, AfdSortRegexValidDirective_1, AfdAccountPceValidDirective_1;
let AfdAccountRegexValidDirective = AfdAccountRegexValidDirective_1 = class AfdAccountRegexValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    validate(control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            const currentInfo = this.afdPceService.accountInfoSource.value;
            currentInfo.accountRegexValid = control.value.length > 7;
            currentInfo.pceValid = false;
            currentInfo.accountNumber = control.value;
            // send useful information to the pce service
            this.afdPceService.accountInfoSource.next(currentInfo);
            // validate regex
            return control.value.length > 7 ? null
                : { afdAccountRegexValid: { message: this.afdPceService.settings.messages.account.invalidAccountRegex } };
        }
        else {
            // if there is nothing in the control
            return null;
        }
    }
};
AfdAccountRegexValidDirective.ɵfac = function AfdAccountRegexValidDirective_Factory(t) { return new (t || AfdAccountRegexValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdAccountRegexValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdAccountRegexValidDirective, selectors: [["", "afdAccountRegexValid", ""]], features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_VALIDATORS,
                useExisting: AfdAccountRegexValidDirective_1,
                multi: true
            }
        ])] });
AfdAccountRegexValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
AfdAccountRegexValidDirective = AfdAccountRegexValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdAccountRegexValidDirective);
let AfdSortRegexValidDirective = AfdSortRegexValidDirective_1 = class AfdSortRegexValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    validate(control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            const currentInfo = this.afdPceService.accountInfoSource.value;
            currentInfo.pceValid = false;
            currentInfo.sortRegexValid = control.value.length === 8;
            currentInfo.sortCode = control.value;
            // send useful information to the pce service
            this.afdPceService.accountInfoSource.next(currentInfo);
            // validate regex
            return control.value.length === 8 ? null
                : { afdSortRegexValid: { message: this.afdPceService.settings.messages.account.invalidSortRegex } };
        }
        else {
            // if there is nothing in the control
            return null;
        }
    }
};
AfdSortRegexValidDirective.ɵfac = function AfdSortRegexValidDirective_Factory(t) { return new (t || AfdSortRegexValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdSortRegexValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdSortRegexValidDirective, selectors: [["", "afdSortRegexValid", ""]], inputs: { country: "country" }, features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_VALIDATORS,
                useExisting: AfdSortRegexValidDirective_1,
                multi: true
            }
        ])] });
AfdSortRegexValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], AfdSortRegexValidDirective.prototype, "country", void 0);
AfdSortRegexValidDirective = AfdSortRegexValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdSortRegexValidDirective);
let AfdAccountPceValidDirective = AfdAccountPceValidDirective_1 = class AfdAccountPceValidDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    validate(control) {
        const currentInfo = this.afdPceService.accountInfoSource.value;
        const account = control.get('accountControl');
        const sort = control.get('sortControl');
        // Text mask seems to play around with the touched attribute of sort so I have to create manual checks
        const sortTouched = control.touched && sort.value.length > 0 && sort.valid;
        const accountTouched = control.touched && account.value.length > 0 && account.valid;
        if (control.touched && accountTouched && sortTouched) {
            // validate
            return this.afdPceService.validateAccount(account.value, sort.value).pipe(map(data => JSON.parse(data)), map(data => {
                // Check if valid
                if (data['Result'] === '1') {
                    // emit observable update with useful information
                    this.afdPceService.accountInfoSource.next({
                        pceValid: true,
                        accountRegexValid: true,
                        sortRegexValid: true,
                        iban: data['Item'][0].IBAN,
                        clearingSystem: data['Item'][0].ClearingSystem,
                        rollNumber: data['Item'][0].RollNumber,
                        accountType: data['Item'][0].TypeOfAccount,
                        accountNumber: currentInfo.accountNumber,
                        sortCode: currentInfo.sortCode
                    });
                    return null;
                }
                else {
                    return {
                        afdAccountPceValid: {
                            message: this.afdPceService.settings.messages.account.invalidPce ? this.afdPceService.settings.messages.account.invalidPce
                                : data['ErrorText']
                        }
                    };
                }
            }));
        }
        else {
            return new Promise((resolve => resolve(null)));
        }
    }
};
AfdAccountPceValidDirective.ɵfac = function AfdAccountPceValidDirective_Factory(t) { return new (t || AfdAccountPceValidDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdAccountPceValidDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdAccountPceValidDirective, selectors: [["", "afdAccountPceValid", ""]], inputs: { country: "country" }, features: [ɵngcc0.ɵɵProvidersFeature([
            {
                provide: NG_ASYNC_VALIDATORS,
                useExisting: AfdAccountPceValidDirective_1,
                multi: true
            }
        ])] });
AfdAccountPceValidDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
__decorate([
    Input(),
    __metadata("design:type", String)
], AfdAccountPceValidDirective.prototype, "country", void 0);
AfdAccountPceValidDirective = AfdAccountPceValidDirective_1 = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdAccountPceValidDirective);

let AfdCountriesDirective = 
// directive that sets an input to work as a result box for PCE, the afdResult attribute sets the relevant PCE field
class AfdCountriesDirective {
    constructor(el, afdPceService) {
        this.el = el;
        this.afdPceService = afdPceService;
    }
    ngAfterViewInit() {
        const startEvent = new CustomEvent('afdGetCountriesStart');
        document.dispatchEvent(startEvent);
        this.afdPceService.getCountries().subscribe((res) => {
            this.afdPceService.countries = res.body['Item'];
            const endEvent = new CustomEvent('afdGetCountriesComplete', { detail: res });
            document.dispatchEvent(endEvent);
            if (this.defaultCountry) {
                this.defaultCountry = this.defaultCountry.toUpperCase();
                for (const country of this.afdPceService.countries) {
                    if (this.defaultCountry === country.iso) {
                        this.afdPceService.selectedCountry = country;
                    }
                }
            }
        });
    }
};
AfdCountriesDirective.ɵfac = function AfdCountriesDirective_Factory(t) { return new (t || AfdCountriesDirective)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef), ɵngcc0.ɵɵdirectiveInject(AfdPceService)); };
AfdCountriesDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdCountriesDirective, selectors: [["", "afdCountries", ""]], inputs: { defaultCountry: ["afdCountries", "defaultCountry"] } });
AfdCountriesDirective.ctorParameters = () => [
    { type: ElementRef },
    { type: AfdPceService }
];
__decorate([
    Input('afdCountries'),
    __metadata("design:type", String)
], AfdCountriesDirective.prototype, "defaultCountry", void 0);
AfdCountriesDirective = __decorate([ __metadata("design:paramtypes", [ElementRef,
        AfdPceService])
], AfdCountriesDirective);

let AfdReverseGeocodeDirective = 
// directive that sets an input to work as a result box for PCE, the afdResult attribute sets the relevant PCE field
class AfdReverseGeocodeDirective {
    constructor(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    afdReverseGeocodeInitiate(e) {
        this.el.nativeElement.disabled = true;
        navigator.geolocation.getCurrentPosition((position) => {
            this.afdPceService.reverseGeocode(position.coords.latitude, position.coords.longitude).subscribe((data) => {
                const result = JSON.parse(data);
                // Populate form fields
                this.afdPceService.typeAheadResults = result.Item;
                const event = new CustomEvent('afdReverseGeocodeComplete', { detail: result });
                document.dispatchEvent(event);
                this.el.nativeElement.disabled = false;
            });
        }, (error) => {
            switch (error.code) {
                case error.PERMISSION_DENIED:
                    console.error('User denied the request for Geolocation.');
                    this.el.nativeElement.disabled = false;
                    break;
                case error.POSITION_UNAVAILABLE:
                    console.error('Location information is unavailable.');
                    this.el.nativeElement.disabled = false;
                    break;
                case error.TIMEOUT:
                    console.error('The request to get user location timed out.');
                    this.el.nativeElement.disabled = false;
                    break;
                default:
                    console.error('An unknown error occurred.');
                    break;
            }
        });
    }
};
AfdReverseGeocodeDirective.ɵfac = function AfdReverseGeocodeDirective_Factory(t) { return new (t || AfdReverseGeocodeDirective)(ɵngcc0.ɵɵdirectiveInject(AfdPceService), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef)); };
AfdReverseGeocodeDirective.ɵdir = ɵngcc0.ɵɵdefineDirective({ type: AfdReverseGeocodeDirective, selectors: [["", "afdReverseGeocode", ""]], hostBindings: function AfdReverseGeocodeDirective_HostBindings(rf, ctx) { if (rf & 1) {
        ɵngcc0.ɵɵlistener("click", function AfdReverseGeocodeDirective_click_HostBindingHandler($event) { return ctx.afdReverseGeocodeInitiate($event); });
    } } });
AfdReverseGeocodeDirective.ctorParameters = () => [
    { type: AfdPceService },
    { type: ElementRef }
];
__decorate([
    HostListener('click', ['$event']),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], AfdReverseGeocodeDirective.prototype, "afdReverseGeocodeInitiate", null);
AfdReverseGeocodeDirective = __decorate([ __metadata("design:paramtypes", [AfdPceService,
        ElementRef])
], AfdReverseGeocodeDirective);

let AfdTypeaheadComponent = class AfdTypeaheadComponent {
    constructor(el, afdPceService) {
        this.el = el;
        this.afdPceService = afdPceService;
        this.country = null;
        this.group = [
            CreateNewAutocompleteGroup('', 'completer', [], { titleKey: 'list', childrenKey: null }),
        ];
    }
    ngOnInit() {
        if (this.country) {
            this.afdPceService.getCountries(this.country);
        }
        const req = (str) => {
            return new Promise((resolve) => {
                // check to see if new unique id is needed
                this.afdPceService.manageUniqueId(str);
                this.afdPceService.pceLookup(str, this.data).subscribe(function (data) {
                    const event = new CustomEvent('afdLookupComplete', { detail: JSON.parse(data) });
                    document.dispatchEvent(event);
                    data = JSON.parse(data);
                    const output = [];
                    for (const item in data.Item) {
                        if (data.Item.hasOwnProperty(item)) {
                            output.push({
                                id: item,
                                list: data.Item[item].List,
                                key: data.Item[item].Key
                            });
                        }
                    }
                    resolve(output);
                });
            });
        };
        this.completer.SetAsync('completer', req);
    }
    typeAheadOptionSelected(item) {
        if (item.item) {
            this.chooseAddress(item.item.original.key);
        }
    }
    chooseAddress(key) {
        const retrieve = this.afdPceService.pceRetrieve(key, this.data);
        retrieve.subscribe(res => {
            this.afdPceService.lookupResults = res;
            const event = new CustomEvent('afdRetrieveComplete', { detail: res });
            document.dispatchEvent(event);
        });
    }
};
AfdTypeaheadComponent.ɵfac = function AfdTypeaheadComponent_Factory(t) { return new (t || AfdTypeaheadComponent)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef), ɵngcc0.ɵɵdirectiveInject(AfdPceService)); };
AfdTypeaheadComponent.ɵcmp = ɵngcc0.ɵɵdefineComponent({ type: AfdTypeaheadComponent, selectors: [["afd-typeahead-component"]], viewQuery: function AfdTypeaheadComponent_Query(rf, ctx) { if (rf & 1) {
        ɵngcc0.ɵɵviewQuery(NgAutoCompleteComponent, true);
    } if (rf & 2) {
        var _t;
        ɵngcc0.ɵɵqueryRefresh(_t = ɵngcc0.ɵɵloadQuery()) && (ctx.completer = _t.first);
    } }, inputs: { country: "country", data: "data" }, decls: 2, vars: 1, consts: [[3, "group", "selected"]], template: function AfdTypeaheadComponent_Template(rf, ctx) { if (rf & 1) {
        ɵngcc0.ɵɵelementStart(0, "div");
        ɵngcc0.ɵɵelementStart(1, "ng-auto-complete", 0);
        ɵngcc0.ɵɵlistener("selected", function AfdTypeaheadComponent_Template_ng_auto_complete_selected_1_listener($event) { return ctx.typeAheadOptionSelected($event); });
        ɵngcc0.ɵɵelementEnd();
        ɵngcc0.ɵɵelementEnd();
    } if (rf & 2) {
        ɵngcc0.ɵɵadvance(1);
        ɵngcc0.ɵɵproperty("group", ctx.group);
    } }, directives: [ɵngcc2.NgAutoCompleteComponent], styles: [""] });
AfdTypeaheadComponent.ctorParameters = () => [
    { type: ElementRef },
    { type: AfdPceService }
];
__decorate([
    ViewChild(NgAutoCompleteComponent, { static: false }),
    __metadata("design:type", NgAutoCompleteComponent)
], AfdTypeaheadComponent.prototype, "completer", void 0);
__decorate([
    Input(),
    __metadata("design:type", String)
], AfdTypeaheadComponent.prototype, "data", void 0);
__decorate([
    Input(),
    __metadata("design:type", String)
], AfdTypeaheadComponent.prototype, "country", void 0);
AfdTypeaheadComponent = __decorate([ __metadata("design:paramtypes", [ElementRef,
        AfdPceService])
], AfdTypeaheadComponent);

let AfdPceAngularModule = class AfdPceAngularModule {
};
AfdPceAngularModule.ɵmod = ɵngcc0.ɵɵdefineNgModule({ type: AfdPceAngularModule });
AfdPceAngularModule.ɵinj = ɵngcc0.ɵɵdefineInjector({ factory: function AfdPceAngularModule_Factory(t) { return new (t || AfdPceAngularModule)(); }, providers: [
    // AfdPceService
    ], imports: [[
            FormsModule,
            ReactiveFormsModule,
            CommonModule,
            HttpClientModule,
            NgAutoCompleteModule,
            TextMaskModule
        ]] });
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdResultDirective, [{
        type: Directive,
        args: [{
                selector: '[afdResult]'
            }]
    }], function () { return [{ type: ɵngcc0.ElementRef }]; }, { afdLookupInitiate: [{
            type: HostListener,
            args: ['document:afdRetrieveComplete', ['$event']]
        }], field: [{
            type: Input,
            args: ['afdResult']
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdPceService, [{
        type: Injectable,
        args: [{
                providedIn: 'root'
            }]
    }], function () { return [{ type: ɵngcc1.HttpClient }]; }, null); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdEmailRegexValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdEmailRegexValid]',
                providers: [
                    {
                        provide: NG_VALIDATORS,
                        useExisting: AfdEmailRegexValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, null); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdEmailPceValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdEmailPceValid]',
                providers: [
                    {
                        provide: NG_ASYNC_VALIDATORS,
                        useExisting: AfdEmailPceValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, null); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdPhoneRegexValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdPhoneRegexValid]',
                providers: [
                    {
                        provide: NG_VALIDATORS,
                        useExisting: AfdPhoneRegexValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, { country: [{
            type: Input
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdPhonePceValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdPhonePceValid]',
                providers: [
                    {
                        provide: NG_ASYNC_VALIDATORS,
                        useExisting: AfdPhonePceValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, { country: [{
            type: Input
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdSearchPhoneDirective, [{
        type: Directive,
        args: [{
                selector: '[afdSearchPhone]'
            }]
    }], function () { return [{ type: AfdPceService }]; }, { onAfdPhonePceValidationComplete: [{
            type: HostListener,
            args: ['document:afdPhonePceValidationComplete', ['$event']]
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdPhoneCountriesDirective, [{
        type: Directive,
        args: [{
                selector: '[afdPhoneCountries]'
            }]
    }], function () { return [{ type: ɵngcc0.ElementRef }]; }, null); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdCardRegexValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdCardRegexValid]',
                providers: [
                    {
                        provide: NG_VALIDATORS,
                        useExisting: AfdCardRegexValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, null); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdExpiryRegexValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdExpiryRegexValid]',
                providers: [
                    {
                        provide: NG_VALIDATORS,
                        useExisting: AfdExpiryRegexValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, { country: [{
            type: Input
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdCardPceValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdCardPceValid]',
                providers: [
                    {
                        provide: NG_ASYNC_VALIDATORS,
                        useExisting: AfdCardPceValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, { country: [{
            type: Input
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdAccountRegexValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdAccountRegexValid]',
                providers: [
                    {
                        provide: NG_VALIDATORS,
                        useExisting: AfdAccountRegexValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, null); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdSortRegexValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdSortRegexValid]',
                providers: [
                    {
                        provide: NG_VALIDATORS,
                        useExisting: AfdSortRegexValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, { country: [{
            type: Input
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdAccountPceValidDirective, [{
        type: Directive,
        args: [{
                selector: '[afdAccountPceValid]',
                providers: [
                    {
                        provide: NG_ASYNC_VALIDATORS,
                        useExisting: AfdAccountPceValidDirective_1,
                        multi: true
                    }
                ]
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, { country: [{
            type: Input
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdCountriesDirective, [{
        type: Directive,
        args: [{
                selector: '[afdCountries]'
            }]
    }], function () { return [{ type: ɵngcc0.ElementRef }, { type: AfdPceService }]; }, { defaultCountry: [{
            type: Input,
            args: ['afdCountries']
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdReverseGeocodeDirective, [{
        type: Directive,
        args: [{
                selector: '[afdReverseGeocode]'
            }]
    }], function () { return [{ type: AfdPceService }, { type: ɵngcc0.ElementRef }]; }, { afdReverseGeocodeInitiate: [{
            type: HostListener,
            args: ['click', ['$event']]
        }] }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdTypeaheadComponent, [{
        type: Component,
        args: [{
                selector: 'afd-typeahead-component',
                template: "<div>\r\n  <ng-auto-complete\r\n    (selected)=\"typeAheadOptionSelected($event)\"\r\n    [group]=\"group\"\r\n  ></ng-auto-complete>\r\n</div>\r\n",
                styles: [""]
            }]
    }], function () { return [{ type: ɵngcc0.ElementRef }, { type: AfdPceService }]; }, { country: [{
            type: Input
        }], completer: [{
            type: ViewChild,
            args: [NgAutoCompleteComponent, { static: false }]
        }], data: [{
            type: Input
        }] }); })();
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵngcc0.ɵɵsetNgModuleScope(AfdPceAngularModule, { declarations: function () { return [AfdResultDirective,
        AfdEmailRegexValidDirective,
        AfdEmailPceValidDirective,
        AfdPhoneRegexValidDirective,
        AfdPhonePceValidDirective,
        AfdPhoneCountriesDirective,
        AfdSearchPhoneDirective,
        AfdCardRegexValidDirective,
        AfdExpiryRegexValidDirective,
        AfdCardPceValidDirective,
        AfdAccountRegexValidDirective,
        AfdSortRegexValidDirective,
        AfdAccountPceValidDirective,
        AfdCountriesDirective,
        AfdReverseGeocodeDirective,
        AfdTypeaheadComponent]; }, imports: function () { return [FormsModule,
        ReactiveFormsModule,
        CommonModule,
        HttpClientModule,
        NgAutoCompleteModule,
        TextMaskModule]; }, exports: function () { return [AfdResultDirective,
        AfdEmailRegexValidDirective,
        AfdEmailPceValidDirective,
        AfdPhoneRegexValidDirective,
        AfdPhonePceValidDirective,
        AfdPhoneCountriesDirective,
        AfdSearchPhoneDirective,
        AfdCardRegexValidDirective,
        AfdExpiryRegexValidDirective,
        AfdCardPceValidDirective,
        AfdAccountRegexValidDirective,
        AfdSortRegexValidDirective,
        AfdAccountPceValidDirective,
        AfdCountriesDirective,
        AfdReverseGeocodeDirective,
        AfdTypeaheadComponent]; } }); })();
/*@__PURE__*/ (function () { ɵngcc0.ɵsetClassMetadata(AfdPceAngularModule, [{
        type: NgModule,
        args: [{
                imports: [
                    FormsModule,
                    ReactiveFormsModule,
                    CommonModule,
                    HttpClientModule,
                    NgAutoCompleteModule,
                    TextMaskModule
                ],
                declarations: [
                    AfdResultDirective,
                    AfdEmailRegexValidDirective,
                    AfdEmailPceValidDirective,
                    AfdPhoneRegexValidDirective,
                    AfdPhonePceValidDirective,
                    AfdPhoneCountriesDirective,
                    AfdSearchPhoneDirective,
                    AfdCardRegexValidDirective,
                    AfdExpiryRegexValidDirective,
                    AfdCardPceValidDirective,
                    AfdAccountRegexValidDirective,
                    AfdSortRegexValidDirective,
                    AfdAccountPceValidDirective,
                    AfdCountriesDirective,
                    AfdReverseGeocodeDirective,
                    AfdTypeaheadComponent
                ],
                exports: [
                    AfdResultDirective,
                    AfdEmailRegexValidDirective,
                    AfdEmailPceValidDirective,
                    AfdPhoneRegexValidDirective,
                    AfdPhonePceValidDirective,
                    AfdPhoneCountriesDirective,
                    AfdSearchPhoneDirective,
                    AfdCardRegexValidDirective,
                    AfdExpiryRegexValidDirective,
                    AfdCardPceValidDirective,
                    AfdAccountRegexValidDirective,
                    AfdSortRegexValidDirective,
                    AfdAccountPceValidDirective,
                    AfdCountriesDirective,
                    AfdReverseGeocodeDirective,
                    AfdTypeaheadComponent
                ],
                entryComponents: [],
                providers: [
                // AfdPceService
                ]
            }]
    }], null, null); })();

/*
 * Public API Surface of pce-angular
 */

/**
 * Generated bundle index. Do not edit.
 */

export { AfdAccountPceValidDirective, AfdAccountRegexValidDirective, AfdCardPceValidDirective, AfdCardRegexValidDirective, AfdCountriesDirective, AfdEmailPceValidDirective, AfdEmailRegexValidDirective, AfdExpiryRegexValidDirective, AfdPceAngularModule, AfdPceService, AfdPhoneCountriesDirective, AfdPhonePceValidDirective, AfdPhoneRegexValidDirective, AfdResultDirective, AfdReverseGeocodeDirective, AfdSearchPhoneDirective, AfdSortRegexValidDirective, AfdTypeaheadComponent, Countries };

//# sourceMappingURL=afd-software-pce-angular.js.map