import bisector from "../../d3-array/src/bisector.js";
import { tickStep } from "../../d3-array/src/ticks.js";
import { millisecond } from "./millisecond.js";
import { durationDay, durationHour, durationMinute, durationMonth, durationSecond, durationWeek, durationYear } from "./duration.js";
import { second } from "./second.js";
import { timeMinute, utcMinute } from "./minute.js";
import { timeHour, utcHour } from "./hour.js";
import { timeDay, unixDay } from "./day.js";
import { timeSunday, utcSunday } from "./week.js";
import { timeMonth, utcMonth } from "./month.js";
import { timeYear, utcYear } from "./year.js";
function ticker(y, b, x, S, C, w) {
	let T = [
		[
			second,
			1,
			durationSecond
		],
		[
			second,
			5,
			5 * durationSecond
		],
		[
			second,
			15,
			15 * durationSecond
		],
		[
			second,
			30,
			30 * durationSecond
		],
		[
			w,
			1,
			durationMinute
		],
		[
			w,
			5,
			5 * durationMinute
		],
		[
			w,
			15,
			15 * durationMinute
		],
		[
			w,
			30,
			30 * durationMinute
		],
		[
			C,
			1,
			durationHour
		],
		[
			C,
			3,
			3 * durationHour
		],
		[
			C,
			6,
			6 * durationHour
		],
		[
			C,
			12,
			12 * durationHour
		],
		[
			S,
			1,
			durationDay
		],
		[
			S,
			2,
			2 * durationDay
		],
		[
			x,
			1,
			durationWeek
		],
		[
			b,
			1,
			durationMonth
		],
		[
			b,
			3,
			3 * durationMonth
		],
		[
			y,
			1,
			durationYear
		]
	];
	function E(e, u, d) {
		let f = u < e;
		f && ([e, u] = [u, e]);
		let p = d && typeof d.range == "function" ? d : D(e, u, d), m = p ? p.range(e, +u + 1) : [];
		return f ? m.reverse() : m;
	}
	function D(f, p, m) {
		let h = Math.abs(p - f) / m, g = bisector(([, , e]) => e).right(T, h);
		if (g === T.length) return y.every(tickStep(f / durationYear, p / durationYear, m));
		if (g === 0) return millisecond.every(Math.max(tickStep(f, p, m), 1));
		let [_, v] = T[h / T[g - 1][2] < T[g][2] / h ? g - 1 : g];
		return _.every(v);
	}
	return [E, D];
}
var [utcTicks, utcTickInterval] = ticker(utcYear, utcMonth, utcSunday, unixDay, utcHour, utcMinute), [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, timeDay, timeHour, timeMinute);
export { timeTickInterval, timeTicks };
