import { Task } from "@lit/task";
import _decorate from "@oxc-project/runtime/helpers/decorate";
import { property } from "lit/decorators/property.js";
function EFSourceMixin(superClass, options) {
	class EFSourceElement extends superClass {
		constructor(..._args) {
			super(..._args);
			this.src = "";
			this.md5SumLoader = new Task(this, {
				autoRun: false,
				args: () => [this.src],
				task: async ([src], { signal }) => {
					const md5Path = `/@ef-asset/${src}`;
					const response = await fetch(md5Path, {
						method: "HEAD",
						signal
					});
					return response.headers.get("etag") ?? void 0;
				}
			});
		}
		get apiHost() {
			const apiHost = this.closest("ef-configuration")?.apiHost ?? this.closest("ef-workbench")?.apiHost ?? this.closest("ef-preview")?.apiHost;
			return apiHost || "https://editframe.dev";
		}
		productionSrc() {
			if (!this.md5SumLoader.value) throw new Error(`MD5 sum not available for ${this}. Cannot generate production URL`);
			if (!this.apiHost) throw new Error(`apiHost not available for ${this}. Cannot generate production URL`);
			return `${this.apiHost}/api/v1/${options.assetType}/${this.md5SumLoader.value}`;
		}
	}
	_decorate([property({ type: String })], EFSourceElement.prototype, "src", void 0);
	return EFSourceElement;
}
export { EFSourceMixin };
