import { forwardRef, createElement } from 'react';
import { getIconSvgPaintProps, hasA11yProp, mergeClasses, iconNodeElementAttrs } from '@opudoc/opicon-shared';
import defaultAttributes from './defaultAttributes.mjs';

const renderNode = (node, filled) => {
  if (node.length === 3) {
    const [tag2, attrs2, children] = node;
    const { key: key2, ...rest2 } = iconNodeElementAttrs(tag2, attrs2, filled);
    return createElement(tag2, { key: key2, ...rest2 }, ...children.map((child) => renderNode(child, filled)));
  }
  const [tag, attrs] = node;
  const { key, ...rest } = iconNodeElementAttrs(tag, attrs, filled);
  return createElement(tag, { key, ...rest });
};
const Icon = forwardRef(
  ({ color, size = 24, strokeWidth = 2, absoluteStrokeWidth, className = "", iconNode, children, ...rest }, ref) => {
    const paint = getIconSvgPaintProps(iconNode, {
      color,
      strokeWidth,
      absoluteStrokeWidth,
      size
    });
    return createElement(
      "svg",
      {
        ref,
        ...defaultAttributes,
        width: size,
        height: size,
        color: paint.color,
        fill: paint.fill,
        stroke: paint.stroke,
        ...paint.strokeWidth !== void 0 && { strokeWidth: paint.strokeWidth },
        className: mergeClasses("opicon", className),
        ...!children && !hasA11yProp(rest) && { "aria-hidden": true },
        ...rest
      },
      [...iconNode.map((node) => renderNode(node, paint.filled)), children]
    );
  }
);
Icon.displayName = "OpiconIcon";

export { Icon as default };
//# sourceMappingURL=Icon.mjs.map
