import { classifyCharacter as e } from "../../micromark-util-classify-character/index.js";
import { push as t, splice as n } from "../../micromark-util-chunked/index.js";
import { resolveAll as r } from "../../micromark-util-resolve-all/index.js";
//#region ../../node_modules/micromark-core-commonmark/lib/attention.js
var i = {
	name: "attention",
	resolveAll: a,
	tokenize: o
};
function a(e, i) {
	let a = -1, o, c, l, u, d, f, p, m;
	for (; ++a < e.length;) if (e[a][0] === "enter" && e[a][1].type === "attentionSequence" && e[a][1]._close) {
		for (o = a; o--;) if (e[o][0] === "exit" && e[o][1].type === "attentionSequence" && e[o][1]._open && i.sliceSerialize(e[o][1]).charCodeAt(0) === i.sliceSerialize(e[a][1]).charCodeAt(0)) {
			if ((e[o][1]._close || e[a][1]._open) && (e[a][1].end.offset - e[a][1].start.offset) % 3 && !((e[o][1].end.offset - e[o][1].start.offset + e[a][1].end.offset - e[a][1].start.offset) % 3)) continue;
			f = e[o][1].end.offset - e[o][1].start.offset > 1 && e[a][1].end.offset - e[a][1].start.offset > 1 ? 2 : 1;
			let h = { ...e[o][1].end }, g = { ...e[a][1].start };
			s(h, -f), s(g, f), u = {
				type: f > 1 ? "strongSequence" : "emphasisSequence",
				start: h,
				end: { ...e[o][1].end }
			}, d = {
				type: f > 1 ? "strongSequence" : "emphasisSequence",
				start: { ...e[a][1].start },
				end: g
			}, l = {
				type: f > 1 ? "strongText" : "emphasisText",
				start: { ...e[o][1].end },
				end: { ...e[a][1].start }
			}, c = {
				type: f > 1 ? "strong" : "emphasis",
				start: { ...u.start },
				end: { ...d.end }
			}, e[o][1].end = { ...u.start }, e[a][1].start = { ...d.end }, p = [], e[o][1].end.offset - e[o][1].start.offset && (p = t(p, [[
				"enter",
				e[o][1],
				i
			], [
				"exit",
				e[o][1],
				i
			]])), p = t(p, [
				[
					"enter",
					c,
					i
				],
				[
					"enter",
					u,
					i
				],
				[
					"exit",
					u,
					i
				],
				[
					"enter",
					l,
					i
				]
			]), p = t(p, r(i.parser.constructs.insideSpan.null, e.slice(o + 1, a), i)), p = t(p, [
				[
					"exit",
					l,
					i
				],
				[
					"enter",
					d,
					i
				],
				[
					"exit",
					d,
					i
				],
				[
					"exit",
					c,
					i
				]
			]), e[a][1].end.offset - e[a][1].start.offset ? (m = 2, p = t(p, [[
				"enter",
				e[a][1],
				i
			], [
				"exit",
				e[a][1],
				i
			]])) : m = 0, n(e, o - 1, a - o + 3, p), a = o + p.length - m - 2;
			break;
		}
	}
	for (a = -1; ++a < e.length;) e[a][1].type === "attentionSequence" && (e[a][1].type = "data");
	return e;
}
function o(t, n) {
	let r = this.parser.constructs.attentionMarkers.null, i = this.previous, a = e(i), o;
	return s;
	function s(e) {
		return o = e, t.enter("attentionSequence"), c(e);
	}
	function c(s) {
		if (s === o) return t.consume(s), c;
		let l = t.exit("attentionSequence"), u = e(s), d = !u || u === 2 && a || r.includes(s), f = !a || a === 2 && u || r.includes(i);
		return l._open = !!(o === 42 ? d : d && (a || !f)), l._close = !!(o === 42 ? f : f && (u || !d)), n(s);
	}
}
function s(e, t) {
	e.column += t, e.offset += t, e._bufferIndex += t;
}
//#endregion
export { i as attention };
