/**
 * This file is part of the MedSafe application which is commercial software created by MedVision360 B.V.
 * The source code is proprietary and confidential.
 *
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 *
 * Copyright (c) by MedVision360 B.V. All rights reserved.
 *
 * For the application name: io.medrecord.medsafe
 */
import { __decorate, __param } from "tslib";
import { Component, HostBinding, Input, Optional, Self, ViewChild } from '@angular/core';
import { NgControl } from '@angular/forms';
import { showError } from '../../../../../core/utils/form-controls.util';
import { MomentDateFormat } from '../../../../../core/constants/shared-constants';
import { parseFloatString } from '../../../../../core/utils/common.util';
import { dateTimePickerType, dateTimePickerView, IconType, inputControlType, inputValueType } from '../../../../models';
var InputComponent = /** @class */ (function () {
    function InputComponent(ngControl) {
        this.ngControl = ngControl;
        this.defaultOptions = {
            dateTimePickerType: dateTimePickerType.calendar,
            dateTimePickerView: dateTimePickerView.full,
            type: inputControlType.text,
            dateTimeDisplayFormat: MomentDateFormat.display,
            dateTimeStorageFormat: MomentDateFormat.storageDateTime,
        };
        this.preparedOptions = this.defaultOptions;
        // Label props
        // Todo move label from input
        this.hint = '';
        // Label props end
        this.inputWidth = null;
        this.placeholder = '';
        this.formControlStyles = true;
        this.isDisabled = false;
        this.showPasswordString = false;
        this.marginBottom = false;
        this.maxSelectableDate = null;
        this.onChange = function () { };
        this.onTouched = function () { };
        if (ngControl) {
            ngControl.valueAccessor = this;
        }
    }
    Object.defineProperty(InputComponent.prototype, "options", {
        set: function (options) {
            this.preparedOptions = Object.assign({}, this.defaultOptions, options);
        },
        enumerable: true,
        configurable: true
    });
    InputComponent.prototype.valueChange = function (value) {
        if (this.inputType) {
            this.convertToInputType(value);
            return;
        }
        this.onChange(value.trim());
    };
    InputComponent.prototype.convertToInputType = function (value) {
        switch (this.inputType) {
            case inputValueType.float: {
                this.onChange(parseFloatString(value));
                break;
            }
        }
    };
    InputComponent.prototype.ngAfterViewInit = function () {
        if (this.inputElementRef) {
            this.inputElementRef.nativeElement.disabled = this.isDisabled;
        }
    };
    Object.defineProperty(InputComponent.prototype, "inputId", {
        get: function () {
            return this.ngControl ? this.ngControl.name : null;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(InputComponent.prototype, "isPasswordInput", {
        get: function () {
            return this.preparedOptions.type === inputControlType.password;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(InputComponent.prototype, "preparedLeftIcon", {
        get: function () {
            if (this.isPasswordInput) {
                return IconType.lock;
            }
            return this.preparedOptions.iconLeft;
        },
        enumerable: true,
        configurable: true
    });
    InputComponent.prototype.onIconClick = function () {
        return this.isPasswordInput && this.setShowPasswordString(!this.showPasswordString);
    };
    Object.defineProperty(InputComponent.prototype, "showError", {
        get: function () {
            return this.ngControl ? showError(this.ngControl.errors, this.ngControl.touched) : false;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(InputComponent.prototype, "preparedInputType", {
        get: function () {
            if (this.showPasswordString) {
                return inputControlType.text;
            }
            return this.preparedOptions.type;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(InputComponent.prototype, "warningIcon", {
        get: function () {
            return IconType.warning;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(InputComponent.prototype, "preparedIconRight", {
        get: function () {
            if (this.isPasswordInput) {
                return this.showPasswordString ? IconType.eye : IconType.eyeCrossed;
            }
            return this.preparedOptions.iconRight;
        },
        enumerable: true,
        configurable: true
    });
    InputComponent.prototype.setShowPasswordString = function (value) {
        this.showPasswordString = value;
    };
    // ControlValueAccessor implementations
    InputComponent.prototype.writeValue = function (value) {
        var _this = this;
        setTimeout(function () {
            if (_this.inputElementRef) {
                _this.inputElementRef.nativeElement.value = value;
            }
        });
    };
    InputComponent.prototype.registerOnChange = function (fn) {
        this.onChange = fn;
    };
    InputComponent.prototype.registerOnTouched = function (fn) {
        this.onTouched = fn;
    };
    InputComponent.prototype.setDisabledState = function (disabled) {
        this.isDisabled = disabled;
    };
    InputComponent.ctorParameters = function () { return [
        { type: NgControl, decorators: [{ type: Self }, { type: Optional }] }
    ]; };
    __decorate([
        ViewChild('input')
    ], InputComponent.prototype, "inputElementRef", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "options", null);
    __decorate([
        Input()
    ], InputComponent.prototype, "disabledTo", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "disabledAfter", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "description", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "hint", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "label", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "labelDescription", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "setDateNow", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "inputWidth", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "placeholder", void 0);
    __decorate([
        HostBinding('class.form-control-styles'), Input()
    ], InputComponent.prototype, "formControlStyles", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "isDisabled", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "marginBottom", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "maxSelectableDate", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "inputType", void 0);
    __decorate([
        Input()
    ], InputComponent.prototype, "dateTimePickerStartsWithYear", void 0);
    InputComponent = __decorate([
        Component({
            selector: 'app-input',
            template: "<!--~\n  ~ This file is part of the MedSafe application which is commercial software created by MedVision360 B.V.\n  ~ The source code is proprietary and confidential.\n  ~ Unauthorized copying of this file, via any medium is strictly prohibited.\n  ~\n  ~ Copyright (c) by MedVision360 B.V. All rights reserved.\n  ~\n  ~ For the application name: io.medrecord.medsafe\n  ~-->\n\n<app-label\n  [label]=\"label\"\n  [labelDescription]=\"labelDescription\"\n  [hint]=\"hint\"\n  [fieldId]=\"inputId\"\n></app-label>\n\n<app-date-time-input  *ngIf=\"preparedOptions.type|inputType:'datetime'\"\n                      [dateTimeDisplayFormat]=\"preparedOptions.dateTimeDisplayFormat\"\n                      [dateTimePickerView]=\"preparedOptions.dateTimePickerView\"\n                      [dateTimePickerType]=\"preparedOptions.dateTimePickerType\"\n                      [dateTimeStorageFormat]=\"preparedOptions.dateTimeStorageFormat\"\n                      [inputWidth]=\"inputWidth\"\n                      [setDateNow]=\"setDateNow\"\n                      [isDisabled]=\"isDisabled\"\n                      [disabledTo]=\"disabledTo\"\n                      [disabledAfter]=\"disabledAfter\"\n                      [wrapperControl]=\"ngControl\"\n></app-date-time-input>\n\n<div *ngIf=\"!(preparedOptions.type|inputType:'datetime')\"\n class=\"input-wrapper\"\n [style.max-width.px]=\"inputWidth\"\n>\n  <app-icon class=\"icon-left\" *ngIf=\"preparedLeftIcon\" [icon]=\"preparedLeftIcon\"></app-icon>\n\n  <input #input\n         class=\"input\"\n         [placeholder]=\"placeholder\"\n         [max]=\"maxSelectableDate\"\n         [ngClass]=\"{\n          'input_icon-left': preparedLeftIcon,\n          'input_icon-right': preparedIconRight || showError,\n          'input_icon-right-double': preparedIconRight && showError,\n          'input_warning': showError\n         }\"\n         [type]=\"preparedInputType\"\n         [id]=\"inputId\"\n         [disabled]=\"isDisabled\"\n         (input)=\"valueChange($event.target.value)\"\n         (blur)=\"onTouched()\"\n  />\n\n  <span class=\"icon-right\">\n    <span>\n      <app-icon\n        *ngIf=\"preparedIconRight\"\n        (click)=\"onIconClick()\"\n        [icon]=\"preparedIconRight\"></app-icon>\n    </span>\n  </span>\n\n  <span\n    [ngClass]=\"{'icon-warning_optional-offset': preparedIconRight}\"\n    class=\"icon-warning\"\n    *ngIf=\"showError\"\n  >\n    <app-icon [icon]=\"warningIcon\"></app-icon>\n  </span>\n</div>\n\n<app-input-errors\n  *ngIf=\"!(preparedOptions.type|inputType:'datetime') && ngControl && ngControl.errors && ngControl.touched\"\n  [errors]=\"ngControl.errors\"\n  [touched]=\"ngControl.touched\"\n></app-input-errors>\n",
            styles: [":host{display:block}:host .input-wrapper{width:100%;position:relative}:host .input-wrapper_no-margin{margin-bottom:0}:host.form-control-styles{margin-bottom:24px}:host .icon-left{position:absolute;top:50%;transform:translate(0,-50%);left:20px}:host .input-warning{position:absolute;top:50%;transform:translate(0,-50%);left:20px}:host .icons-right{position:absolute;top:50%;transform:translate(0,-50%);right:16px;display:flex;align-items:center}:host .icons-right>*{width:16px;margin-left:8px}:host .description{position:absolute;top:50%;transform:translate(0,-50%);margin-left:20px;white-space:nowrap}:host .input{background-color:var(--athens-darken-color);border-radius:5px;border:2px solid transparent;outline:0;color:var(--cape-cod-color);height:40px;width:100%;padding:0 17px;box-sizing:border-box;font-size:13px;font-weight:500}:host .input::-webkit-input-placeholder{color:var(--secondary-color)}:host .input::-moz-placeholder{color:var(--secondary-color)}:host .input:-ms-input-placeholder{color:var(--secondary-color)}:host .input:-moz-placeholder{color:var(--secondary-color)}:host .input:hover{border-color:var(--athens-darken-hover-color);background-color:var(--athens-darken-hover-color)}:host .input:focus{border-color:var(--geyser-color);background-color:var(--white-color)}:host .input_warning{border-color:var(--warning-color)!important;background-color:var(--athens-darken-color)}:host .input_warning:focus{border-color:var(--geyser-color)!important;background-color:var(--white-color)}:host .input_warning:hover{border-color:var(--warning-hover-color)!important;background-color:var(--athens-darken-hover-color)}:host .input_icon-left{padding-left:56px}:host .input_icon-right-triple{padding-right:88px!important}:host .input_icon-right-double{padding-right:64px!important}:host .input_icon-right{padding-right:40px}"]
        }),
        __param(0, Self()), __param(0, Optional())
    ], InputComponent);
    return InputComponent;
}());
export { InputComponent };
//# sourceMappingURL=data:application/json;base64, 