"use client";
import { W as g, c as l, g as h, a as y, p as b, M as f, B as C, s as o, b as S, d as m, V as B, T } from "./index.package-DVXWP15X.js";
const I = ({
  solanaWallet: a,
  walletDetailsParams: s,
  connection: c
}) => l((t) => ({
  ...s,
  isSolanaConnector: !0,
  id: a.adapter.name,
  name: a.adapter.name,
  type: a.adapter.name,
  showQrModal: !1,
  sendTransaction: async (e) => {
    const n = m.from(e, "base64"), p = n.toString("base64") === e ? n : m.from(e, "hex");
    let i, r;
    try {
      i = B.deserialize(p);
    } catch (u) {
      r = u;
      try {
        i = T.from(p);
      } catch (d) {
        throw new Error(`Failed to deserialize Solana transaction. VersionedTransaction error: ${r instanceof Error ? r.message : String(r)}. Legacy Transaction error: ${d instanceof Error ? d.message : String(d)}`);
      }
    }
    return await a.adapter.sendTransaction(i, c);
  },
  connect: async (e) => (t.emitter.emit("message", {
    type: "connecting"
  }), t.storage?.removeItem("solana.disconnected"), await a.adapter.connect(), {
    accounts: e?.withCapabilities ? [{
      address: a.adapter.publicKey?.toBase58(),
      capabilities: {}
    }] : [a.adapter.publicKey?.toBase58()],
    chainId: o.id
  }),
  disconnect: () => (t.storage?.setItem("solana.disconnected", !0), a.adapter.disconnect()),
  getAccounts: async () => S.fromNullable(a.adapter.publicKey?.toBase58()).map((e) => [e]).unsafeCoerce(),
  switchChain: async () => o,
  getChainId: async () => o.id,
  isAuthorized: async () => await t.storage?.getItem("solana.disconnected") ? !1 : !!(a.adapter.connected && a.adapter.publicKey?.toBase58()),
  onAccountsChanged: (e) => {
    e.length === 0 ? t.emitter.emit("disconnect") : t.emitter.emit("change", {
      accounts: e
    });
  },
  onChainChanged: (e) => {
    t.emitter.emit("change", {
      chainId: e
    });
  },
  onDisconnect: () => {
    t.emitter.emit("disconnect");
  },
  getProvider: async () => ({}),
  $filteredChains: new C([o]).asObservable()
})), A = ({
  wallets: a,
  forceWalletConnectOnly: s,
  connection: c,
  variant: t
}) => ({
  groupName: "Solana",
  wallets: s ? [] : a.filter((e) => t === "porto" ? e.adapter instanceof g : !0).map((e) => () => ({
    id: e.adapter.name,
    name: t === "porto" ? "Porto" : e.adapter.name,
    iconUrl: t === "porto" ? b : e.adapter.icon,
    iconBackground: t === "porto" ? "#000" : "#fff",
    chainGroup: {
      iconUrl: y(f.Solana),
      title: "Solana",
      id: "solana"
    },
    installed: e.readyState === "Installed" || e.readyState === "Loadable",
    ...h(e.adapter),
    createConnector: (n) => I({
      solanaWallet: e,
      walletDetailsParams: n,
      connection: c
    })
  }))
});
export {
  A as getSolanaConnectors
};
