import { __decorate, __metadata, __values } 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';

var AfdResultDirective = /** @class */ (function () {
    function AfdResultDirective(el) {
        this.el = el;
    }
    AfdResultDirective.prototype.afdLookupInitiate = function (e) {
        this.el.nativeElement.value = e.detail.body.Item[0][this.field];
    };
    AfdResultDirective.ctorParameters = function () { return [
        { 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([
        Directive({
            selector: '[afdResult]'
        })
        // directive that sets an input to work as a result box for PCE, the afdResult attribute sets the relevant PCE field
        ,
        __metadata("design:paramtypes", [ElementRef])
    ], AfdResultDirective);
    return AfdResultDirective;
}());

var AfdPceService = /** @class */ (function () {
    function AfdPceService(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
    AfdPceService.prototype.getCountries = function (defaultCountry) {
        if (defaultCountry === void 0) { defaultCountry = null; }
        var 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');
        var headers = new HttpHeaders({
            'Content-Type': 'text/plain'
        });
        return this.http.get(this.settings.afdPceUrl, {
            params: params,
            headers: headers,
            observe: 'response'
        });
    };
    // normal lookup
    AfdPceService.prototype.pceLookup = function (lookup, data) {
        if (typeof data === 'undefined') {
            data = 'address';
        }
        var 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);
        }
        var headers = new HttpHeaders({
            'Content-Type': 'text/plain'
        });
        return this.http.get(this.settings.afdPceUrl, {
            params: params,
            headers: headers,
            observe: 'response'
        });
    };
    // normal retrieve
    AfdPceService.prototype.pceRetrieve = function (key, data) {
        if (typeof data === 'undefined') {
            data = 'address';
        }
        var 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);
        }
        var headers = new HttpHeaders({
            'Content-Type': 'text/plain'
        });
        return this.http.get(this.settings.afdPceUrl, {
            params: params,
            observe: 'response',
            headers: headers
        });
    };
    //
    AfdPceService.prototype.reverseGeocode = function (lat, lng) {
        var 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');
        var headers = new HttpHeaders({
            'Content-Type': 'text/plain'
        });
        var options = {
            params: params,
            responseType: 'text',
            headers: headers
        };
        return this.http.get(this.settings.afdPceUrl, options);
    };
    // email validation
    AfdPceService.prototype.validateEmail = function (email) {
        var 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');
        var options = {
            params: params,
            responseType: 'text'
        };
        return this.http.get(this.settings.afdPceUrl, options);
    };
    // phone validation
    AfdPceService.prototype.validatePhone = function (phone) {
        var 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
    AfdPceService.prototype.searchPhone = function (phone) {
        var 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
    AfdPceService.prototype.validateCard = function (cardNumber, expiryDate) {
        var 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');
        var options = {
            params: params,
            responseType: 'text'
        };
        return this.http.get(this.settings.afdPceUrl, options);
    };
    // card validation
    AfdPceService.prototype.validateAccount = function (accountNumber, sortCode) {
        var 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');
        var options = {
            params: params,
            responseType: 'text'
        };
        return this.http.get(this.settings.afdPceUrl, options);
    };
    AfdPceService.prototype.typeAheadSelected = function (result, data) {
        var _this = this;
        if (typeof data === 'undefined') {
            data = 'address';
        }
        this.typeAheadString = '';
        this.pceRetrieve(result.Key, data).subscribe(function (res) {
            var event = new CustomEvent('afdRetrieveComplete', { detail: res });
            document.dispatchEvent(event);
            _this.typeAheadResults = [];
        });
    };
    AfdPceService.prototype.refreshUniqueId = function () {
        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
    AfdPceService.prototype.manageUniqueId = function (value) {
        var _this = this;
        // 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(function () {
            _this.typeAheadTimer = null;
            _this.refreshUniqueId();
        }, 10000);
    };
    // Mask Functions
    AfdPceService.prototype.phoneMaskFunction = function (input) {
        var output = [/[+/\d/]/];
        for (var i = 0; i < input.length; i++) {
            output.push(/\d/);
        }
        return output;
    };
    AfdPceService.prototype.cardMaskFunction = function (input) {
        var cardValid = number(input);
        if (cardValid.card) {
            var totalLength = cardValid.card.lengths[cardValid.card.lengths.length - 1] + cardValid.card.gaps.length;
            var output = [];
            var actualPositions = [];
            for (var i = 0; i < cardValid.card.gaps.length; i++) {
                actualPositions.push(cardValid.card.gaps[i] + i);
            }
            for (var i = 0; i < totalLength; i++) {
                if (actualPositions.indexOf(output.length) > -1) {
                    output.push(' ');
                }
                else {
                    output.push(/\d/);
                }
            }
            return output;
        }
        else {
            var output = [];
            for (var i = 0; i < 16; i++) {
                output.push(/\d/);
            }
            return output;
        }
    };
    AfdPceService.ctorParameters = function () { return [
        { type: HttpClient }
    ]; };
    AfdPceService.ɵprov = ɵɵdefineInjectable({ factory: function AfdPceService_Factory() { return new AfdPceService(ɵɵinject(HttpClient)); }, token: AfdPceService, providedIn: "root" });
    AfdPceService = __decorate([
        Injectable({
            providedIn: 'root'
        }),
        __metadata("design:paramtypes", [HttpClient])
    ], AfdPceService);
    return AfdPceService;
}());

var AfdEmailRegexValidDirective = /** @class */ (function () {
    function AfdEmailRegexValidDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdEmailRegexValidDirective_1 = AfdEmailRegexValidDirective;
    AfdEmailRegexValidDirective.prototype.validate = function (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;
        }
    };
    var AfdEmailRegexValidDirective_1;
    AfdEmailRegexValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    AfdEmailRegexValidDirective = AfdEmailRegexValidDirective_1 = __decorate([
        Directive({
            selector: '[afdEmailRegexValid]',
            providers: [
                {
                    provide: NG_VALIDATORS,
                    useExisting: AfdEmailRegexValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdEmailRegexValidDirective);
    return AfdEmailRegexValidDirective;
}());
var AfdEmailPceValidDirective = /** @class */ (function () {
    function AfdEmailPceValidDirective(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');
        }
    }
    AfdEmailPceValidDirective_1 = AfdEmailPceValidDirective;
    AfdEmailPceValidDirective.prototype.validate = function (control) {
        var _this = this;
        if (control.value) {
            // validate
            return this.afdPceService.validateEmail(control.value).pipe(map(function (data) { return JSON.parse(data); }), map(function (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((function (resolve) { return resolve(null); }));
        }
    };
    var AfdEmailPceValidDirective_1;
    AfdEmailPceValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    AfdEmailPceValidDirective = AfdEmailPceValidDirective_1 = __decorate([
        Directive({
            selector: '[afdEmailPceValid]',
            providers: [
                {
                    provide: NG_ASYNC_VALIDATORS,
                    useExisting: AfdEmailPceValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdEmailPceValidDirective);
    return AfdEmailPceValidDirective;
}());

var 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 = /** @class */ (function () {
    function AfdPhoneRegexValidDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdPhoneRegexValidDirective_1 = AfdPhoneRegexValidDirective;
    AfdPhoneRegexValidDirective.prototype.ngOnInit = function () {
        // Set the initial country
        this.afdPceService.phoneCountry = setInitialCountry(this.country);
    };
    // https://angular.io/guide/form-validation#custom-validators
    AfdPhoneRegexValidDirective.prototype.validate = function (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
            var 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;
        }
    };
    var AfdPhoneRegexValidDirective_1;
    AfdPhoneRegexValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], AfdPhoneRegexValidDirective.prototype, "country", void 0);
    AfdPhoneRegexValidDirective = AfdPhoneRegexValidDirective_1 = __decorate([
        Directive({
            selector: '[afdPhoneRegexValid]',
            providers: [
                {
                    provide: NG_VALIDATORS,
                    useExisting: AfdPhoneRegexValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdPhoneRegexValidDirective);
    return AfdPhoneRegexValidDirective;
}());
var AfdPhonePceValidDirective = /** @class */ (function () {
    function AfdPhonePceValidDirective(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');
        }
    }
    AfdPhonePceValidDirective_1 = AfdPhonePceValidDirective;
    AfdPhonePceValidDirective.prototype.ngOnInit = function () {
        // Set the initial country if there is no Regex directive on the lement
        if (!this.hasRegexCheck) {
            this.afdPceService.phoneCountry = setInitialCountry(this.country);
        }
    };
    AfdPhonePceValidDirective.prototype.validate = function (control) {
        var _this = this;
        var phoneNumber = '';
        var 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());
            }
            var countryCode = '+' + Phone.getCountryCodeForRegionCode(pn.getRegionCode());
            // validate
            return this.afdPceService.validatePhone(pn.getNumber().replace(countryCode, '0')).pipe(map(function (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()
                });
                var output = data;
                output['phone'] = pn.getNumber('national');
                var 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((function (resolve) { return resolve(null); }));
        }
    };
    var AfdPhonePceValidDirective_1;
    AfdPhonePceValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], AfdPhonePceValidDirective.prototype, "country", void 0);
    AfdPhonePceValidDirective = AfdPhonePceValidDirective_1 = __decorate([
        Directive({
            selector: '[afdPhonePceValid]',
            providers: [
                {
                    provide: NG_ASYNC_VALIDATORS,
                    useExisting: AfdPhonePceValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdPhonePceValidDirective);
    return AfdPhonePceValidDirective;
}());
var AfdSearchPhoneDirective = /** @class */ (function () {
    function AfdSearchPhoneDirective(afdPceService) {
        this.afdPceService = afdPceService;
    }
    AfdSearchPhoneDirective.prototype.onAfdPhonePceValidationComplete = function (e) {
        this.afdPceService.searchPhone(e.detail.phone).subscribe(function (res) {
            var endEvent = new CustomEvent('afdPhoneSearchComplete', { detail: res });
            document.dispatchEvent(endEvent);
        });
    };
    AfdSearchPhoneDirective.ctorParameters = function () { return [
        { 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([
        Directive({
            selector: '[afdSearchPhone]'
        }),
        __metadata("design:paramtypes", [AfdPceService])
    ], AfdSearchPhoneDirective);
    return AfdSearchPhoneDirective;
}());
var AfdPhoneCountriesDirective = /** @class */ (function () {
    function AfdPhoneCountriesDirective(el) {
        this.el = el;
        console.log(el);
    }
    AfdPhoneCountriesDirective.ctorParameters = function () { return [
        { type: ElementRef }
    ]; };
    AfdPhoneCountriesDirective = __decorate([
        Directive({
            selector: '[afdPhoneCountries]'
        }),
        __metadata("design:paramtypes", [ElementRef])
    ], AfdPhoneCountriesDirective);
    return AfdPhoneCountriesDirective;
}());
function getPhoneObject(phoneNumber, country) {
    if (phoneNumber !== null) {
        // set the default dialing code
        var defaultCountryDialingCode = void 0;
        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
    var initialCountry = typeof countryAttribute !== 'undefined' ? countryAttribute : 'GB';
    return setCountry(initialCountry);
}
function setCountry(newCountry) {
    var e_1, _a;
    var phoneCountry = {
        name: null,
        iso2: null,
        iso3: null
    };
    try {
        for (var Countries_1 = __values(Countries), Countries_1_1 = Countries_1.next(); !Countries_1_1.done; Countries_1_1 = Countries_1.next()) {
            var country = Countries_1_1.value;
            if (country.iso2 === newCountry) {
                phoneCountry = country;
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (Countries_1_1 && !Countries_1_1.done && (_a = Countries_1.return)) _a.call(Countries_1);
        }
        finally { if (e_1) throw e_1.error; }
    }
    return phoneCountry;
}

var AfdCardRegexValidDirective = /** @class */ (function () {
    function AfdCardRegexValidDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdCardRegexValidDirective_1 = AfdCardRegexValidDirective;
    AfdCardRegexValidDirective.prototype.validate = function (control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            var regexValid = number(control.value);
            var 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;
        }
    };
    var AfdCardRegexValidDirective_1;
    AfdCardRegexValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    AfdCardRegexValidDirective = AfdCardRegexValidDirective_1 = __decorate([
        Directive({
            selector: '[afdCardRegexValid]',
            providers: [
                {
                    provide: NG_VALIDATORS,
                    useExisting: AfdCardRegexValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdCardRegexValidDirective);
    return AfdCardRegexValidDirective;
}());
var AfdExpiryRegexValidDirective = /** @class */ (function () {
    function AfdExpiryRegexValidDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdExpiryRegexValidDirective_1 = AfdExpiryRegexValidDirective;
    AfdExpiryRegexValidDirective.prototype.validate = function (control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            var regexValid = expirationDate(control.value);
            var 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;
        }
    };
    var AfdExpiryRegexValidDirective_1;
    AfdExpiryRegexValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], AfdExpiryRegexValidDirective.prototype, "country", void 0);
    AfdExpiryRegexValidDirective = AfdExpiryRegexValidDirective_1 = __decorate([
        Directive({
            selector: '[afdExpiryRegexValid]',
            providers: [
                {
                    provide: NG_VALIDATORS,
                    useExisting: AfdExpiryRegexValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdExpiryRegexValidDirective);
    return AfdExpiryRegexValidDirective;
}());
var AfdCardPceValidDirective = /** @class */ (function () {
    function AfdCardPceValidDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdCardPceValidDirective_1 = AfdCardPceValidDirective;
    AfdCardPceValidDirective.prototype.validate = function (control) {
        var _this = this;
        var currentInfo = this.afdPceService.cardInfoSource.value;
        var card = control.get('cardControl');
        var expiry = control.get('expiryControl');
        var cardTouched = control.touched && card.value.length > 0 && card.valid;
        var 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(function (data) { return JSON.parse(data); }), map(function (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((function (resolve) { return resolve(null); }));
        }
    };
    var AfdCardPceValidDirective_1;
    AfdCardPceValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], AfdCardPceValidDirective.prototype, "country", void 0);
    AfdCardPceValidDirective = AfdCardPceValidDirective_1 = __decorate([
        Directive({
            selector: '[afdCardPceValid]',
            providers: [
                {
                    provide: NG_ASYNC_VALIDATORS,
                    useExisting: AfdCardPceValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdCardPceValidDirective);
    return AfdCardPceValidDirective;
}());

var AfdAccountRegexValidDirective = /** @class */ (function () {
    function AfdAccountRegexValidDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdAccountRegexValidDirective_1 = AfdAccountRegexValidDirective;
    AfdAccountRegexValidDirective.prototype.validate = function (control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            var 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;
        }
    };
    var AfdAccountRegexValidDirective_1;
    AfdAccountRegexValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    AfdAccountRegexValidDirective = AfdAccountRegexValidDirective_1 = __decorate([
        Directive({
            selector: '[afdAccountRegexValid]',
            providers: [
                {
                    provide: NG_VALIDATORS,
                    useExisting: AfdAccountRegexValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdAccountRegexValidDirective);
    return AfdAccountRegexValidDirective;
}());
var AfdSortRegexValidDirective = /** @class */ (function () {
    function AfdSortRegexValidDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdSortRegexValidDirective_1 = AfdSortRegexValidDirective;
    AfdSortRegexValidDirective.prototype.validate = function (control) {
        // only try to validate if there is a value in the input
        if (control.value) {
            var 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;
        }
    };
    var AfdSortRegexValidDirective_1;
    AfdSortRegexValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], AfdSortRegexValidDirective.prototype, "country", void 0);
    AfdSortRegexValidDirective = AfdSortRegexValidDirective_1 = __decorate([
        Directive({
            selector: '[afdSortRegexValid]',
            providers: [
                {
                    provide: NG_VALIDATORS,
                    useExisting: AfdSortRegexValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdSortRegexValidDirective);
    return AfdSortRegexValidDirective;
}());
var AfdAccountPceValidDirective = /** @class */ (function () {
    function AfdAccountPceValidDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdAccountPceValidDirective_1 = AfdAccountPceValidDirective;
    AfdAccountPceValidDirective.prototype.validate = function (control) {
        var _this = this;
        var currentInfo = this.afdPceService.accountInfoSource.value;
        var account = control.get('accountControl');
        var sort = control.get('sortControl');
        // Text mask seems to play around with the touched attribute of sort so I have to create manual checks
        var sortTouched = control.touched && sort.value.length > 0 && sort.valid;
        var 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(function (data) { return JSON.parse(data); }), map(function (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((function (resolve) { return resolve(null); }));
        }
    };
    var AfdAccountPceValidDirective_1;
    AfdAccountPceValidDirective.ctorParameters = function () { return [
        { type: AfdPceService },
        { type: ElementRef }
    ]; };
    __decorate([
        Input(),
        __metadata("design:type", String)
    ], AfdAccountPceValidDirective.prototype, "country", void 0);
    AfdAccountPceValidDirective = AfdAccountPceValidDirective_1 = __decorate([
        Directive({
            selector: '[afdAccountPceValid]',
            providers: [
                {
                    provide: NG_ASYNC_VALIDATORS,
                    useExisting: AfdAccountPceValidDirective_1,
                    multi: true
                }
            ]
        }),
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdAccountPceValidDirective);
    return AfdAccountPceValidDirective;
}());

var AfdCountriesDirective = /** @class */ (function () {
    function AfdCountriesDirective(el, afdPceService) {
        this.el = el;
        this.afdPceService = afdPceService;
    }
    AfdCountriesDirective.prototype.ngAfterViewInit = function () {
        var _this = this;
        var startEvent = new CustomEvent('afdGetCountriesStart');
        document.dispatchEvent(startEvent);
        this.afdPceService.getCountries().subscribe(function (res) {
            var e_1, _a;
            _this.afdPceService.countries = res.body['Item'];
            var endEvent = new CustomEvent('afdGetCountriesComplete', { detail: res });
            document.dispatchEvent(endEvent);
            if (_this.defaultCountry) {
                _this.defaultCountry = _this.defaultCountry.toUpperCase();
                try {
                    for (var _b = __values(_this.afdPceService.countries), _c = _b.next(); !_c.done; _c = _b.next()) {
                        var country = _c.value;
                        if (_this.defaultCountry === country.iso) {
                            _this.afdPceService.selectedCountry = country;
                        }
                    }
                }
                catch (e_1_1) { e_1 = { error: e_1_1 }; }
                finally {
                    try {
                        if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
                    }
                    finally { if (e_1) throw e_1.error; }
                }
            }
        });
    };
    AfdCountriesDirective.ctorParameters = function () { return [
        { type: ElementRef },
        { type: AfdPceService }
    ]; };
    __decorate([
        Input('afdCountries'),
        __metadata("design:type", String)
    ], AfdCountriesDirective.prototype, "defaultCountry", void 0);
    AfdCountriesDirective = __decorate([
        Directive({
            selector: '[afdCountries]'
        })
        // directive that sets an input to work as a result box for PCE, the afdResult attribute sets the relevant PCE field
        ,
        __metadata("design:paramtypes", [ElementRef,
            AfdPceService])
    ], AfdCountriesDirective);
    return AfdCountriesDirective;
}());

var AfdReverseGeocodeDirective = /** @class */ (function () {
    function AfdReverseGeocodeDirective(afdPceService, el) {
        this.afdPceService = afdPceService;
        this.el = el;
    }
    AfdReverseGeocodeDirective.prototype.afdReverseGeocodeInitiate = function (e) {
        var _this = this;
        this.el.nativeElement.disabled = true;
        navigator.geolocation.getCurrentPosition(function (position) {
            _this.afdPceService.reverseGeocode(position.coords.latitude, position.coords.longitude).subscribe(function (data) {
                var result = JSON.parse(data);
                // Populate form fields
                _this.afdPceService.typeAheadResults = result.Item;
                var event = new CustomEvent('afdReverseGeocodeComplete', { detail: result });
                document.dispatchEvent(event);
                _this.el.nativeElement.disabled = false;
            });
        }, function (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.ctorParameters = function () { return [
        { 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([
        Directive({
            selector: '[afdReverseGeocode]'
        })
        // directive that sets an input to work as a result box for PCE, the afdResult attribute sets the relevant PCE field
        ,
        __metadata("design:paramtypes", [AfdPceService,
            ElementRef])
    ], AfdReverseGeocodeDirective);
    return AfdReverseGeocodeDirective;
}());

var AfdTypeaheadComponent = /** @class */ (function () {
    function AfdTypeaheadComponent(el, afdPceService) {
        this.el = el;
        this.afdPceService = afdPceService;
        this.country = null;
        this.group = [
            CreateNewAutocompleteGroup('', 'completer', [], { titleKey: 'list', childrenKey: null }),
        ];
    }
    AfdTypeaheadComponent.prototype.ngOnInit = function () {
        var _this = this;
        if (this.country) {
            this.afdPceService.getCountries(this.country);
        }
        var req = function (str) {
            return new Promise(function (resolve) {
                // check to see if new unique id is needed
                _this.afdPceService.manageUniqueId(str);
                _this.afdPceService.pceLookup(str, _this.data).subscribe(function (data) {
                    var event = new CustomEvent('afdLookupComplete', { detail: JSON.parse(data) });
                    document.dispatchEvent(event);
                    data = JSON.parse(data);
                    var output = [];
                    for (var 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);
    };
    AfdTypeaheadComponent.prototype.typeAheadOptionSelected = function (item) {
        if (item.item) {
            this.chooseAddress(item.item.original.key);
        }
    };
    AfdTypeaheadComponent.prototype.chooseAddress = function (key) {
        var _this = this;
        var retrieve = this.afdPceService.pceRetrieve(key, this.data);
        retrieve.subscribe(function (res) {
            _this.afdPceService.lookupResults = res;
            var event = new CustomEvent('afdRetrieveComplete', { detail: res });
            document.dispatchEvent(event);
        });
    };
    AfdTypeaheadComponent.ctorParameters = function () { return [
        { 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([
        Component({
            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: [""]
        }),
        __metadata("design:paramtypes", [ElementRef,
            AfdPceService])
    ], AfdTypeaheadComponent);
    return AfdTypeaheadComponent;
}());

var AfdPceAngularModule = /** @class */ (function () {
    function AfdPceAngularModule() {
    }
    AfdPceAngularModule = __decorate([
        NgModule({
            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
            ]
        })
    ], AfdPceAngularModule);
    return AfdPceAngularModule;
}());

/*
 * 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
