import { createTheme as p, responsiveFontSizes as O } from "@mui/material";
import A from "webfontloader";
import { DEFAULT_FONTS as _, getDefaultThemePrefer as b, mergeThemeOptions as f, getBlockletThemeOptions as d, mergeAllThemeOptions as C, BLOCKLET_THEME_DARK as k, BLOCKLET_THEME_LIGHT as x } from "@blocklet/theme";
import { mergeThemeOptions as Q, mergeAllThemeOptions as V } from "@blocklet/theme";
import { cleanedObj as c } from "../Util/index.js";
import "@fontsource/roboto/latin-400.css";
import "@fontsource/roboto/latin-500.css";
import "@fontsource/roboto/latin-700.css";
import "@fontsource/roboto/latin-ext-400.css";
import "@fontsource/roboto/latin-ext-500.css";
import "@fontsource/roboto/latin-ext-700.css";
function E(e) {
  return e && typeof e == "object" && e.palette && typeof e.palette.getContrastText == "function";
}
function R(e) {
  return E(e) && e.__isUxTheme__ === !0;
}
function h(e, t = /* @__PURE__ */ new Set()) {
  return !e || typeof e != "object" || (typeof e.fontFamily == "string" && e.fontFamily.replace(/"/g, "").split(",").map((o) => o.trim()).filter(Boolean).forEach((o) => t.add(o)), Object.values(e).forEach((o) => {
    typeof o == "object" && h(o, t);
  })), t;
}
const l = new Set(_.concat("inherit"));
function D(e) {
  const t = e.filter((n) => !l.has(n));
  if (t.length === 0)
    return Promise.resolve(!0);
  t.forEach((n) => l.add(n));
  const o = t.length - 1;
  return t[o] = `${t[o]}&display=swap`, new Promise((n) => {
    A.load({
      google: {
        families: t
      },
      active: () => n(!0),
      inactive: () => n(!0),
      fontinactive: (r, i) => {
        l.delete(r), console.warn(`font ${r} ${i} download failed`);
      }
    });
  });
}
function u(e = "light") {
  return e === "dark" ? k : x;
}
function w(e) {
  let t = null;
  return () => {
    if (t) return t;
    const o = f(u(e), d(e));
    return t = p(o), t;
  };
}
const m = ({ palette: e, components: t, overrides: o, ...n }) => ({
  palette: e,
  components: {
    ...o,
    ...t
  },
  ...n
}), v = {
  themeName: "ArcBlock",
  pageWidth: "md",
  disableBlockletTheme: !1,
  // @deprecated use theme.palette
  colors: {
    white: "#FFFFFF",
    dark: "#4A707C",
    gray: "#222222",
    minor: "#9B9B9B",
    darkText: "#DCDCDC",
    background: "#F7F8F8",
    yellow: "#FFCF71",
    green: "#44cdc6",
    red: "#D0021B",
    blue: "#4E6AF6",
    primary: "#222222",
    black: "#222222",
    secondary: "#44cdc6",
    mint: "#44cdc6",
    textSecondary: "#4A4A4A",
    active: "#5b9025",
    danger: "#D0021B",
    lightGrey: "#BCBCBC"
  }
}, L = (...e) => {
  const t = b(), o = w(t), n = e.reduce(
    (B, a) => f(B, m(typeof a == "function" ? a(o()) : a)),
    m(v)
  ), r = n.mode || n.palette?.mode || t, i = d(r), T = u(r), { disableBlockletTheme: g } = n, F = C(
    [
      T,
      !g && c(i),
      c(n),
      // 确保 mode 跟 prefer 一致
      {
        mode: r,
        palette: { mode: r }
      }
    ].filter(Boolean)
  ), s = p(F);
  s.__isUxTheme__ = !0;
  const y = h(s.typography);
  return D(Array.from(y)), O(s, {
    breakpoints: ["xs", "sm", "md", "lg"],
    disableAlign: !1,
    factor: 3,
    variants: [
      "h1",
      "h2",
      "h3",
      "h4",
      "h5",
      "h6",
      "subtitle1",
      "subtitle2",
      "body1",
      "body2",
      "caption",
      "button",
      "overline"
    ]
  });
}, W = L;
export {
  h as collectFontFamilies,
  L as create,
  u as createDefaultThemeOptions,
  W as createTheme,
  Q as deepmerge,
  V as deepmergeAll,
  E as isTheme,
  R as isUxTheme,
  w as lazyCreateDefaultTheme,
  D as loadFonts
};
