import { attachInternals as e } from "../internal/utils/a11y.js";
import { statusStateStyles as t, supportStateStyles as n, useStyles as r } from "../internal/styles/index.js";
import { __decorate as i } from "../_virtual/_@oxc-project_runtime@0.133.0/helpers/esm/decorate.js";
import { calculateDomain as a, calculateSymbolIndices as o, calculateViewBox as s, toAreaPath as c, toColumnRects as l, toInterpolation as u, toLinePath as d, toPlotPoints as f, toValidData as p, toWinLossRects as m, valueToY as h } from "./sparkline.utils.js";
import g from "./sparkline.js";
import { LitElement as _, html as v, nothing as y, svg as b } from "lit";
import { property as x } from "lit/decorators/property.js";
import { state as S } from "lit/decorators/state.js";
//#region src/sparkline/sparkline.ts
var C = class extends _ {
	constructor(...e) {
		super(...e), this.data = [], this.mark = "line", this.interpolation = "linear", this.denoteFirst = !1, this.denoteLast = !1, this.denoteMin = !1, this.denoteMax = !1, this.intervalLength = .6, this.validData = [];
	}
	static {
		this.styles = r([
			g,
			t,
			n
		]);
	}
	static {
		this.metadata = {
			tag: "nve-sparkline",
			version: "2.0.2"
		};
	}
	render() {
		return v`<div internal-host>${this.#e()}</div>`;
	}
	connectedCallback() {
		super.connectedCallback(), e(this), this._internals.role = "img";
	}
	willUpdate(e) {
		super.willUpdate(e), e.has("data") && (this.validData = p(this.data));
	}
	#e() {
		let { width: e, height: t } = s(this.mark, this.validData.length, this.intervalLength);
		switch (this.mark) {
			case "line":
			case "area":
			case "gradient": return this.#t(e, t);
			case "column": return this.#a(e, t);
			case "winloss": return this.#o(100 / 2, e, t);
			default: return this.mark, y;
		}
	}
	updated(e) {
		super.updated(e);
		let { width: t, height: n } = s(this.mark, this.validData.length, this.intervalLength), r = t / n, i = Number.isFinite(r) && r > 0 ? r : 1;
		this.style.setProperty("--_aspect-ratio", i.toFixed(4));
	}
	#t(e, t) {
		let n = a(this.validData, {
			explicitMin: this.min,
			explicitMax: this.max
		});
		if (!n) return y;
		let r = h(0, n), i = n.min < 0 && n.max > 0, s = f(this.validData, n, { width: e }), l = o(this.validData, {
			first: this.denoteFirst,
			last: this.denoteLast,
			min: this.denoteMin,
			max: this.denoteMax
		}), p = u(this.interpolation), m = d(s, p, e), g = this.mark === "area" || this.mark === "gradient" ? c(s, p, 100) : "";
		return b`<svg viewBox="0 0 ${e} ${t}" preserveAspectRatio="xMidYMid meet" aria-hidden="true">${this.mark === "gradient" ? this.#n(t) : y} ${g.length ? this.mark === "gradient" ? b`<path class="area" d="${g}" style="fill:url(#gradient)"></path>` : b`<path class="area" d="${g}"></path>` : y} ${i ? this.#r(r, e) : y} ${m ? b`<path class="line" d="${m}" vector-effect="non-scaling-stroke"></path>` : y}</svg> ${this.#i(s, l)}`;
	}
	#n(e) {
		return b`<defs><linearGradient id="gradient" x1="0" y1="0" x2="0" y2="${e}" gradientUnits="userSpaceOnUse"><stop offset="0%" style="stop-color:var(--gradient-max-color)"></stop><stop offset="100%" style="stop-color:var(--gradient-min-color)"></stop></linearGradient></defs>`;
	}
	#r(e, t) {
		return b`<line class="zero-line" vector-effect="non-scaling-stroke" x1="0" y1="${e.toFixed(2)}" x2="${t}" y2="${e.toFixed(2)}"></line>`;
	}
	#i(e, t) {
		return e.length === 0 || t.size === 0 ? y : v`${Array.from(t).map((t) => {
			let n = e[t];
			return n ? v`<span style="${`--x: ${n.x.toFixed(2)}; --y: ${n.y.toFixed(2)}`}" class="accent"></span>` : y;
		})}`;
	}
	#a(e, t) {
		let n = a(this.validData, {
			explicitMin: this.min,
			explicitMax: this.max,
			includeZero: !0
		});
		if (!n) return y;
		let r = h(0, n), i = n.min < 0 && n.max > 0, o = l(f(this.validData, n, { width: e }), r, e);
		return b`<svg viewBox="0 0 ${e} ${t}" preserveAspectRatio="xMidYMid meet" aria-hidden="true">${i ? this.#r(r, e) : y} ${o.map((e) => b`<rect class="column" x="${e.x.toFixed(2)}" y="${e.y.toFixed(2)}" width="${e.width.toFixed(2)}" height="${e.height.toFixed(2)}"></rect>`)}</svg>`;
	}
	#o(e, t, n) {
		if (this.validData.length === 0) return y;
		let r = m(this.validData, e, {
			width: t,
			height: n
		});
		return b`<svg viewBox="0 0 ${t} ${n}" preserveAspectRatio="xMidYMid meet" aria-hidden="true">${this.#r(e, t)} ${r.map((e) => b`<rect class="${e.className}" x="${e.x.toFixed(2)}" y="${e.y.toFixed(2)}" width="${e.width.toFixed(2)}" height="${e.height.toFixed(2)}"></rect>`)}</svg>`;
	}
};
i([x({ type: Array })], C.prototype, "data", void 0), i([x({ type: String })], C.prototype, "mark", void 0), i([x({ type: String })], C.prototype, "interpolation", void 0), i([x({
	type: String,
	reflect: !0
})], C.prototype, "status", void 0), i([x({
	type: String,
	reflect: !0
})], C.prototype, "size", void 0), i([x({
	type: Boolean,
	attribute: "denote-first",
	reflect: !0
})], C.prototype, "denoteFirst", void 0), i([x({
	type: Boolean,
	attribute: "denote-last",
	reflect: !0
})], C.prototype, "denoteLast", void 0), i([x({
	type: Boolean,
	attribute: "denote-min",
	reflect: !0
})], C.prototype, "denoteMin", void 0), i([x({
	type: Boolean,
	attribute: "denote-max",
	reflect: !0
})], C.prototype, "denoteMax", void 0), i([x({
	type: Number,
	attribute: "interval-length"
})], C.prototype, "intervalLength", void 0), i([x({ type: Number })], C.prototype, "min", void 0), i([x({ type: Number })], C.prototype, "max", void 0), i([S()], C.prototype, "validData", void 0);
//#endregion
export { C as Sparkline };

//# sourceMappingURL=sparkline2.js.map