import { timeDay, utcDay } from "../../d3-time/src/day.js";
import { timeMonday, timeSunday, timeThursday, utcMonday, utcSunday, utcThursday } from "../../d3-time/src/week.js";
import { timeYear, utcYear } from "../../d3-time/src/year.js";
function localDate(e) {
	if (0 <= e.y && e.y < 100) {
		var o = new Date(-1, e.m, e.d, e.H, e.M, e.S, e.L);
		return o.setFullYear(e.y), o;
	}
	return new Date(e.y, e.m, e.d, e.H, e.M, e.S, e.L);
}
function utcDate(e) {
	if (0 <= e.y && e.y < 100) {
		var o = new Date(Date.UTC(-1, e.m, e.d, e.H, e.M, e.S, e.L));
		return o.setUTCFullYear(e.y), o;
	}
	return new Date(Date.UTC(e.y, e.m, e.d, e.H, e.M, e.S, e.L));
}
function newDate(e, o, s) {
	return {
		y: e,
		m: o,
		d: s,
		H: 0,
		M: 0,
		S: 0,
		L: 0
	};
}
function formatLocale(c) {
	var l = c.dateTime, d = c.date, f = c.time, p = c.periods, m = c.days, h = c.shortDays, g = c.months, _ = c.shortMonths, v = formatRe(p), y = formatLookup(p), b = formatRe(m), x = formatLookup(m), S = formatRe(h), C = formatLookup(h), w = formatRe(g), T = formatLookup(g), E = formatRe(_), D = formatLookup(_), O = {
		a: H,
		A: U,
		b: W,
		B: G,
		c: null,
		d: formatDayOfMonth,
		e: formatDayOfMonth,
		f: formatMicroseconds,
		g: formatYearISO,
		G: formatFullYearISO,
		H: formatHour24,
		I: formatHour12,
		j: formatDayOfYear,
		L: formatMilliseconds,
		m: formatMonthNumber,
		M: formatMinutes,
		p: K,
		q,
		Q: formatUnixTimestamp,
		s: formatUnixTimestampSeconds,
		S: formatSeconds,
		u: formatWeekdayNumberMonday,
		U: formatWeekNumberSunday,
		V: formatWeekNumberISO,
		w: formatWeekdayNumberSunday,
		W: formatWeekNumberMonday,
		x: null,
		X: null,
		y: formatYear,
		Y: formatFullYear,
		Z: formatZone,
		"%": formatLiteralPercent
	}, k = {
		a: J,
		A: Y,
		b: X,
		B: Z,
		c: null,
		d: formatUTCDayOfMonth,
		e: formatUTCDayOfMonth,
		f: formatUTCMicroseconds,
		g: formatUTCYearISO,
		G: formatUTCFullYearISO,
		H: formatUTCHour24,
		I: formatUTCHour12,
		j: formatUTCDayOfYear,
		L: formatUTCMilliseconds,
		m: formatUTCMonthNumber,
		M: formatUTCMinutes,
		p: Q,
		q: $,
		Q: formatUnixTimestamp,
		s: formatUnixTimestampSeconds,
		S: formatUTCSeconds,
		u: formatUTCWeekdayNumberMonday,
		U: formatUTCWeekNumberSunday,
		V: formatUTCWeekNumberISO,
		w: formatUTCWeekdayNumberSunday,
		W: formatUTCWeekNumberMonday,
		x: null,
		X: null,
		y: formatUTCYear,
		Y: formatUTCFullYear,
		Z: formatUTCZone,
		"%": formatLiteralPercent
	}, A = {
		a: F,
		A: I,
		b: L,
		B: R,
		c: z,
		d: parseDayOfMonth,
		e: parseDayOfMonth,
		f: parseMicroseconds,
		g: parseYear,
		G: parseFullYear,
		H: parseHour24,
		I: parseHour24,
		j: parseDayOfYear,
		L: parseMilliseconds,
		m: parseMonthNumber,
		M: parseMinutes,
		p: P,
		q: parseQuarter,
		Q: parseUnixTimestamp,
		s: parseUnixTimestampSeconds,
		S: parseSeconds,
		u: parseWeekdayNumberMonday,
		U: parseWeekNumberSunday,
		V: parseWeekNumberISO,
		w: parseWeekdayNumberSunday,
		W: parseWeekNumberMonday,
		x: B,
		X: V,
		y: parseYear,
		Y: parseFullYear,
		Z: parseZone,
		"%": parseLiteralPercent
	};
	O.x = j(d, O), O.X = j(f, O), O.c = j(l, O), k.x = j(d, k), k.X = j(f, k), k.c = j(l, k);
	function j(e, o) {
		return function(s) {
			var c = [], l = -1, u = 0, d = e.length, f, p, m;
			for (s instanceof Date || (s = /* @__PURE__ */ new Date(+s)); ++l < d;) e.charCodeAt(l) === 37 && (c.push(e.slice(u, l)), (p = pads[f = e.charAt(++l)]) == null ? p = f === "e" ? " " : "0" : f = e.charAt(++l), (m = o[f]) && (f = m(s, p)), c.push(f), u = l + 1);
			return c.push(e.slice(u, l)), c.join("");
		};
	}
	function M(c, l) {
		return function(d) {
			var f = newDate(1900, void 0, 1), p = N(f, c, d += "", 0), m, h;
			if (p != d.length) return null;
			if ("Q" in f) return new Date(f.Q);
			if ("s" in f) return new Date(f.s * 1e3 + ("L" in f ? f.L : 0));
			if (l && !("Z" in f) && (f.Z = 0), "p" in f && (f.H = f.H % 12 + f.p * 12), f.m === void 0 && (f.m = "q" in f ? f.q : 0), "V" in f) {
				if (f.V < 1 || f.V > 53) return null;
				"w" in f || (f.w = 1), "Z" in f ? (m = utcDate(newDate(f.y, 0, 1)), h = m.getUTCDay(), m = h > 4 || h === 0 ? utcMonday.ceil(m) : utcMonday(m), m = utcDay.offset(m, (f.V - 1) * 7), f.y = m.getUTCFullYear(), f.m = m.getUTCMonth(), f.d = m.getUTCDate() + (f.w + 6) % 7) : (m = localDate(newDate(f.y, 0, 1)), h = m.getDay(), m = h > 4 || h === 0 ? timeMonday.ceil(m) : timeMonday(m), m = timeDay.offset(m, (f.V - 1) * 7), f.y = m.getFullYear(), f.m = m.getMonth(), f.d = m.getDate() + (f.w + 6) % 7);
			} else ("W" in f || "U" in f) && ("w" in f || (f.w = "u" in f ? f.u % 7 : "W" in f ? 1 : 0), h = "Z" in f ? utcDate(newDate(f.y, 0, 1)).getUTCDay() : localDate(newDate(f.y, 0, 1)).getDay(), f.m = 0, f.d = "W" in f ? (f.w + 6) % 7 + f.W * 7 - (h + 5) % 7 : f.w + f.U * 7 - (h + 6) % 7);
			return "Z" in f ? (f.H += f.Z / 100 | 0, f.M += f.Z % 100, utcDate(f)) : localDate(f);
		};
	}
	function N(e, o, s, c) {
		for (var l = 0, u = o.length, d = s.length, f, p; l < u;) {
			if (c >= d) return -1;
			if (f = o.charCodeAt(l++), f === 37) {
				if (f = o.charAt(l++), p = A[f in pads ? o.charAt(l++) : f], !p || (c = p(e, s, c)) < 0) return -1;
			} else if (f != s.charCodeAt(c++)) return -1;
		}
		return c;
	}
	function P(e, o, s) {
		var c = v.exec(o.slice(s));
		return c ? (e.p = y.get(c[0].toLowerCase()), s + c[0].length) : -1;
	}
	function F(e, o, s) {
		var c = S.exec(o.slice(s));
		return c ? (e.w = C.get(c[0].toLowerCase()), s + c[0].length) : -1;
	}
	function I(e, o, s) {
		var c = b.exec(o.slice(s));
		return c ? (e.w = x.get(c[0].toLowerCase()), s + c[0].length) : -1;
	}
	function L(e, o, s) {
		var c = E.exec(o.slice(s));
		return c ? (e.m = D.get(c[0].toLowerCase()), s + c[0].length) : -1;
	}
	function R(e, o, s) {
		var c = w.exec(o.slice(s));
		return c ? (e.m = T.get(c[0].toLowerCase()), s + c[0].length) : -1;
	}
	function z(e, o, s) {
		return N(e, l, o, s);
	}
	function B(e, o, s) {
		return N(e, d, o, s);
	}
	function V(e, o, s) {
		return N(e, f, o, s);
	}
	function H(e) {
		return h[e.getDay()];
	}
	function U(e) {
		return m[e.getDay()];
	}
	function W(e) {
		return _[e.getMonth()];
	}
	function G(e) {
		return g[e.getMonth()];
	}
	function K(e) {
		return p[+(e.getHours() >= 12)];
	}
	function q(e) {
		return 1 + ~~(e.getMonth() / 3);
	}
	function J(e) {
		return h[e.getUTCDay()];
	}
	function Y(e) {
		return m[e.getUTCDay()];
	}
	function X(e) {
		return _[e.getUTCMonth()];
	}
	function Z(e) {
		return g[e.getUTCMonth()];
	}
	function Q(e) {
		return p[+(e.getUTCHours() >= 12)];
	}
	function $(e) {
		return 1 + ~~(e.getUTCMonth() / 3);
	}
	return {
		format: function(e) {
			var o = j(e += "", O);
			return o.toString = function() {
				return e;
			}, o;
		},
		parse: function(e) {
			var o = M(e += "", !1);
			return o.toString = function() {
				return e;
			}, o;
		},
		utcFormat: function(e) {
			var o = j(e += "", k);
			return o.toString = function() {
				return e;
			}, o;
		},
		utcParse: function(e) {
			var o = M(e += "", !0);
			return o.toString = function() {
				return e;
			}, o;
		}
	};
}
var pads = {
	"-": "",
	_: " ",
	0: "0"
}, numberRe = /^\s*\d+/, percentRe = /^%/, requoteRe = /[\\^$*+?|[\]().{}]/g;
function pad(e, o, s) {
	var c = e < 0 ? "-" : "", l = (c ? -e : e) + "", u = l.length;
	return c + (u < s ? Array(s - u + 1).join(o) + l : l);
}
function requote(e) {
	return e.replace(requoteRe, "\\$&");
}
function formatRe(e) {
	return RegExp("^(?:" + e.map(requote).join("|") + ")", "i");
}
function formatLookup(e) {
	return new Map(e.map((e, o) => [e.toLowerCase(), o]));
}
function parseWeekdayNumberSunday(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 1));
	return c ? (e.w = +c[0], s + c[0].length) : -1;
}
function parseWeekdayNumberMonday(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 1));
	return c ? (e.u = +c[0], s + c[0].length) : -1;
}
function parseWeekNumberSunday(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.U = +c[0], s + c[0].length) : -1;
}
function parseWeekNumberISO(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.V = +c[0], s + c[0].length) : -1;
}
function parseWeekNumberMonday(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.W = +c[0], s + c[0].length) : -1;
}
function parseFullYear(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 4));
	return c ? (e.y = +c[0], s + c[0].length) : -1;
}
function parseYear(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.y = +c[0] + (+c[0] > 68 ? 1900 : 2e3), s + c[0].length) : -1;
}
function parseZone(e, o, s) {
	var c = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(o.slice(s, s + 6));
	return c ? (e.Z = c[1] ? 0 : -(c[2] + (c[3] || "00")), s + c[0].length) : -1;
}
function parseQuarter(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 1));
	return c ? (e.q = c[0] * 3 - 3, s + c[0].length) : -1;
}
function parseMonthNumber(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.m = c[0] - 1, s + c[0].length) : -1;
}
function parseDayOfMonth(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.d = +c[0], s + c[0].length) : -1;
}
function parseDayOfYear(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 3));
	return c ? (e.m = 0, e.d = +c[0], s + c[0].length) : -1;
}
function parseHour24(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.H = +c[0], s + c[0].length) : -1;
}
function parseMinutes(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.M = +c[0], s + c[0].length) : -1;
}
function parseSeconds(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 2));
	return c ? (e.S = +c[0], s + c[0].length) : -1;
}
function parseMilliseconds(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 3));
	return c ? (e.L = +c[0], s + c[0].length) : -1;
}
function parseMicroseconds(e, o, s) {
	var c = numberRe.exec(o.slice(s, s + 6));
	return c ? (e.L = Math.floor(c[0] / 1e3), s + c[0].length) : -1;
}
function parseLiteralPercent(e, o, s) {
	var c = percentRe.exec(o.slice(s, s + 1));
	return c ? s + c[0].length : -1;
}
function parseUnixTimestamp(e, o, s) {
	var c = numberRe.exec(o.slice(s));
	return c ? (e.Q = +c[0], s + c[0].length) : -1;
}
function parseUnixTimestampSeconds(e, o, s) {
	var c = numberRe.exec(o.slice(s));
	return c ? (e.s = +c[0], s + c[0].length) : -1;
}
function formatDayOfMonth(e, o) {
	return pad(e.getDate(), o, 2);
}
function formatHour24(e, o) {
	return pad(e.getHours(), o, 2);
}
function formatHour12(e, o) {
	return pad(e.getHours() % 12 || 12, o, 2);
}
function formatDayOfYear(o, s) {
	return pad(1 + timeDay.count(timeYear(o), o), s, 3);
}
function formatMilliseconds(e, o) {
	return pad(e.getMilliseconds(), o, 3);
}
function formatMicroseconds(e, o) {
	return formatMilliseconds(e, o) + "000";
}
function formatMonthNumber(e, o) {
	return pad(e.getMonth() + 1, o, 2);
}
function formatMinutes(e, o) {
	return pad(e.getMinutes(), o, 2);
}
function formatSeconds(e, o) {
	return pad(e.getSeconds(), o, 2);
}
function formatWeekdayNumberMonday(e) {
	var o = e.getDay();
	return o === 0 ? 7 : o;
}
function formatWeekNumberSunday(e, o) {
	return pad(timeSunday.count(timeYear(e) - 1, e), o, 2);
}
function dISO(e) {
	var o = e.getDay();
	return o >= 4 || o === 0 ? timeThursday(e) : timeThursday.ceil(e);
}
function formatWeekNumberISO(e, o) {
	return e = dISO(e), pad(timeThursday.count(timeYear(e), e) + (timeYear(e).getDay() === 4), o, 2);
}
function formatWeekdayNumberSunday(e) {
	return e.getDay();
}
function formatWeekNumberMonday(e, o) {
	return pad(timeMonday.count(timeYear(e) - 1, e), o, 2);
}
function formatYear(e, o) {
	return pad(e.getFullYear() % 100, o, 2);
}
function formatYearISO(e, o) {
	return e = dISO(e), pad(e.getFullYear() % 100, o, 2);
}
function formatFullYear(e, o) {
	return pad(e.getFullYear() % 1e4, o, 4);
}
function formatFullYearISO(e, o) {
	var s = e.getDay();
	return e = s >= 4 || s === 0 ? timeThursday(e) : timeThursday.ceil(e), pad(e.getFullYear() % 1e4, o, 4);
}
function formatZone(e) {
	var o = e.getTimezoneOffset();
	return (o > 0 ? "-" : (o *= -1, "+")) + pad(o / 60 | 0, "0", 2) + pad(o % 60, "0", 2);
}
function formatUTCDayOfMonth(e, o) {
	return pad(e.getUTCDate(), o, 2);
}
function formatUTCHour24(e, o) {
	return pad(e.getUTCHours(), o, 2);
}
function formatUTCHour12(e, o) {
	return pad(e.getUTCHours() % 12 || 12, o, 2);
}
function formatUTCDayOfYear(e, s) {
	return pad(1 + utcDay.count(utcYear(e), e), s, 3);
}
function formatUTCMilliseconds(e, o) {
	return pad(e.getUTCMilliseconds(), o, 3);
}
function formatUTCMicroseconds(e, o) {
	return formatUTCMilliseconds(e, o) + "000";
}
function formatUTCMonthNumber(e, o) {
	return pad(e.getUTCMonth() + 1, o, 2);
}
function formatUTCMinutes(e, o) {
	return pad(e.getUTCMinutes(), o, 2);
}
function formatUTCSeconds(e, o) {
	return pad(e.getUTCSeconds(), o, 2);
}
function formatUTCWeekdayNumberMonday(e) {
	var o = e.getUTCDay();
	return o === 0 ? 7 : o;
}
function formatUTCWeekNumberSunday(e, o) {
	return pad(utcSunday.count(utcYear(e) - 1, e), o, 2);
}
function UTCdISO(e) {
	var o = e.getUTCDay();
	return o >= 4 || o === 0 ? utcThursday(e) : utcThursday.ceil(e);
}
function formatUTCWeekNumberISO(e, o) {
	return e = UTCdISO(e), pad(utcThursday.count(utcYear(e), e) + (utcYear(e).getUTCDay() === 4), o, 2);
}
function formatUTCWeekdayNumberSunday(e) {
	return e.getUTCDay();
}
function formatUTCWeekNumberMonday(e, o) {
	return pad(utcMonday.count(utcYear(e) - 1, e), o, 2);
}
function formatUTCYear(e, o) {
	return pad(e.getUTCFullYear() % 100, o, 2);
}
function formatUTCYearISO(e, o) {
	return e = UTCdISO(e), pad(e.getUTCFullYear() % 100, o, 2);
}
function formatUTCFullYear(e, o) {
	return pad(e.getUTCFullYear() % 1e4, o, 4);
}
function formatUTCFullYearISO(e, o) {
	var s = e.getUTCDay();
	return e = s >= 4 || s === 0 ? utcThursday(e) : utcThursday.ceil(e), pad(e.getUTCFullYear() % 1e4, o, 4);
}
function formatUTCZone() {
	return "+0000";
}
function formatLiteralPercent() {
	return "%";
}
function formatUnixTimestamp(e) {
	return +e;
}
function formatUnixTimestampSeconds(e) {
	return Math.floor(e / 1e3);
}
export { formatLocale as default };
