import { n as getSubgraphUrl } from "./graphql-DCyS2juN.js";
//#region scripts/alchemy/alchemyEnvironment.ts
/**
* Environment-aware configuration for Alchemy API integration
* Follows the contributor-billing pattern for local/remote compatibility
*/
function getGraphQLUrl() {
	return getSubgraphUrl("acc-txs-addon");
}
let cachedUrl = null;
function getCachedGraphQLUrl() {
	if (cachedUrl === null) cachedUrl = getGraphQLUrl();
	return cachedUrl;
}
const AlchemyEnvironmentConfig = {
	get endpoint() {
		return getCachedGraphQLUrl();
	},
	get isLocal() {
		return getCachedGraphQLUrl().includes("localhost");
	},
	apiKey: typeof process !== "undefined" ? process.env.ALCHEMY_API_KEY : void 0,
	network: typeof process !== "undefined" ? process.env.ALCHEMY_NETWORK || "mainnet" : "mainnet",
	get debugInfo() {
		return {
			mode: this.isLocal ? "Local Connect" : "Remote Switchboard",
			endpoint: this.endpoint,
			network: this.network,
			hasApiKey: !!this.apiKey
		};
	}
};
/**
* Get the appropriate GraphQL endpoint based on environment
*/
function getAlchemyGraphQLEndpoint() {
	return AlchemyEnvironmentConfig.endpoint;
}
/**
* Check if we're running in local development mode
*/
function isLocalEnvironment() {
	return AlchemyEnvironmentConfig.isLocal;
}
//#endregion
//#region editors/account-transactions-editor/alchemyIntegration.ts
/**
* Environment-aware Alchemy integration for AccountTransactions
* Follows the contributor-billing pattern for local/remote compatibility
*/
var AlchemyIntegrationService = class {
	graphqlEndpoint;
	isLocal;
	constructor() {
		this.graphqlEndpoint = getAlchemyGraphQLEndpoint();
		this.isLocal = isLocalEnvironment();
	}
	/**
	* Get transaction data from Alchemy via GraphQL resolver (without document dependency)
	* Works in both local Connect and remote Switchboard environments
	*/
	async getTransactionsFromAlchemy(address, fromBlock) {
		try {
			const response = await fetch(this.graphqlEndpoint, {
				method: "POST",
				headers: { "Content-Type": "application/json" },
				body: JSON.stringify({
					query: `
            mutation GetTransactionsFromAlchemy($address: EthereumAddress!, $fromBlock: String) {
              AccountTransactions_getTransactionsFromAlchemy(address: $address, fromBlock: $fromBlock) {
                success
                transactions {
                  counterParty
                  amount
                  txHash
                  token
                  blockNumber
                  uniqueId
                  datetime
                  accountingPeriod
                  to
                  from
                  direction
                }
                message
                transactionsCount
              }
            }
          `,
					variables: {
						address,
						fromBlock
					}
				})
			});
			if (!response.ok) {
				const errorText = await response.text();
				console.error(`[AlchemyIntegration] GraphQL endpoint error:`, {
					status: response.status,
					statusText: response.statusText,
					errorText
				});
				throw new Error(`GraphQL endpoint error: ${response.status} - ${response.statusText} - ${errorText}`);
			}
			const result = await response.json();
			if (result.errors) throw new Error(result.errors[0]?.message || "GraphQL error");
			if (result.data?.AccountTransactions_getTransactionsFromAlchemy) return result.data.AccountTransactions_getTransactionsFromAlchemy;
			else throw new Error("Failed to get transactions from Alchemy");
		} catch (error) {
			console.error(`[AlchemyIntegration] Error in ${this.isLocal ? "local" : "remote"} mode:`, error);
			throw error;
		}
	}
	/**
	* Fetch transactions from Alchemy via GraphQL resolver
	* Works in both local Connect and remote Switchboard environments
	*/
	async fetchTransactionsForDocument(docId, address, fromBlock) {
		try {
			const response = await fetch(this.graphqlEndpoint, {
				method: "POST",
				headers: { "Content-Type": "application/json" },
				body: JSON.stringify({
					query: `
            mutation FetchTransactionsFromAlchemy($docId: PHID!, $address: EthereumAddress!, $fromBlock: String) {
              AccountTransactions_fetchTransactionsFromAlchemy(docId: $docId, address: $address, fromBlock: $fromBlock) {
                success
                transactionsAdded
                message
              }
            }
          `,
					variables: {
						docId,
						address,
						fromBlock
					}
				})
			});
			if (!response.ok) throw new Error(`GraphQL endpoint error: ${response.status} - ${response.statusText}`);
			const result = await response.json();
			if (result.errors) throw new Error(result.errors[0]?.message || "GraphQL error");
			if (result.data?.AccountTransactions_fetchTransactionsFromAlchemy?.success) return result.data.AccountTransactions_fetchTransactionsFromAlchemy;
			else throw new Error("Failed to fetch transactions from Alchemy");
		} catch (error) {
			console.error(`[AlchemyIntegration] Error in ${this.isLocal ? "local" : "remote"} mode:`, error);
			throw error;
		}
	}
	/**
	* Get environment information for debugging
	*/
	getEnvironmentInfo() {
		return {
			endpoint: this.graphqlEndpoint,
			mode: this.isLocal ? "Local Connect" : "Remote Switchboard",
			isLocal: this.isLocal
		};
	}
};
const alchemyIntegration = new AlchemyIntegrationService();
//#endregion
export { alchemyIntegration as t };

//# sourceMappingURL=alchemyIntegration-DsK1H6XE.js.map