import { appendRootNodeStyle as e } from "../../internal/utils/dom.js";
import { attachInternals as t } from "../../internal/utils/a11y.js";
import { useStyles as n } from "../../internal/styles/index.js";
import { __decorate as r } from "../../_virtual/_@oxc-project_runtime@0.130.0/helpers/decorate.js";
import i from "./column.js";
import { LitElement as a, html as o } from "lit";
import { property as s } from "lit/decorators/property.js";
//#region src/grid/column/column.ts
var c = class r extends a {
	static {
		this.styles = n([i]);
	}
	static {
		this.metadata = {
			tag: "nve-grid-column",
			version: "0.2.3"
		};
	}
	get #e() {
		return this.parentElement.parentElement;
	}
	render() {
		return o`<div internal-host focusable="active"><slot></slot><slot name="actions"></slot></div>`;
	}
	connectedCallback() {
		super.connectedCallback(), t(this), this._internals.role = "columnheader", this.addEventListener("sort", this.#t);
	}
	disconnectedCallback() {
		super.disconnectedCallback(), this.removeEventListener("sort", this.#t);
	}
	#t = (e) => {
		this.ariaSort = e.detail.next;
	};
	willUpdate(e) {
		e.has("width") && this.width && Number.isFinite(Number(this.width)) && (this.width = `${this.width}px`);
	}
	async updated(e) {
		super.updated(e), e.get("columnAlign") !== this.columnAlign && this.#o(), e.get("position") !== this.position && this.#r(), e.get("ariaColIndex") !== this.ariaColIndex && (this.#r(), this.#o()), e.get("width") !== this.width && this.dispatchEvent(new CustomEvent("nve-grid-column-resize", {
			bubbles: !0,
			composed: !0
		}));
	}
	#n;
	#r() {
		if (this.position !== "fixed") {
			this.removeAttribute("left"), this.removeAttribute("right"), this.#n?.replaceSync("");
			return;
		}
		let { side: t, positionStyle: n, borderStyle: r } = this.#i(), i = `${n}\n${r}`;
		this.#n ? this.#n.replaceSync(i) : this.#n = e(this.#e, i), this.setAttribute(t, "");
	}
	#i() {
		let e = Array.from(this.parentElement.querySelectorAll(r.metadata.tag)), t = e.slice(e.indexOf(this) + 1, e.length), n = this.getBoundingClientRect(), i = this.#e.getBoundingClientRect(), a = this.offsetLeft < i.width / 2 ? "left" : "right", o = n.left - i.left, s = t.reduce((e, t) => e + t.getBoundingClientRect().width, 0), c = `[id='${this.#e.id}'] nve-grid-column:nth-of-type(${this.ariaColIndex}),
        [id='${this.#e.id}'] nve-grid-cell:nth-of-type(${this.ariaColIndex})`;
		return {
			side: a,
			positionStyle: `
        ${c} {
          position: sticky;
          z-index: 99;
          ${a === "left" ? `left: ${o}px;` : `right: ${s}px;`}
        }
      `,
			borderStyle: this.#a(c, a)
		};
	}
	#a(e, t) {
		let n = t === "left" && this.nextElementSibling?.position !== this.position, r = t === "right" && this.previousElementSibling?.position !== this.position;
		return !n && !r ? "" : `
        ${e} {
          box-shadow: var(--scroll-shadow);
          clip-path: inset(0px ${n ? "-4px" : "0"} 0px ${r ? "-4px" : "0"});
          --border-${t === "right" ? "left" : "right"}: var(--nve-ref-border-width-sm) solid var(--nve-ref-border-color-muted);
        }
      `;
	}
	#o() {
		this.columnAlign !== void 0 && e(this.#e, `[id='${this.#e.id}'] nve-grid-column:nth-of-type(${this.ariaColIndex}),
        [id='${this.#e.id}'] nve-grid-cell:nth-of-type(${this.ariaColIndex}) {
          --justify-content: ${this.columnAlign}
        }`);
	}
};
r([s({
	type: String,
	reflect: !0
})], c.prototype, "width", void 0), r([s({
	type: String,
	reflect: !0
})], c.prototype, "position", void 0), r([s({
	type: String,
	reflect: !0,
	attribute: "column-align"
})], c.prototype, "columnAlign", void 0), r([s({
	type: String,
	reflect: !0,
	attribute: "aria-colindex"
})], c.prototype, "ariaColIndex", void 0);
//#endregion
export { c as GridColumn };

//# sourceMappingURL=column2.js.map