import { audit as e } from "../internal/controllers/audit.controller.js";
import { I18nController as t } from "../internal/controllers/i18n.controller.js";
import { getFlattenedFocusableItems as n } from "../internal/utils/dom.js";
import { attachInternals as r } from "../internal/utils/a11y.js";
import { stateExpanded as i } from "../internal/controllers/state-expanded.controller.js";
import { stateHighlighted as a } from "../internal/controllers/state-highlighted.controller.js";
import { stateSelected as o } from "../internal/controllers/state-selected.controller.js";
import { typeAnchor as s } from "../internal/controllers/type-anchor.controller.js";
import { TypeExpandableController as c } from "../internal/controllers/type-expandable.controller.js";
import { TypeSelectableController as l } from "../internal/controllers/type-selectable.controller.js";
import { typeSSR as u } from "../internal/controllers/type-ssr.controller.js";
import { hostAttr as d } from "../internal/decorators/host-attr.js";
import { scopedRegistry as f } from "../internal/decorators/scoped-registry.js";
import { useStyles as p } from "../internal/styles/index.js";
import { __decorate as m } from "../_virtual/_@oxc-project_runtime@0.130.0/helpers/decorate.js";
import { Icon as h } from "../icon/icon2.js";
import { IconButton as g } from "../icon-button/icon-button2.js";
import { updateNodeSelection as _ } from "./utils.js";
import { Checkbox as v } from "../checkbox/checkbox2.js";
import y from "./tree-node.js";
import { LitElement as b, html as x, nothing as S } from "lit";
import { property as C } from "lit/decorators/property.js";
import { state as w } from "lit/decorators/state.js";
import { queryAssignedElements as T } from "lit/decorators/query-assigned-elements.js";
//#region src/tree/tree-node.ts
var E = class extends b {
	constructor(...e) {
		super(...e), this.expanded = !1, this.selected = !1, this.expandable = !1, this.highlighted = !1, this.#e = new t(this), this.i18n = this.#e.i18n, this.slot = "nodes", this.indeterminate = !1, this.behaviorExpand = !1, this.behaviorSelect = !1, this.#n = new c(this), this.#r = new l(this), this.#s = (e) => {
			this.#i && e.code === "ArrowLeft" && e.target === this && this.close(), this.#i && e.code === "ArrowRight" && e.target === this && this.open(), e.code === "Space" && e.target === this && this.selectable && (e.preventDefault(), this.#u());
		};
	}
	#e;
	get #t() {
		return this.closest("nve-tree");
	}
	#n;
	#r;
	get #i() {
		return this.expandable || this.expanded || !!this.nodes?.length;
	}
	static {
		this.metadata = {
			tag: "nve-tree-node",
			version: "0.2.3",
			parents: ["nve-tree", "nve-tree-node"]
		};
	}
	static {
		this.elementDefinitions = {
			[g.metadata.tag]: g,
			[h.metadata.tag]: h,
			[v.metadata.tag]: v
		};
	}
	static {
		this.styles = p([y]);
	}
	render() {
		return x`<div internal-host @slotchange="${this.#a}"><div part="_node">${this.#i ? x`<nve-icon-button part="icon-button" exportparts="icon:icon-button-icon" @pointerup="${this.#l}" role="presentation" tabindex="-1" size="sm" container="inline" nofocus><nve-icon part="icon" name="caret" direction="${this.expanded ? "down" : "right"}" size="sm"></nve-icon></nve-icon-button>` : S} ${this.selectable === "multi" ? x`<nve-checkbox part="checkbox" nofocus><input type="checkbox" @change="${this.#f}" .checked="${this.selected}" .indeterminate="${this.indeterminate}" .ariaLabel="${this.i18n.expand}" tabindex="-1"></nve-checkbox>` : S}<div tabindex="0" part="_node-header"><slot tabindex="0" class="node-title" @click="${this.#c}"></slot><slot name="content" part="_content"></slot></div></div><div role="group" part="_nodes"><slot name="nodes"></slot></div></div>`;
	}
	connectedCallback() {
		super.connectedCallback(), r(this), this._internals.role = "treeitem", this.addEventListener("keyup", this.#s), this.#a();
	}
	disconnectedCallback() {
		super.disconnectedCallback(), this.removeEventListener("keyup", this.#s);
	}
	open() {
		this.#n.open();
	}
	close() {
		this.#n.close();
	}
	#a() {
		this.requestUpdate(), this.#o();
	}
	#o() {
		this.#i ? this._internals.states.add("is-expandable") : this._internals.states.delete("is-expandable");
	}
	#s;
	#c(e) {
		let t = n(e.currentTarget).length;
		this.#i && !this.selectable && !t && this.#l(), this.selectable && (!t || e.target.localName === "a") && this.#u();
	}
	#l() {
		this.#n.toggle();
	}
	#u() {
		this.selectable === "single" && this.#d(), this.selectable === "multi" && this.#f();
	}
	#d() {
		this.#r.toggle(), this.behaviorSelect && this.#t.nodes.filter((e) => e !== this).forEach((e) => e.selected = !1);
	}
	#f() {
		this.#r.toggle(), this.behaviorSelect && (this.nodes.forEach((e) => {
			e.selected = this.selected, e.indeterminate = !1;
		}), this.#t.nodes.forEach((e) => _(e)));
	}
};
m([C({
	type: Boolean,
	reflect: !0
})], E.prototype, "expanded", void 0), m([C({
	type: Boolean,
	reflect: !0
})], E.prototype, "selected", void 0), m([C({ type: Boolean })], E.prototype, "expandable", void 0), m([C({ type: String })], E.prototype, "selectable", void 0), m([C({ type: Boolean })], E.prototype, "highlighted", void 0), m([C({ type: Object })], E.prototype, "i18n", void 0), m([d()], E.prototype, "slot", void 0), m([T({ slot: "nodes" })], E.prototype, "nodes", void 0), m([w()], E.prototype, "indeterminate", void 0), m([w()], E.prototype, "behaviorExpand", void 0), m([w()], E.prototype, "behaviorSelect", void 0), E = m([
	e(),
	u({ log: !1 }),
	s(),
	o(),
	i(),
	f(),
	a()
], E);
//#endregion
export { E as TreeNode };

//# sourceMappingURL=tree-node2.js.map