import { markdownLineEnding, markdownSpace } from "../../micromark-util-character/index.js";
import { factorySpace } from "../../micromark-factory-space/index.js";
const thematicBreak = {
	name: "thematicBreak",
	tokenize: tokenizeThematicBreak
};
function tokenizeThematicBreak(r, i, a) {
	let o = 0, s;
	return c;
	function c(e) {
		return r.enter("thematicBreak"), l(e);
	}
	function l(e) {
		return s = e, u(e);
	}
	function u(n) {
		return n === s ? (r.enter("thematicBreakSequence"), d(n)) : o >= 3 && (n === null || markdownLineEnding(n)) ? (r.exit("thematicBreak"), i(n)) : a(n);
	}
	function d(e) {
		return e === s ? (r.consume(e), o++, d) : (r.exit("thematicBreakSequence"), markdownSpace(e) ? factorySpace(r, u, "whitespace")(e) : u(e));
	}
}
export { thematicBreak };
