import { jsx as n } from "react/jsx-runtime";
import "iconify-icon";
import { useState as c } from "react";
import { useAsyncEffect as d } from "ahooks";
import { Avatar as e } from "@mui/material";
import { loadIcon as m, Icon as h } from "@iconify/react";
import { isUrl as g } from "../utils.js";
function M({
  icon: r,
  size: t = void 0,
  sx: i = {},
  ...a
}) {
  const o = [...Array.isArray(i) ? i : [i]];
  t && o.push({ width: t, height: t });
  const [p, f] = c(!1), [l, s] = c(!0);
  if (d(async () => {
    s(!0);
    try {
      await m(r), f(!0);
    } catch {
      f(!1);
    }
    s(!1);
  }, [r]), a.variant || o.push({
    "&.MuiAvatar-root": {
      color: "inherit",
      fontWeight: "bold",
      backgroundColor: "transparent",
      borderRadius: 0
    },
    // 无 icon 背景时, svg icon 尺寸与窗口尺寸一致
    "&.MuiAvatar-root svg": {
      width: "100%",
      height: "100%"
    }
  }), g(r))
    return /* @__PURE__ */ n(e, { component: "span", ...a, src: r, sx: o });
  const u = t ? 0.6 * t + 4 : 0;
  return l ? /* @__PURE__ */ n(h, { icon: "codicon:blank", height: u || void 0 }) : p ? /* @__PURE__ */ n(e, { component: "span", ...a, sx: o, children: /* @__PURE__ */ n(h, { icon: r, height: u || void 0 }) }) : r && typeof r == "string" ? (o.push({
    "&.MuiAvatar-root": {
      display: "inline-flex",
      ...t && { fontSize: t - 2 }
    }
  }), /* @__PURE__ */ n(e, { component: "span", ...a, sx: o, children: Array.from(r)[0] })) : null;
}
export {
  M as default
};
