import {
  darkTheme
} from "./chunk-FRF2GUPO.js";
import {
  midnightTheme
} from "./chunk-O2CXI27D.js";
import {
  AsteroidKitSyncProvider,
  Box,
  CloseButton,
  ConnectButton,
  DesktopOptions,
  Dialog,
  DialogContent,
  MobileOptions,
  RainbowKitAuthenticationProvider,
  RainbowKitProvider,
  Text,
  argentWallet,
  braveWallet,
  coinbaseWallet,
  connectorsForWallets,
  createAuthenticationAdapter,
  cssObjectFromTheme,
  cssStringFromTheme,
  dialogContent,
  dialogContentMobile,
  getWalletConnectConnector,
  injectedWallet,
  isMobile,
  ledgerWallet,
  metaMaskWallet,
  rainbowWallet,
  trustWallet,
  useAccountModal,
  useAsteroidKitSyncState,
  useChainId,
  useChainModal,
  useConnectModal,
  useTransactionStore,
  walletConnectWallet
} from "./chunk-QLZP4L26.js";
import {
  lightTheme
} from "./chunk-ATKR4544.js";
import "./chunk-4QPBWJI3.js";

// src/asteroidkit/AsteroidKitProvider.tsx
import React4, { useEffect, useRef, useState as useState2 } from "react";
import { SiweMessage } from "siwe";
import { configureChains, useAccount, useClient } from "wagmi";
import {
  avalanche,
  avalancheFuji,
  goerli,
  mainnet,
  optimism,
  optimismGoerli,
  polygon,
  polygonMumbai
} from "wagmi/chains";
import { publicProvider } from "wagmi/providers/public";

// src/asteroidkit/connectors/social/connector.ts
import { CHAIN_NAMESPACES } from "@web3auth/base";
import { Web3AuthCore } from "@web3auth/core";
import { OpenloginAdapter } from "@web3auth/openlogin-adapter";

// src/asteroidkit/connectors/social/GenericSocialConnector.ts
import { Connector, normalizeChainId } from "@wagmi/core";
import {
  ADAPTER_STATUS
} from "@web3auth/base";
import { providers } from "ethers";
import { getAddress } from "ethers/lib/utils";
import { UserRejectedRequestError } from "wagmi";
var IS_SERVER = typeof window === "undefined";
var GenericSocialConnector = class extends Connector {
  constructor(config) {
    super(config);
    this.ready = !IS_SERVER;
    this.id = "socialConnector";
    this.name = "Social Connector";
    this.provider = null;
    this.web3AuthInstance = config.options.web3AuthInstance;
    this.socialProviderName = config.options.socialProviderName;
    this.initialChainId = config.chains[0].id;
  }
  async connect() {
    try {
      this.emit("message", {
        type: "connecting"
      });
      if (this.web3AuthInstance.status === ADAPTER_STATUS.NOT_READY) {
        await this.web3AuthInstance.init();
      }
      let { provider } = this.web3AuthInstance;
      if (!provider) {
        provider = await this.web3AuthInstance.connectTo("openlogin", {
          loginProvider: this.options.socialProviderName
        });
      }
      if (!provider) {
        throw new Error("Provider not found");
      }
      const signer = await this.getSigner();
      const account = await signer.getAddress();
      provider.on("accountsChanged", this.onAccountsChanged.bind(this));
      provider.on("chainChanged", this.onChainChanged.bind(this));
      const chainId = await this.getChainId();
      const unsupported = this.isChainUnsupported(chainId);
      return {
        account,
        chain: {
          id: chainId,
          unsupported
        },
        provider
      };
    } catch (error) {
      throw new UserRejectedRequestError("Something went wrong");
    }
  }
  async getAccount() {
    const p = await this.getProvider();
    if (!p) {
      throw new Error("No Provider");
    }
    const provider = new providers.Web3Provider(p);
    const signer = provider.getSigner();
    const account = await signer.getAddress();
    return account;
  }
  async getChainId() {
    try {
      if (this.provider) {
        const chainId = await this.provider.request({ method: "eth_chainId" });
        if (chainId) {
          return normalizeChainId(chainId);
        }
      }
      if (this.initialChainId) {
        return this.initialChainId;
      }
      throw new Error("Chain ID is not defined");
    } catch (error) {
      throw error;
    }
  }
  async getProvider() {
    if (this.provider) {
      return this.provider;
    }
    this.provider = this.web3AuthInstance.provider;
    if (!this.provider) {
      throw new Error("Provider not found");
    }
    return this.provider;
  }
  async getSigner() {
    const provider = new providers.Web3Provider(await this.getProvider());
    const signer = provider.getSigner();
    return signer;
  }
  async isAuthorized() {
    try {
      const account = await this.getAccount();
      return !!(account && this.provider);
    } catch {
      return false;
    }
  }
  async switchChain(chainId) {
    var _a, _b, _c;
    try {
      const chain = this.chains.find((x) => x.id === chainId);
      if (!chain)
        throw new Error(`Unsupported chainId: ${chainId}`);
      const provider = await this.getProvider();
      if (!provider)
        throw new Error("Please login first");
      provider.request({
        method: "wallet_addEthereumChain",
        params: [
          {
            blockExplorerUrls: [(_b = (_a = chain.blockExplorers) == null ? void 0 : _a.default) == null ? void 0 : _b.url],
            chainId: `0x${chain.id.toString(16)}`,
            chainName: chain.name,
            nativeCurrency: {
              symbol: ((_c = chain.nativeCurrency) == null ? void 0 : _c.symbol) || "ETH"
            },
            rpcUrls: [chain.rpcUrls.default.http]
          }
        ]
      });
      await provider.request({
        method: "wallet_switchEthereumChain",
        params: [
          {
            chainId: `0x${chain.id.toString(16)}`
          }
        ]
      });
      return chain;
    } catch (error) {
      throw error;
    }
  }
  async disconnect() {
    await this.web3AuthInstance.logout();
    this.provider = null;
  }
  onAccountsChanged(accounts) {
    if (accounts.length === 0)
      this.emit("disconnect");
    else {
      this.emit("change", { account: `0x${getAddress(accounts[0])}` });
    }
  }
  isChainUnsupported(chainId) {
    return !this.chains.some((x) => x.id === chainId);
  }
  onChainChanged(chainId) {
    const id = normalizeChainId(chainId);
    const unsupported = this.isChainUnsupported(id);
    this.emit("change", { chain: { id, unsupported } });
  }
  onDisconnect() {
    this.emit("disconnect");
  }
};

// src/asteroidkit/connectors/social/OpenLoginAdapterConfig.ts
var OpenLoginAdapterConfig = {
  adapterSettings: {
    clientId: "BOpE2QwLzG8lTiFOblI4-5Tv7dEuQ3--ZCVdNpmnC7DqMhsxdKpUaE2tF3IUizccy7_B4h04uEj6g5zpqYbRf9c",
    loginConfig: {
      google: {
        clientId: "52560353044-dru4anqjptro5ssbsha1tosq222gfcpa.apps.googleusercontent.com",
        name: "Google",
        typeOfLogin: "google",
        verifier: "AsteroidKit Google"
      },
      twitch: {
        clientId: "8bhn7spr5h1nwby5gdq14uza8qmonj",
        name: "Twitch",
        typeOfLogin: "twitch",
        verifier: "AsteroidKit Twich"
      }
    },
    network: "cyan",
    storageKey: "local",
    uxMode: "popup"
  }
};

// src/asteroidkit/connectors/social/connector.ts
var configureWeb3Auth = (chains) => {
  var _a, _b, _c, _d;
  const chainConfig = {
    blockExplorer: (_b = (_a = chains[0]) == null ? void 0 : _a.blockExplorers.default) == null ? void 0 : _b.url,
    chainId: `0x${chains[0].id.toString(16)}`,
    chainNamespace: CHAIN_NAMESPACES.EIP155,
    displayName: chains[0].name,
    rpcTarget: chains[0].rpcUrls.default.http[0],
    ticker: (_c = chains[0].nativeCurrency) == null ? void 0 : _c.symbol,
    tickerName: (_d = chains[0].nativeCurrency) == null ? void 0 : _d.name
  };
  const web3AuthInstance = new Web3AuthCore({
    chainConfig,
    clientId: "BOpE2QwLzG8lTiFOblI4-5Tv7dEuQ3--ZCVdNpmnC7DqMhsxdKpUaE2tF3IUizccy7_B4h04uEj6g5zpqYbRf9c"
  });
  web3AuthInstance.configureAdapter(new OpenloginAdapter(OpenLoginAdapterConfig));
  return web3AuthInstance;
};
var GoogleConnector = ({
  chains,
  web3AuthInstance
}) => ({
  createConnector: () => {
    const connector = new GenericSocialConnector({
      chains,
      options: {
        socialProviderName: "google",
        web3AuthInstance
      }
    });
    return {
      connector
    };
  },
  iconBackground: "#fff",
  iconUrl: "https://www.freepnglogos.com/uploads/google-logo-png/google-logo-png-google-icon-logo-png-transparent-svg-vector-bie-supply-14.png",
  id: "openlogin_google",
  name: "Google"
});
var TwitchConnector = ({
  chains,
  web3AuthInstance
}) => ({
  createConnector: () => {
    const connector = new GenericSocialConnector({
      chains,
      options: {
        socialProviderName: "twitch",
        web3AuthInstance
      }
    });
    return { connector };
  },
  iconBackground: "#fff",
  iconUrl: "https://cdn4.iconfinder.com/data/icons/logos-brands-7/512/twitch-1024.png",
  id: "openlogin_twitch",
  name: "Twitch"
});

// src/asteroidkit/lib/fetcher.ts
import { logEvent as firebaseLogEvent, getAnalytics } from "firebase/analytics";
import { initializeApp } from "firebase/app";
import {
  addDoc,
  collection,
  doc,
  getDoc,
  getFirestore,
  serverTimestamp,
  setDoc
} from "firebase/firestore";
var firebaseConfig = {
  apiKey: "AIzaSyC6VU0evv45aA8auEpAR7_oJkNrUtu_vm0",
  appId: "1:770385218222:web:f2e9b78ee12eb871a47b3f",
  authDomain: "asteroidkit-dashboard.firebaseapp.com",
  measurementId: "G-X8B1V12YB8",
  messagingSenderId: "770385218222",
  projectId: "asteroidkit-dashboard",
  storageBucket: "asteroidkit-dashboard.appspot.com"
};
var app = initializeApp(firebaseConfig);
var db = getFirestore(app);
var hasSentLoadConfigurationEvent = false;
var getAppInfo = async (appId) => {
  const appInfoDocRef = doc(db, "appInfo", appId);
  const appInfoSnap = await getDoc(appInfoDocRef);
  if (!appInfoSnap.exists()) {
    throw new Error("No application was found");
  }
  if (!hasSentLoadConfigurationEvent) {
    firebaseLogEvent(getAnalytics(app), "fetch_app_config", {
      appId
    });
    hasSentLoadConfigurationEvent = true;
  }
  return {
    ...appInfoSnap.data(),
    appId: appInfoSnap.id
  };
};
var getUserInfo = async ({
  address,
  appId
}) => {
  const userInfoDocRef = getUserInfoRef(appId, address);
  const userInfoSnap = await getDoc(userInfoDocRef);
  if (!userInfoSnap.data()) {
    return null;
  }
  return {
    ...userInfoSnap.data()
  };
};
var setUserInfo = async ({
  address,
  appId,
  userInfo
}) => {
  const userInfoDocRef = getUserInfoRef(appId, address);
  await setDoc(userInfoDocRef, userInfo);
  return userInfo;
};
var addEvent = async ({
  address,
  appId,
  eventType
}) => {
  const eventCollectionRef = getEventsCollectionRef(appId);
  const newEventData = {
    address,
    createdAt: serverTimestamp(),
    type: eventType
  };
  const newEventRef = await addDoc(eventCollectionRef, newEventData);
  return { ...newEventData, id: newEventRef.id };
};
var getUserInfoRef = (appId, address) => doc(db, "appInfo", appId, "users", address);
var getEventsCollectionRef = (appId) => collection(db, "appInfo", appId, "events");

// src/asteroidkit/ui/UserDetailsModal/UserDetailsModal.tsx
import React3, { useState } from "react";

// src/asteroidkit/ui/AKButton.tsx
import React from "react";

// src/asteroidkit/isMobileUtil.ts
var isAndroid = () => typeof navigator !== "undefined" && /android/i.test(navigator.userAgent);
var isSmallIOS = () => typeof navigator !== "undefined" && /iPhone|iPod/.test(navigator.userAgent);
var isMobile2 = () => isAndroid() || isSmallIOS();

// src/asteroidkit/ui/AKButton.tsx
var AKButton = ({
  autoComplete = "off",
  children,
  disabled,
  fullWidth,
  name,
  placeholder,
  type
}) => {
  const mobile = isMobile2();
  return /* @__PURE__ */ React.createElement(Box, {
    as: "button",
    background: {
      base: "profileAction",
      ...!mobile && !disabled ? { hover: "profileActionHover" } : {}
    },
    display: "flex",
    justifyContent: "center",
    ...disabled ? { cursor: "not-allowed" } : {},
    autoComplete,
    children,
    color: "modalText",
    disabled,
    fontWeight: "heavy",
    name,
    padding: "14",
    placeholder,
    type,
    width: fullWidth ? "full" : void 0
  });
};

// src/asteroidkit/ui/AKInput.tsx
import React2 from "react";
var AKInput = ({
  autoComplete = "off",
  label,
  name,
  placeholder,
  type
}) => {
  const mobile = isMobile2();
  return /* @__PURE__ */ React2.createElement(Box, {
    color: "modalText",
    display: "flex",
    flexDirection: "column"
  }, /* @__PURE__ */ React2.createElement(Box, {
    as: "label",
    fontSize: "14",
    fontWeight: "medium",
    paddingY: "4"
  }, label), /* @__PURE__ */ React2.createElement(Box, {
    as: "input",
    autoComplete,
    background: {
      base: "profileAction",
      ...!mobile ? { hover: "profileActionHover" } : {}
    },
    color: "modalText",
    name,
    padding: "14",
    placeholder,
    type
  }));
};

// src/asteroidkit/ui/UserDetailsModal/UserDetailsModal.tsx
function UserDetailsModal({
  onClose,
  onSubmit,
  open
}) {
  const titleId = "ak_user_details_title";
  const [isLoading, setIsLoading] = useState(false);
  const mobile = isMobile();
  const onSubmitLocalHandle = async (event) => {
    const name = event.target.name.value;
    const email = event.target.email.value;
    event.preventDefault();
    setIsLoading(true);
    await onSubmit({ email, name }).then(() => onClose(1 /* SUCCESS */)).catch(() => {
      onClose(2 /* ERROR */);
    }).finally(() => {
      setIsLoading(false);
    });
  };
  return /* @__PURE__ */ React3.createElement(Dialog, {
    onClose: () => {
      onClose(2 /* ERROR */);
    },
    open,
    titleId
  }, /* @__PURE__ */ React3.createElement(DialogContent, {
    bottomSheetOnMobile: true,
    padding: "0",
    wide: true
  }, /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(Box, {
    display: "flex",
    flexDirection: "column"
  }, /* @__PURE__ */ React3.createElement(Box, {
    background: "profileForeground",
    padding: "16"
  }, /* @__PURE__ */ React3.createElement(Box, {
    alignItems: "center",
    display: "flex",
    flexDirection: "column",
    gap: mobile ? "16" : "12",
    justifyContent: "center",
    margin: "8",
    style: { textAlign: "center" }
  }, /* @__PURE__ */ React3.createElement(Box, {
    style: {
      position: "absolute",
      right: 16,
      top: 16,
      willChange: "transform"
    }
  }, /* @__PURE__ */ React3.createElement(CloseButton, {
    onClose: () => {
      setIsLoading(true);
      onClose(0 /* USER_CANCEL */);
    }
  })), /* @__PURE__ */ React3.createElement(Box, {
    display: "flex",
    flexDirection: "row"
  }, /* @__PURE__ */ React3.createElement(Box, {
    display: "flex",
    flexDirection: "column",
    gap: mobile ? "4" : "0",
    justifyContent: "center",
    marginLeft: "20",
    textAlign: "center"
  }, /* @__PURE__ */ React3.createElement(Text, {
    as: "h1",
    color: "modalText",
    id: titleId,
    size: mobile ? "20" : "18",
    textAlign: "center",
    weight: "heavy"
  }, "More about you")))), /* @__PURE__ */ React3.createElement(Box, {
    background: "generalBorder",
    height: "1",
    marginY: "10",
    width: "full"
  }), /* @__PURE__ */ React3.createElement(Box, {
    color: "modalText",
    fontWeight: "bold",
    margin: "2",
    marginTop: "16",
    textAlign: "left"
  }, "We need bit of information to get started"), /* @__PURE__ */ React3.createElement(Box, {
    as: "form",
    display: "flex",
    flexDirection: "column",
    gap: "4",
    marginTop: "16",
    onSubmit: onSubmitLocalHandle
  }, /* @__PURE__ */ React3.createElement(AKInput, {
    label: "Name",
    name: "name",
    placeholder: "Your Name"
  }), /* @__PURE__ */ React3.createElement(AKInput, {
    label: "Email",
    name: "email",
    placeholder: "example@email.com",
    type: "email"
  }), /* @__PURE__ */ React3.createElement(Box, {
    paddingTop: "24"
  }, /* @__PURE__ */ React3.createElement(AKButton, {
    disabled: isLoading,
    fullWidth: true,
    type: "submit"
  }, isLoading ? "Loading..." : "Complete"))))))));
}

// src/asteroidkit/AsteroidKitProvider.tsx
var mapChainNameToWAGMIChain = (chains) => {
  const SupportedChains = {
    avalanche,
    avalancheFuji,
    goerli,
    mainnet,
    optimism,
    optimismGoerli,
    polygon,
    polygonMumbai
  };
  return chains.filter((chain) => Object.keys(SupportedChains).includes(chain)).map((chain) => SupportedChains[chain]);
};
var mapWalletNameToRainbowKitWallet = (walletList = [], chainsList = []) => {
  const { chains } = configureChains(chainsList, [publicProvider()]);
  return walletList.map((walletName) => {
    switch (walletName) {
      case "metamask":
        return metaMaskWallet({ chains, shimDisconnect: true });
      case "coinbase":
        return coinbaseWallet({ appName: "AsteroidKit", chains });
      case "ledgerlive":
        return ledgerWallet({ chains });
      case "trust":
        return trustWallet({ chains });
      case "argent":
        return argentWallet({ chains });
      case "walletconnect":
        return walletConnectWallet({ chains });
      default:
        throw new Error("Wallet not supported");
    }
  });
};
var mapThemeNameToRainbowKitTheme = (themeName, accentColor, accentColorForeground) => {
  const t256noir = {
    blurs: {
      modalOverlay: "blur(0px)"
    },
    colors: {
      accentColor,
      accentColorForeground,
      actionButtonBorder: "rgba(255, 255, 255, 0.04)",
      actionButtonBorderMobile: "rgba(255, 255, 255, 0.08)",
      actionButtonSecondaryBackground: "rgba(255, 255, 255, 0.08)",
      closeButton: "rgba(224, 232, 255, 0.6)",
      closeButtonBackground: "rgba(255, 255, 255, 0.08)",
      connectButtonBackground: "#1A1B1F",
      connectButtonBackgroundError: "#FF494A",
      connectButtonInnerBackground: "linear-gradient(0deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.15))",
      connectButtonText: "#FFF",
      connectButtonTextError: "#FFF",
      connectionIndicator: "#30E000",
      downloadBottomCardBackground: "linear-gradient(126deg, rgba(0, 0, 0, 0) 9.49%, rgba(120, 120, 120, 0.2) 71.04%), #1A1B1F",
      downloadTopCardBackground: "linear-gradient(126deg, rgba(120, 120, 120, 0.2) 9.49%, rgba(0, 0, 0, 0) 71.04%), #1A1B1F",
      error: "#FF494A",
      generalBorder: "rgba(255, 255, 255, 0.08)",
      generalBorderDim: "rgba(255, 255, 255, 0.04)",
      menuItemBackground: "rgba(224, 232, 255, 0.1)",
      modalBackdrop: "rgba(0, 0, 0, 0.5)",
      modalBackground: "#1A1B1F",
      modalBorder: "rgba(255, 255, 255, 0.08)",
      modalText: "#FFF",
      modalTextDim: "rgba(224, 232, 255, 0.3)",
      modalTextSecondary: "rgba(255, 255, 255, 0.6)",
      profileAction: "rgba(224, 232, 255, 0.1)",
      profileActionHover: "rgba(224, 232, 255, 0.2)",
      profileForeground: "rgba(224, 232, 255, 0.05)",
      selectedOptionBorder: "rgba(224, 232, 255, 0.1)",
      standby: "#FFD641"
    },
    fonts: {
      body: 'SFRounded, ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'
    },
    radii: {
      actionButton: "9999px",
      connectButton: "12px",
      menuButton: "12px",
      modal: "24px",
      modalMobile: "28px"
    },
    shadows: {
      connectButton: "0px 4px 12px rgba(0, 0, 0, 0.1)",
      dialog: "0px 8px 32px rgba(0, 0, 0, 0.32)",
      profileDetailsAction: "0px 2px 6px rgba(37, 41, 46, 0.04)",
      selectedOption: "0px 2px 6px rgba(0, 0, 0, 0.24)",
      selectedWallet: "0px 2px 6px rgba(0, 0, 0, 0.24)",
      walletLogo: "0px 2px 16px rgba(0, 0, 0, 0.16)"
    }
  };
  const tdefault = {
    blurs: {
      modalOverlay: "blur(0px)"
    },
    colors: {
      accentColor,
      accentColorForeground,
      actionButtonBorder: "rgba(0, 0, 0, 0.04)",
      actionButtonBorderMobile: "rgba(0, 0, 0, 0.06)",
      actionButtonSecondaryBackground: "rgba(0, 0, 0, 0.06)",
      closeButton: "rgba(60, 66, 66, 0.8)",
      closeButtonBackground: "rgba(0, 0, 0, 0.06)",
      connectButtonBackground: "#FFF",
      connectButtonBackgroundError: "#FF494A",
      connectButtonInnerBackground: "linear-gradient(0deg, rgba(0, 0, 0, 0.03), rgba(0, 0, 0, 0.06))",
      connectButtonText: "#25292E",
      connectButtonTextError: "#FFF",
      connectionIndicator: "#30E000",
      downloadBottomCardBackground: "linear-gradient(126deg, rgba(255, 255, 255, 0) 9.49%, rgba(171, 171, 171, 0.04) 71.04%), #FFFFFF",
      downloadTopCardBackground: "linear-gradient(126deg, rgba(171, 171, 171, 0.2) 9.49%, rgba(255, 255, 255, 0) 71.04%), #FFFFFF",
      error: "#FF494A",
      generalBorder: "rgba(0, 0, 0, 0.06)",
      generalBorderDim: "rgba(0, 0, 0, 0.03)",
      menuItemBackground: "rgba(60, 66, 66, 0.1)",
      modalBackdrop: "rgba(0, 0, 0, 0.3)",
      modalBackground: "#FFF",
      modalBorder: "transparent",
      modalText: "#25292E",
      modalTextDim: "rgba(60, 66, 66, 0.3)",
      modalTextSecondary: "rgba(60, 66, 66, 0.6)",
      profileAction: "#FFF",
      profileActionHover: "rgba(255, 255, 255, 0.5)",
      profileForeground: "rgba(60, 66, 66, 0.06)",
      selectedOptionBorder: "rgba(60, 66, 66, 0.1)",
      standby: "#FFD641"
    },
    fonts: {
      body: 'SFRounded, ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'
    },
    radii: {
      actionButton: "9999px",
      connectButton: "12px",
      menuButton: "12px",
      modal: "24px",
      modalMobile: "28px"
    },
    shadows: {
      connectButton: "0px 4px 12px rgba(0, 0, 0, 0.1)",
      dialog: "0px 8px 32px rgba(0, 0, 0, 0.32)",
      profileDetailsAction: "0px 2px 6px rgba(37, 41, 46, 0.04)",
      selectedOption: "0px 2px 6px rgba(0, 0, 0, 0.24)",
      selectedWallet: "0px 2px 6px rgba(0, 0, 0, 0.12)",
      walletLogo: "0px 2px 16px rgba(0, 0, 0, 0.16)"
    }
  };
  const teverforest = {
    blurs: {
      modalOverlay: "blur(50px)"
    },
    colors: {
      accentColor,
      accentColorForeground,
      actionButtonBorder: "rgba(0, 0, 0, 0.04)",
      actionButtonBorderMobile: "rgba(0, 0, 0, 0.06)",
      actionButtonSecondaryBackground: "rgba(0, 0, 0, 0.06)",
      closeButton: "#575757",
      closeButtonBackground: "#D3D6D8",
      connectButtonBackground: "#2F383E",
      connectButtonBackgroundError: "#FF494A",
      connectButtonInnerBackground: "linear-gradient(0deg, rgba(0, 0, 0, 0.03), rgba(0, 0, 0, 0.06))",
      connectButtonText: accentColorForeground,
      connectButtonTextError: "#FFF",
      connectionIndicator: "#30E000",
      downloadBottomCardBackground: "linear-gradient(126deg, rgba(255, 255, 255, 0) 9.49%, rgba(171, 171, 171, 0.04) 71.04%), #FFFFFF",
      downloadTopCardBackground: "linear-gradient(126deg, rgba(171, 171, 171, 0.2) 9.49%, rgba(255, 255, 255, 0) 71.04%), #FFFFFF",
      error: "#FF494A",
      generalBorder: "#404C51",
      generalBorderDim: "red",
      menuItemBackground: "#404C51",
      modalBackdrop: "rgba(0, 0, 0, 0.3)",
      modalBackground: "#2F383E",
      modalBorder: "transparent",
      modalText: "#FFFFFF",
      modalTextDim: "#FFFFFF",
      modalTextSecondary: "rgba(255,255, 255, 0.6)",
      profileAction: "rgb(60, 66, 66)",
      profileActionHover: "#313232a6",
      profileForeground: "rgba(60, 66, 66, 0.06)",
      selectedOptionBorder: "rgba(60, 66, 66, 0.1)",
      standby: "#FFD641"
    },
    fonts: {
      body: 'SFRounded, ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"'
    },
    radii: {
      actionButton: "9999px",
      connectButton: "12px",
      menuButton: "12px",
      modal: "25px",
      modalMobile: "28px"
    },
    shadows: {
      connectButton: "0px 4px 12px rgba(0, 0, 0, 0.1)",
      dialog: "0px 8px 32px rgba(0, 0, 0, 0.32)",
      profileDetailsAction: "0px 2px 6px rgba(37, 41, 46, 0.04)",
      selectedOption: "0px 2px 6px rgba(0, 0, 0, 0.24)",
      selectedWallet: "0px 2px 6px rgba(0, 0, 0, 0.12)",
      walletLogo: "0px 2px 16px rgba(0, 0, 0, 0.16)"
    }
  };
  switch (themeName) {
    case "256noir":
      return t256noir;
    case "everforest":
      return teverforest;
    default:
      return tdefault;
  }
};
var AsteroidKitConfigurationProvider = ({
  appId,
  appInfo,
  avatar,
  children,
  coolMode,
  id,
  initialChain,
  modalSize,
  showRecentTransactions,
  theme
}) => {
  const [configuration, setConfiguration] = useState2({
    chains: [],
    siwe: false,
    size: "compact",
    social: false,
    theme: lightTheme(),
    wallets: []
  });
  const [appConfig, setAppConfig] = useState2();
  const { address, isConnected, status } = useAccount();
  const lastAvailableAddressRef = useRef();
  const lastStatusRef = useRef();
  const [isUserDetailsModalOpen, setIsUserDetailsModalOpen] = useState2(false);
  const onSubmitModal = async (userInfo) => {
    await setUserInfo({
      address,
      appId,
      userInfo: { ...userInfo, cancelled: false }
    }).catch((e) => {
      throw e;
    });
  };
  const onModalClose = async (resolution) => {
    if (resolution === 0 /* USER_CANCEL */) {
      await setUserInfo({
        address,
        appId,
        userInfo: { cancelled: true }
      }).catch((e) => {
        throw e;
      });
    }
    setIsUserDetailsModalOpen(false);
  };
  const { setReady, setValue } = useAsteroidKitSyncState();
  useEffect(() => {
    const init = async () => {
      if (isConnected) {
        const userInfo = await getUserInfo({ address, appId });
        if (!userInfo) {
          if (appConfig == null ? void 0 : appConfig.askUserInformation) {
            setIsUserDetailsModalOpen(true);
          } else {
            setUserInfo({ address, appId, userInfo: { cancelled: false } });
          }
        }
      }
    };
    init();
  }, [isConnected, address, appConfig]);
  useEffect(() => {
    if (status === "connected" /* CONNECTED */) {
      lastAvailableAddressRef.current = address;
    }
    if (lastStatusRef.current === "connected" /* CONNECTED */ && status === "disconnected" /* DISCONNECTED */ && lastAvailableAddressRef.current) {
      addEvent({
        address: lastAvailableAddressRef.current,
        appId,
        eventType: "disconnected" /* DISCONNECTED */
      });
    } else if ((lastStatusRef.current === "disconnected" /* DISCONNECTED */ || lastStatusRef.current === "connecting") && status === "connected" /* CONNECTED */ && lastAvailableAddressRef.current) {
      addEvent({
        address: lastAvailableAddressRef.current,
        appId,
        eventType: "connected" /* CONNECTED */
      });
    }
    lastStatusRef.current = status;
  }, [status]);
  useEffect(() => {
    getAppInfo(appId).then((data) => {
      setAppConfig(data);
      setConfiguration({
        chains: mapChainNameToWAGMIChain(data.chains),
        siwe: data.siwe,
        size: data.compact ? "compact" : "default",
        social: data.social,
        theme: theme != null ? theme : mapThemeNameToRainbowKitTheme(data.themeId, data.accentColor, data.accentForegroundColor),
        wallets: data.wallets
      });
      const wagmiChains = mapChainNameToWAGMIChain(data.chains);
      const defaultWallets = mapWalletNameToRainbowKitWallet(data.wallets, wagmiChains);
      const walletGroups = [
        {
          groupName: "Popular",
          wallets: defaultWallets
        }
      ];
      if (data.social) {
        const web3AuthInstance = configureWeb3Auth(wagmiChains);
        walletGroups.push({
          groupName: "Social",
          wallets: [
            GoogleConnector({
              chains: wagmiChains,
              web3AuthInstance
            }),
            TwitchConnector({
              chains: wagmiChains,
              web3AuthInstance
            })
          ]
        });
      }
      const connectors = connectorsForWallets(walletGroups);
      setValue(connectors);
      setReady(true);
    }).catch((error) => {
      throw new Error(`Unable to load AstereoidKit configuration. Reason: ${error}`);
    }).finally(() => {
    });
  }, []);
  useEffect(() => {
    if (theme) {
      setConfiguration({
        ...configuration,
        theme
      });
    }
  }, [theme]);
  const [AUTHENTICATION_STATUS, setAuthenticationStatus] = useState2("unauthenticated");
  const baseUrl = "https://auth.asteroidkit.com";
  const authenticationAdapter = createAuthenticationAdapter({
    createMessage: ({ address: address2, chainId, nonce }) => new SiweMessage({
      address: address2,
      chainId,
      domain: window.location.host,
      nonce,
      statement: "Sign in with Ethereum to the app.",
      uri: window.location.origin,
      version: "1"
    }),
    getMessageBody: ({ message }) => message.prepareMessage(),
    getNonce: async () => {
      const response = await fetch(`${baseUrl}/nonce`, {
        credentials: "include"
      });
      return response.text();
    },
    signOut: async () => {
      await fetch(`${baseUrl}/logout`);
    },
    verify: async ({ message, signature }) => {
      setAuthenticationStatus("authenticating");
      const verifyRes = await fetch(`${baseUrl}/verify`, {
        body: JSON.stringify({ message, signature }),
        credentials: "include",
        headers: { "Content-Type": "application/json" },
        method: "POST"
      });
      if (verifyRes.ok) {
        setAuthenticationStatus("authenticated");
      } else {
        setAuthenticationStatus("unauthenticated");
      }
      return Boolean(verifyRes.ok);
    }
  });
  return /* @__PURE__ */ React4.createElement(RainbowKitAuthenticationProvider, {
    adapter: authenticationAdapter,
    enabled: configuration.siwe,
    status: AUTHENTICATION_STATUS
  }, /* @__PURE__ */ React4.createElement(RainbowKitProvider, {
    appInfo,
    avatar,
    chains: configuration.chains,
    coolMode,
    id,
    initialChain,
    modalSize: modalSize != null ? modalSize : configuration.size,
    showRecentTransactions,
    theme: configuration.theme
  }, children, /* @__PURE__ */ React4.createElement(UserDetailsModal, {
    onClose: onModalClose,
    onSubmit: onSubmitModal,
    open: isUserDetailsModalOpen
  })));
};
var AsteroidKitProvider = ({
  appId,
  appInfo,
  avatar,
  chains: chainsFromUser,
  children,
  coolMode,
  id,
  initialChain,
  modalSize,
  showRecentTransactions,
  theme
}) => {
  const client = useClient();
  const chainsFromClient = client.chains;
  const chains = chainsFromClient != null ? chainsFromClient : chainsFromUser;
  return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(AsteroidKitSyncProvider, null, /* @__PURE__ */ React4.createElement(AsteroidKitConfigurationProvider, {
    appId,
    appInfo,
    avatar,
    chains,
    coolMode,
    id,
    initialChain,
    modalSize,
    showRecentTransactions,
    theme
  }, children)));
};

// src/asteroidkit/createClient.ts
import { configureChains as configureChains2, createClient as wagmiCreateClient } from "wagmi";
import {
  avalanche as avalanche2,
  avalancheFuji as avalancheFuji2,
  goerli as goerli2,
  mainnet as mainnet2,
  optimism as optimism2,
  optimismGoerli as optimismGoerli2,
  polygon as polygon2,
  polygonMumbai as polygonMumbai2
} from "wagmi/chains";
import { alchemyProvider } from "wagmi/providers/alchemy";
import { publicProvider as publicProvider2 } from "wagmi/providers/public";
var createClient = () => {
  const { chains, provider } = configureChains2([
    mainnet2,
    optimism2,
    avalanche2,
    polygon2,
    polygonMumbai2,
    goerli2,
    avalancheFuji2,
    optimismGoerli2
  ], [
    alchemyProvider({
      apiKey: "oZsv-F9NN3NhersEryE56jM08jomw0Ya"
    }),
    publicProvider2()
  ]);
  const walletList = [
    {
      groupName: "Recommended",
      wallets: [metaMaskWallet({ chains, shimDisconnect: true })]
    }
  ];
  const connectors = connectorsForWallets(walletList);
  const wagmiClient = wagmiCreateClient({
    autoConnect: true,
    connectors,
    provider
  });
  return wagmiClient;
};

// src/wallets/getDefaultWallets.ts
var getDefaultWallets = ({
  appName,
  chains
}) => {
  const wallets = [
    {
      groupName: "Popular",
      wallets: [
        injectedWallet({ chains }),
        rainbowWallet({ chains }),
        coinbaseWallet({ appName, chains }),
        metaMaskWallet({ chains }),
        walletConnectWallet({ chains }),
        braveWallet({ chains })
      ]
    }
  ];
  return {
    connectors: connectorsForWallets(wallets),
    wallets
  };
};

// src/transactions/useAddRecentTransaction.ts
import { useCallback } from "react";
import { useAccount as useAccount2 } from "wagmi";
function useAddRecentTransaction() {
  const store = useTransactionStore();
  const { address } = useAccount2();
  const chainId = useChainId();
  return useCallback((transaction) => {
    if (!address || !chainId) {
      throw new Error("No address or chain ID found");
    }
    store.addTransaction(address, chainId, transaction);
  }, [store, address, chainId]);
}

// src/__private__/index.ts
var __private__ = {
  DesktopOptions,
  dialogContent,
  dialogContentMobile,
  MobileOptions
};
export {
  AsteroidKitProvider,
  AsteroidKitSyncProvider,
  ConnectButton,
  RainbowKitAuthenticationProvider,
  RainbowKitProvider,
  __private__,
  connectorsForWallets,
  createAuthenticationAdapter,
  createClient,
  cssObjectFromTheme,
  cssStringFromTheme,
  darkTheme,
  getDefaultWallets,
  getWalletConnectConnector,
  lightTheme,
  midnightTheme,
  useAccountModal,
  useAddRecentTransaction,
  useAsteroidKitSyncState,
  useChainModal,
  useConnectModal
};
