import { get, set } from "./schedule.js";
function tweenRemove(e, n) {
	var r, i;
	return function() {
		var a = set(this, e), o = a.tween;
		if (o !== r) {
			i = r = o;
			for (var s = 0, c = i.length; s < c; ++s) if (i[s].name === n) {
				i = i.slice(), i.splice(s, 1);
				break;
			}
		}
		a.tween = i;
	};
}
function tweenFunction(e, n, r) {
	var i, a;
	if (typeof r != "function") throw Error();
	return function() {
		var o = set(this, e), s = o.tween;
		if (s !== i) {
			a = (i = s).slice();
			for (var c = {
				name: n,
				value: r
			}, l = 0, u = a.length; l < u; ++l) if (a[l].name === n) {
				a[l] = c;
				break;
			}
			l === u && a.push(c);
		}
		o.tween = a;
	};
}
function tween_default(t, i) {
	var a = this._id;
	if (t += "", arguments.length < 2) {
		for (var o = get(this.node(), a).tween, s = 0, c = o.length, l; s < c; ++s) if ((l = o[s]).name === t) return l.value;
		return null;
	}
	return this.each((i == null ? tweenRemove : tweenFunction)(a, t, i));
}
function tweenValue(n, r, i) {
	var a = n._id;
	return n.each(function() {
		var e = set(this, a);
		(e.value ||= {})[r] = i.apply(this, arguments);
	}), function(t) {
		return get(t, a).value[r];
	};
}
export { tween_default as default, tweenValue };
