import { __assign } from "tslib";
var SvgSpriteService = /** @class */ (function () {
    function SvgSpriteService() {
        this.svgList = {};
    }
    SvgSpriteService.prototype.addSvg = function (svgName, svgString) {
        if (this.svgList[svgName]) {
            if (this.svgList[svgName] !== svgString) {
                // tslint:disable-next-line: no-console
                console.warn("The '" + svgName + "' SVG name is already used to display another SVG. Choose a new name to save the SVG in this sprite.");
            }
            return;
        }
        this.svgList[svgName] = svgString;
    };
    SvgSpriteService.prototype.removeSvg = function (svgNames) {
        var _this = this;
        this.svgList = Object.keys(this.svgList).reduce(function (acc, value) {
            var _a;
            return (svgNames.some(function (sn) { return value === sn; }) ? acc : __assign(__assign({}, acc), (_a = {}, _a[value] = _this.svgList[value], _a)));
        }, {});
    };
    SvgSpriteService.prototype.getSvgString = function (svgName) {
        if (!this.svgList[svgName]) {
            // tslint:disable-next-line: no-console
            console.warn(this.getErrorMessage(svgName));
            return;
        }
        return this.svgList[svgName];
    };
    SvgSpriteService.prototype.getSvg = function (svgName) {
        if (!this.svgList[svgName]) {
            // tslint:disable-next-line: no-console
            console.warn(this.getErrorMessage(svgName));
            return;
        }
        var domParser = new DOMParser().parseFromString(this.svgList[svgName], 'text/html');
        return domParser && domParser.querySelector('svg') ? domParser.querySelector('svg') : undefined;
    };
    SvgSpriteService.prototype.getSvgList = function () {
        return this.svgList;
    };
    SvgSpriteService.prototype.getErrorMessage = function (svgName) {
        return "SVG " + svgName + " hasn't added to the sprite yet. Use the 'addSvg(svgName: string, svgString: string)' method to add the SVG to the sprite";
    };
    return SvgSpriteService;
}());
export { SvgSpriteService };
var SvgSpritesPlugin = {
    install: function (v) {
        v.prototype.$log.debug('$svgSprite', 'plugin.install');
        var svgSprite = new SvgSpriteService();
        (v.prototype).$svgSprite = svgSprite;
    }
};
export default SvgSpritesPlugin;
//# sourceMappingURL=svg-sprite.js.map