import { markdownLineEnding, markdownLineEndingOrSpace, markdownSpace } from "../../micromark-util-character/index.js";
import { normalizeIdentifier } from "../../micromark-util-normalize-identifier/index.js";
import { factorySpace } from "../../micromark-factory-space/index.js";
import { factoryDestination } from "../../micromark-factory-destination/index.js";
import { factoryLabel } from "../../micromark-factory-label/index.js";
import { factoryTitle } from "../../micromark-factory-title/index.js";
import { factoryWhitespace } from "../../micromark-factory-whitespace/index.js";
const definition = {
	name: "definition",
	tokenize: tokenizeDefinition
};
var titleBefore = {
	partial: !0,
	tokenize: tokenizeTitleBefore
};
function tokenizeDefinition(c, l, d) {
	let f = this, p;
	return m;
	function m(e) {
		return c.enter("definition"), h(e);
	}
	function h(e) {
		return factoryLabel.call(f, c, g, d, "definitionLabel", "definitionLabelMarker", "definitionLabelString")(e);
	}
	function g(e) {
		return p = normalizeIdentifier(f.sliceSerialize(f.events[f.events.length - 1][1]).slice(1, -1)), e === 58 ? (c.enter("definitionMarker"), c.consume(e), c.exit("definitionMarker"), _) : d(e);
	}
	function _(e) {
		return markdownLineEndingOrSpace(e) ? factoryWhitespace(c, v)(e) : v(e);
	}
	function v(e) {
		return factoryDestination(c, y, d, "definitionDestination", "definitionDestinationLiteral", "definitionDestinationLiteralMarker", "definitionDestinationRaw", "definitionDestinationString")(e);
	}
	function y(e) {
		return c.attempt(titleBefore, b, b)(e);
	}
	function b(e) {
		return markdownSpace(e) ? factorySpace(c, x, "whitespace")(e) : x(e);
	}
	function x(i) {
		return i === null || markdownLineEnding(i) ? (c.exit("definition"), f.parser.defined.push(p), l(i)) : d(i);
	}
}
function tokenizeTitleBefore(a, o, s) {
	return l;
	function l(e) {
		return markdownLineEndingOrSpace(e) ? factoryWhitespace(a, u)(e) : s(e);
	}
	function u(e) {
		return factoryTitle(a, d, s, "definitionTitle", "definitionTitleMarker", "definitionTitleString")(e);
	}
	function d(e) {
		return markdownSpace(e) ? factorySpace(a, f, "whitespace")(e) : f(e);
	}
	function f(i) {
		return i === null || markdownLineEnding(i) ? o(i) : s(i);
	}
}
export { definition };
