// brodo-icons.jsx — render real Lucide icons as React components
// Loads from the global `lucide` UMD bundle.
(function () {
  function camel(k) {
    return k.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
  }
  function nodeToReact(node, key) {
    // node = [tag, attrs, children?]
    const [tag, attrs = {}, children] = node;
    const props = { key };
    for (const k in attrs) props[camel(k)] = attrs[k];
    const kids = Array.isArray(children) ? children.map((c, i) => nodeToReact(c, i)) : null;
    return React.createElement(tag, props, kids);
  }
  function getIcon(name) {
    const L = window.lucide;
    if (!L) return null;
    return (L.icons && L.icons[name]) || L[name] || null;
  }
  function Icon({ name, size = 22, stroke = 2, className = "", style }) {
    const data = getIcon(name);
    const svgProps = {
      width: size, height: size, viewBox: "0 0 24 24", fill: "none",
      stroke: "currentColor", strokeWidth: stroke, strokeLinecap: "round",
      strokeLinejoin: "round", className, style, "aria-hidden": true,
    };
    if (!data) return React.createElement("svg", svgProps);
    // lucide data is a full IconNode: ["svg", attrs, [ [tag, attrs], ... ]]
    let childNodes;
    if (Array.isArray(data) && data[0] === "svg") {
      childNodes = Array.isArray(data[2]) ? data[2] : [];
    } else {
      childNodes = data; // fallback: array of child tuples
    }
    const children = childNodes.map((n, i) => nodeToReact(n, i));
    return React.createElement("svg", svgProps, children);
  }
  window.Icon = Icon;
})();
