//#region src/elements/FetchMixin.ts
function FetchMixin(superClass) {
	class FetchElement extends superClass {
		constructor(..._args) {
			super(..._args);
			this.fetch = (url, init) => {
				try {
					let fetchPromise;
					const workbench = this.closest("ef-workbench");
					if (workbench?.fetch) fetchPromise = workbench.fetch(url, init);
					else {
						const preview = this.closest("ef-preview");
						if (preview?.fetch) fetchPromise = preview.fetch(url, init);
						else {
							const configuration = this.closest("ef-configuration");
							if (configuration?.fetch) fetchPromise = configuration.fetch(url, init);
							else fetchPromise = window.fetch(url, init);
						}
					}
					return fetchPromise.catch((error) => {
						const isAbortError = error instanceof Error && (error.name === "AbortError" || error.message.includes("signal is aborted") || error.message.includes("The user aborted a request"));
						const isDisconnected = !this.isConnected;
						const isNavigationAbort = isDisconnected && error instanceof TypeError && error.message === "Failed to fetch";
						if (isAbortError || isNavigationAbort || isDisconnected) throw error;
						console.error("FetchMixin fetch error", url, error, window.location.href);
						const enhancedError = new (error instanceof Error ? error.constructor : Error)(`Failed to fetch: ${url}. Original error: ${error instanceof Error ? error.message : String(error)}`);
						if (error instanceof Error) {
							try {
								enhancedError.name = error.name;
							} catch {
								try {
									Object.defineProperty(enhancedError, "name", {
										value: error.name,
										writable: true,
										enumerable: false,
										configurable: true
									});
								} catch {}
							}
							enhancedError.stack = error.stack;
							Object.assign(enhancedError, error);
						}
						throw enhancedError;
					});
				} catch (error) {
					console.error("FetchMixin error (synchronous)", url, error);
					throw error;
				}
			};
		}
	}
	return FetchElement;
}

//#endregion
export { FetchMixin };
//# sourceMappingURL=FetchMixin.js.map