import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Model, Prop, Watch } from 'vue-property-decorator';
import { ModulVue } from '../../utils/vue/vue';
var InputManagement = /** @class */ (function (_super) {
    __extends(InputManagement, _super);
    function InputManagement() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.trimWordWrap = false;
        _this.internalValue = '';
        _this.internalIsFocus = false;
        return _this;
    }
    InputManagement.prototype.emitClick = function (event) { };
    InputManagement.prototype.emitInput = function (internalValue) { };
    InputManagement.prototype.emitFocus = function (event) { };
    InputManagement.prototype.emitBlur = function (event) { };
    InputManagement.prototype.emitKeyup = function (event, model) { };
    InputManagement.prototype.emitKeydown = function (event) { };
    InputManagement.prototype.emitChange = function (model) { };
    InputManagement.prototype.emitPaste = function (event) { };
    InputManagement.prototype.mounted = function () {
        if (this.focus) {
            this.focusChanged(this.focus);
        }
    };
    InputManagement.prototype.focusInput = function () {
        var inputEl = this.as().getInput();
        if (!inputEl) {
            return;
        }
        inputEl.focus();
    };
    Object.defineProperty(InputManagement.prototype, "hasValue", {
        get: function () {
            return !!(this.model || '').toString().trim();
        },
        enumerable: false,
        configurable: true
    });
    InputManagement.prototype.onClick = function (event) {
        this.internalIsFocus = this.as().active;
        var inputEl = this.as().getInput();
        if (this.internalIsFocus && inputEl) {
            inputEl.focus();
        }
        this.emitClick(event);
    };
    InputManagement.prototype.onFocus = function (event) {
        this.internalIsFocus = this.as().active;
        if (this.internalIsFocus) {
            this.emitFocus(event);
        }
    };
    InputManagement.prototype.onBlur = function (event) {
        this.internalIsFocus = false;
        this.emitBlur(event);
    };
    InputManagement.prototype.onKeyup = function (event) {
        if (this.as().active) {
            this.emitKeyup(event, this.model);
        }
    };
    InputManagement.prototype.onKeydown = function (event) {
        if (this.as().active) {
            this.emitKeydown(event);
        }
    };
    InputManagement.prototype.onChange = function (event) {
        this.emitChange(this.model);
    };
    InputManagement.prototype.onPaste = function (event) {
        this.emitPaste(event);
    };
    InputManagement.prototype.getTrimValue = function (value) {
        return /\n/g.test(value) && this.trimWordWrap ? value.replace(/\n/g, '') : value;
    };
    Object.defineProperty(InputManagement.prototype, "model", {
        get: function () {
            return this.internalValue;
        },
        set: function (value) {
            this.internalValue = this.getTrimValue(value);
            this.emitInput(this.internalValue);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputManagement.prototype, "isEmpty", {
        get: function () {
            return !this.isFocus && !this.hasValue && !Boolean(this.placeholder);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputManagement.prototype, "isFocus", {
        get: function () {
            return this.internalIsFocus;
        },
        enumerable: false,
        configurable: true
    });
    InputManagement.prototype.onValueChange = function (value) {
        this.internalValue = this.getTrimValue(this.value || '');
    };
    InputManagement.prototype.focusChanged = function (focus) {
        this.internalIsFocus = focus && this.as().active;
        var inputEl = this.as().getInput();
        if (inputEl) {
            if (this.internalIsFocus) {
                inputEl.focus();
            }
            else {
                inputEl.blur();
            }
        }
    };
    __decorate([
        Prop(),
        Model('input')
    ], InputManagement.prototype, "value", void 0);
    __decorate([
        Prop()
    ], InputManagement.prototype, "placeholder", void 0);
    __decorate([
        Prop()
    ], InputManagement.prototype, "autocomplete", void 0);
    __decorate([
        Prop()
    ], InputManagement.prototype, "focus", void 0);
    __decorate([
        Emit('click')
    ], InputManagement.prototype, "emitClick", null);
    __decorate([
        Emit('input')
    ], InputManagement.prototype, "emitInput", null);
    __decorate([
        Emit('focus')
    ], InputManagement.prototype, "emitFocus", null);
    __decorate([
        Emit('blur')
    ], InputManagement.prototype, "emitBlur", null);
    __decorate([
        Emit('keyup')
    ], InputManagement.prototype, "emitKeyup", null);
    __decorate([
        Emit('keydown')
    ], InputManagement.prototype, "emitKeydown", null);
    __decorate([
        Emit('change')
    ], InputManagement.prototype, "emitChange", null);
    __decorate([
        Emit('paste')
    ], InputManagement.prototype, "emitPaste", null);
    __decorate([
        Watch('value', { immediate: true })
    ], InputManagement.prototype, "onValueChange", null);
    __decorate([
        Watch('focus')
    ], InputManagement.prototype, "focusChanged", null);
    InputManagement = __decorate([
        Component
    ], InputManagement);
    return InputManagement;
}(ModulVue));
export { InputManagement };
//# sourceMappingURL=input-management.js.map