import { Component } from '@angular/core';
import { Validators, UntypedFormControl } from '@angular/forms';
import * as i0 from "@angular/core";
import * as i1 from "../core";
import * as i2 from "@angular/router";
import * as i3 from "@angular/forms";
import * as i4 from "../user-config";
import * as i5 from "@angular/common";
import * as i6 from "@angular/material/button";
import * as i7 from "@angular/material/form-field";
import * as i8 from "@angular/material/input";
const errorMessages = {
    business_email: {
        required: 'Business email is required',
        email: 'Invalid email'
    },
    business_name: {
        required: 'Business name is required'
    },
    user_email: {
        required: 'User email is required',
        email: 'Invalid email'
    },
    user_name: {
        required: 'User name is required'
    }
};
export class SignUpComponent {
    constructor(http, alertService, router, errorService, fb, formValidatorService, userConfigService) {
        this.http = http;
        this.alertService = alertService;
        this.router = router;
        this.errorService = errorService;
        this.fb = fb;
        this.formValidatorService = formValidatorService;
        this.userConfigService = userConfigService;
        this.isWorking = false;
        this.signUpForm = fb.group({
            business_name: new UntypedFormControl('', Validators.compose([Validators.required])),
            business_email: new UntypedFormControl('', Validators.compose([Validators.email, Validators.required])),
            user_name: new UntypedFormControl('', Validators.compose([Validators.required])),
            user_email: new UntypedFormControl('', Validators.compose([Validators.email, Validators.required])),
        });
        this.userConfig = userConfigService.getConfig();
    }
    ngOnInit() { }
    signUp() {
        if (!this.signUpForm.valid) {
            return;
        }
        this.isWorking = true;
        this.http.post('api/company-sign-up', this.signUpForm.value).toPromise().then(res => {
            this.alertService.addAlert('Successfully created an account', 'success');
            this.router.navigate(['/user/login']);
        }, error => {
            this.isWorking = false;
            this.alertService.addAlert('Account Already exists.', 'warning');
        });
    }
    redirect(provider) {
        window.location.href = this.userConfig.socialLoginRedirectUrl + provider;
    }
    /** Method to evaluate form fields*/
    isFieldValid(field) {
        return this.formValidatorService.isFieldValid(field, this.signUpForm);
    }
    /** Method to find error in form fields*/
    getErrorMessage(field) {
        return this.formValidatorService.getErrorMessage(field, this.signUpForm, errorMessages);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SignUpComponent, deps: [{ token: i1.HttpService }, { token: i1.AlertService }, { token: i2.Router }, { token: i1.ErrorHandlerService }, { token: i3.UntypedFormBuilder }, { token: i1.FormValidatorService }, { token: i4.UserConfigService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: SignUpComponent, selector: "signup", ngImport: i0, template: "<div class=\"h-100  row align-items-center mx-0\">\n    <div class=\"col\">\n        <header class=\"branding-block mb-0 mt-4\">\n            <div class=\"branding text-center\">\n                <a *ngIf=\"userConfig.appLogoUrl\" href=\"{{userConfig.appUrl}}\" target=\"_blank\">\n                    <img class=\"techlify-logo d-inline-block\" [src]=\"userConfig.appLogoUrl\" />\n                </a>\n            </div>\n            <div class=\"product-info text-center mt-2\">\n                <h3 class=\"product-name\">{{ userConfig.appName }}</h3>\n            </div>\n        </header>\n\n        <div id=\"login-form-wrapper\"\n            class=\"form-bordered mx-auto form-medium form-bordered form-centered form-horizontal mt-3 white-box\"\n            style=\"width:550px\">\n\n            <h4 class=\"section-title text-center\">REGISTER</h4>\n\n            <form [formGroup]=\"signUpForm\" (ngSubmit)=\"signUp()\" class=\"pt-4 pr-4 pl-4 pb-1 mt-4 ml-4 mr-4 mb-1\">\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"col-12\">\n                        <input matInput formControlName=\"business_name\" placeholder=\"Business / Company Name\"\n                            type=\"text\" autocomplete=\"off\" required />\n                        <mat-error *ngIf=\"isFieldValid('business_name')\">{{getErrorMessage('business_name')}}\n                        </mat-error>\n                    </mat-form-field>\n                </div>\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"col-12\">\n                        <input matInput formControlName=\"business_email\" placeholder=\"Business / Company Email\"\n                            type=\"email\" autocomplete=\"off\" required />\n                        <mat-error *ngIf=\"isFieldValid('business_email')\">{{getErrorMessage('business_email')}}\n                        </mat-error>\n                    </mat-form-field>\n                </div>\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"col-12\">\n                        <input matInput formControlName=\"user_name\" placeholder=\"User Name\" type=\"text\"\n                            autocomplete=\"off\" required />\n                        <mat-error *ngIf=\"isFieldValid('user_name')\">{{getErrorMessage('user_name')}}</mat-error>\n                    </mat-form-field>\n                </div>\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"col-12\">\n                        <input matInput formControlName=\"user_email\" placeholder=\"User Email\" type=\"email\"\n                            autocomplete=\"off\" required />\n                        <mat-error *ngIf=\"isFieldValid('user_email')\">{{getErrorMessage('user_email')}}</mat-error>\n                    </mat-form-field>\n                </div>\n                <div class=\"row mt-4\">\n                    <div class=\"col-12 text-center\">\n                        <button mat-button type=\"submit\" class=\"btn btn-sm btn-primary w-100\"\n                            [disabled]=\"isWorking\">Register</button>\n                    </div>\n                </div>\n                <div class=\"row mt-2\" *ngIf=\"userConfig.showSocialLogin\">\n                    <div class=\"col-6\">\n                        <button class=\"col-12 google-button\" mat-raised-button type=\"button\"\n                            (click)=\"redirect('google')\">Google</button>\n                    </div>\n                    <div class=\"col-6\">\n                        <button class=\"col-12 facebook-button\" mat-raised-button type=\"button\"\n                            (click)=\"redirect('facebook')\">Facebook</button>\n                    </div>\n                </div>\n            </form>\n        </div>\n        <div class=\"row mt-3 mr-0 ml-0\">\n            <div class=\"col-12 text-center\">\n                <p>Already an {{ userConfig.appName }} member?</p>\n                <button mat-button class=\"btn btn-sm btn-secondary text-white\" style=\"width: 550px;\" type=\"button\"\n                    [routerLink]=\"['/login']\">\n                    Continue with login\n                </button>\n            </div>\n        </div>\n    </div>\n</div>", styles: ["#login-form-wrapper{margin-top:40px}#login-form-wrapper .branding-block{margin-bottom:60px}#login-form-wrapper .techlify-logo{height:40px;padding-right:10px;bottom:10px;position:relative}#login-form-wrapper .company-name{margin-bottom:0}#login-form-wrapper .google-button{background:#ce1d1d;color:#fff}#login-form-wrapper .facebook-button{background:#38388e;color:#fff}:host{width:100%}.white-box{background-color:#fff;padding:10px}mat-selection-list{width:100%;display:flex;flex-direction:column;justify-content:center;align-items:center}mat-list-option{border:1px solid #ccc;text-align:center;border-radius:4px;padding:10px;cursor:pointer}mat-list-option:hover{background-color:#f0f0f0}\n"], dependencies: [{ kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.ɵNgNoValidate, selector: "form:not([ngNoForm]):not([ngNativeValidate])" }, { kind: "directive", type: i3.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i3.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i3.NgControlStatusGroup, selector: "[formGroupName],[formArrayName],[ngModelGroup],[formGroup],form:not([ngNoForm]),[ngForm]" }, { kind: "directive", type: i3.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i3.FormGroupDirective, selector: "[formGroup]", inputs: ["formGroup"], outputs: ["ngSubmit"], exportAs: ["ngForm"] }, { kind: "directive", type: i3.FormControlName, selector: "[formControlName]", inputs: ["formControlName", "disabled", "ngModel"], outputs: ["ngModelChange"] }, { kind: "component", type: i6.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "component", type: i7.MatFormField, selector: "mat-form-field", inputs: ["hideRequiredMarker", "color", "floatLabel", "appearance", "subscriptSizing", "hintLabel"], exportAs: ["matFormField"] }, { kind: "directive", type: i7.MatError, selector: "mat-error, [matError]", inputs: ["id"] }, { kind: "directive", type: i8.MatInput, selector: "input[matInput], textarea[matInput], select[matNativeControl],      input[matNativeControl], textarea[matNativeControl]", inputs: ["disabled", "id", "placeholder", "name", "required", "type", "errorStateMatcher", "aria-describedby", "value", "readonly"], exportAs: ["matInput"] }, { kind: "directive", type: i2.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SignUpComponent, decorators: [{
            type: Component,
            args: [{ selector: 'signup', template: "<div class=\"h-100  row align-items-center mx-0\">\n    <div class=\"col\">\n        <header class=\"branding-block mb-0 mt-4\">\n            <div class=\"branding text-center\">\n                <a *ngIf=\"userConfig.appLogoUrl\" href=\"{{userConfig.appUrl}}\" target=\"_blank\">\n                    <img class=\"techlify-logo d-inline-block\" [src]=\"userConfig.appLogoUrl\" />\n                </a>\n            </div>\n            <div class=\"product-info text-center mt-2\">\n                <h3 class=\"product-name\">{{ userConfig.appName }}</h3>\n            </div>\n        </header>\n\n        <div id=\"login-form-wrapper\"\n            class=\"form-bordered mx-auto form-medium form-bordered form-centered form-horizontal mt-3 white-box\"\n            style=\"width:550px\">\n\n            <h4 class=\"section-title text-center\">REGISTER</h4>\n\n            <form [formGroup]=\"signUpForm\" (ngSubmit)=\"signUp()\" class=\"pt-4 pr-4 pl-4 pb-1 mt-4 ml-4 mr-4 mb-1\">\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"col-12\">\n                        <input matInput formControlName=\"business_name\" placeholder=\"Business / Company Name\"\n                            type=\"text\" autocomplete=\"off\" required />\n                        <mat-error *ngIf=\"isFieldValid('business_name')\">{{getErrorMessage('business_name')}}\n                        </mat-error>\n                    </mat-form-field>\n                </div>\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"col-12\">\n                        <input matInput formControlName=\"business_email\" placeholder=\"Business / Company Email\"\n                            type=\"email\" autocomplete=\"off\" required />\n                        <mat-error *ngIf=\"isFieldValid('business_email')\">{{getErrorMessage('business_email')}}\n                        </mat-error>\n                    </mat-form-field>\n                </div>\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"col-12\">\n                        <input matInput formControlName=\"user_name\" placeholder=\"User Name\" type=\"text\"\n                            autocomplete=\"off\" required />\n                        <mat-error *ngIf=\"isFieldValid('user_name')\">{{getErrorMessage('user_name')}}</mat-error>\n                    </mat-form-field>\n                </div>\n                <div class=\"form-group row\">\n                    <mat-form-field class=\"col-12\">\n                        <input matInput formControlName=\"user_email\" placeholder=\"User Email\" type=\"email\"\n                            autocomplete=\"off\" required />\n                        <mat-error *ngIf=\"isFieldValid('user_email')\">{{getErrorMessage('user_email')}}</mat-error>\n                    </mat-form-field>\n                </div>\n                <div class=\"row mt-4\">\n                    <div class=\"col-12 text-center\">\n                        <button mat-button type=\"submit\" class=\"btn btn-sm btn-primary w-100\"\n                            [disabled]=\"isWorking\">Register</button>\n                    </div>\n                </div>\n                <div class=\"row mt-2\" *ngIf=\"userConfig.showSocialLogin\">\n                    <div class=\"col-6\">\n                        <button class=\"col-12 google-button\" mat-raised-button type=\"button\"\n                            (click)=\"redirect('google')\">Google</button>\n                    </div>\n                    <div class=\"col-6\">\n                        <button class=\"col-12 facebook-button\" mat-raised-button type=\"button\"\n                            (click)=\"redirect('facebook')\">Facebook</button>\n                    </div>\n                </div>\n            </form>\n        </div>\n        <div class=\"row mt-3 mr-0 ml-0\">\n            <div class=\"col-12 text-center\">\n                <p>Already an {{ userConfig.appName }} member?</p>\n                <button mat-button class=\"btn btn-sm btn-secondary text-white\" style=\"width: 550px;\" type=\"button\"\n                    [routerLink]=\"['/login']\">\n                    Continue with login\n                </button>\n            </div>\n        </div>\n    </div>\n</div>", styles: ["#login-form-wrapper{margin-top:40px}#login-form-wrapper .branding-block{margin-bottom:60px}#login-form-wrapper .techlify-logo{height:40px;padding-right:10px;bottom:10px;position:relative}#login-form-wrapper .company-name{margin-bottom:0}#login-form-wrapper .google-button{background:#ce1d1d;color:#fff}#login-form-wrapper .facebook-button{background:#38388e;color:#fff}:host{width:100%}.white-box{background-color:#fff;padding:10px}mat-selection-list{width:100%;display:flex;flex-direction:column;justify-content:center;align-items:center}mat-list-option{border:1px solid #ccc;text-align:center;border-radius:4px;padding:10px;cursor:pointer}mat-list-option:hover{background-color:#f0f0f0}\n"] }]
        }], ctorParameters: () => [{ type: i1.HttpService }, { type: i1.AlertService }, { type: i2.Router }, { type: i1.ErrorHandlerService }, { type: i3.UntypedFormBuilder }, { type: i1.FormValidatorService }, { type: i4.UserConfigService }] });
//# sourceMappingURL=data:application/json;base64, 