import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Prop } from 'vue-property-decorator';
import { ModulVue } from '../../utils/vue/vue';
export var InputStateValue;
(function (InputStateValue) {
    InputStateValue["Default"] = "default";
    InputStateValue["Disabled"] = "disabled";
    InputStateValue["Readonly"] = "readonly";
    InputStateValue["Waiting"] = "waiting";
    InputStateValue["Error"] = "error";
    InputStateValue["Valid"] = "valid";
})(InputStateValue || (InputStateValue = {}));
export var InputStateTagStyle;
(function (InputStateTagStyle) {
    InputStateTagStyle["Default"] = "default";
    InputStateTagStyle["H1"] = "h1";
    InputStateTagStyle["H2"] = "h2";
    InputStateTagStyle["H3"] = "h3";
    InputStateTagStyle["H4"] = "h4";
    InputStateTagStyle["H5"] = "h5";
    InputStateTagStyle["H6"] = "h6";
    InputStateTagStyle["P"] = "p";
})(InputStateTagStyle || (InputStateTagStyle = {}));
var InputState = /** @class */ (function (_super) {
    __extends(InputState, _super);
    function InputState() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Object.defineProperty(InputState.prototype, "active", {
        get: function () {
            return !this.isDisabled && !this.isWaiting && !this.readonly;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "isDisabled", {
        get: function () {
            return this.state === InputStateValue.Disabled;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "isReadonly", {
        get: function () {
            return this.state === InputStateValue.Readonly;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "isWaiting", {
        get: function () {
            return this.state === InputStateValue.Waiting;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "hasError", {
        get: function () {
            return this.state === InputStateValue.Error;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "isValid", {
        get: function () {
            return this.state === InputStateValue.Valid;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "state", {
        get: function () {
            if (this.waiting) {
                return InputStateValue.Waiting;
            }
            if (this.readonly) {
                return InputStateValue.Readonly;
            }
            if (this.disabled) {
                return InputStateValue.Disabled;
            }
            if (this.hasErrorMessage || this.error) {
                return InputStateValue.Error;
            }
            if (this.hasValidMessage || this.valid) {
                return InputStateValue.Valid;
            }
            return InputStateValue.Default;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "hasErrorMessage", {
        get: function () {
            return (!!this.errorMessage || this.errorMessage === ' ') && !this.disabled && !this.waiting;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "hasValidMessage", {
        get: function () {
            return (!!this.validMessage || this.validMessage === ' ') && !this.disabled && !this.waiting && !this.hasErrorMessage;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "hasHelperMessage", {
        get: function () {
            return (!!this.helperMessage || this.helperMessage === ' ') && !this.disabled && !this.waiting;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(InputState.prototype, "hasValidationMessage", {
        get: function () {
            return (this.hasErrorMessage || this.hasValidMessage || this.hasHelperMessage) && this.active;
        },
        enumerable: false,
        configurable: true
    });
    InputState.prototype.getInput = function () {
        var selector = this.as().selector || 'input, textarea, [contenteditable=true]';
        var elements = this.$el.querySelectorAll(selector);
        if (elements.length > 1) {
            throw new Error("Input state can manage 1 and only 1 nested editable element (" + selector + ")");
        }
        return elements[0];
    };
    __decorate([
        Prop()
    ], InputState.prototype, "disabled", void 0);
    __decorate([
        Prop()
    ], InputState.prototype, "waiting", void 0);
    __decorate([
        Prop()
    ], InputState.prototype, "error", void 0);
    __decorate([
        Prop()
    ], InputState.prototype, "valid", void 0);
    __decorate([
        Prop()
    ], InputState.prototype, "errorMessage", void 0);
    __decorate([
        Prop()
    ], InputState.prototype, "validMessage", void 0);
    __decorate([
        Prop()
    ], InputState.prototype, "helperMessage", void 0);
    __decorate([
        Prop({
            default: InputStateTagStyle.Default,
            validator: function (value) {
                return value === InputStateTagStyle.Default ||
                    value === InputStateTagStyle.H1 ||
                    value === InputStateTagStyle.H2 ||
                    value === InputStateTagStyle.H3 ||
                    value === InputStateTagStyle.H4 ||
                    value === InputStateTagStyle.H5 ||
                    value === InputStateTagStyle.H6 ||
                    value === InputStateTagStyle.P;
            }
        })
    ], InputState.prototype, "tagStyle", void 0);
    __decorate([
        Prop()
    ], InputState.prototype, "readonly", void 0);
    __decorate([
        Prop()
    ], InputState.prototype, "required", void 0);
    InputState = __decorate([
        Component
    ], InputState);
    return InputState;
}(ModulVue));
export { InputState };
//# sourceMappingURL=input-state.js.map