import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Prop, Watch } 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 L10nPlugin from '../../utils/l10n/l10n';
import uuid from '../../utils/uuid/uuid';
import { ModulVue } from '../../utils/vue/vue';
import { DECIMALFIELD_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 './decimalfield.html?style=./decimalfield.scss';
var MDecimalfield = /** @class */ (function (_super) {
    __extends(MDecimalfield, _super);
    function MDecimalfield() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.validationMessageId = uuid.generate();
        _this.text = '';
        return _this;
    }
    Object.defineProperty(MDecimalfield.prototype, "hasDecimalfieldError", {
        get: function () {
            return this.as().hasError;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MDecimalfield.prototype, "isDecimalfieldValid", {
        get: function () {
            return this.as().isValid;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MDecimalfield.prototype, "inputMaskOptions", {
        get: function () {
            var decimalFormat = this.$l10n.getDecimalFormat(this.currentLocale);
            return {
                numeral: true,
                numeralThousandsGroupStyle: 'thousand',
                numeralIntegerScale: this.precision - this.rounding,
                numeralDecimalScale: this.rounding,
                numeralDecimalMark: decimalFormat.decimalMark,
                numeralPositiveOnly: true,
                stripLeadingZeroes: true,
                delimiter: decimalFormat.thousandSeparator,
                removeTrailingDecimalMark: true,
                forceDecimalScale: this.forceRoundingFormat
            };
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MDecimalfield.prototype, "currentLocale", {
        get: function () {
            return this.$i18n.currentLocale;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MDecimalfield.prototype, "model", {
        get: function () {
            return this.text;
        },
        set: function (value) {
            this.text = value;
            var valueAsNumber = Number.parseFloat(value);
            this.emitNewValue(valueAsNumber);
        },
        enumerable: false,
        configurable: true
    });
    MDecimalfield.prototype.onValueChange = function (newValue) {
        var currentTextAsNumber = Number.parseFloat(this.text);
        if (newValue !== currentTextAsNumber) {
            this.text = (!newValue && newValue !== 0 ? '' : newValue).toString();
        }
    };
    MDecimalfield.prototype.emitNewValue = function (_newValue) { };
    __decorate([
        Prop()
    ], MDecimalfield.prototype, "value", void 0);
    __decorate([
        Prop({
            default: 2
        })
    ], MDecimalfield.prototype, "rounding", void 0);
    __decorate([
        Prop({
            default: 14
        })
    ], MDecimalfield.prototype, "precision", void 0);
    __decorate([
        Prop({ default: false })
    ], MDecimalfield.prototype, "forceRoundingFormat", void 0);
    __decorate([
        Prop({ default: function () { return "mDecimalfield-" + uuid.generate(); } })
    ], MDecimalfield.prototype, "id", void 0);
    __decorate([
        Watch('value', { immediate: true })
    ], MDecimalfield.prototype, "onValueChange", null);
    __decorate([
        Emit('input')
    ], MDecimalfield.prototype, "emitNewValue", null);
    MDecimalfield = __decorate([
        WithRender,
        Component({
            mixins: [
                InputState,
                InputWidth,
                InputLabel,
                InputManagement
            ],
            components: {
                MInputMask: MInputMask,
                MValidationMessage: MValidationMessage,
                MInputStyle: MInputStyle
            }
        })
    ], MDecimalfield);
    return MDecimalfield;
}(ModulVue));
export { MDecimalfield };
var DecimalfieldPlugin = {
    install: function (v) {
        v.use(L10nPlugin);
        v.component(DECIMALFIELD_NAME, MDecimalfield);
    }
};
export default DecimalfieldPlugin;
//# sourceMappingURL=decimalfield.js.map