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 __());
    };
})();
import React from 'react';
import replace from 'lodash/replace';
import uniqueId from 'lodash/uniqueId';
import styled from '@monstrosity/utilities/themed-components';
import SVG from 'react-inlinesvg';
import { Loader } from './icon';
var DuotoneTones = styled.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(replace(currentMatch[0], '.', ''), '{', '');
                var uniqueClassName = uniqueId('duotone-icon-segment-');
                var replacer = new RegExp(className, 'g');
                newData = replace(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.createElement(DuotoneTones, { size: size },
            React.createElement(SVG, { src: require("./duotones/" + duotone + ".svg"), loader: React.createElement(Loader, { size: size }), preProcessor: this.preProcessor }, "SVG Not Found")));
    };
    return DuotoneIcon;
}(React.Component));
export { DuotoneIcon };
var templateObject_1;
