var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Router } from "@angular/router";
import { BehaviorSubject } from 'rxjs';
import { ComponentHelper } from '../../../classes/component-helper';
import { Constants } from '../../../core.consts';
import { AuthService } from '../../../services/auth.service';
import { ParametersService } from '../../../services/parameters.service';
import { ToastService } from '../../../utils/toast.service';
let RegisterWholesalerFormEcComponent = class RegisterWholesalerFormEcComponent extends ComponentHelper {
    constructor(authService, toastr, router, consts, paramsService, formBuilder) {
        super();
        this.authService = authService;
        this.toastr = toastr;
        this.router = router;
        this.consts = consts;
        this.paramsService = paramsService;
        this.formBuilder = formBuilder;
        this.provincesSubject = new BehaviorSubject([]);
        this.countriesSubject = new BehaviorSubject([]);
        this.documentTypesSubject = new BehaviorSubject([]);
        this.provinces$ = this.provincesSubject.asObservable();
        this.countries$ = this.countriesSubject.asObservable();
        this.documentTypes$ = this.documentTypesSubject.asObservable();
        this.isLogged = true;
        this.darkMode = false;
        this.redirect = true;
        this.complete = true;
        this.ready = new EventEmitter();
        this.success = false;
        this.requestTerms = false;
        this.campospersonajuridica = false;
        this.params = {};
        this.onCountrySelected = (value) => {
            $('#selectOpPais').attr('disabled', true);
            this.registerForm.controls['countryCode'].setValue(value);
            this.registerForm.controls['provinceCode'].setValue('');
            value != '' && this.provincesSubject.next(this.countriesSubject.value.find(country => country.code == value).provinces);
        };
        this.onProvincesSelected = (value) => {
            $('#selectOpProvincia').attr('disabled', true);
            this.registerForm.controls['provinceName'].setValue(this.provincesSubject.value.find(province => province.code == value).name);
        };
        this.onGenderSelected = (value) => {
            $('#selectOpSexo').attr('disabled', true);
        };
        this.onDocumentTypeSelected = (value) => {
            $('#selectOpDocumentType').attr('disabled', true);
        };
        this.redirectHome = () => {
            this.router.navigateByUrl('/');
        };
        this.register = (event) => {
            event.preventDefault();
            this.register_loading = true;
            if (!this.registerForm.valid) {
                this.toastr.show('Aún hay campos sin completar o invalidos');
                this.register_loading = false;
                return;
            }
            ;
            this.register_loading = true;
            if (this.registerForm.valid) {
                this.authService.signUpWholesaler(this.registerForm.value).toPromise().then(res => {
                    this.register_loading = false;
                    this.toastr.show('register-ok');
                    this.success = true;
                    this.ready.emit(true);
                    if (this.redirect) {
                        this.router.navigateByUrl('home');
                    }
                }, error => {
                    this.register_loading = false;
                    if (error.status == 400) {
                        this.toastr.show('El email ingresado ya se encuentra registrado.');
                    }
                    else {
                        this.toastr.show('Error en el registro. Vuelva a intentarlo más tarde.');
                    }
                });
            }
            else {
                this.toastr.show('invalid-form');
            }
        };
        this.ecOnConstruct();
    }
    ngOnInit() {
        this.paramsService.parameters.subscribe(res => this.params = res);
        this.registerForm = this.formBuilder.group({
            firstName: ['', [Validators.required]],
            lastName: ['', [Validators.required]],
            documentType: [null, [Validators.required]],
            documentNumber: ['', [Validators.required]],
            email: ['', [Validators.required, Validators.email]],
            plainPassword: ['', Validators.required],
            plainPassword2: ['', []],
            countryCode: [null, Validators.required],
            street: [null, [Validators.maxLength(50)]],
            city: ['', Validators.required],
            postcode: ['', Validators.required],
            provinceName: ['', Validators.required],
            provinceCode: [null, Validators.required],
            companyName: ['', [Validators.required]],
            phoneNumber: ['', [Validators.required, Validators.pattern('[0-9]+')]],
            gender: [null, []],
            birthday: [null, [Validators.maxLength(11)]],
            taxIdentification: ['', Validators.required],
            comments: ['', []],
            contactFirstName: ['', []],
            contactLastName: ['', []],
            contactCompanyPosition: ['', []],
            contactEmail: ['', []],
            contactDocumentType: ['', []],
            contactDocumentNumber: ['', []],
            subscribedToNewsletter: [false],
            terms: [true, Validators.required],
        });
        this.authService.getCountriesData().then(res => {
            this.countriesSubject.next(res);
            let documentTypes = [];
            res.map(paises => {
                this.consts.getLocale().toLocaleLowerCase().includes(paises.code.toLocaleLowerCase()) && (documentTypes = paises.documentTypes || []);
            });
            this.documentTypesSubject.next(documentTypes);
        });
        this.ecOnInit();
    }
};
RegisterWholesalerFormEcComponent.ctorParameters = () => [
    { type: AuthService },
    { type: ToastService },
    { type: Router },
    { type: Constants },
    { type: ParametersService },
    { type: FormBuilder }
];
__decorate([
    Input()
], RegisterWholesalerFormEcComponent.prototype, "darkMode", void 0);
__decorate([
    Input()
], RegisterWholesalerFormEcComponent.prototype, "redirect", void 0);
__decorate([
    Input()
], RegisterWholesalerFormEcComponent.prototype, "complete", void 0);
__decorate([
    Output()
], RegisterWholesalerFormEcComponent.prototype, "ready", void 0);
RegisterWholesalerFormEcComponent = __decorate([
    Component({
        selector: 'app-register-wholesaler-form-ec',
        template: "\n<div class=\"container\">\n    <div class=\"row\">\n        <div class=\"col-12\">\n            <div class=\"\">\n                <div class=\"pt-5 pb-3 border-bottom\">\n                    <h3 class=\"my-auto mx-2 text-left w-fit bold text-beige1 white-space-md-nowrap\">CREAR CUENTA MAYORISTA</h3>\n                </div>\n                <div class=\" py-3\">\n                    <p>Si todavia no tienes una cuenta de grandes consumidores en Vi\u00F1als registrate ingresando estos\n                        datos:</p>\n                </div>\n                <form [formGroup]=\"registerForm\" (submit)=\"register($event)\">\n                    <div class=\"row w-100 mx-auto d-flex justify-content-center px-0 py-3\">\n            \n                        <div class=\"col-12 col-md-6 px-0 pr-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">Nombre</label>\n                                <input type=\"text\" id=\"\" placeholder=\"Nombre\" required name=\"firstName\"\n                                    formControlName=\"firstName\"\n                                    [class]=\"registerForm.controls.firstName.touched ? (registerForm.controls.firstName.valid && registerForm.controls.firstName.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">El nombre es un campo obligatorio.</span>\n                            </div>\n                        </div>\n                        <div class=\"col-12 col-md-6 px-0 pl-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">Apellidos</label>\n                                <input type=\"text\" id=\"\" placeholder=\"Apellido\" required\n                                    name=\"lastName\" formControlName=\"lastName\"\n                                    [class]=\"registerForm.controls.lastName.touched ? (registerForm.controls.lastName.valid && registerForm.controls.lastName.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">El apellido es un campo obligatorio.</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pr-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">Email</label>\n                                <input type=\"email\" id=\"\" placeholder=\"Email\" email required\n                                    name=\"email\" formControlName=\"email\"\n                                    [class]=\"registerForm.controls.email.touched ? (registerForm.controls.email.valid && registerForm.controls.email.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">El email no posee un formato correcto.</span>\n                            </div>\n                        </div>\n                        <div class=\"col-12 col-md-6 px-0 pl-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">Contrase\u00F1a</label>\n                                <input type=\"password\" id=\"\" placeholder=\"Contrase\u00F1a\" required\n                                    name=\"plainPassword\" formControlName=\"plainPassword\"\n                                    [class]=\"registerForm.controls.plainPassword.touched ? (registerForm.controls.plainPassword.valid && registerForm.controls.plainPassword.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">La contrase\u00F1a es un campo obligatorio.</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pl-md-1\" *ngIf=\"(countries$ | async) as countries\">\n                            <div class=\"form-group\">\n                                <label for=\"\">{{'country'|translate}}</label>\n                                <select name=\"countryCode\" formControlName=\"countryCode\" required\n                                    (change)=\"onCountrySelected($event.target.value)\"\n                                    [class]=\"registerForm.controls.countryCode.touched ? (registerForm.controls.countryCode.valid && registerForm.controls.countryCode.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                    <option value=\"null\" id=\"selectOpPais\">Seleccione un pais</option>\n                                    <option *ngFor=\"let country of countries\" [value]=\"country.code\"> {{ country.name }}</option>\n                                </select>\n                                <span class=\"invalid-feedback\">{{'country-help'|translate}}</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pl-md-1\" *ngIf=\"(provinces$ | async) as provinces\">\n                            <div class=\"form-group\">\n                                <label for=\"\">{{'state'|translate}}</label>\n                                <select name=\"provinceCode\" formControlName=\"provinceCode\" required\n                                    (change)=\"onProvincesSelected($event.target.value)\"\n                                    [class]=\"registerForm.controls.countryCode.touched ? (registerForm.controls.countryCode.valid && registerForm.controls.countryCode.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                    <option value=\"null\" id=\"selectOpProvincia\">Seleccione una provincia</option>\n                                    <option *ngFor=\"let province of provinces\" [value]=\"province.code\">{{ province.name }}</option>\n                                </select>\n                                <span class=\"invalid-feedback\">{{'state-help'|translate}}</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pl-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">{{'address'|translate}}</label>\n                                <input placeholder=\"{{'address'|translate}}\" required type=\"text\" name=\"street\"\n                                    formControlName=\"street\"\n                                    [class]=\"registerForm.controls.street.touched ? (registerForm.controls.street.valid && registerForm.controls.street.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">{{'address-help1'|translate}}</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pl-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">{{'town-city'|translate}}</label>\n                                <input placeholder=\"{{'town-city'|translate}}\" required type=\"text\" name=\"city\"\n                                    formControlName=\"city\"\n                                    [class]=\"registerForm.controls.city.touched ? (registerForm.controls.city.valid && registerForm.controls.city.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">{{'town-city-help'|translate}}</span>\n                            </div>\n                        </div>\n            \n            \n                        <div class=\"col-12 col-md-6 px-0 pl-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">{{'postal-code'|translate}}</label>\n                                <input placeholder=\"{{'postal-code'|translate}}\" required type=\"text\" name=\"postcode\"\n                                    formControlName=\"postcode\"\n                                    [class]=\"registerForm.controls.postcode.touched ? (registerForm.controls.postcode.valid && registerForm.controls.postcode.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">{{'postal-code-help'|translate}}</span>\n                            </div>\n                        </div>\n            \n            \n            \n                        <div class=\"col-12 col-md-6 px-0 pr-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">Nombre compa\u00F1\u00EDa</label>\n                                <input type=\"text\" id=\"\" placeholder=\"Nombre compa\u00F1\u00EDa\" required\n                                    name=\"companyName\" formControlName=\"companyName\"\n                                    [class]=\"registerForm.controls.companyName.touched ? (registerForm.controls.companyName.valid && registerForm.controls.companyName.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">El nombre compa\u00F1\u00EDa es un campo obligatorio.</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pr-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">{{'phone'|translate}}</label>\n                                <input type=\"text\" id=\"\" placeholder=\"{{'phone'|translate}}\" required\n                                    name=\"phoneNumber\" formControlName=\"phoneNumber\"\n                                    [class]=\"registerForm.controls.phoneNumber.touched ? (registerForm.controls.phoneNumber.valid && registerForm.controls.phoneNumber.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">El numero de telefono es un campo obligatorio.</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pr-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">Sexo</label>\n                                <select (change)=\"onGenderSelected($event.target.value)\" required name=\"gender\"\n                                    formControlName=\"gender\"\n                                    [class]=\"registerForm.controls.gender.touched ? (registerForm.controls.gender.valid && registerForm.controls.gender.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                    <option value=\"null\" id=\"selectOpSexo\">Sexo</option>\n                                    <option value=\"u\">Desconocido</option>\n                                    <option value=\"s\">Femenino</option>\n                                    <option value=\"m\">Masculino</option>\n                                </select>\n                                <span class=\"invalid-feedback\">El sexo es un campo obligatorio.</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pr-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">Fecha creacion</label>\n                                <input type=\"date\" id=\"\" placeholder=\"Fecha creacion\" required\n                                    name=\"birthday\" formControlName=\"birthday\"\n                                    [class]=\"registerForm.controls.birthday.touched ? (registerForm.controls.birthday.valid && registerForm.controls.birthday.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">La fecha de creacion es un campo obligatorio.</span>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 pr-md-1\">\n                            <div class=\"form-group\">\n                                <label for=\"\">Identificacion</label>\n                                <input type=\"text\" id=\"\" placeholder=\"Identificacion\" required\n                                    name=\"taxIdentification\" formControlName=\"taxIdentification\"\n                                    [class]=\"registerForm.controls.taxIdentification.touched ? (registerForm.controls.taxIdentification.valid && registerForm.controls.taxIdentification.touched) ?  'form-control rounded-0 is-valid' :  'form-control rounded-0 is-invalid' : 'form-control rounded-0'\">\n                                <span class=\"invalid-feedback\">La identificacion de la compa\u00F1\u00EDa es un campo obligatorio.</span>\n                            </div>\n                        </div>\n            \n            \n            \n                        <div class=\"col-12 col-md-6 px-0 py-4 pl-md-1 order-1 order-md-2\">\n                            <!-- <div class=\"form-check py-2\">\n                                <input class=\"form-check-input\" type=\"checkbox\" value=\"\" id=\"defaultCheck1\" #terms=\"ngModel\"\n                                    name=\"terms\" [(ngModel)]=\"registroUsuario.terms\" type=\"checkbox\" required\n                                    [class]=\"terms.touched ? (terms.valid && terms.touched && registroUsuario.terms != false) ?  'form-check-input is-valid' :  'form-check-input is-invalid' : 'form-check-input '\" />\n                                <label class=\"form-check-label\" for=\"defaultCheck1\">\n                                    He leido y acepto las <a routerLink=\"/section/politicas-privacidad\" class=\"text\">pol\u00EDticas de\n                                        privacidad</a>\n                                    y los <a routerLink=\"/section/terminos-y-condiciones\" class=\"text\">t\u00E9rminos y condiciones</a>\n                                </label>\n                                <span class=\"invalid-feedback\">Debe aceptar los t\u00E9rminos y condiciones para continuar.</span>\n                            </div> -->\n                            <div class=\"form-check py-2\">\n                                <input class=\"form-check-input\" type=\"checkbox\" value=\"\" id=\"defaultCheck2\"\n                                    name=\"subscribedToNewsletter\" formControlName=\"subscribedToNewsletter\" type=\"checkbox\">\n                                <label class=\"form-check-label\" for=\"defaultCheck2\">\n                                    Suscripci\u00F3n al newsletter\n                                </label>\n                            </div>\n                        </div>\n            \n                        <div class=\"col-12 col-md-6 px-0 py-4 pr-md-1 d-flex justify-content-md-start order-2 order-md-1\">\n                            <button *ngIf=\"!register_loading\" [disabled]=\"registerForm.invalid\" type=\"submit\" role=\"button\"\n                                class=\"btn btn-dark bg-beige1 text-blanco bold rounded-0 px-5 py-2 w-100 w-md-auto h-fit\">REGISTRATE</button>\n                        </div>\n            \n                    </div>\n            \n                </form>\n            </div>\n        </div>\n    </div>\n</div>",
        styles: [".loading-container-form{margin-top:20px}#register{color:#000;font-size:.8rem}#register.dark{color:#fff}#selectOpPais,#selectOpProvincia,#selectOpSexo{color:#666}"]
    })
], RegisterWholesalerFormEcComponent);
export { RegisterWholesalerFormEcComponent };
//# sourceMappingURL=data:application/json;base64, 