import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Model, Prop, Watch } from 'vue-property-decorator';
import { InputState } from '../../mixins/input-state/input-state';
import { Enums } from '../../utils/enums/enums';
import uuid from '../../utils/uuid/uuid';
import { ModulVue } from '../../utils/vue/vue';
import { CHECKBOX_NAME } from '../component-names';
import { MValidationMessage } from '../validation-message/validation-message';
import WithRender from './checkbox.html?style=./checkbox.scss';
export var MCheckboxPosition;
(function (MCheckboxPosition) {
    MCheckboxPosition["Left"] = "left";
    MCheckboxPosition["Right"] = "right";
})(MCheckboxPosition || (MCheckboxPosition = {}));
export var MCheckboxVerticalAlignement;
(function (MCheckboxVerticalAlignement) {
    MCheckboxVerticalAlignement["Center"] = "center";
    MCheckboxVerticalAlignement["Top"] = "top";
})(MCheckboxVerticalAlignement || (MCheckboxVerticalAlignement = {}));
var MCheckbox = /** @class */ (function (_super) {
    __extends(MCheckbox, _super);
    function MCheckbox() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.validationMessageId = uuid.generate();
        _this.isFocus = false;
        _this.internalValue = false;
        return _this;
    }
    MCheckbox.prototype.onChange = function (value) { };
    MCheckbox.prototype.onClick = function (event) {
        // NOTE: Edge does not change the checkbox value when indeterminate="true"
        if (this.propIndeterminate) {
            this.propValue = true;
            event.preventDefault();
        }
    };
    MCheckbox.prototype.onValueChange = function (value) {
        this.internalValue = value;
    };
    Object.defineProperty(MCheckbox.prototype, "propValue", {
        get: function () {
            return this.value !== undefined ? this.value : this.internalValue;
        },
        set: function (value) {
            this.onChange(value);
            this.internalValue = value;
        },
        enumerable: false,
        configurable: true
    });
    MCheckbox.prototype.setFocus = function (value) {
        this.isFocus = value;
    };
    Object.defineProperty(MCheckbox.prototype, "propIndeterminate", {
        get: function () {
            return this.indeterminate && !this.propValue;
        },
        set: function (newValue) {
            this.indeterminate = newValue;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MCheckbox.prototype, "hasCheckboxLeft", {
        get: function () {
            return this.position === MCheckboxPosition.Left;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MCheckbox.prototype, "isAlignTop", {
        get: function () {
            return this.verticalAlign === MCheckboxVerticalAlignement.Top;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MCheckbox.prototype, "forId", {
        get: function () {
            if (this.as().readonly) {
                return undefined;
            }
            else {
                return this.id;
            }
        },
        enumerable: false,
        configurable: true
    });
    __decorate([
        Model('change'),
        Prop()
    ], MCheckbox.prototype, "value", void 0);
    __decorate([
        Prop({
            default: function () { return "mCheckbox-" + uuid.generate(); }
        })
    ], MCheckbox.prototype, "id", void 0);
    __decorate([
        Prop({ default: false })
    ], MCheckbox.prototype, "indeterminate", void 0);
    __decorate([
        Prop({
            default: MCheckboxPosition.Left,
            validator: function (value) { return Enums.toValueArray(MCheckboxPosition).includes(value); }
        })
    ], MCheckbox.prototype, "position", void 0);
    __decorate([
        Prop({
            default: MCheckboxVerticalAlignement.Center,
            validator: function (value) { return Enums.toValueArray(MCheckboxVerticalAlignement).includes(value); }
        })
    ], MCheckbox.prototype, "verticalAlign", void 0);
    __decorate([
        Prop()
    ], MCheckbox.prototype, "ariaLabel", void 0);
    __decorate([
        Prop()
    ], MCheckbox.prototype, "focused", void 0);
    __decorate([
        Emit('change')
    ], MCheckbox.prototype, "onChange", null);
    __decorate([
        Emit('click')
    ], MCheckbox.prototype, "onClick", null);
    __decorate([
        Watch('value')
    ], MCheckbox.prototype, "onValueChange", null);
    MCheckbox = __decorate([
        WithRender,
        Component({
            components: {
                MValidationMessage: MValidationMessage
            },
            mixins: [InputState]
        })
    ], MCheckbox);
    return MCheckbox;
}(ModulVue));
export { MCheckbox };
var CheckboxPlugin = {
    install: function (v, options) {
        v.prototype.$log.debug(CHECKBOX_NAME, 'plugin.install');
        v.component(CHECKBOX_NAME, MCheckbox);
    }
};
export default CheckboxPlugin;
//# sourceMappingURL=checkbox.js.map