import { __decorate } from "tslib";
import { Component, Input } from "@angular/core";
import { AbstractControl, FormBuilder, FormGroup, ValidationErrors, Validators } from "@angular/forms";
import { ActivatedRoute } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { Subject } from "rxjs";
import { takeUntil } from "rxjs/operators";
import { EmployeeDependentService } from "../../../../core/entities/employee-dependent-core/employee-dependent-core.service";
import { EnumTipSex } from "../../../../core/enums/enum-tip-sex";
import { GenericValidator } from "../../../../shared/validators/generic-validator";
import * as moment_ from "moment";
var moment = moment_; // @HACK Necessary because of https://github.com/rollup/rollup/issues/670
var EmployeeDependentPersonalStepComponent = /** @class */ (function () {
    function EmployeeDependentPersonalStepComponent(translateService, route, formBuilder, service) {
        var _this = this;
        this.translateService = translateService;
        this.route = route;
        this.formBuilder = formBuilder;
        this.service = service;
        this.maxlength = 80;
        this.emailMax = 500;
        this.localeConfig = {};
        this.ngUnsubscribe = new Subject();
        this.genderType = Object.keys(EnumTipSex).map(function (item) {
            return {
                label: _this.translateService.instant("hcm_contract.employment_contract.employee_dependent_gender_type_" + item),
                value: item,
            };
        });
    }
    EmployeeDependentPersonalStepComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.createFormGroup();
        this.parentFormGroup.addControl("basicDependentPersonData", this.formGroup);
        this.route.data
            .pipe(takeUntil(this.ngUnsubscribe))
            .subscribe(function (data) { return _this.onRouteDataChange(data); });
        this.subscribeEvents();
    };
    EmployeeDependentPersonalStepComponent.prototype.createFormGroup = function () {
        this.formGroup = this.formBuilder.group({
            birthDate: this.formBuilder.control({ value: null, disabled: false }, [Validators.required, this.validateBirthDateIsAfterNow()]),
            cpf: this.formBuilder.control({ value: null, disabled: false }, [Validators.required, GenericValidator.isValidCpf()]),
            fullName: this.formBuilder.control({ value: null, disabled: false }, Validators.compose([Validators.required, Validators.maxLength(this.maxlength)])),
            email: this.formBuilder.control({ value: null, disabled: null }, Validators.compose([Validators.maxLength(this.emailMax), this.validatorEmailsList()])),
            genderType: this.formBuilder.control({ value: null, disabled: false }, Validators.required),
            nickname: this.formBuilder.control({ value: null, disabled: false }, Validators.maxLength(this.maxlength)),
        });
    };
    EmployeeDependentPersonalStepComponent.prototype.validateBirthDateIsAfterNow = function () {
        return function (control) {
            if (control.value) {
                var birthDate = moment(control.value);
                if (birthDate.isAfter(moment())) {
                    return { birthDateIsAfter: true };
                }
            }
            return null;
        };
    };
    EmployeeDependentPersonalStepComponent.prototype.subscribeEvents = function () {
        var _this = this;
        this.service.getDependentFormData()
            .pipe(takeUntil(this.ngUnsubscribe))
            .subscribe(function (personData) {
            var _a;
            _this.formGroup.patchValue((_a = personData === null || personData === void 0 ? void 0 : personData.personDependentData) === null || _a === void 0 ? void 0 : _a.basicDependentPersonData);
        });
    };
    EmployeeDependentPersonalStepComponent.prototype.onRouteDataChange = function (data) {
        this.localeConfig = data.localeConfig;
    };
    EmployeeDependentPersonalStepComponent.prototype.validatorEmailsList = function () {
        return function (control) {
            if (control.value) {
                if (!/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(control.value)) {
                    return { email: true };
                }
            }
            return null;
        };
    };
    EmployeeDependentPersonalStepComponent.ctorParameters = function () { return [
        { type: TranslateService },
        { type: ActivatedRoute },
        { type: FormBuilder },
        { type: EmployeeDependentService }
    ]; };
    __decorate([
        Input()
    ], EmployeeDependentPersonalStepComponent.prototype, "parentFormGroup", void 0);
    EmployeeDependentPersonalStepComponent = __decorate([
        Component({
            selector: "fnd-employee-dependent-personal-step",
            template: "<div class=\"ui-fluid \" [formGroup]=\"formGroup\">\n    <div class=\"ui-g\">\n        <div class=\"ui-md-12\">\n            <h3>{{'hcm_contract.employment_contract.employee_dependent_personal_data_title' | translate}}</h3>\n        </div>\n        <!-- CPF -->\n        <div id=\"dv-cpf\" class=\"ui-sm-12 ui-md-6 ui-lg-6 ui-xl-6 required\">\n            <label id=\"lb-cpf\" for=\"ff-cpf\">{{\n                'hcm_contract.employment_contract.admission_employee_form_sheet_documents_personal_data_cpf' | translate\n                }}</label>\n            <p-inputMask id=\"ff-cpf\" formControlName=\"cpf\" mask=\"999.999.999-99\" [unmask]=\"true\"></p-inputMask>\n            <s-control-errors\n                id=\"er-cpf\"\n                [control]=\"formGroup.get('cpf')\"\n                [errorMessages]=\"{\n                    cpfNotValid: 'hcm_contract.employment_contract.employee_dependent_error_invalid' | translate,\n                    required: 'hcm_contract.employment_contract.admission_generic_field_validator_required' | translate\n                }\"\n            ></s-control-errors>\n        </div>\n\n        <!-- Nome Completo -->\n        <div id=\"dv-fullname\" class=\"ui-sm-12 ui-md-12 ui-lg-12 required\">\n            <label id=\"lb-fullname\" for=\"ff-fullname\">{{\n                'hcm_contract.employment_contract.admission_employee_form_sheet_person_basic_data_full_name' | translate\n                }}</label>\n\n            <input\n                id=\"ff-fullName\"\n                type=\"text\" pInputText\n                formControlName=\"fullName\"\n                autocomplete=\"off\"\n            />\n\n            <s-control-errors\n                id=\"er-full-name\"\n                [control]=\"formGroup.get('fullName')\"\n                [errorMessages]=\"{\n                    required: 'hcm_contract.employment_contract.admission_generic_field_validator_required' | translate,\n                    maxlength: translateService.instant('hcm_contract.employment_contract.admission_generic_field_validator_max_length', {\n                    value: formGroup.get('fullName').errors?.maxlength?.requiredLength\n            })\n          }\"\n            ></s-control-errors>\n        </div>\n\n        <!-- Apelido -->\n        <div id=\"dv-nickname\" class=\"ui-sm-12 ui-md-12 ui-lg-12\">\n            <label id=\"lb-nickname\" for=\"ff-nickname\">{{\n                'hcm_contract.employment_contract.admission_employee_form_sheet_person_basic_data_nickname' | translate\n                }}</label>\n\n            <input id=\"ff-nickname\" type=\"text\" pInputText formControlName=\"nickname\" autocomplete=\"off\"/>\n\n            <s-control-errors\n                id=\"er-nickname\"\n                [control]=\"formGroup.get('nickname')\"\n                [errorMessages]=\"{\n                    maxlength: translateService.instant('hcm_contract.employment_contract.admission_generic_field_validator_max_length', {\n                    value: formGroup.get('nickname').errors?.maxlength?.requiredLength\n                 })\n          }\"\n            ></s-control-errors>\n        </div>\n        <!-- Sexo -->\n        <div class=\"ui-g-12 ui-md-6 required\">\n            <label for=\"genderType\">{{\"hcm_contract.employment_contract.employee_dependent_gender_label\" |\n                translate}}</label>\n            <p-dropdown inputId=\"genderType\" id=\"genderType\" name=\"genderType\" [options]=\"genderType\"\n                        formControlName=\"genderType\"\n                        placeholder=\"{{\n                            'hcm_contract.employment_contract.employee_dependent_gender_type_placeholder'\n                            | translate}}\">\n            </p-dropdown>\n            <s-control-errors\n                id=\"er-gender-type\"\n                [control]=\"formGroup.get('genderType')\"\n                [errorMessages]=\"{\n                    required: 'hcm_contract.employment_contract.admission_generic_field_validator_required' | translate\n                    }\"\n            ></s-control-errors>\n        </div>\n        <!-- Nascimento -->\n        <div id=\"dv-birth-date\" class=\"ui-sm-12 ui-md-6 required\">\n            <label id=\"lb-birth-date\" for=\"ff-birth-date\">{{\n                'hcm_contract.employment_contract.admission_employee_form_sheet_person_basic_data_birth_date' | translate\n                }}</label>\n\n            <p-calendar\n                id=\"ff-birth-date\"\n                name=\"birthDate\"\n                formControlName=\"birthDate\"\n                [dateFormat]=\"localeConfig?.calendar?.dateFormat\"\n                [locale]=\"localeConfig?.calendar\"\n                [showIcon]=\"true\"\n                icon=\"fa fa-calendar\"\n                sCalendarMask\n            ></p-calendar>\n            <s-control-errors\n                id=\"er-hire-date\"\n                [control]=\"formGroup.get('birthDate')\"\n                [errorMessages]=\"{\n                    birthDateIsAfter:\n                        'hcm_contract.employment_contract.employee_dependent_error_date_must_be_today_or_later'\n                        | translate,\n                    required:\n                        'hcm_contract.employment_contract.admission_generic_field_validator_required'\n                        | translate\n                    }\"\n            ></s-control-errors>\n        </div>\n        <!-- E-mail -->\n        <div id=\"dv-email\" class=\"ui-sm-12 ui-md-12\">\n            <label id=\"lb-email\" for=\"ff-email\">{{\n                'hcm_contract.employment_contract.admission_employee_form_sheet_person_email_data_email' | translate\n                }}</label>\n\n            <input id=\"ff-email\" type=\"text\" pInputText formControlName=\"email\" autocomplete=\"off\" />\n\n            <s-control-errors\n                id=\"er-email\"\n                [control]=\"formGroup.get('email')\"\n                [errorMessages]=\"{\n                    email: translateService.instant('hcm_contract.employment_contract.employee_dependent_email_invalid'),\n                    maxlength: translateService.instant('hcm_contract.employment_contract.admission_generic_field_validator_max_length', {\n                        value: formGroup.get('email').errors?.maxlength?.requiredLength\n                    })\n                }\"\n            ></s-control-errors>\n        </div>\n\n    </div>\n</div>\n"
        })
    ], EmployeeDependentPersonalStepComponent);
    return EmployeeDependentPersonalStepComponent;
}());
export { EmployeeDependentPersonalStepComponent };
//# sourceMappingURL=data:application/json;base64, 