import { GlobalStateService as e } from "../services/global.service.js";
import { auditParentElement as t, auditSlots as n } from "../utils/audit.js";
//#region src/internal/controllers/audit.controller.ts
var r = 50;
async function i(e) {
	let { LogService: t } = await import("../services/log.service.js");
	t.warn(e);
}
function a(e = {}) {
	return (t) => t.addInitializer((t) => new o(t, e));
}
var o = class {
	get #e() {
		return e.state.audit[this.host.localName] ?? { count: 0 };
	}
	get #t() {
		return e.state.env === "production";
	}
	get #n() {
		return this.host.constructor.metadata;
	}
	constructor(e, t) {
		this.host = e, this.options = t, this.#t || (this.host.addController(this), this.#r());
	}
	async hostConnected() {
		await this.host.updateComplete, this.#t || (this.#i(), this.#s(), this.#c());
	}
	hostDisconnected() {
		this.#a();
	}
	#r() {
		e.state.audit[this.host.localName] || this.#o({ [this.host.localName]: { count: 0 } });
	}
	async #i() {
		if (this.options.excessiveInstanceLimit !== void 0) if (this.#e.count > this.options.excessiveInstanceLimit && !this.#e.excessiveInstanceLimitAudited) {
			let { getExcessiveInstanceLimitWarning: e } = await import("../utils/audit-logs.js");
			i(e(this.#e.count, this.host.localName)), this.#o({ [this.host.localName]: {
				count: this.#e.count + 1,
				excessiveInstanceLimitAudited: !0
			} });
		} else this.#o({ [this.host.localName]: { count: this.#e.count + 1 } });
	}
	#a() {
		this.options.excessiveInstanceLimit && this.#o({ [this.host.localName]: {
			count: this.#e.count - 1,
			excessiveInstanceLimitAudited: !1
		} });
	}
	#o(t) {
		e.dispatch("NVE_ELEMENTS_AUDIT_UPDATE", { audit: t });
	}
	async #s() {
		if (this.#n.children || this.#n.disallowedChildren) {
			let [e, t] = n(this.host);
			if (e.length) {
				let { getInvalidSlottedChildrenWarning: e } = await import("../utils/audit-logs.js");
				i(e(this.host.localName, t));
			}
		}
	}
	async #c() {
		if (this.#n.parents) {
			let [e, n] = t(this.host);
			if (!e) {
				let { getInvalidParentWarning: e } = await import("../utils/audit-logs.js");
				i(e(this.host.localName, n.join(", ")));
			}
		}
	}
};
//#endregion
export { o as AuditController, a as audit, r as excessiveInstanceLimit };

//# sourceMappingURL=audit.controller.js.map