import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Prop } from 'vue-property-decorator';
import { InputLabel } from '../../mixins/input-label/input-label';
import { InputManagement } from '../../mixins/input-management/input-management';
import { InputState } from '../../mixins/input-state/input-state';
import { InputWidth } from '../../mixins/input-width/input-width';
import uuid from '../../utils/uuid/uuid';
import { ModulVue } from '../../utils/vue/vue';
import { INTEGERFIELD_NAME } from '../component-names';
import { MInputMask } from '../input-mask/input-mask';
import { MInputStyle } from '../input-style/input-style';
import { MValidationMessage } from '../validation-message/validation-message';
import WithRender from './integerfield.html?style=./integerfield.scss';
var MIntegerfield = /** @class */ (function (_super) {
    __extends(MIntegerfield, _super);
    function MIntegerfield() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.validationMessageId = uuid.generate();
        return _this;
    }
    Object.defineProperty(MIntegerfield.prototype, "hasDecimalfieldError", {
        get: function () {
            return this.as().hasError;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MIntegerfield.prototype, "isDecimalfieldValid", {
        get: function () {
            return this.as().isValid;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MIntegerfield.prototype, "inputMaskOptions", {
        get: function () {
            return {
                numeral: true,
                numeralThousandsGroupStyle: 'none',
                numeralIntegerScale: this.maxLength,
                numeralDecimalScale: 0,
                numeralDecimalMark: '',
                numeralPositiveOnly: true,
                stripLeadingZeroes: true,
                delimiter: ''
            };
        },
        enumerable: false,
        configurable: true
    });
    MIntegerfield.prototype.emitInput = function (_value) { };
    MIntegerfield.prototype.emitUpdateValue = function (_value) { };
    MIntegerfield.prototype.emitChange = function (_event) { };
    MIntegerfield.prototype.onChange = function (event) {
        this.clamp();
        this.emitChange(event);
    };
    MIntegerfield.prototype.clamp = function () {
        var value = Number.parseFloat(this.model);
        if (this.min && value < this.min) {
            value = this.min;
        }
        else if (this.max && value > this.max) {
            value = this.max;
        }
        this.model = value.toString();
        this.emitUpdateValue(value);
    };
    Object.defineProperty(MIntegerfield.prototype, "currentLocale", {
        get: function () {
            return this.$i18n.currentLocale;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MIntegerfield.prototype, "model", {
        get: function () {
            return (!this.value && this.value !== 0 ? '' : this.value).toString();
        },
        set: function (value) {
            this.emitInput(Number.parseFloat(value));
        },
        enumerable: false,
        configurable: true
    });
    MIntegerfield.prototype.created = function () {
        this.clamp();
    };
    __decorate([
        Prop()
    ], MIntegerfield.prototype, "value", void 0);
    __decorate([
        Prop()
    ], MIntegerfield.prototype, "min", void 0);
    __decorate([
        Prop()
    ], MIntegerfield.prototype, "max", void 0);
    __decorate([
        Prop({
            default: 16,
            validator: function (value) {
                if (!(typeof value === 'number')) {
                    return false;
                }
                if (!isNaN(value) && value <= 16) {
                    return true;
                }
                return false;
            }
        })
    ], MIntegerfield.prototype, "maxLength", void 0);
    __decorate([
        Prop({ default: function () { return "mIntegerfield-" + uuid.generate(); } })
    ], MIntegerfield.prototype, "id", void 0);
    __decorate([
        Emit('input')
    ], MIntegerfield.prototype, "emitInput", null);
    __decorate([
        Emit('update:value')
    ], MIntegerfield.prototype, "emitUpdateValue", null);
    __decorate([
        Emit('change')
    ], MIntegerfield.prototype, "emitChange", null);
    MIntegerfield = __decorate([
        WithRender,
        Component({
            mixins: [
                InputState,
                InputWidth,
                InputLabel,
                InputManagement
            ],
            components: {
                MInputMask: MInputMask,
                MInputStyle: MInputStyle,
                MValidationMessage: MValidationMessage
            }
        })
    ], MIntegerfield);
    return MIntegerfield;
}(ModulVue));
export { MIntegerfield };
var IntegerfieldPlugin = {
    install: function (v) {
        v.component(INTEGERFIELD_NAME, MIntegerfield);
    }
};
export default IntegerfieldPlugin;
//# sourceMappingURL=integerfield.js.map