var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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 { ComponentHelper } from '../../../classes/component-helper';
import { AnalyticsService } from '../../../services/analytics.service';
import { AuthService } from '../../../services/auth.service';
import { ToastService } from '../../../utils/toast.service';
var RegisterFormEcComponent = /** @class */ (function (_super) {
    __extends(RegisterFormEcComponent, _super);
    function RegisterFormEcComponent(authService, toastr, router, analyticsService, formBuilder) {
        var _this = _super.call(this) || this;
        _this.authService = authService;
        _this.toastr = toastr;
        _this.router = router;
        _this.analyticsService = analyticsService;
        _this.formBuilder = formBuilder;
        _this.isLogged = true;
        _this.darkMode = false;
        _this.redirect = true;
        _this.complete = true;
        _this.ready = new EventEmitter();
        _this.success = false;
        _this.campospersonajuridica = false;
        _this.registroUsuario = {
            firstName: '',
            lastName: '',
            email: '',
            plainPassword: '',
            plainPassword2: '',
            newsletter: false,
            terms: false,
        };
        _this.setProp = function (prop, event) {
            _this.registroUsuario[prop] = event.target.value;
        };
        _this.redirectHome = function () {
            _this.router.navigateByUrl('/');
        };
        _this.register = function (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.value.plainPassword != _this.registerForm.value.plainPassword2) {
                _this.toastr.show('Las contraseñas no coinciden');
                _this.register_loading = false;
                return;
            }
            if (_this.registerForm.valid) {
                _this.authService.signUp(_this.registerForm.value).toPromise().then(function (res) {
                    _this.register_loading = false;
                    _this.toastr.show('register-ok');
                    _this.analyticsService.callEvent('sign_up', {
                        firstName: _this.registerForm.value.firstName,
                        lastName: _this.registerForm.value.lastName,
                        email: _this.registerForm.value.email
                    });
                    _this.success = true;
                    _this.ready.emit(true);
                    if (_this.redirect) {
                        _this.router.navigateByUrl('home');
                    }
                }, function (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();
        return _this;
    }
    RegisterFormEcComponent.prototype.ngOnInit = function () {
        this.registerForm = this.formBuilder.group({
            firstName: ['', Validators.required],
            lastName: ['', Validators.required],
            email: ['', Validators.required],
            plainPassword: ['', Validators.required],
            plainPassword2: ['', Validators.required],
            newsletter: [false],
            terms: ['', Validators.required],
        });
        this.ecOnInit();
    };
    RegisterFormEcComponent.ctorParameters = function () { return [
        { type: AuthService },
        { type: ToastService },
        { type: Router },
        { type: AnalyticsService },
        { type: FormBuilder }
    ]; };
    __decorate([
        Input()
    ], RegisterFormEcComponent.prototype, "darkMode", void 0);
    __decorate([
        Input()
    ], RegisterFormEcComponent.prototype, "redirect", void 0);
    __decorate([
        Input()
    ], RegisterFormEcComponent.prototype, "complete", void 0);
    __decorate([
        Output()
    ], RegisterFormEcComponent.prototype, "ready", void 0);
    RegisterFormEcComponent = __decorate([
        Component({
            selector: 'app-register-form-ec',
            template: "<div class=\"w-100 pl-md-5\" id=\"register\">\n    <div class=\"py-2\">\n        <h5>CREAR CUENTA</h5>\n    </div>\n    <form id=\"registro\" [formGroup]=\"registerForm\" (submit)=\"register($event)\">\n        <div class=\"form-group\">\n            <label for=\"\" class=\"\">NOMBRE</label>\n            <input formControlName=\"firstName\" class=\"form-control rounded-0\" type=\"text\" placeholder=\"Nombre\">\n        </div>\n        <div class=\"form-group\">\n            <label for=\"\" class=\"\">APELLIDO</label>\n            <input formControlName=\"lastName\" class=\"form-control rounded-0\" type=\"text\" placeholder=\"Apellido\">\n        </div>\n        <div class=\"form-group\">\n            <label for=\"\" class=\"\">CORREO ELECTRONICO</label>\n            <input formControlName=\"email\" email required class=\"form-control rounded-0\" type=\"email\"\n                placeholder=\"Correo electr\u00F3nico\">\n        </div>\n        <div class=\"form-group\">\n            <label for=\"\" class=\"\">CONTRASE\u00D1A</label>\n            <input formControlName=\"plainPassword\" required class=\"form-control rounded-0\" type=\"password\"\n                placeholder=\"Contrase\u00F1a\">\n        </div>\n        <div class=\"form-group\">\n            <label for=\"\" class=\"\">REPETIR CONTRASE\u00D1A</label>\n            <input formControlName=\"plainPassword2\" required class=\"form-control rounded-0\" type=\"password\"\n                placeholder=\"Repetir contrase\u00F1a\">\n        </div>\n\n        <div class=\"custom-control custom-checkbox mr-sm-2 mt-4 mb-2\">\n            <input type=\"checkbox\" formControlName=\"terms\" required class=\"custom-control-input\" name=\"Color2\"\n                id=\"Color2\">\n            <label class=\"custom-control-label ff-ubuntu-light font-sm\" for=\"Color2\"> He\n                le\u00EDdo y acepto las pol\u00EDticas de privacidad y los t\u00E9rminos y\n                condiciones</label>\n        </div>\n\n        <div class=\"custom-control custom-checkbox mr-sm-2 mb-4\">\n            <input type=\"checkbox\" formControlName=\"newsletter\" class=\"custom-control-input\" name=\"Color3\" id=\"Color3\">\n            <label class=\"custom-control-label ff-ubuntu-light font-sm\" for=\"Color3\">\n                Suscripci\u00F3n al Newsletter</label>\n        </div>\n\n        <div class=\"row\">\n            <div class=\"col-12\">\n                <button [disabled]=\"registerForm.invalid\" type=\"submit\"\n                    class=\"btn btn-dark bg-black btn-block px-5 py-2 rounded-0 h-fit\">CREAR</button>\n            </div>\n        </div>\n    </form>\n</div>\n\n\n\n\n<!-- <div class=\"w-100\" id=\"register\">\n     <h1 class=\"right-line ff-ubuntu-light mb-2\"><span>Crear Cuenta</span></h1>\n     <p class=\"ff-ubuntu-light font-sm pr-4\">\n          Si todav\u00EDa no tienes una cuenta en D2Dcor registrate ingresando estos datos.\n     </p>\n     <form id=\"registro\" (submit)=\"register($event)\">\n          <input [formControl]=\"registerForm.controls['firstName']\" (change)=\"setProp('firstName', $event)\" \n               class=\"form-control mb-4 radius-0 border-0\" type=\"text\" placeholder=\"Nombre\">\n          <input [formControl]=\"registerForm.controls['lastName']\" (change)=\"setProp('lastName', $event)\" \n               class=\"form-control mb-4 radius-0 border-0\" type=\"text\" placeholder=\"Apellido\">\n          <input [formControl]=\"registerForm.controls['email']\" (change)=\"setProp('email', $event)\" \n               class=\"form-control mb-4 radius-0 border-0\" type=\"text\" placeholder=\"Correo electr\u00F3nico\">\n          <input [formControl]=\"registerForm.controls['plainPassword']\" (change)=\"setProp('plainPassword', $event)\" \n               class=\"form-control mb-4 radius-0 border-0\" type=\"password\" placeholder=\"Contrase\u00F1a\">\n          <input [formControl]=\"registerForm.controls['plainPassword2']\" (change)=\"setProp('plainPassword2', $event)\" \n               class=\"form-control mb-4 radius-0 border-0\" type=\"password\" placeholder=\"Repetir contrase\u00F1a\">\n     \n          <div class=\"row\">\n               <div class=\"col-6\">\n                    <button type=\"submit\" class=\"bg-gray border-0 px-4 py-2 color-white ff-ubuntu-light\">REGISTRARSE</button>\n               </div>\n               <div class=\"col-6 d-flex align-items-center\">\n               </div>\n          </div>\n     \n          <div class=\"custom-control custom-checkbox mr-sm-2 mt-4 mb-2\">\n               <input type=\"checkbox\" [formControl]=\"registerForm.controls['terms']\" class=\"custom-control-input\" name=\"Color2\" id=\"Color2\">\n               <label class=\"custom-control-label ff-ubuntu-light font-sm\" for=\"Color2\"> He\n                    le\u00EDdo y acepto las pol\u00EDticas de privacidad y los t\u00E9rminos y\n                    condiciones</label>\n          </div>\n     \n          <div class=\"custom-control custom-checkbox mr-sm-2 mb-4\">\n               <input type=\"checkbox\" [formControl]=\"registerForm.controls['newsletter']\" class=\"custom-control-input\" name=\"Color3\" id=\"Color3\">\n               <label class=\"custom-control-label ff-ubuntu-light font-sm\" for=\"Color3\">\n                    Suscripci\u00F3n al Newsletter</label>\n          </div>\n     </form>\n</div> -->",
            styles: [".loading-container-form{margin-top:20px}#register{color:#000;font-size:.8rem}#register.dark{color:#fff}"]
        })
    ], RegisterFormEcComponent);
    return RegisterFormEcComponent;
}(ComponentHelper));
export { RegisterFormEcComponent };
//# sourceMappingURL=data:application/json;base64, 