/**
 * @fileoverview added by tsickle
 * Generated from: lib/fhir/patient/add/patient-add.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import * as tslib_1 from "tslib";
import { ModalService } from '../../../widgets/entry-components/modal/services/modal.service';
import { Component, Input } from '@angular/core';
import { ActionSheetController } from '@ionic/angular';
import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms';
import { TranslatePipe } from '../../../shared/translate/pipes/translate.pipe';
import { AbstractAddWmodalComponent } from '../../../shared/abstracts/add/abstract-add-wmodal/abstract-add-wmodal.component';
import { AlertService } from '../../../widgets/entry-components/alert/services/alert.service';
import { setValidators } from '../../../shared/validators/set-validators';
/** @type {?} */
export var GENDER_LIST = [
    { label: 'FEMALE', value: 'FEMALE' },
    { label: 'MALE', value: 'MALE' },
    { label: 'OTHER', value: 'OTHER' }
];
/** @type {?} */
export var OTHER_DATAS = ['address', 'contact', 'telecom'];
var PatientAddComponent = /** @class */ (function (_super) {
    tslib_1.__extends(PatientAddComponent, _super);
    function PatientAddComponent(modalService, actionSheetController, translatePipe, alertService) {
        var _this = _super.call(this, modalService, actionSheetController, translatePipe) || this;
        _this.alertService = alertService;
        _this.genderList = GENDER_LIST;
        _this.hasOtherDatasRequiredModal = false;
        _this.savePressed = false;
        _this.isRequiredField = {};
        return _this;
    }
    /**
     * @return {?}
     */
    PatientAddComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        _super.prototype.ngOnInit.call(this);
        if (this.extraValidators) {
            this.form = setValidators(this.form, this.extraValidators);
            this.setRedStars(this.extraValidators);
        }
    };
    /**
     * @return {?}
     */
    PatientAddComponent.prototype.resetForm = /**
     * @return {?}
     */
    function () {
        return new FormGroup({
            id: new FormControl(),
            extension: new FormArray([
                new FormGroup({ valueString: new FormControl('') }),
                new FormGroup({ valueString: new FormControl('') })
            ]),
            identifier: new FormArray([new FormGroup({
                    value: new FormControl('', Validators.compose([Validators.required, Validators.minLength(11)]))
                })]),
            active: new FormControl(false),
            name: new FormArray([], Validators.required),
            gender: new FormControl('OTHER'),
            telecom: new FormArray([]),
            birthDate: new FormControl(''),
            address: new FormArray([]),
            contact: new FormArray([])
        });
    };
    /**
     * @param {?} extraValidators
     * @param {?=} path
     * @return {?}
     */
    PatientAddComponent.prototype.setRedStars = /**
     * @param {?} extraValidators
     * @param {?=} path
     * @return {?}
     */
    function (extraValidators, path) {
        var _this = this;
        Object.keys(extraValidators).forEach((/**
         * @param {?} key
         * @return {?}
         */
        function (key) {
            /** @type {?} */
            var newPath = path ? path + '.' + key : key;
            if (Array.isArray(extraValidators[key])) {
                if (extraValidators[key].includes(Validators.required)) {
                    if (OTHER_DATAS.includes(key)) {
                        _this.hasOtherDatasRequiredModal = true;
                    }
                    else {
                        _this.isRequiredField[newPath] = true;
                    }
                }
            }
            else {
                _this.setRedStars(extraValidators[key], newPath);
            }
        }));
    };
    /**
     * @param {?} componentName
     * @param {?=} param
     * @return {?}
     */
    PatientAddComponent.prototype.openModal = /**
     * @param {?} componentName
     * @param {?=} param
     * @return {?}
     */
    function (componentName, param) {
        var _this = this;
        this.modalService.presentModal(this.modalComponents[componentName](), param).then((/**
         * @param {?} modal
         * @return {?}
         */
        function (modal) {
            modal.onDidDismiss().then((/**
             * @param {?} detail
             * @return {?}
             */
            function (detail) {
                if (detail.data) {
                    if (detail.data.value.hasOwnProperty(componentName)) {
                        /** @type {?} */
                        var formArray = _this.form.controls[componentName] ? (/** @type {?} */ (_this.form.controls[componentName])) : new FormArray([]);
                        formArray.push(detail.data.value[componentName]);
                        _this.form.setControl(componentName, formArray);
                        _this.form.updateValueAndValidity();
                        _this.form.markAsDirty();
                    }
                }
            }));
        }));
    };
    /**
     * @return {?}
     */
    PatientAddComponent.prototype.addDetails = /**
     * @return {?}
     */
    function () {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var actionSheet;
            var _this = this;
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.actionSheetController.create({
                            header: this.translatePipe.transform('ADDOTHERDATAS'),
                            buttons: [
                                {
                                    text: this.translatePipe.transform('ADDRESS'),
                                    icon: 'business',
                                    cssClass: this.handleCssClass('address'),
                                    handler: (/**
                                     * @return {?}
                                     */
                                    function () {
                                        _this.openModal('address', _this.handleModalParameters('address'));
                                    })
                                }, {
                                    text: this.translatePipe.transform('AVAILABILITY'),
                                    icon: 'call',
                                    cssClass: this.handleCssClass('telecom'),
                                    handler: (/**
                                     * @return {?}
                                     */
                                    function () {
                                        _this.openModal('telecom', _this.handleModalParameters('telecom'));
                                    })
                                }, {
                                    text: this.translatePipe.transform('CONTACT_PERSON'),
                                    icon: 'contact',
                                    cssClass: this.handleCssClass('contact'),
                                    handler: (/**
                                     * @return {?}
                                     */
                                    function () {
                                        _this.openModal('contact', _this.handleModalParameters('contact'));
                                    })
                                }, {
                                    text: this.translatePipe.transform('BACK'),
                                    icon: 'close',
                                    role: 'cancel'
                                }
                            ]
                        })];
                    case 1:
                        actionSheet = _a.sent();
                        return [4 /*yield*/, actionSheet.present()];
                    case 2:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * @param {?} inData
     * @return {?}
     */
    PatientAddComponent.prototype.save = /**
     * @param {?} inData
     * @return {?}
     */
    function (inData) {
        this.savePressed = true;
        if (this.inData) {
            this.inData = inData;
        }
        _super.prototype.save.call(this, inData);
    };
    /**
     * @param {?} type
     * @return {?}
     */
    PatientAddComponent.prototype.handleModalParameters = /**
     * @param {?} type
     * @return {?}
     */
    function (type) {
        if (this.modalParameters && this.modalParameters[type]) {
            return { extraValidators: this.modalParameters[type] };
        }
        return null;
    };
    /**
     * @param {?} type
     * @return {?}
     */
    PatientAddComponent.prototype.handleCssClass = /**
     * @param {?} type
     * @return {?}
     */
    function (type) {
        if (this.extraValidators && this.extraValidators[type] && this.extraValidators[type].includes(Validators.required)) {
            return 'required-action-button';
        }
        return '';
    };
    /**
     * @param {?} key
     * @return {?}
     */
    PatientAddComponent.prototype.isRequired = /**
     * @param {?} key
     * @return {?}
     */
    function (key) {
        if (this.isRequiredField[key]) {
            return true;
        }
    };
    PatientAddComponent.decorators = [
        { type: Component, args: [{
                    selector: 'inc-patient-add',
                    template: "<form [formGroup]=\"form\" (ngSubmit)=\"save(form.value)\">\r\n  <ion-grid class=\"ion-padding\">\r\n    <ion-row class=\"ion-align-items-end\">\r\n      <ion-col size=\"12\" sizeMd=\"6\">\r\n        <ion-radio-group class=\"radio-hor\" formControlName=\"gender\">\r\n          <ion-item *ngFor=\"let gender of genderList\" lines=\"none\" id=\"patient-gender\">\r\n            <ion-label>\r\n              {{gender.label | translate}}</ion-label>\r\n            <ion-radio slot=\"start\" value=\"{{gender.value}}\" color=\"secondary\">\r\n            </ion-radio>\r\n          </ion-item>\r\n        </ion-radio-group>\r\n      </ion-col>\r\n      <ion-col size=\"12\" sizeMd=\"6\" formArrayName=\"identifier\">\r\n        <ion-item formGroupName=\"0\">\r\n          <ion-label position=\"floating\">\r\n            {{'TAJ' | translate}}\r\n            <span class=\"required\">*</span>\r\n          </ion-label>\r\n          <ion-input id=\"patient-social-security-number\" type=\"text\" autofocus=\"true\" formControlName=\"value\" clearInput\r\n            incSinController>\r\n          </ion-input>\r\n        </ion-item>\r\n      </ion-col>\r\n    </ion-row>\r\n    <ion-col>\r\n      <ion-button expand=\"block\" fill=\"outline\" color=\"secondary\" (click)=\"openModal('name')\" id=\"patient-name-button\">\r\n        <ion-icon name=\"add\"></ion-icon>&nbsp;{{'NAME_L' | translate}}&nbsp;\r\n        <span class=\"required\">*</span>\r\n      </ion-button>\r\n    </ion-col>\r\n    <ion-row *ngIf=\"form.value.name.length > 0\">\r\n      <ion-col>\r\n        <span class=\"ion-text-uppercase\"> {{'NAME_L' | translate}} </span>\r\n        <ion-chip outline=\"true\" *ngFor=\"let name of form.value.name; let i = index\" id=\"patient-full-name\">\r\n          <ion-label color=\"primary\" *ngIf=\"i === 0\">{{name.text}}</ion-label>\r\n          <ion-label *ngIf=\"i !== 0\">{{name.text}}</ion-label>\r\n          <ion-icon name=\"close\" (click)=\"deleteFromFormArray('name', i)\"></ion-icon>\r\n        </ion-chip>\r\n      </ion-col>\r\n    </ion-row>\r\n    <ion-row class=\"ion-align-items-end\">\r\n      <ion-col size=\"12\" sizeMd=\"4\">\r\n        <ion-item>\r\n          <ion-label position=\"floating\">{{'BIRTH_DATE' | translate}} <span *ngIf=\"isRequired('birthDate')\"\r\n              class=\"required\">*</span>\r\n          </ion-label>\r\n          <ion-datetime displayFormat=\"YYYY.MM.DD\" formControlName=\"birthDate\" id=\"birth-date\"\r\n            doneText=\"{{'DONE' | translate}}\" cancelText=\"{{'CANCEL' | translate}}\">\r\n          </ion-datetime>\r\n        </ion-item>\r\n      </ion-col>\r\n      <ion-col size=\"12\" sizeMd=\"4\" formArrayName=\"extension\">\r\n        <ion-item formGroupName=\"0\">\r\n          <ion-label position=\"floating\">{{'MOTHER' | translate}} <span *ngIf=\"isRequired('extension.0.valueString')\"\r\n              class=\"required\">*</span>\r\n          </ion-label>\r\n          <ion-input id=\"mother-name\" type=\"text\" formControlName=\"valueString\" clearInput></ion-input>\r\n        </ion-item>\r\n      </ion-col>\r\n      <ion-col size=\"12\" sizeMd=\"4\" formArrayName=\"extension\">\r\n        <ion-item formGroupName=\"1\">\r\n          <ion-label position=\"floating\">{{'PLACE_OF_BIRTH' | translate}} <span\r\n              *ngIf=\"isRequired('extension.1.valueString')\" class=\"required\">*</span>\r\n          </ion-label>\r\n          <ion-input id=\"birthplace\" type=\"text\" formControlName=\"valueString\" clearInput></ion-input>\r\n        </ion-item>\r\n      </ion-col>\r\n    </ion-row>\r\n    <ion-col>\r\n      <ion-button expand=\"block\" fill=\"outline\" (click)=\"addDetails()\" id=\"plus-data-button\">\r\n        <ion-icon slot=\"start\" name=\"add\"></ion-icon>{{'DATA' | translate}}\r\n        <span *ngIf=\"hasOtherDatasRequiredModal\" class=\"required\">&nbsp;*</span>\r\n      </ion-button>\r\n    </ion-col>\r\n    <ion-row *ngIf=\"form.value.address.length > 0\">\r\n      <ion-col>\r\n        <span class=\"ion-text-uppercase\">{{'ADDRESS' | translate}}</span>\r\n        <ion-chip *ngFor=\"let addressElement of form.value.address; let i = index\" outline=\"true\"\r\n          id=\"patient-full-address\">\r\n          <ion-label>{{addressElement | address}}</ion-label>\r\n          <ion-icon name=\"close\" (click)=\"deleteFromFormArray('address', i)\"></ion-icon>\r\n        </ion-chip>\r\n      </ion-col>\r\n    </ion-row>\r\n    <ion-row *ngIf=\"form.value.telecom.length > 0\">\r\n      <ion-col>\r\n        <span class=\"ion-text-uppercase\">{{'AVAILABILITY' | translate}} </span>\r\n        <ion-chip *ngFor=\"let tel of form.value.telecom; let i = index\" outline=\"true\" id=\"patient-telecom\">\r\n          <ion-label color=\"primary\" *ngIf=\"i === 0\">{{tel.value}}</ion-label>\r\n          <ion-label *ngIf=\"i !== 0\">{{tel.value}}</ion-label>\r\n          <ion-icon name=\"close\" (click)=\"deleteFromFormArray('telecom', i)\"></ion-icon>\r\n        </ion-chip>\r\n      </ion-col>\r\n    </ion-row>\r\n    <ion-row *ngIf=\"form.value.contact.length > 0\">\r\n      <ion-col>\r\n        <ion-text class=\"ion-text-uppercase\">\r\n          <p> {{'CONTACT_PERSON' | translate}} </p>\r\n        </ion-text>\r\n        <ion-list lines=\"none\">\r\n          <ion-item *ngFor=\"let contact of form.value.contact; let i = index\" id=\"patient-contact\">\r\n            <ion-avatar slot=\"start\">\r\n              <div incMonoAvatar [name]=\"contact.name.text\"></div>\r\n            </ion-avatar>\r\n            <ion-label>\r\n              <h2>{{contact.name.text}}</h2>\r\n              <h3 *ngIf=\"contact.telecom[0].value\">{{contact.telecom[0].value}}</h3>\r\n              <p *ngIf=\"contact.telecom[1].value\">{{contact.telecom[1].value}}</p>\r\n            </ion-label>\r\n            <ion-buttons>\r\n              <ion-button (click)=\"deleteFromFormArray('contact', i)\">\r\n                <ion-icon slot=\"icon-only\" name=\"close\"></ion-icon>\r\n              </ion-button>\r\n            </ion-buttons>\r\n          </ion-item>\r\n        </ion-list>\r\n      </ion-col>\r\n    </ion-row>\r\n    <ion-row class=\"ion-float-right ion-margin-bottom ion-margin-top\">\r\n      <ion-button fill=\"outline\" color=\"primary\" id=\"basic-data-reject-button\" *ngIf=\"inData\" (click)=\"discard()\"\r\n        class=\"ion-margin-end\">\r\n        <ion-icon slot=\"start\" name=\"close\"></ion-icon>{{'REJECT_BUTTON' | translate}}\r\n      </ion-button>\r\n      <ion-button fill=\"outline\" *ngIf=\"!inData\" color=\"primary\" id=\"basic-data-reset-button\" (click)=\"reset()\"\r\n        class=\"ion-margin-end\">\r\n        <ion-icon slot=\"start\" name=\"refresh\"></ion-icon>{{'AGAIN_BUTTON' | translate}}\r\n      </ion-button>\r\n      <!-- ha invalid akkor disabled, ha ha addolunk m\u00E1r mentett\u00FCnk akkor is disabled (avoid multi add),\r\n      ha m\u00F3dos\u00EDtunk \u00E9s nem ny\u00FAltunk a formhoz, akkor is disabled, amint m\u00F3dos\u00EDtottunk valid a ment\u00E9s -->\r\n      <ion-button id=\"basic-data-save-button\" type=\"submit\"\r\n        [disabled]=\"form.invalid || (!inData && savePressed) || (inData && form.pristine)\">\r\n        <ion-icon slot=\"start\" name=\"save\"></ion-icon>{{'SAVE_BUTTON' | translate}}\r\n      </ion-button>\r\n    </ion-row>\r\n  </ion-grid>\r\n</form>",
                    styles: ["@media (min-width:768px){.radio-hor{display:flex;flex-direction:row}.radio-hor ion-item{width:100%}}"]
                }] }
    ];
    /** @nocollapse */
    PatientAddComponent.ctorParameters = function () { return [
        { type: ModalService },
        { type: ActionSheetController },
        { type: TranslatePipe },
        { type: AlertService }
    ]; };
    PatientAddComponent.propDecorators = {
        extraValidators: [{ type: Input }],
        modalParameters: [{ type: Input }]
    };
    return PatientAddComponent;
}(AbstractAddWmodalComponent));
export { PatientAddComponent };
if (false) {
    /** @type {?} */
    PatientAddComponent.prototype.extraValidators;
    /** @type {?} */
    PatientAddComponent.prototype.modalParameters;
    /** @type {?} */
    PatientAddComponent.prototype.genderList;
    /** @type {?} */
    PatientAddComponent.prototype.hasOtherDatasRequiredModal;
    /** @type {?} */
    PatientAddComponent.prototype.savePressed;
    /** @type {?} */
    PatientAddComponent.prototype.isRequiredField;
    /**
     * @type {?}
     * @private
     */
    PatientAddComponent.prototype.alertService;
}
//# sourceMappingURL=data:application/json;base64, 