import { I18nController as e, i18n as t } from "../internal/controllers/i18n.controller.js";
import { onChildListMutation as n } from "../internal/utils/events.js";
import { focusElementTimeout as r, onListboxActivate as i } from "../internal/utils/focus.js";
import { appendRootNodeStyle as a, getElementUpdate as o } from "../internal/utils/dom.js";
import { scopedRegistry as s } from "../internal/decorators/scoped-registry.js";
import { useStyles as c } from "../internal/styles/index.js";
import { __decorate as l } from "../_virtual/_@oxc-project_runtime@0.133.0/helpers/esm/decorate.js";
import { Icon as u } from "../icon/icon2.js";
import { Control as d } from "../forms/control/control2.js";
import { Tag as f } from "../tag/tag2.js";
import { Menu as p } from "../menu/menu2.js";
import { MenuItem as m } from "../menu/menu-item2.js";
import { Dropdown as h } from "../dropdown/dropdown2.js";
import g from "./select.js";
import _ from "./select.global.js";
import { html as v, nothing as y } from "lit";
import { property as b } from "lit/decorators/property.js";
import { ifDefined as x } from "lit/directives/if-defined.js";
//#region src/select/select.ts
var S = class extends d {
	constructor(...t) {
		super(...t), this.#e = new e(this), this.i18n = this.#e.i18n, this.#l = [], this.#p = /* @__PURE__ */ new Map();
	}
	static {
		this.styles = c([...d.styles, g]);
	}
	static {
		this.metadata = {
			tag: "nve-select",
			version: "2.0.2"
		};
	}
	static {
		this.elementDefinitions = {
			[u.metadata.tag]: u,
			[h.metadata.tag]: h,
			[p.metadata.tag]: p,
			[m.metadata.tag]: m,
			[f.metadata.tag]: f
		};
	}
	#e;
	get #t() {
		return this.input;
	}
	get #n() {
		return Array.from(this.#t?.options ? this.#t.options : []);
	}
	get #r() {
		return this.shadowRoot.querySelector(h.metadata.tag);
	}
	get #i() {
		return this.shadowRoot.querySelectorAll(m.metadata.tag);
	}
	get #a() {
		return this.shadowRoot.querySelector("[input]");
	}
	get #o() {
		return this.shadowRoot.querySelector(".tags");
	}
	get #s() {
		return this.shadowRoot.querySelector("[name=\"caret\"]");
	}
	get #c() {
		return this.#n.find((e) => e.selected && e.hidden && e.disabled);
	}
	#l;
	get #u() {
		let e = this.#c, t = e ? e.innerText : `${this.#t.selectedOptions.length} ${this.i18n.selected}`;
		return v`<div class="tags-label ${e ? "placeholder" : ""}" aria-hidden="true">${t}</div>`;
	}
	get prefixContent() {
		return this.#t?.multiple && this.#t?.size === 0 ? v`${this.#u}<div class="tags">${this.#n.filter((e) => e.selected && e !== this.#c).map((e) => v`<nve-tag part="tag" readonly="readonly" color="gray-slate" closable .value="${e.value}" @click="${() => this.#x(e, !1)}">${e.textContent}</nve-tag>`)}</div>` : y;
	}
	get #d() {
		return v`<nve-menu part="menu" role="listbox" style="--width:100%;--min-width:fit-content" aria-label="${x(this.i18n.select)}">${this.#n.filter((e) => e !== this.#c).map((e, t) => v`<nve-menu-item part="menu-item" role="option" @click="${() => this.#x(e, !e.selected)}" ?selected="${e.selected}" ?disabled="${e.disabled}" ?hidden="${!!e.hidden}" aria-selected="${e.selected}"><slot name="option-${t + 1}"><nve-icon part="icon" name="check" size="sm" aria-hidden="true"></nve-icon>${e.innerText}</slot></nve-menu-item>`)}</nve-menu>`;
	}
	get suffixContent() {
		return this.#t?.size === 0 ? v`<nve-icon name="caret" part="caret" direction="down" size="sm" aria-hidden="true"></nve-icon><nve-dropdown part="dropdown" @close="${this.#y}" @open="${this.#v}" hidden .anchor="${this.#a}" position="bottom">${this.#d}</nve-dropdown>` : this.#d;
	}
	async firstUpdated(e) {
		super.firstUpdated(e), await this.updateComplete, this.#_();
	}
	#f() {
		this.#l.push(o(this.#t, "value", () => this.requestUpdate()), n(this.#t, () => this.requestUpdate(), {
			attributes: !0,
			subtree: !0
		}), n(this.#t, () => this.#g(), { subtree: !0 }));
	}
	#p;
	#m() {
		this.#h(), this.#b(), this.#f(), this.#g();
	}
	#h() {
		this.#l.forEach((e) => e.disconnect()), this.#l = [], this.#p.clear();
	}
	#g() {
		let e = new Set(this.#n);
		this.#p.forEach((t, n) => {
			e.has(n) || (t.disconnect(), this.#p.delete(n), this.#l = this.#l.filter((e) => e !== t));
		}), this.#n.forEach((e) => {
			if (!this.#p.has(e)) {
				let t = o(e, "selected", () => this.requestUpdate());
				this.#p.set(e, t), this.#l.push(t);
			}
		});
	}
	connectedCallback() {
		super.connectedCallback(), a(this, _), this.updateComplete.then(() => {
			this.isConnected && this.#m();
		});
	}
	disconnectedCallback() {
		super.disconnectedCallback(), this.#h();
	}
	async updated(e) {
		super.updated(e), this.#t?.size && this.#t?.size !== 0 ? (this._internals.states.add("size"), this.style.setProperty("--size", `${this.#t?.size + .75}`)) : (this._internals.states.delete("size"), this.style.removeProperty("--size")), this.#t?.multiple && this.#t?.size === 0 ? this._internals.states.add("multiple") : this._internals.states.delete("multiple");
	}
	#_() {
		this.#t?.size === 0 && i(this.#t, () => {
			this.requestUpdate(), this.#r.style.setProperty("--min-width", `${this.#a.getBoundingClientRect().width}px`), this.#r.showPopover(), r(this.#i[0]);
		});
	}
	#v() {
		this.#r.hidden = !1, this.#s.direction = "up";
	}
	#y() {
		this.#r.hidden = !0, this.#s.direction = "down";
	}
	#b() {
		let e = new ResizeObserver((e) => this.#S(e[0].contentRect.width));
		this.#l.push(e), e.observe(this.#a);
	}
	async #x(e, t) {
		(this.#t.multiple || !this.#t.multiple && e.value !== this.#t.value) && (e.selected = t), this.#t.selectedOptions.length < 1 && (this.#t.value = t ? e.value : ""), this.#t.dispatchEvent(new Event("input", { bubbles: !0 })), this.#t.dispatchEvent(new Event("change", { bubbles: !0 })), this.requestUpdate(), !this.#t.multiple && this.#r ? this.#r.hidePopover() : (await this.updateComplete, this.#S(this.#a.getBoundingClientRect().width));
	}
	#S(e) {
		let t = this.#o;
		this.#t?.multiple && t && t.getBoundingClientRect().width > e - 48 ? this._internals.states.add("multiple-overflow") : this._internals.states.delete("multiple-overflow");
	}
};
l([b({
	type: String,
	reflect: !0
})], S.prototype, "container", void 0), l([b({ type: Object })], S.prototype, "i18n", void 0), S = l([t(), s()], S);
//#endregion
export { S as Select };

//# sourceMappingURL=select2.js.map