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

//#region src/gui/EFActiveRootTemporal.ts
let EFActiveRootTemporal = class EFActiveRootTemporal$1 extends LitElement {
	constructor(..._args) {
		super(..._args);
		this.canvas = "";
		this.activeRootTemporal = null;
		this.canvasElement = null;
	}
	static {
		this.styles = css`
    :host {
      display: inline-block;
    }
  `;
	}
	connectedCallback() {
		super.connectedCallback();
		this.findCanvas();
		this.setupListener();
	}
	disconnectedCallback() {
		super.disconnectedCallback();
		this.removeListener();
	}
	updated(changedProperties) {
		if (changedProperties.has("canvas")) {
			this.findCanvas();
			this.setupListener();
		}
	}
	/**
	* Find the canvas element to bind to.
	*/
	findCanvas() {
		if (this.canvas) {
			const byId = document.getElementById(this.canvas);
			if (byId && byId.tagName === "EF-CANVAS") {
				this.canvasElement = byId;
				return;
			}
			try {
				const bySelector = document.querySelector(this.canvas);
				if (bySelector && bySelector.tagName === "EF-CANVAS") {
					this.canvasElement = bySelector;
					return;
				}
			} catch {}
		}
		const ancestor = this.closest("ef-canvas");
		if (ancestor) {
			this.canvasElement = ancestor;
			return;
		}
		this.canvasElement = null;
	}
	/**
	* Setup listener for activeroottemporalchange events.
	*/
	setupListener() {
		this.removeListener();
		if (!this.canvasElement) {
			this.activeRootTemporal = null;
			return;
		}
		this.activeRootTemporal = this.canvasElement.activeRootTemporal || null;
		this.activeroottemporalchangeHandler = () => {
			this.activeRootTemporal = this.canvasElement.activeRootTemporal || null;
		};
		this.canvasElement.addEventListener("activeroottemporalchange", this.activeroottemporalchangeHandler);
	}
	/**
	* Remove event listener.
	*/
	removeListener() {
		if (this.canvasElement && this.activeroottemporalchangeHandler) {
			this.canvasElement.removeEventListener("activeroottemporalchange", this.activeroottemporalchangeHandler);
			this.activeroottemporalchangeHandler = void 0;
		}
	}
	render() {
		return html`<span>${this.activeRootTemporal?.id || this.textContent || "None"}</span>`;
	}
};
__decorate([property({ type: String })], EFActiveRootTemporal.prototype, "canvas", void 0);
__decorate([state()], EFActiveRootTemporal.prototype, "activeRootTemporal", void 0);
EFActiveRootTemporal = __decorate([customElement("ef-active-root-temporal")], EFActiveRootTemporal);

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