import { __decorate, __extends } from "tslib";
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop } from 'vue-property-decorator';
import uuid from '../../utils/uuid/uuid';
import { DYNAMIC_TEMPLATE_NAME } from '../component-names';
import WithRender from './dynamic-template.html';
var MDynamicTemplate = /** @class */ (function (_super) {
    __extends(MDynamicTemplate, _super);
    function MDynamicTemplate() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.tag = 'm-dt-' + uuid.generate();
        return _this;
    }
    MDynamicTemplate.prototype.mounted = function () {
        this.$emit('mounted', this.$children);
    };
    MDynamicTemplate.prototype.updated = function () {
        this.$emit('updated', this.$children);
    };
    Object.defineProperty(MDynamicTemplate.prototype, "internalTemplate", {
        get: function () {
            if (typeof this.template === 'string') {
                if (Vue.compile !== undefined) {
                    Vue.component(this.tag, {
                        template: "<div>" + this.template + "</div>"
                    });
                }
                else {
                    var innerHTML_1 = this.template;
                    Vue.component(this.tag, {
                        render: function (createElement) {
                            return createElement('div', { domProps: { innerHTML: innerHTML_1 } });
                        }
                    });
                }
            }
            else {
                Vue.component(this.tag, this.template);
            }
            return this.tag;
        },
        enumerable: false,
        configurable: true
    });
    __decorate([
        Prop()
    ], MDynamicTemplate.prototype, "template", void 0);
    MDynamicTemplate = __decorate([
        WithRender,
        Component
    ], MDynamicTemplate);
    return MDynamicTemplate;
}(Vue));
export { MDynamicTemplate };
var DynamicTemplatePlugin = {
    install: function (v, options) {
        v.component(DYNAMIC_TEMPLATE_NAME, MDynamicTemplate);
    }
};
export default DynamicTemplatePlugin;
//# sourceMappingURL=dynamic-template.js.map