var _a, _b;
import { __decorate, __extends } from "tslib";
import Component from 'vue-class-component';
import { Emit, Prop } from 'vue-property-decorator';
import { I18N_NAME as FILTER_I18N_NAME } from '../../filters/filter-names';
import { i18nFilter } from '../../filters/i18n/i18n';
import { MediaQueries } from '../../mixins/media-queries/media-queries';
import { BackdropMode, Portal } from '../../mixins/portal/portal';
import MediaQueriesPlugin from '../../utils/media-queries/media-queries';
import { ModulVue } from '../../utils/vue/vue';
import { ICON_BUTTON_NAME, ICON_NAME, LINK_NAME, TOAST } from '../component-names';
import { MIconButton } from '../icon-button/icon-button';
import { MIcon } from '../icon/icon';
import { MLink, MLinkMode } from '../link/link';
import WithRender from './toast.html?style=./toast.scss';
export var MToastTimeout;
(function (MToastTimeout) {
    MToastTimeout["none"] = "none";
    MToastTimeout["xshort"] = "xshort";
    MToastTimeout["short"] = "short";
    MToastTimeout["long"] = "long";
})(MToastTimeout || (MToastTimeout = {}));
export var MToastPosition;
(function (MToastPosition) {
    MToastPosition["TopLeft"] = "top-left";
    MToastPosition["TopCenter"] = "top-center";
    MToastPosition["TopRight"] = "top-right";
    MToastPosition["BottomLeft"] = "bottom-left";
    MToastPosition["BottomCenter"] = "bottom-center";
    MToastPosition["BottomRight"] = "bottom-right";
})(MToastPosition || (MToastPosition = {}));
export var MToastState;
(function (MToastState) {
    MToastState["Confirmation"] = "confirmation";
    MToastState["Information"] = "information";
    MToastState["Warning"] = "warning";
    MToastState["Error"] = "error";
})(MToastState || (MToastState = {}));
export var MToastDuration;
(function (MToastDuration) {
    MToastDuration[MToastDuration["MobileLong"] = 5000] = "MobileLong";
    MToastDuration[MToastDuration["MobileShort"] = 3000] = "MobileShort";
    MToastDuration[MToastDuration["MobileXShort"] = 1500] = "MobileXShort";
    MToastDuration[MToastDuration["DesktopLong"] = 8000] = "DesktopLong";
    MToastDuration[MToastDuration["DesktopShort"] = 5000] = "DesktopShort";
    MToastDuration[MToastDuration["DesktopXShort"] = 2500] = "DesktopXShort";
    MToastDuration[MToastDuration["None"] = 0] = "None";
})(MToastDuration || (MToastDuration = {}));
var MToast = /** @class */ (function (_super) {
    __extends(MToast, _super);
    function MToast() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.buttonMode = MLinkMode.Button;
        return _this;
    }
    MToast.prototype.doCustomPropOpen = function (value, el) {
        el.style.position = 'absolute';
        if (value) {
            if (this.offset !== '0') {
                this.getPortalElement().style.transform = "translateY(" + this.offset + ")";
            }
            this.internalTimeout = this.convertTimeout(this.timeout);
            this.startCloseToast();
        }
        return true;
    };
    MToast.prototype.startCloseToast = function () {
        var _this = this;
        this.instantTimeoutStart = Date.now();
        if (this.internalTimeout > 0) {
            this.timerCloseToast
                = setTimeout(function () {
                    _this.onClose();
                }, this.internalTimeout);
        }
    };
    MToast.prototype.getPortalElement = function () {
        return this.$refs.toast;
    };
    MToast.prototype.getBackdropMode = function () {
        return BackdropMode.None;
    };
    MToast.prototype.handlesFocus = function () {
        return false;
    };
    MToast.prototype.mounted = function () {
        if (this.open === undefined || this.open === true) {
            this.as().propOpen = true;
        }
    };
    MToast.prototype.convertTimeout = function (timeout) {
        switch (timeout) {
            case MToastTimeout.long:
                return this.isMobile ? MToastDuration.MobileLong : MToastDuration.DesktopLong;
            case MToastTimeout.short:
                return this.isMobile ? MToastDuration.MobileShort : MToastDuration.DesktopShort;
            case MToastTimeout.xshort:
                return this.isMobile ? MToastDuration.MobileXShort : MToastDuration.DesktopXShort;
            case MToastTimeout.none:
            default:
                return MToastDuration.None;
        }
    };
    MToast.prototype.onAction = function (event) {
        this.onClose();
    };
    MToast.prototype.onClose = function () {
        this.as().propOpen = false;
    };
    Object.defineProperty(MToast.prototype, "isStateInformation", {
        get: function () {
            return this.state === MToastState.Information;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MToast.prototype, "isStateWarning", {
        get: function () {
            return this.state === MToastState.Warning;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MToast.prototype, "isStateError", {
        get: function () {
            return this.state === MToastState.Error;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MToast.prototype, "isStateConfirmation", {
        get: function () {
            return this.state === MToastState.Confirmation;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MToast.prototype, "isTop", {
        get: function () {
            return this.position === MToastPosition.TopLeft ||
                this.position === MToastPosition.TopCenter ||
                this.position === MToastPosition.TopRight;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MToast.prototype, "isLeft", {
        get: function () {
            return this.position === MToastPosition.TopLeft ||
                this.position === MToastPosition.BottomLeft;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MToast.prototype, "isCenter", {
        get: function () {
            return this.position === MToastPosition.TopCenter ||
                this.position === MToastPosition.BottomCenter;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MToast.prototype, "isRight", {
        get: function () {
            return this.position === MToastPosition.TopRight ||
                this.position === MToastPosition.BottomRight;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MToast.prototype, "isMobile", {
        get: function () {
            return this.as().isMqMaxS;
        },
        enumerable: false,
        configurable: true
    });
    MToast.prototype.getIcon = function () {
        var icon = '';
        switch (this.state) {
            case MToastState.Confirmation:
                icon = 'm-svg__confirmation';
                break;
            case MToastState.Information:
                icon = 'm-svg__information';
                break;
            case MToastState.Warning:
                icon = 'm-svg__warning';
                break;
            case MToastState.Error:
                icon = 'm-svg__error';
                break;
            default:
                break;
        }
        return icon;
    };
    MToast.prototype.mouseEnterToast = function () {
        if (!this.isMobile && this.timerCloseToast !== undefined) {
            this.restoreTimeout();
            clearTimeout(this.timerCloseToast);
            this.timerCloseToast = undefined;
        }
    };
    MToast.prototype.restoreTimeout = function () {
        var instantTimeoutStop = Date.now();
        this.internalTimeout -= (instantTimeoutStop - this.instantTimeoutStart);
    };
    MToast.prototype.mouseLeaveToast = function () {
        if (!this.isMobile) {
            this.startCloseToast();
        }
    };
    __decorate([
        Prop({
            default: MToastState.Confirmation,
            validator: function (value) {
                return value === MToastState.Confirmation ||
                    value === MToastState.Information ||
                    value === MToastState.Warning ||
                    value === MToastState.Error;
            }
        })
    ], MToast.prototype, "state", void 0);
    __decorate([
        Prop({
            default: MToastPosition.BottomRight,
            validator: function (value) {
                return value === MToastPosition.TopRight ||
                    value === MToastPosition.TopCenter ||
                    value === MToastPosition.TopLeft ||
                    value === MToastPosition.BottomLeft ||
                    value === MToastPosition.BottomCenter ||
                    value === MToastPosition.BottomRight;
            }
        })
    ], MToast.prototype, "position", void 0);
    __decorate([
        Prop({
            default: MToastTimeout.none,
            validator: function (value) {
                return value === MToastTimeout.none ||
                    value === MToastTimeout.xshort ||
                    value === MToastTimeout.short ||
                    value === MToastTimeout.long;
            }
        })
    ], MToast.prototype, "timeout", void 0);
    __decorate([
        Prop()
    ], MToast.prototype, "open", void 0);
    __decorate([
        Prop()
    ], MToast.prototype, "actionLabel", void 0);
    __decorate([
        Prop({
            default: true
        })
    ], MToast.prototype, "icon", void 0);
    __decorate([
        Prop({
            default: '0'
        })
    ], MToast.prototype, "offset", void 0);
    __decorate([
        Prop({
            default: true
        })
    ], MToast.prototype, "closeButton", void 0);
    __decorate([
        Emit('action-button')
    ], MToast.prototype, "onAction", null);
    MToast = __decorate([
        WithRender,
        Component({
            components: (_a = {},
                _a[ICON_NAME] = MIcon,
                _a[ICON_BUTTON_NAME] = MIconButton,
                _a[LINK_NAME] = MLink,
                _a),
            filters: (_b = {},
                _b[FILTER_I18N_NAME] = i18nFilter,
                _b),
            mixins: [MediaQueries, Portal]
        })
    ], MToast);
    return MToast;
}(ModulVue));
export { MToast };
var ToastPlugin = {
    install: function (v, options) {
        v.use(MediaQueriesPlugin);
        v.component(TOAST, MToast);
    }
};
export default ToastPlugin;
//# sourceMappingURL=toast.js.map