import { classifyCharacter as e } from "../../micromark-util-classify-character/index.js";
import { splice as t } from "../../micromark-util-chunked/index.js";
import { resolveAll as n } from "../../micromark-util-resolve-all/index.js";
//#region ../../node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js
function r(r) {
	let i = (r || {}).singleTilde, a = {
		name: "strikethrough",
		tokenize: s,
		resolveAll: o
	};
	return i ??= !0, {
		text: { 126: a },
		insideSpan: { null: [a] },
		attentionMarkers: { null: [126] }
	};
	function o(e, r) {
		let i = -1;
		for (; ++i < e.length;) if (e[i][0] === "enter" && e[i][1].type === "strikethroughSequenceTemporary" && e[i][1]._close) {
			let a = i;
			for (; a--;) if (e[a][0] === "exit" && e[a][1].type === "strikethroughSequenceTemporary" && e[a][1]._open && e[i][1].end.offset - e[i][1].start.offset === e[a][1].end.offset - e[a][1].start.offset) {
				e[i][1].type = "strikethroughSequence", e[a][1].type = "strikethroughSequence";
				let o = {
					type: "strikethrough",
					start: Object.assign({}, e[a][1].start),
					end: Object.assign({}, e[i][1].end)
				}, s = {
					type: "strikethroughText",
					start: Object.assign({}, e[a][1].end),
					end: Object.assign({}, e[i][1].start)
				}, c = [
					[
						"enter",
						o,
						r
					],
					[
						"enter",
						e[a][1],
						r
					],
					[
						"exit",
						e[a][1],
						r
					],
					[
						"enter",
						s,
						r
					]
				], l = r.parser.constructs.insideSpan.null;
				l && t(c, c.length, 0, n(l, e.slice(a + 1, i), r)), t(c, c.length, 0, [
					[
						"exit",
						s,
						r
					],
					[
						"enter",
						e[i][1],
						r
					],
					[
						"exit",
						e[i][1],
						r
					],
					[
						"exit",
						o,
						r
					]
				]), t(e, a - 1, i - a + 3, c), i = a + c.length - 2;
				break;
			}
		}
		for (i = -1; ++i < e.length;) e[i][1].type === "strikethroughSequenceTemporary" && (e[i][1].type = "data");
		return e;
	}
	function s(t, n, r) {
		let a = this.previous, o = this.events, s = 0;
		return c;
		function c(e) {
			return a === 126 && o[o.length - 1][1].type !== "characterEscape" ? r(e) : (t.enter("strikethroughSequenceTemporary"), l(e));
		}
		function l(o) {
			let c = e(a);
			if (o === 126) return s > 1 ? r(o) : (t.consume(o), s++, l);
			if (s < 2 && !i) return r(o);
			let u = t.exit("strikethroughSequenceTemporary"), d = e(o);
			return u._open = !d || d === 2 && !!c, u._close = !c || c === 2 && !!d, n(o);
		}
	}
}
//#endregion
export { r as gfmStrikethrough };
