import { factorySpace as d } from "../../../../micromark-factory-space@2.0.1/node_modules/micromark-factory-space/index.js";
import { markdownSpace as g, markdownLineEnding as y } from "../../../../micromark-util-character@2.1.1/node_modules/micromark-util-character/index.js";
const c = {
  name: "setextUnderline",
  resolveTo: h,
  tokenize: m
};
function h(e, l) {
  let i = e.length, t, a, r;
  for (; i--; )
    if (e[i][0] === "enter") {
      if (e[i][1].type === "content") {
        t = i;
        break;
      }
      e[i][1].type === "paragraph" && (a = i);
    } else
      e[i][1].type === "content" && e.splice(i, 1), !r && e[i][1].type === "definition" && (r = i);
  const p = {
    type: "setextHeading",
    start: {
      ...e[t][1].start
    },
    end: {
      ...e[e.length - 1][1].end
    }
  };
  return e[a][1].type = "setextHeadingText", r ? (e.splice(a, 0, ["enter", p, l]), e.splice(r + 1, 0, ["exit", e[t][1], l]), e[t][1].end = {
    ...e[r][1].end
  }) : e[t][1] = p, e.push(["exit", p, l]), e;
}
function m(e, l, i) {
  const t = this;
  let a;
  return r;
  function r(n) {
    let u = t.events.length, f;
    for (; u--; )
      if (t.events[u][1].type !== "lineEnding" && t.events[u][1].type !== "linePrefix" && t.events[u][1].type !== "content") {
        f = t.events[u][1].type === "paragraph";
        break;
      }
    return !t.parser.lazy[t.now().line] && (t.interrupt || f) ? (e.enter("setextHeadingLine"), a = n, p(n)) : i(n);
  }
  function p(n) {
    return e.enter("setextHeadingLineSequence"), o(n);
  }
  function o(n) {
    return n === a ? (e.consume(n), o) : (e.exit("setextHeadingLineSequence"), g(n) ? d(e, x, "lineSuffix")(n) : x(n));
  }
  function x(n) {
    return n === null || y(n) ? (e.exit("setextHeadingLine"), l(n)) : i(n);
  }
}
export {
  c as setextUnderline
};
//# sourceMappingURL=setext-underline.js.map
