"use client";
import { factoryDestination as D } from "../../micromark-factory-destination/index.js";
import { factoryLabel as S } from "../../micromark-factory-label/index.js";
import { factorySpace as s } from "../../micromark-factory-space/index.js";
import { factoryTitle as g } from "../../micromark-factory-title/index.js";
import { factoryWhitespace as d } from "../../micromark-factory-whitespace/index.js";
import { markdownLineEndingOrSpace as k, markdownSpace as c, markdownLineEnding as h } from "../../micromark-util-character/index.js";
import { normalizeIdentifier as w } from "../../micromark-util-normalize-identifier/index.js";
const O = {
  name: "definition",
  tokenize: M
}, z = {
  partial: !0,
  tokenize: y
};
function M(t, f, e) {
  const r = this;
  let o;
  return u;
  function u(i) {
    return t.enter("definition"), a(i);
  }
  function a(i) {
    return S.call(
      r,
      t,
      n,
      // Note: we don’t need to reset the way `markdown-rs` does.
      e,
      "definitionLabel",
      "definitionLabelMarker",
      "definitionLabelString"
    )(i);
  }
  function n(i) {
    return o = w(r.sliceSerialize(r.events[r.events.length - 1][1]).slice(1, -1)), i === 58 ? (t.enter("definitionMarker"), t.consume(i), t.exit("definitionMarker"), L) : e(i);
  }
  function L(i) {
    return k(i) ? d(t, l)(i) : l(i);
  }
  function l(i) {
    return D(
      t,
      b,
      // Note: we don’t need to reset the way `markdown-rs` does.
      e,
      "definitionDestination",
      "definitionDestinationLiteral",
      "definitionDestinationLiteralMarker",
      "definitionDestinationRaw",
      "definitionDestinationString"
    )(i);
  }
  function b(i) {
    return t.attempt(z, m, m)(i);
  }
  function m(i) {
    return c(i) ? s(t, p, "whitespace")(i) : p(i);
  }
  function p(i) {
    return i === null || h(i) ? (t.exit("definition"), r.parser.defined.push(o), f(i)) : e(i);
  }
}
function y(t, f, e) {
  return r;
  function r(n) {
    return k(n) ? d(t, o)(n) : e(n);
  }
  function o(n) {
    return g(t, u, e, "definitionTitle", "definitionTitleMarker", "definitionTitleString")(n);
  }
  function u(n) {
    return c(n) ? s(t, a, "whitespace")(n) : a(n);
  }
  function a(n) {
    return n === null || h(n) ? f(n) : e(n);
  }
}
export {
  O as definition
};
