import { __awaiter, __decorate, __extends, __generator } from "tslib";
import Component from 'vue-class-component';
import { Emit, Prop } from 'vue-property-decorator';
import SvgAddCircleFilled from '../../assets/icons/svg/profile.svg';
import { eraseTag, eraseTagAndAllIsContent } from '../../utils/clean/htmlClean';
import { REGEX_CSS_NUMBER_VALUE } from '../../utils/props-validation/props-validation';
import { ModulVue } from '../../utils/vue/vue';
import { SVG_NAME } from '../component-names';
import WithRender from './svg.html';
var MSvg = /** @class */ (function (_super) {
    __extends(MSvg, _super);
    function MSvg() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    MSvg.prototype.emitClick = function (event) { };
    MSvg.prototype.emitKeydown = function (event) { };
    MSvg.prototype.emitMouseOver = function (event) { };
    MSvg.prototype.emitMouseLeave = function (event) { };
    MSvg.prototype.emitSvgId = function (svgId) { };
    MSvg.prototype.beforeCreated = function () {
        if (!this.$svgSprite) {
            throw new Error('$svgSprite not installed , install SvgSpritesPlugin to use this component');
        }
    };
    MSvg.prototype.onDataSvgIdChange = function (svgId) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (!svgId) {
                            return [2 /*return*/];
                        }
                        return [4 /*yield*/, this.$nextTick()];
                    case 1:
                        _a.sent();
                        this.emitSvgId(svgId);
                        return [2 /*return*/];
                }
            });
        });
    };
    Object.defineProperty(MSvg.prototype, "testSvg", {
        get: function () {
            return SvgAddCircleFilled;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "svg", {
        get: function () {
            if (!this.name || !this.$svgSprite) {
                return '';
            }
            var svgString = this.$svgSprite.getSvgString(this.name);
            return svgString ? svgString : '';
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "svgChildrenContent", {
        get: function () {
            var cleanSvg = this.svg ? eraseTagAndAllIsContent('title', eraseTag('svg', this.svg)) : '';
            if (this.svgTitle) {
                cleanSvg = "<title>" + this.svgTitle + "</title>" + cleanSvg;
            }
            return cleanSvg;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "svgHTML", {
        get: function () {
            var domParser = new DOMParser().parseFromString(this.svg, 'text/html');
            return domParser && domParser.querySelector('svg') ? domParser.querySelector('svg') : undefined;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "classAttribute", {
        get: function () {
            return this.getSvgAttibute('class');
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "version", {
        get: function () {
            return this.getSvgAttibute('version');
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "xmlns", {
        get: function () {
            return this.getSvgAttibute('xmlns');
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "viewBox", {
        get: function () {
            return this.getSvgAttibute('viewBox');
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "dataSvgId", {
        get: function () {
            var svgId = this.getSvgAttibute('id');
            this.onDataSvgIdChange(svgId);
            return svgId;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(MSvg.prototype, "badgeOrigin", {
        get: function () {
            return this.getSvgAttibute('data-badge-origin');
        },
        enumerable: false,
        configurable: true
    });
    MSvg.prototype.getSvgAttibute = function (attribute) {
        return this.svgHTML && this.svgHTML.getAttribute(attribute)
            ? this.svgHTML.getAttribute(attribute).toString()
            : undefined;
    };
    __decorate([
        Prop({ required: true })
    ], MSvg.prototype, "name", void 0);
    __decorate([
        Prop({
            default: '1em',
            validator: function (value) {
                return REGEX_CSS_NUMBER_VALUE.test(value);
            }
        })
    ], MSvg.prototype, "width", void 0);
    __decorate([
        Prop({
            default: '1em',
            validator: function (value) {
                return REGEX_CSS_NUMBER_VALUE.test(value);
            }
        })
    ], MSvg.prototype, "height", void 0);
    __decorate([
        Prop()
    ], MSvg.prototype, "svgTitle", void 0);
    __decorate([
        Emit('click')
    ], MSvg.prototype, "emitClick", null);
    __decorate([
        Emit('keydown')
    ], MSvg.prototype, "emitKeydown", null);
    __decorate([
        Emit('mouseover')
    ], MSvg.prototype, "emitMouseOver", null);
    __decorate([
        Emit('mouseleave')
    ], MSvg.prototype, "emitMouseLeave", null);
    __decorate([
        Emit('svg-id')
    ], MSvg.prototype, "emitSvgId", null);
    MSvg = __decorate([
        WithRender,
        Component
    ], MSvg);
    return MSvg;
}(ModulVue));
export { MSvg };
var MSvgPlugin = {
    install: function (v) {
        v.component(SVG_NAME, MSvg);
    }
};
export default MSvgPlugin;
//# sourceMappingURL=svg.js.map