"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var icon_exports = {};
__export(icon_exports, {
  IconThemeContext: () => IconThemeContext,
  IconThemeProvider: () => IconThemeProvider,
  icon: () => icon
});
module.exports = __toCommonJS(icon_exports);
var import_react = __toESM(require("react"));
var import_react_error_boundary = require("react-error-boundary");
var import_fetcher = require("./fetcher");
var import_empty_state = require("./components/empty-state");
var import_utils = require("./utils");
if (!globalThis.__WDSIconThemeContext__) {
  globalThis.__WDSIconThemeContext__ = (0, import_react.createContext)("default");
}
const IconThemeContext = globalThis.__WDSIconThemeContext__;
const IconThemeProvider = ({
  theme = "default",
  children
}) => /* @__PURE__ */ import_react.default.createElement(IconThemeContext.Provider, { value: theme }, children);
const icon = (params) => {
  const { name, hashes, category, width, height } = params;
  const IconContent = (props) => {
    const { size, ...restProps } = props;
    const selectedTheme = (0, import_react.useContext)(IconThemeContext);
    let themeToUse = selectedTheme;
    let hash = hashes[themeToUse];
    if (!hash) {
      themeToUse = hashes.default ? "default" : "odeditor";
      hash = hashes.default || hashes.odeditor;
    }
    const content = import_fetcher.iconContentFetcher.fetch({
      name,
      theme: themeToUse,
      category,
      hash
    });
    const { dimensions, viewBox } = (0, import_utils.getIconAttrs)({
      size,
      width,
      height
    });
    return /* @__PURE__ */ import_react.default.createElement("svg", { fill: "currentColor", viewBox, ...dimensions, ...restProps }, /* @__PURE__ */ import_react.default.createElement(
      "g",
      {
        ...{
          // eslint-disable-next-line no-useless-concat
          ["dangerouslySetInnerHTML"]: { __html: content }
        }
      }
    ));
  };
  const Icon = (props) => {
    const { size, ...restProps } = props;
    return /* @__PURE__ */ import_react.default.createElement(
      import_react_error_boundary.ErrorBoundary,
      {
        fallback: /* @__PURE__ */ import_react.default.createElement(
          import_empty_state.EmptyState,
          {
            width,
            height,
            size,
            restProps
          }
        )
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_react.Suspense,
        {
          fallback: /* @__PURE__ */ import_react.default.createElement(
            import_empty_state.EmptyState,
            {
              width,
              height,
              size,
              restProps
            }
          )
        },
        /* @__PURE__ */ import_react.default.createElement(IconContent, { ...props })
      )
    );
  };
  Icon.displayName = `Icon(${params.name})`;
  return Icon;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  IconThemeContext,
  IconThemeProvider,
  icon
});
