/**
 * @fileoverview added by tsickle
 * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { CITIES } from '../../../../../const/city.const';
import { API, DEF } from '../../../../../api';
var IdentityUserUsersCreateComponent = /** @class */ (function () {
    function IdentityUserUsersCreateComponent() {
        this.visible = false;
        this.visibleChange = new EventEmitter();
        this.ok = new EventEmitter();
        this.saving = false;
        this.formGroup = new FormGroup({
            userName: new FormControl('', {
                validators: Validators.required,
            }),
            name: new FormControl('', {
                validators: Validators.required,
            }),
            cities: new FormControl([]),
            street: new FormControl(''),
            zipCode: new FormControl('', {
                validators: [Validators.pattern(/^[0-9]{5,6}$/)],
            }),
            phoneNumber: new FormControl(''),
            cardNumber: new FormControl(''),
            cardHolderName: new FormControl(''),
            expiration: new FormControl('', {
                validators: [Validators.pattern(/^[0-9]{2}\/[0-9]{2}$/)],
            }),
            securityNumber: new FormControl('', {
                validators: [Validators.pattern(/^[0-9]{3}$/)],
            }),
            email: new FormControl('', {
                validators: [Validators.required, Validators.email],
            }),
            initialPassword: new FormControl('', {
                validators: Validators.required,
            }),
        });
        this.initialPasswordVisible = false;
        this.cities = CITIES;
    }
    /**
     * @return {?}
     */
    IdentityUserUsersCreateComponent.prototype.handleOk = /**
     * @return {?}
     */
    function () {
        var _this = this;
        if (this.formGroup.invalid) {
            return;
        }
        this.saving = true;
        /** @type {?} */
        var applicationUser = new DEF.Identity.ApplicationUser(this.formGroup.getRawValue());
        //region country / state / city
        {
            /** @type {?} */
            var formControl = this.formGroup.get('cities');
            if (formControl) {
                /** @type {?} */
                var citiesValue = (/** @type {?} */ (formControl.value));
                if (citiesValue.length === 3) {
                    applicationUser.country = citiesValue[0];
                    applicationUser.state = citiesValue[1];
                    applicationUser.city = citiesValue[2];
                }
                else if (citiesValue.length === 2) {
                    applicationUser.country = citiesValue[0];
                    applicationUser.city = citiesValue[1];
                }
            }
        }
        //endregion
        //region delete redundant fields
        {
            delete applicationUser.id;
            delete applicationUser.accessFailedCount;
            delete applicationUser.concurrencyStamp;
            delete applicationUser.emailConfirmed;
            delete applicationUser.lockoutEnabled;
            delete applicationUser.lockoutEnd;
            delete applicationUser.normalizedEmail;
            delete applicationUser.normalizedUserName;
            delete applicationUser.permissions;
            delete applicationUser.passwordHash;
            delete applicationUser.phoneNumberConfirmed;
            delete applicationUser.securityStamp;
            delete applicationUser.twoFactorEnabled;
            delete applicationUser.firstName;
            delete applicationUser.lastName;
        }
        //endregion
        API.Identity.UserController.AddUser(undefined, applicationUser).subscribe((/**
         * @return {?}
         */
        function () {
            _this.formGroup.reset({
                cities: [],
            });
            _this.saving = false;
            _this.visibleChange.emit(false);
            _this.ok.emit();
        }), (/**
         * @return {?}
         */
        function () {
            _this.saving = false;
        }));
    };
    /**
     * @return {?}
     */
    IdentityUserUsersCreateComponent.prototype.handleCancel = /**
     * @return {?}
     */
    function () {
        this.formGroup.reset({
            cities: [],
        });
        this.visibleChange.emit(false);
    };
    IdentityUserUsersCreateComponent.decorators = [
        { type: Component, args: [{
                    selector: 'kg---identity--user--users--create',
                    template: "<nz-modal\r\n  (nzOnCancel)=\"handleCancel()\"\r\n  (nzOnOk)=\"handleOk()\"\r\n  [nzCancelDisabled]=\"saving\"\r\n  [nzClosable]=\"!saving\"\r\n  [nzKeyboard]=\"false\"\r\n  [nzMaskClosable]=\"false\"\r\n  [nzOkDisabled]=\"!formGroup.valid || saving\"\r\n  [nzOkLoading]=\"saving\"\r\n  [nzVisible]=\"visible\"\r\n  nzTitle=\"{{ 'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.add-user' | i18n }}\"\r\n  nzWidth=\"748px\"\r\n>\r\n  <form (ngSubmit)=\"handleOk()\" [formGroup]=\"formGroup\" [nzNoAnimation]=\"true\" nz-form nzLayout=\"vertical\">\r\n    <div [nzGutter]=\"12\" nz-row>\r\n      <div [nzMd]=\"12\" [nzSm]=\"24\" nz-col>\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'userName'\" [nzRequired]=\"true\"> {{ 'app.common.user-name' | i18n }}: </nz-form-label>\r\n          <nz-form-control\r\n            nzErrorTip=\"{{\r\n              'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.username-is-required' | i18n\r\n            }}\"\r\n          >\r\n            <input [attr.id]=\"'userName'\" [formControlName]=\"'userName'\" nz-input />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>\r\n\r\n      <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'name'\" [nzRequired]=\"true\"> {{ 'app.common.name' | i18n }}: </nz-form-label>\r\n          <nz-form-control nzErrorTip=\"{{ 'app.common.form.name.required' | i18n }}\">\r\n            <input nz-input [formControlName]=\"'name'\" [attr.id]=\"'name'\" />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>\r\n\r\n      <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'email'\" [nzRequired]=\"true\"> {{ 'app.common.email' | i18n }}: </nz-form-label>\r\n          <nz-form-control [nzErrorTip]=\"emailErrorTipTpl\">\r\n            <ng-template #emailErrorTipTpl let-control>\r\n              <ng-container *ngIf=\"control.hasError('email')\">\r\n                {{ 'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.invalid-email' | i18n }}\r\n              </ng-container>\r\n              <ng-container *ngIf=\"control.hasError('required')\">\r\n                {{\r\n                  'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.email-is-required' | i18n\r\n                }}\r\n              </ng-container>\r\n            </ng-template>\r\n\r\n            <input nz-input [formControlName]=\"'email'\" [attr.id]=\"'email'\" />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>\r\n\r\n      <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'initialPassword'\" [nzRequired]=\"true\">\r\n            {{ 'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.initial-password' | i18n }}:\r\n          </nz-form-label>\r\n          <nz-form-control\r\n            nzErrorTip=\"{{\r\n              'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.initial-password-is-required'\r\n                | i18n\r\n            }}\"\r\n          >\r\n            <nz-input-group [nzSuffix]=\"nzSuffixTpl\">\r\n              <input\r\n                nz-input\r\n                [formControlName]=\"'initialPassword'\"\r\n                [attr.id]=\"'initialPassword'\"\r\n                [type]=\"initialPasswordVisible ? 'text' : 'password'\"\r\n              />\r\n            </nz-input-group>\r\n\r\n            <ng-template #nzSuffixTpl>\r\n              <i\r\n                nz-icon\r\n                [nzType]=\"initialPasswordVisible ? 'eye-invisible' : 'eye'\"\r\n                [ngStyle]=\"{\r\n                  cursor: 'pointer'\r\n                }\"\r\n                (click)=\"initialPasswordVisible = !initialPasswordVisible\"\r\n              ></i>\r\n            </ng-template>\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>\r\n\r\n      <!--      <div nz-col [nzSm]=\"24\" [nzMd]=\"24\">-->\r\n      <!--        <nz-form-item>-->\r\n      <!--          <nz-form-label [nzFor]=\"'country'\">-->\r\n      <!--            {{-->\r\n      <!--              'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.country-state-city'-->\r\n      <!--                | i18n-->\r\n      <!--            }}:-->\r\n      <!--          </nz-form-label>-->\r\n      <!--          <nz-form-control>-->\r\n      <!--            <nz-cascader-->\r\n      <!--              [nzOptions]=\"cities\"-->\r\n      <!--              formControlName=\"cities\"-->\r\n      <!--              nzPlaceHolder=\"{{-->\r\n      <!--                'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.country-state-city'-->\r\n      <!--                  | i18n-->\r\n      <!--              }}\"-->\r\n      <!--              [nzShowSearch]=\"true\"-->\r\n      <!--            >-->\r\n      <!--            </nz-cascader>-->\r\n      <!--          </nz-form-control>-->\r\n      <!--        </nz-form-item>-->\r\n      <!--      </div>-->\r\n\r\n      <!--      <div nz-col [nzSm]=\"24\" [nzMd]=\"24\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'street'\">\r\n            {{ 'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.street' | i18n }}:\r\n          </nz-form-label>\r\n          <nz-form-control>\r\n            <input nz-input [formControlName]=\"'street'\" [attr.id]=\"'street'\" />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>-->\r\n\r\n      <!--      <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'zipCode'\"> {{ 'app.common.zip-code' | i18n }}: </nz-form-label>\r\n          <nz-form-control\r\n\r\n          >\r\n            <input nz-input  />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>-->\r\n      <!--      <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'phoneNumber'\"> {{ 'app.common.phone-number' | i18n }}: </nz-form-label>\r\n          <nz-form-control>\r\n            <input nz-input [formControlName]=\"'phoneNumber'\" [attr.id]=\"'phoneNumber'\" />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>-->\r\n\r\n      <div nz-col [nzSm]=\"24\" [nzMd]=\"24\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'phoneNumber'\"> {{ 'app.common.phone-number' | i18n }}: </nz-form-label>\r\n          <nz-form-control>\r\n            <input nz-input [formControlName]=\"'phoneNumber'\" [attr.id]=\"'phoneNumber'\" />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>\r\n\r\n      <!--      <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">-->\r\n      <!--        <nz-form-item>-->\r\n      <!--          <nz-form-label [nzFor]=\"'cardNumber'\">-->\r\n      <!--            {{ 'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.card-number' | i18n }}:-->\r\n      <!--          </nz-form-label>-->\r\n      <!--          <nz-form-control>-->\r\n      <!--            <input nz-input [formControlName]=\"'cardNumber'\" [attr.id]=\"'cardNumber'\" />-->\r\n      <!--          </nz-form-control>-->\r\n      <!--        </nz-form-item>-->\r\n      <!--      </div>-->\r\n\r\n      <!--      <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'cardHolderName'\">\r\n            {{\r\n              'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.card-holder-name' | i18n\r\n            }}:\r\n          </nz-form-label>\r\n          <nz-form-control>\r\n            <input nz-input [formControlName]=\"'cardHolderName'\" [attr.id]=\"'cardHolderName'\" />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>-->\r\n\r\n      <!--      <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'expiration'\">\r\n            {{ 'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.expiration' | i18n }}:\r\n          </nz-form-label>\r\n          <nz-form-control\r\n            nzErrorTip=\"{{\r\n              'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.invalid-expiration'\r\n                | i18n\r\n            }}\"\r\n          >\r\n            <input nz-input [formControlName]=\"'expiration'\" [attr.id]=\"'expiration'\" placeholder=\"MM/YY\" />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>-->\r\n\r\n      <!-- <div nz-col [nzSm]=\"24\" [nzMd]=\"12\">\r\n        <nz-form-item>\r\n          <nz-form-label [nzFor]=\"'securityNumber'\">\r\n            {{\r\n              'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.security-number' | i18n\r\n            }}:\r\n          </nz-form-label>\r\n          <nz-form-control\r\n            nzErrorTip=\"{{\r\n              'projects/fe-ng/src/lib/page/identity/user/users/create/user-users-create.invalid-security-number'\r\n                | i18n\r\n            }}\"\r\n          >\r\n            <input nz-input [formControlName]=\"'securityNumber'\" [attr.id]=\"'securityNumber'\" placeholder=\"XXX\" />\r\n          </nz-form-control>\r\n        </nz-form-item>\r\n      </div>-->\r\n    </div>\r\n\r\n    <button [hidden]=\"true\"></button>\r\n  </form>\r\n</nz-modal>\r\n"
                }] }
    ];
    IdentityUserUsersCreateComponent.propDecorators = {
        visible: [{ type: Input }],
        visibleChange: [{ type: Output }],
        ok: [{ type: Output }]
    };
    return IdentityUserUsersCreateComponent;
}());
export { IdentityUserUsersCreateComponent };
if (false) {
    /** @type {?} */
    IdentityUserUsersCreateComponent.prototype.visible;
    /** @type {?} */
    IdentityUserUsersCreateComponent.prototype.visibleChange;
    /** @type {?} */
    IdentityUserUsersCreateComponent.prototype.ok;
    /** @type {?} */
    IdentityUserUsersCreateComponent.prototype.saving;
    /** @type {?} */
    IdentityUserUsersCreateComponent.prototype.formGroup;
    /** @type {?} */
    IdentityUserUsersCreateComponent.prototype.initialPasswordVisible;
    /** @type {?} */
    IdentityUserUsersCreateComponent.prototype.cities;
}
//# sourceMappingURL=data:application/json;base64, 