"use client";
import { d as w } from "./index-DpX_wMlr.js";
import { S as l, d as p } from "./sdk-CvwOTvDp.js";
import { i as e, c as g, B as v, E as h, P as o, j as y, w as C, k as S, d as x } from "./index.package-CCkqpqsB.js";
function A(m = {}) {
  const {
    shimDisconnect: r = !1
  } = m;
  let i, n;
  return g((s) => {
    const d = new v([]), a = new l();
    return {
      id: e.id,
      name: e.name,
      type: e.type,
      async connect() {
        const t = await this.getProvider();
        if (!t) throw new o();
        const u = await this.getAccounts(), f = await this.getChainId();
        return d.next(x.fromNullable(s.chains.find((c) => c.id === f)).map((c) => [c]).orDefault([])), n || (n = this.onDisconnect.bind(this), t.on("disconnect", n)), r && await s.storage?.removeItem("safe.disconnected"), {
          accounts: u,
          chainId: f
        };
      },
      async disconnect() {
        const t = await this.getProvider();
        if (!t) throw new o();
        n && (t.removeListener("disconnect", n), n = void 0), r && await s.storage?.setItem("safe.disconnected", !0);
      },
      async getAccounts() {
        const t = await this.getProvider();
        if (!t) throw new o();
        return (await t.request({
          method: "eth_accounts"
        })).map(S);
      },
      async getProvider() {
        if (y()) {
          if (!i) {
            const t = await C(() => a.safe.getInfo(), {
              timeout: 10
            });
            if (!t) throw new Error("Could not load Safe information");
            i = new w.SafeAppProvider(t, a);
          }
          return i;
        }
      },
      async getChainId() {
        const t = await this.getProvider();
        if (!t) throw new o();
        return Number(t.chainId);
      },
      async isAuthorized() {
        try {
          return r && // If shim exists in storage, connector is disconnected
          await s.storage?.getItem("safe.disconnected") ? !1 : !!(await this.getAccounts()).length;
        } catch {
          return !1;
        }
      },
      onAccountsChanged() {
      },
      onChainChanged() {
      },
      onDisconnect() {
        s.emitter.emit("disconnect");
      },
      $filteredChains: d,
      getTxStatus(t) {
        return h(() => a.txs.getBySafeTxHash(t)).mapLeft(() => new Error("Could not get transaction status"));
      },
      txStatus: p.TransactionStatus,
      sendTransactions(t) {
        return h(() => a.txs.send(t)).mapLeft(() => new Error("Could not send transactions"));
      }
    };
  });
}
const P = () => ({
  groupName: "Safe Wallet",
  wallets: [() => ({
    id: e.id,
    name: e.name,
    iconUrl: "",
    iconBackground: "#fff",
    chainGroup: {
      id: e.id,
      title: e.name,
      iconUrl: ""
    },
    createConnector: () => A({
      shimDisconnect: !0
    })
  })]
});
export {
  P as safeConnector
};
//# sourceMappingURL=safe-connector-DMUtWiH_.js.map
