import { __decorate } from "../_virtual/_@oxc-project_runtime@0.95.0/helpers/decorate.js";
import { panZoomTransformContext } from "./panZoomTransformContext.js";
import { consume } from "@lit/context";
import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators.js";

//#region src/gui/EFOverlayLayer.ts
let EFOverlayLayer = class EFOverlayLayer$1 extends LitElement {
	constructor(..._args) {
		super(..._args);
		this.registeredItems = /* @__PURE__ */ new Set();
		this.rafId = null;
	}
	static {
		this.styles = [css`
      :host {
        display: block;
        position: absolute;
        inset: 0;
        pointer-events: none;
        transform-origin: 0 0;
      }
    `];
	}
	/**
	* Register an overlay item for coordinated updates.
	* Called by EFOverlayItem in connectedCallback.
	*/
	registerOverlayItem(item) {
		this.registeredItems.add(item);
	}
	/**
	* Unregister an overlay item.
	* Called by EFOverlayItem in disconnectedCallback.
	*/
	unregisterOverlayItem(item) {
		this.registeredItems.delete(item);
	}
	/**
	* Single source of truth for reading the current transform.
	* Priority: context > sibling DOM read > prop > default
	*/
	readTransform() {
		if (this.panZoomTransformFromContext) return this.panZoomTransformFromContext;
		const panZoomElement = this.parentElement?.querySelector("ef-pan-zoom");
		if (panZoomElement && typeof panZoomElement.x === "number") {
			const contentWrapper = panZoomElement.shadowRoot?.querySelector(".content-wrapper");
			const matrixMatch = (contentWrapper && window.getComputedStyle(contentWrapper).transform)?.match(/matrix\(([^)]+)\)/);
			const scale = matrixMatch ? parseFloat(matrixMatch[1].split(",")[0].trim()) : panZoomElement.scale ?? 1;
			return {
				x: panZoomElement.x ?? 0,
				y: panZoomElement.y ?? 0,
				scale
			};
		}
		if (this.panZoomTransform) return this.panZoomTransform;
		return {
			x: 0,
			y: 0,
			scale: 1
		};
	}
	/**
	* Simple RAF loop: Update everything on every frame.
	*/
	startLoop() {
		const update = () => {
			const transform = this.readTransform();
			if (this.panZoomTransformFromContext) this.style.transform = "none";
			else this.style.transform = `translate(${transform.x}px, ${transform.y}px)`;
			for (const item of this.registeredItems) item.updatePosition();
			this.rafId = requestAnimationFrame(update);
		};
		this.rafId = requestAnimationFrame(update);
	}
	stopLoop() {
		if (this.rafId !== null) {
			cancelAnimationFrame(this.rafId);
			this.rafId = null;
		}
	}
	connectedCallback() {
		super.connectedCallback();
		this.startLoop();
	}
	disconnectedCallback() {
		super.disconnectedCallback();
		this.stopLoop();
	}
	updated() {}
	render() {
		return html`<slot></slot>`;
	}
};
__decorate([consume({
	context: panZoomTransformContext,
	subscribe: true
})], EFOverlayLayer.prototype, "panZoomTransformFromContext", void 0);
__decorate([property({ type: Object })], EFOverlayLayer.prototype, "panZoomTransform", void 0);
EFOverlayLayer = __decorate([customElement("ef-overlay-layer")], EFOverlayLayer);

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