import { asciiDigit as e, markdownSpace as t } from "../../micromark-util-character/index.js";
import { factorySpace as n } from "../../micromark-factory-space/index.js";
import { blankLine as r } from "./blank-line.js";
import { thematicBreak as i } from "./thematic-break.js";
//#region ../../node_modules/micromark-core-commonmark/lib/list.js
var a = {
	continuation: { tokenize: l },
	exit: d,
	name: "list",
	tokenize: c
}, o = {
	partial: !0,
	tokenize: f
}, s = {
	partial: !0,
	tokenize: u
};
function c(n, a, s) {
	let c = this, l = c.events[c.events.length - 1], u = l && l[1].type === "linePrefix" ? l[2].sliceSerialize(l[1], !0).length : 0, d = 0;
	return f;
	function f(t) {
		let r = c.containerState.type || (t === 42 || t === 43 || t === 45 ? "listUnordered" : "listOrdered");
		if (r === "listUnordered" ? !c.containerState.marker || t === c.containerState.marker : e(t)) {
			if (c.containerState.type || (c.containerState.type = r, n.enter(r, { _container: !0 })), r === "listUnordered") return n.enter("listItemPrefix"), t === 42 || t === 45 ? n.check(i, s, m)(t) : m(t);
			if (!c.interrupt || t === 49) return n.enter("listItemPrefix"), n.enter("listItemValue"), p(t);
		}
		return s(t);
	}
	function p(t) {
		return e(t) && ++d < 10 ? (n.consume(t), p) : (!c.interrupt || d < 2) && (c.containerState.marker ? t === c.containerState.marker : t === 41 || t === 46) ? (n.exit("listItemValue"), m(t)) : s(t);
	}
	function m(e) {
		return n.enter("listItemMarker"), n.consume(e), n.exit("listItemMarker"), c.containerState.marker = c.containerState.marker || e, n.check(r, c.interrupt ? s : h, n.attempt(o, _, g));
	}
	function h(e) {
		return c.containerState.initialBlankLine = !0, u++, _(e);
	}
	function g(e) {
		return t(e) ? (n.enter("listItemPrefixWhitespace"), n.consume(e), n.exit("listItemPrefixWhitespace"), _) : s(e);
	}
	function _(e) {
		return c.containerState.size = u + c.sliceSerialize(n.exit("listItemPrefix"), !0).length, a(e);
	}
}
function l(e, i, o) {
	let c = this;
	return c.containerState._closeFlow = void 0, e.check(r, l, u);
	function l(t) {
		return c.containerState.furtherBlankLines = c.containerState.furtherBlankLines || c.containerState.initialBlankLine, n(e, i, "listItemIndent", c.containerState.size + 1)(t);
	}
	function u(n) {
		return c.containerState.furtherBlankLines || !t(n) ? (c.containerState.furtherBlankLines = void 0, c.containerState.initialBlankLine = void 0, d(n)) : (c.containerState.furtherBlankLines = void 0, c.containerState.initialBlankLine = void 0, e.attempt(s, i, d)(n));
	}
	function d(t) {
		return c.containerState._closeFlow = !0, c.interrupt = void 0, n(e, e.attempt(a, i, o), "linePrefix", c.parser.constructs.disable.null.includes("codeIndented") ? void 0 : 4)(t);
	}
}
function u(e, t, r) {
	let i = this;
	return n(e, a, "listItemIndent", i.containerState.size + 1);
	function a(e) {
		let n = i.events[i.events.length - 1];
		return n && n[1].type === "listItemIndent" && n[2].sliceSerialize(n[1], !0).length === i.containerState.size ? t(e) : r(e);
	}
}
function d(e) {
	e.exit(this.containerState.type);
}
function f(e, r, i) {
	let a = this;
	return n(e, o, "listItemPrefixWhitespace", a.parser.constructs.disable.null.includes("codeIndented") ? void 0 : 5);
	function o(e) {
		let n = a.events[a.events.length - 1];
		return !t(e) && n && n[1].type === "listItemPrefixWhitespace" ? r(e) : i(e);
	}
}
//#endregion
export { a as list };
