//#region src/form/cron-editor/parser.ts
var e = {
	minute: [0, 59],
	hour: [0, 23],
	day: [1, 31],
	month: [1, 12],
	weekday: [0, 6]
}, t = [
	"minute",
	"hour",
	"day",
	"month",
	"weekday"
], n = [
	"",
	"January",
	"February",
	"March",
	"April",
	"May",
	"June",
	"July",
	"August",
	"September",
	"October",
	"November",
	"December"
], r = [
	"Sunday",
	"Monday",
	"Tuesday",
	"Wednesday",
	"Thursday",
	"Friday",
	"Saturday"
];
function i(t, n) {
	let [r, i] = e[n];
	if (t === "*") return { mode: "every" };
	if (t.includes("/")) {
		let e = t.split("/"), n = e[0] ?? "*";
		return {
			mode: "interval",
			interval: parseInt(e[1] ?? "1", 10),
			intervalStart: n === "*" ? r : parseInt(n, 10)
		};
	}
	if (t.includes("-") && !t.includes(",")) {
		let e = t.split("-");
		return {
			mode: "range",
			rangeStart: parseInt(e[0] ?? String(r), 10),
			rangeEnd: parseInt(e[1] ?? String(i), 10)
		};
	}
	let a = t.split(",").map((e) => parseInt(e.trim(), 10)).filter((e) => !isNaN(e));
	return a.length > 0 ? {
		mode: "specific",
		specific: a
	} : { mode: "every" };
}
function a(t, n) {
	let [r] = e[n];
	switch (t.mode) {
		case "every": return "*";
		case "specific": {
			let e = t.specific ?? [];
			return e.length === 0 ? "*" : e.sort((e, t) => e - t).join(",");
		}
		case "range": {
			let e = t.rangeStart ?? r, n = t.rangeEnd ?? r;
			return `${String(e)}-${String(n)}`;
		}
		case "interval": {
			let e = t.interval ?? 1, n = t.intervalStart ?? r;
			return `${n === r ? "*" : String(n)}/${String(e)}`;
		}
		default: return "*";
	}
}
function o(e) {
	let n = e.trim().split(/\s+/), r = t.map((e, t) => i(n[t] ?? "*", e));
	return {
		minute: r[0] ?? { mode: "every" },
		hour: r[1] ?? { mode: "every" },
		day: r[2] ?? { mode: "every" },
		month: r[3] ?? { mode: "every" },
		weekday: r[4] ?? { mode: "every" }
	};
}
function s(e) {
	return t.map((t) => a(e[t], t)).join(" ");
}
function c(e) {
	let t = e.trim().split(/\s+/);
	if (t.length < 5) return "Invalid cron expression";
	let [i, a, o, s, c] = t, l = [];
	if (i === "*" && a === "*" && o === "*" && s === "*" && c === "*") return "Every minute";
	if (i.includes("/")) {
		let e = i.split("/")[1] ?? "1";
		l.push(`Every ${e} minutes`);
	} else if (i !== "0" && i !== "*") {
		let e = i.split(",");
		e.length === 1 ? l.push(`At minute ${i}`) : l.push(`At minutes ${e.join(", ")}`);
	}
	if (a.includes("/")) {
		let e = a.split("/")[1] ?? "1";
		l.push(`every ${e} hours`);
	} else if (a !== "*") {
		let e = a.split(",");
		if (i === "0" && e.length === 1) {
			let t = parseInt(e[0] ?? "0", 10), n = t >= 12 ? "PM" : "AM", r = t === 0 ? 12 : t > 12 ? t - 12 : t;
			l.push(`At ${String(r)}:00 ${n}`);
		} else if (e.length === 1 && !i.includes("/") && i !== "*") {
			let t = parseInt(e[0] ?? "0", 10), n = i.padStart(2, "0"), r = t >= 12 ? "PM" : "AM", a = t === 0 ? 12 : t > 12 ? t - 12 : t;
			l.length = 0, l.push(`At ${String(a)}:${n} ${r}`);
		} else l.push(`at hours ${e.join(", ")}`);
	}
	if (o !== "*") if (o.includes("/")) {
		let e = o.split("/")[1] ?? "1";
		l.push(`every ${e} days`);
	} else if (o.includes("-")) {
		let [e, t] = o.split("-");
		l.push(`on days ${e ?? ""} through ${t ?? ""}`);
	} else {
		let e = o.split(",").map((e) => {
			let t = parseInt(e, 10);
			return t === 1 || t === 21 || t === 31 ? `${e}st` : t === 2 || t === 22 ? `${e}nd` : t === 3 || t === 23 ? `${e}rd` : `${e}th`;
		});
		l.push(`on the ${e.join(" and ")}`);
	}
	if (s !== "*") if (s.includes("/")) {
		let e = s.split("/")[1] ?? "1";
		l.push(`every ${e} months`);
	} else {
		let e = s.split(",").map((e) => n[parseInt(e, 10)] ?? e);
		l.push(`in ${e.join(", ")}`);
	}
	if (c !== "*") if (c.includes("/")) {
		let e = c.split("/")[1] ?? "1";
		l.push(`every ${e} days of the week`);
	} else {
		let e = c.split(",").map((e) => r[parseInt(e, 10)] ?? e);
		l.push(`on ${e.join(", ")}`);
	}
	if (l.length === 0) return "Every minute";
	let u = l.join(", ");
	return u.charAt(0).toUpperCase() + u.slice(1);
}
function l(t, n, r) {
	let [i] = e[r];
	if (n === "*") return !0;
	let a = n.split(",");
	if (a.length > 1) return a.some((e) => l(t, e.trim(), r));
	if (n.includes("/")) {
		let e = n.split("/"), r = e[0] ?? "*", a = parseInt(e[1] ?? "1", 10), o = r === "*" ? i : parseInt(r, 10);
		return a <= 0 ? !1 : t >= o && (t - o) % a === 0;
	}
	if (n.includes("-")) {
		let e = n.split("-"), r = parseInt(e[0] ?? "0", 10), i = parseInt(e[1] ?? "0", 10);
		return t >= r && t <= i;
	}
	return t === parseInt(n, 10);
}
function u(e, t, n) {
	let r = e.trim().split(/\s+/);
	if (r.length < 5) return [];
	let [i, a, o, s, c] = r, u = [], d = n ? new Date(n.getTime()) : /* @__PURE__ */ new Date();
	d.setSeconds(0, 0), d.setMinutes(d.getMinutes() + 1);
	let f = new Date(d.getTime());
	for (let e = 0; e < 525600 && u.length < t; e++) {
		let e = f.getMinutes(), t = f.getHours(), n = f.getDate(), r = f.getMonth() + 1, d = f.getDay();
		l(e, i, "minute") && l(t, a, "hour") && l(n, o, "day") && l(r, s, "month") && l(d, c, "weekday") && u.push(new Date(f.getTime())), f.setMinutes(f.getMinutes() + 1);
	}
	return u;
}
function d(n) {
	let r = n.trim().split(/\s+/);
	if (r.length !== 5) return !1;
	for (let n = 0; n < 5; n++) {
		let i = r[n] ?? "", a = t[n];
		if (a === void 0) return !1;
		let [o, s] = e[a], c = i.split(",");
		for (let e of c) if (!f(e.trim(), o, s)) return !1;
	}
	return !0;
}
function f(e, t, n) {
	if (e === "*") return !0;
	if (e.includes("/")) {
		let r = e.split("/");
		if (r.length !== 2) return !1;
		let i = r[0] ?? "", a = r[1] ?? "";
		if (i !== "*" && !p(i, t, n)) return !1;
		let o = parseInt(a, 10);
		return !isNaN(o) && o > 0;
	}
	if (e.includes("-")) {
		let r = e.split("-");
		return r.length === 2 ? p(r[0] ?? "", t, n) && p(r[1] ?? "", t, n) : !1;
	}
	return p(e, t, n);
}
function p(e, t, n) {
	let r = parseInt(e, 10);
	return !isNaN(r) && r >= t && r <= n;
}
//#endregion
export { c as cronToHuman, s as formatCron, u as getNextRuns, d as isValidCron, o as parseCron };

//# sourceMappingURL=parser.js.map