"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _createBlobUrl = _interopRequireDefault(require("../../utils/create-blob-url"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var getColorsTag = function getColorsTag(key) {
  return "{{colors[\"".concat(key, "\"]}}");
};

var SvgModel =
/*#__PURE__*/
function () {
  function SvgModel(props) {
    _classCallCheck(this, SvgModel);

    _defineProperty(this, "url", void 0);

    _defineProperty(this, "width", void 0);

    _defineProperty(this, "height", void 0);

    _defineProperty(this, "colors", void 0);

    this.url = SvgModel.getUrl(props);
    this.width = props.width;
    this.height = props.height;
    this.colors = props.colors;
    return this;
  }

  _createClass(SvgModel, null, [{
    key: "getUrl",
    value: function getUrl(props) {
      var url = '';

      if (props.url) {
        url = props.url;
      } else if (props.content) {
        url = (0, _createBlobUrl.default)(props.content, 'image/svg+xml').get();
      }

      return url;
    }
  }, {
    key: "parseSVGTemplate",
    value: function parseSVGTemplate(content, colors) {
      var res = content;
      Object.keys(colors).forEach(function (key) {
        res = res.replace(getColorsTag(key), colors[key]);
      });
      return res;
    }
  }]);

  return SvgModel;
}();

exports.default = SvgModel;