import { __decorate, __extends } from "tslib";
import Vue from 'vue';
import Component from 'vue-class-component';
import { ENGLISH, FRENCH } from '../i18n/i18n';
var MComponentMixin = /** @class */ (function (_super) {
    __extends(MComponentMixin, _super);
    function MComponentMixin() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MComponentMixin.prototype.beforeCreate = function () {
        var _this = this;
        if (this.$options.modul) {
            if (this.$options.modul.i18n) {
                if (!this.$i18n) {
                    throw new Error('You must install I18nPlugin to use the i18n option');
                }
                var i18nComponentOptions = this.$options.modul.i18n;
                var _loop_1 = function (key) {
                    if ([FRENCH, ENGLISH].includes(key)) {
                        var msgs = i18nComponentOptions[key];
                        if (Array.isArray(msgs)) {
                            msgs.forEach(function (msg) {
                                _this.$i18n.addMessages(key, msg);
                            });
                        }
                        else {
                            this_1.$i18n.addMessages(key, msgs);
                        }
                    }
                    else {
                        throw new Error("Unknown lang " + key);
                    }
                };
                var this_1 = this;
                for (var key in i18nComponentOptions) {
                    _loop_1(key);
                }
            }
            if (this.$options.modul.sprites) {
                if (!this.$svg) {
                    throw new Error('You must install SpritesPlugin to use the sprites option');
                }
                var svgComponentOptions = this.$options.modul.sprites;
                if (svgComponentOptions.internalSprites) {
                    this.componentMixinsInternalSpriteIds = [];
                    if (Array.isArray(svgComponentOptions.internalSprites)) {
                        svgComponentOptions.internalSprites.forEach(function (sprite) {
                            _this.componentMixinsInternalSpriteIds.push(_this.$svg.addInternalSprites(sprite));
                        });
                    }
                    else {
                        this.componentMixinsInternalSpriteIds.push(this.$svg.addInternalSprites(svgComponentOptions.internalSprites));
                    }
                }
                else {
                    throw new Error("You must provide an internalSprites option");
                }
            }
        }
    };
    MComponentMixin.prototype.destroyed = function () {
        var _this = this;
        if (this.componentMixinsInternalSpriteIds && this.componentMixinsInternalSpriteIds.length > 0) {
            this.componentMixinsInternalSpriteIds.forEach(function (componentMixinsInternalSpriteId) {
                _this.$svg.removeInternalSprite(componentMixinsInternalSpriteId);
            });
        }
    };
    MComponentMixin = __decorate([
        Component
    ], MComponentMixin);
    return MComponentMixin;
}(Vue));
export { MComponentMixin };
var ComponentMixinPlugin = {
    install: function (v, options) {
        Vue.mixin(MComponentMixin);
    }
};
export default ComponentMixinPlugin;
//# sourceMappingURL=component-mixin.js.map