"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IconBase = exports.GenIcon = void 0;
var React = require("react");
var iconContext_1 = require("./iconContext");
function Tree2Element(tree) {
    return tree && tree.map(function (node, i) { return React.createElement(node.tag, __assign({ key: i }, node.attr), Tree2Element(node.child)); });
    return tree && tree.map(function (node, i) { return React.createElement(node.tag, __assign({ key: i }, node.attr), node.content, Tree2Element(node.child)); });
}
function HasStrokes(svg) {
    for (var prop in svg) {
        if (prop[0] === '_') {
            continue; // don't go into any "private" properties
        }
        if (prop === "stroke") {
            return true;
        }
        else if (typeof svg[prop] === "object") {
            var result = HasStrokes(svg[prop]);
            if (result) {
                return result;
            }
        }
        else if (prop === "content") {
            // check if this content is for the <style> tag
            if (svg["tag"] === "style") {
                // "content" may have styles for the stroke
                if (svg[prop].includes("stroke:")) {
                    return true;
                }
            }
        }
    }
    return false;
}
function GenIcon(data) {
    return function (props) { return (React.createElement(IconBase, __assign({ attr: __assign({}, data.attr) }, props, { hasStrokes: HasStrokes(data) }), Tree2Element(data.child))); };
}
exports.GenIcon = GenIcon;
function IconBase(props) {
    var elem = function (conf) {
        var computedSize = props.size || conf.size || "1em";
        var className;
        if (conf.className)
            className = conf.className;
        if (props.className)
            className = (className ? className + ' ' : '') + props.className;
        var attr = props.attr, fill = props.fill, title = props.title, hasStrokes = props.hasStrokes, svgProps = __rest(props, ["attr", "fill", "title", "hasStrokes"]);
        // If the icon has explicit "stroke" attribute, do NOT set zero stroke width
        var stroke = hasStrokes ? null : { strokeWidth: 0 };
        fill = "currentColor";
        return (React.createElement("svg", __assign({ stroke: "currentColor", fill: fill }, stroke, conf.attr, attr, svgProps, { className: className, style: __assign(__assign({ color: props.color || conf.color }, conf.style), props.style), height: computedSize, width: computedSize, xmlns: "http://www.w3.org/2000/svg" }),
            title && React.createElement("title", null, title),
            props.children));
    };
    return iconContext_1.IconContext !== undefined
        ? React.createElement(iconContext_1.IconContext.Consumer, null, function (conf) { return elem(conf); })
        : elem(iconContext_1.DefaultContext);
}
exports.IconBase = IconBase;
