/**
 * @fileoverview added by tsickle
 * Generated from: lib/attribute/attribute.component.ts
 * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
 */
import { Component, Input, ViewChild } from '@angular/core';
import { AttributeBase } from './attribute-base';
import { FormGroup } from '@angular/forms';
import { SearchHelpComponent } from '../search-help/search-help.component';
var AttributeComponent = /** @class */ (function () {
    function AttributeComponent() {
    }
    /**
     * @return {?}
     */
    AttributeComponent.prototype.ngOnInit = /**
     * @return {?}
     */
    function () {
        /** @type {?} */
        var fieldCtrl = this.formGroup.get(this.attributeControl.name);
        switch (this.attributeControl.controlType) {
            case 'timestamp':
                if (!this.readonly && !fieldCtrl.value) {
                    /** @type {?} */
                    var currentTimestamp = new Date();
                    fieldCtrl.setValue(currentTimestamp.getFullYear() + '-' + ('0' + (currentTimestamp.getMonth() + 1)).slice(-2) + '-'
                        + ('0' + currentTimestamp.getDate()).slice(-2) + ' ' + ('0' + currentTimestamp.getHours()).slice(-2) +
                        ':' + ('0' + currentTimestamp.getMinutes()).slice(-2) + ':' + ('0' + currentTimestamp.getSeconds()).slice(-2));
                    fieldCtrl.markAsDirty();
                }
                break;
            case 'date':
                if (!this.readonly && !fieldCtrl.value) {
                    /** @type {?} */
                    var currentDate = new Date();
                    fieldCtrl.setValue(currentDate.getFullYear() + '-' + ('0' + (currentDate.getMonth() + 1)).slice(-2) + '-'
                        + ('0' + currentDate.getDate()).slice(-2));
                    fieldCtrl.markAsDirty();
                }
                break;
            default:
        }
    };
    /**
     * @return {?}
     */
    AttributeComponent.prototype.ngOnChanges = /**
     * @return {?}
     */
    function () {
        if (this.attributeControl.controlType === 'dropdown' ||
            this.attributeControl.controlType === 'checkbox') {
            this.readonly ? this.formGroup.get(this.attributeControl.name).disable() :
                this.formGroup.get(this.attributeControl.name).enable();
        }
    };
    Object.defineProperty(AttributeComponent.prototype, "invalid", {
        get: /**
         * @return {?}
         */
        function () { return this.formGroup.controls[this.attributeControl.name].invalid; },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AttributeComponent.prototype, "errorMessage", {
        get: /**
         * @return {?}
         */
        function () {
            /** @type {?} */
            var fieldCtrl = this.formGroup.get(this.attributeControl.name);
            if (fieldCtrl.getError('pattern')) {
                return 'The pattern is not correct';
            }
            else if (fieldCtrl.getError('required')) {
                return 'Required';
            }
            else if (fieldCtrl.getError('message')) {
                return fieldCtrl.getError('message');
            }
            else {
                return null;
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(AttributeComponent.prototype, "isReadonly", {
        get: /**
         * @return {?}
         */
        function () { return this.readonly || this.attributeControl.autoIncrement; },
        enumerable: true,
        configurable: true
    });
    /**
     * @param {?} attributeName
     * @return {?}
     */
    AttributeComponent.prototype.onKeyup = /**
     * @param {?} attributeName
     * @return {?}
     */
    function (attributeName) {
        /** @type {?} */
        var fieldCtrl = this.formGroup.get(attributeName);
        fieldCtrl.setValue(fieldCtrl.value.toUpperCase());
    };
    /**
     * @param {?} attributeControl
     * @return {?}
     */
    AttributeComponent.prototype.onSearchHelp = /**
     * @param {?} attributeControl
     * @return {?}
     */
    function (attributeControl) {
        this.searchHelpComponent.openSearchHelpModalByEntity(attributeControl.domainEntityId, attributeControl.domainRelationId, this.formGroup, this.readonly, attributeControl.name, attributeControl.domainId);
    };
    AttributeComponent.decorators = [
        { type: Component, args: [{
                    selector: 'dk-app-attribute',
                    template: "<div [formGroup]=\"formGroup\">\n  <div [ngSwitch]=\"attributeControl.controlType\">\n    <div class=\"input-group\">\n      <input *ngSwitchCase=\"'text'\" type=\"text\" class=\"form-control\"\n             [class.form-control-sm] = \"isSmallSize\"\n             [formControlName]=\"attributeControl.name\"\n             [id]=\"attributeControl.key\"\n             [maxlength]=\"attributeControl.maxLength\"\n             [pattern]=\"attributeControl.pattern\"\n             [readonly]=\"isReadonly\" >\n      <input *ngSwitchCase=\"'text_capital'\" type=\"text\" class=\"form-control\"\n             [class.form-control-sm] = \"isSmallSize\"\n             [formControlName]=\"attributeControl.name\"\n             [id]=\"attributeControl.key\"\n             [maxlength]=\"attributeControl.maxLength\"\n             (keyup)=\"onKeyup(attributeControl.name)\"\n             [readonly]=\"isReadonly\" >\n      <input *ngSwitchCase=\"'integer'\" type=\"number\" class=\"form-control\"\n             [class.form-control-sm] = \"isSmallSize\"\n             [formControlName]=\"attributeControl.name\"\n             [id]=\"attributeControl.key\"\n             [pattern]=\"attributeControl.pattern\"\n             [readonly]=\"isReadonly\" >\n      <div *ngIf=\"attributeControl.searchHelpId || attributeControl.domainRelationId\" class=\"input-group-append\">\n        <button class=\"btn btn-outline-secondary btn-sm\" type=\"button\" (click)=\"onSearchHelp(attributeControl)\">\n          <span class=\"fas fa-search\"></span>\n        </button>\n      </div>\n    </div>\n    <input *ngSwitchCase=\"'decimal'\" type=\"number\" class=\"form-control\"\n           [class.form-control-sm] = \"isSmallSize\"\n           [formControlName]=\"attributeControl.name\"\n           [id]=\"attributeControl.key\"\n           [step]=\"attributeControl.step\"\n           [placeholder]=\"attributeControl.placeholder\"\n           [pattern]=\"attributeControl.pattern\"\n           [readonly]=\"isReadonly\" >\n    <input *ngSwitchCase=\"'checkbox'\" type=\"checkbox\" class=\"form-control\"\n           [class.form-control-sm] = \"isSmallSize\"\n           [formControlName]=\"attributeControl.name\"\n           [id]=\"attributeControl.key\">\n    <input *ngSwitchCase=\"'textarea'\" type=\"textarea\" class=\"form-control\"\n           [class.form-control-sm] = \"isSmallSize\"\n           [formControlName]=\"attributeControl.name\"\n           [id]=\"attributeControl.key\"\n           [readonly]=\"isReadonly\" >\n    <input *ngSwitchCase=\"'file'\" type=\"file\" class=\"form-control\"\n           [class.form-control-sm] = \"isSmallSize\"\n           [formControlName]=\"attributeControl.name\"\n           [id]=\"attributeControl.key\"\n           [readonly]=\"isReadonly\" >\n    <input *ngSwitchCase=\"'date'\" type=\"date\" class=\"form-control\"\n           [class.form-control-sm] = \"isSmallSize\"\n           [formControlName]=\"attributeControl.name\"\n           [id]=\"attributeControl.key\"\n           [readonly]=\"isReadonly\" >\n    <input *ngSwitchCase=\"'timestamp'\" type=\"text\" class=\"form-control\"\n           [class.form-control-sm] = \"isSmallSize\"\n           [formControlName]=\"attributeControl.name\"\n           [id]=\"attributeControl.key\"\n           [readonly]=\"isReadonly\" >\n    <select *ngSwitchCase=\"'dropdown'\" class=\"form-control\"\n            [class.form-control-sm] = \"isSmallSize\"\n            [formControlName]=\"attributeControl.name\"\n            [id]=\"attributeControl.key\">\n      <option *ngFor=\"let opt of attributeControl.dropdownList\" [value]=\"opt.key\">{{opt.value}}</option>\n    </select>\n  </div>\n\n  <div *ngIf=\"!noErrorMsg\" [class.ng-invalid]=\"invalid\" class=\"dk-invalid-feedback\">\n    {{errorMessage}}\n  </div>\n</div>\n\n<dk-app-search-help></dk-app-search-help>\n",
                    styles: [""]
                }] }
    ];
    /** @nocollapse */
    AttributeComponent.ctorParameters = function () { return []; };
    AttributeComponent.propDecorators = {
        attributeControl: [{ type: Input }],
        formGroup: [{ type: Input }],
        readonly: [{ type: Input }],
        isSmallSize: [{ type: Input }],
        noErrorMsg: [{ type: Input }],
        searchHelpComponent: [{ type: ViewChild, args: [SearchHelpComponent, { static: false },] }]
    };
    return AttributeComponent;
}());
export { AttributeComponent };
if (false) {
    /** @type {?} */
    AttributeComponent.prototype.attributeControl;
    /** @type {?} */
    AttributeComponent.prototype.formGroup;
    /** @type {?} */
    AttributeComponent.prototype.readonly;
    /** @type {?} */
    AttributeComponent.prototype.isSmallSize;
    /** @type {?} */
    AttributeComponent.prototype.noErrorMsg;
    /**
     * @type {?}
     * @private
     */
    AttributeComponent.prototype.searchHelpComponent;
}
//# sourceMappingURL=data:application/json;base64, 