import { getElementUpdate as e } from "../internal/utils/dom.js";
import { scopedRegistry as t } from "../internal/decorators/scoped-registry.js";
import { useStyles as n } from "../internal/styles/index.js";
import { __decorate as r } from "../_virtual/_@oxc-project_runtime@0.133.0/helpers/esm/decorate.js";
import { Icon as i } from "../icon/icon2.js";
import { Control as a } from "../forms/control/control2.js";
import o from "./star-rating.js";
import { html as s } from "lit";
import { state as c } from "lit/decorators/state.js";
//#region src/star-rating/star-rating.ts
var l = class extends a {
	constructor(...e) {
		super(...e), this.min = 0, this.max = 5, this.value = 0, this.active = 0, this.precision = .5;
	}
	static {
		this.styles = n([...a.styles, o]);
	}
	static {
		this.metadata = {
			tag: "nve-star-rating",
			version: "2.0.2"
		};
	}
	static {
		this.elementDefinitions = { [i.metadata.tag]: i };
	}
	firstUpdated(t) {
		super.firstUpdated(t), e(this.input, "max", (e) => {
			e && (this.max = parseInt(e));
		}), e(this.input, "min", (e) => {
			e && (this.min = parseInt(e));
		}), e(this.input, "value", (e) => {
			this.#n(e ? parseFloat(e) : this.input.valueAsNumber);
		}), this.input.addEventListener("input", () => this.value = this.input.valueAsNumber), this.value = this.input.valueAsNumber;
	}
	get prefixContent() {
		return s`<div aria-hidden="true" class="stars" @mouseleave="${() => this.active = 0}">${Array(this.max).fill("").map((e, t) => {
			let n = t + 1, r = (this.active || this.value) - t;
			return s`<nve-icon part="icon" @click="${() => this.#n(this.#t(t, n))}" @mousemove="${(e) => this.#e(e, t, n)}" name="${r >= 1 ? "star" : r >= .5 ? "star-half" : "star-stroke"}"></nve-icon>`;
		})}</div>`;
	}
	#e(e, t, n) {
		let r = e.currentTarget.getBoundingClientRect(), i = (e.clientX - r.left) / r.width;
		this.active = i <= .5 ? t + .5 : n;
	}
	#t(e, t) {
		return this.active > 0 ? this.active : this.value === t || this.value === e + .5 ? 0 : t;
	}
	#n(e) {
		this.input.valueAsNumber = e === this.value ? 0 : e, this.input.dispatchEvent(new Event("input", { bubbles: !0 })), this.input.dispatchEvent(new Event("change", { bubbles: !0 }));
	}
};
r([c()], l.prototype, "min", void 0), r([c()], l.prototype, "max", void 0), r([c()], l.prototype, "value", void 0), r([c()], l.prototype, "active", void 0), r([c()], l.prototype, "precision", void 0), l = r([t()], l);
//#endregion
export { l as StarRating };

//# sourceMappingURL=star-rating2.js.map