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

//#region src/canvas/EFCanvasItem.ts
let EFCanvasItem = class EFCanvasItem$1 extends LitElement {
	constructor(..._args) {
		super(..._args);
		this.id = "";
		this.canvas = null;
		this.api = null;
		this.registeredId = null;
	}
	static {
		this.styles = css`
    :host {
      display: block;
      position: absolute;
    }
  `;
	}
	connectedCallback() {
		super.connectedCallback();
		this.findAndRegister();
	}
	disconnectedCallback() {
		super.disconnectedCallback();
		this.unregister();
	}
	/**
	* Find parent ef-canvas and register this element.
	*/
	findAndRegister() {
		this.canvas = this.closest("ef-canvas");
		if (!this.canvas) {
			console.warn("[EFCanvasItem] No parent ef-canvas found. Element will not be registered.");
			return;
		}
		this.canvas.updateComplete.then(() => {
			this.api = new CanvasAPI(this.canvas);
			if (!this.id) {
				console.error("[EFCanvasItem] Element must have an 'id' attribute. Set it before adding to canvas.");
				return;
			}
			this.registeredId = this.api.registerElement(this, this.id);
		});
	}
	/**
	* Unregister this element from the canvas.
	*/
	unregister() {
		if (this.api && this.registeredId) {
			this.api.unregisterElement(this.registeredId);
			this.registeredId = null;
		}
		this.api = null;
		this.canvas = null;
	}
	render() {
		return html`<slot></slot>`;
	}
};
__decorate([property({
	type: String,
	reflect: true
})], EFCanvasItem.prototype, "id", void 0);
EFCanvasItem = __decorate([customElement("ef-canvas-item")], EFCanvasItem);

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