"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var replace_1 = __importDefault(require("lodash/replace"));
var uniqueId_1 = __importDefault(require("lodash/uniqueId"));
var themed_components_1 = __importDefault(require("@monstrosity/utilities/themed-components"));
var react_inlinesvg_1 = __importDefault(require("react-inlinesvg"));
var icon_1 = require("./icon");
var DuotoneTones = themed_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n    --duo-colour-main: ", ";\n    --duo-colour-secondary: ", ";\n\n    all: initial;\n\n\t& svg {\n\t\twidth: ", ";\n\t\theight: ", ";\n\t}\n"], ["\n    --duo-colour-main: ", ";\n    --duo-colour-secondary: ", ";\n\n    all: initial;\n\n\t& svg {\n\t\twidth: ", ";\n\t\theight: ", ";\n\t}\n"])), function (_a) {
    var theme = _a.theme;
    return theme.style.colour.highlight;
}, function (_a) {
    var theme = _a.theme;
    return theme.style.colour.constrast;
}, function (_a) {
    var size = _a.size;
    return size || '2rem';
}, function (_a) {
    var size = _a.size;
    return size || '2rem';
});
var classFinder = /.-?[_a-zA-Z]+[_a-zA-Z0-9-]*s*{/g;
var DuotoneIcon = /** @class */ (function (_super) {
    __extends(DuotoneIcon, _super);
    function DuotoneIcon() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.preProcessor = function (data) {
            var currentMatch = classFinder.exec(data);
            var newData = data;
            while (currentMatch) {
                var className = replace_1.default(replace_1.default(currentMatch[0], '.', ''), '{', '');
                var uniqueClassName = uniqueId_1.default('duotone-icon-segment-');
                var replacer = new RegExp(className, 'g');
                newData = replace_1.default(newData, replacer, uniqueClassName);
                currentMatch = classFinder.exec(data);
            }
            return newData;
        };
        return _this;
    }
    DuotoneIcon.prototype.render = function () {
        var _a = this.props, size = _a.size, duotone = _a.duotone;
        return (react_1.default.createElement(DuotoneTones, { size: size },
            react_1.default.createElement(react_inlinesvg_1.default, { src: require("./duotones/" + duotone + ".svg"), loader: react_1.default.createElement(icon_1.Loader, { size: size }), preProcessor: this.preProcessor }, "SVG Not Found")));
    };
    return DuotoneIcon;
}(react_1.default.Component));
exports.DuotoneIcon = DuotoneIcon;
var templateObject_1;
