import { jsx as i } from "react/jsx-runtime";
import { useState as f, useEffect as S } from "react";
import { defaultColorMap as p, convertAttributes as w } from "./svgConverter.js";
import E from "./SvgElement.js";
const F = (t, s, o = p) => {
  const [g, m] = f(null), [v, n] = f(!1);
  return S(() => {
    (async () => {
      try {
        const r = `${s}/${t}.svg`, c = await fetch(r);
        if (!c.ok)
          throw new Error("Failed to load SVG");
        const a = await c.text();
        if (a.startsWith("<html>"))
          throw new Error(`Could not load SVG with URL: ${r}`);
        const e = new DOMParser().parseFromString(a, "image/svg+xml").querySelector("svg");
        if (!e)
          throw new Error("Invalid SVG format");
        const d = w(e, o), u = /* @__PURE__ */ i("svg", { ...d, children: Array.from(e.childNodes).map(
          (l, h) => l.nodeType === 1 ? (
            // biome-ignore lint/suspicious/noArrayIndexKey: <explanation>
            /* @__PURE__ */ i(E, { node: l, colorMap: o }, h)
          ) : null
        ) });
        m(u), n(!1);
      } catch (r) {
        console.error(`Error loading SVG "${t}":`, r), n(!0);
      }
    })();
  }, [t, s, o]), { svgElement: g, error: v };
};
export {
  F as useSvgLoader
};
//# sourceMappingURL=useSvgLoader.js.map
