"use client";
import { splice as g } from "../../micromark-util-chunked/index.js";
import { classifyCharacter as k } from "../../micromark-util-classify-character/index.js";
import { resolveAll as d } from "../../micromark-util-resolve-all/index.js";
function j(m) {
  let l = (m || {}).singleTilde;
  const f = {
    name: "strikethrough",
    tokenize: S,
    resolveAll: y
  };
  return l == null && (l = !0), {
    text: {
      126: f
    },
    insideSpan: {
      null: [f]
    },
    attentionMarkers: {
      null: [126]
    }
  };
  function y(r, i) {
    let e = -1;
    for (; ++e < r.length; )
      if (r[e][0] === "enter" && r[e][1].type === "strikethroughSequenceTemporary" && r[e][1]._close) {
        let t = e;
        for (; t--; )
          if (r[t][0] === "exit" && r[t][1].type === "strikethroughSequenceTemporary" && r[t][1]._open && // If the sizes are the same:
          r[e][1].end.offset - r[e][1].start.offset === r[t][1].end.offset - r[t][1].start.offset) {
            r[e][1].type = "strikethroughSequence", r[t][1].type = "strikethroughSequence";
            const s = {
              type: "strikethrough",
              start: Object.assign({}, r[t][1].start),
              end: Object.assign({}, r[e][1].end)
            }, u = {
              type: "strikethroughText",
              start: Object.assign({}, r[t][1].end),
              end: Object.assign({}, r[e][1].start)
            }, o = [["enter", s, i], ["enter", r[t][1], i], ["exit", r[t][1], i], ["enter", u, i]], h = i.parser.constructs.insideSpan.null;
            h && g(o, o.length, 0, d(h, r.slice(t + 1, e), i)), g(o, o.length, 0, [["exit", u, i], ["enter", r[e][1], i], ["exit", r[e][1], i], ["exit", s, i]]), g(r, t - 1, e - t + 3, o), e = t + o.length - 2;
            break;
          }
      }
    for (e = -1; ++e < r.length; )
      r[e][1].type === "strikethroughSequenceTemporary" && (r[e][1].type = "data");
    return r;
  }
  function S(r, i, e) {
    const t = this.previous, s = this.events;
    let u = 0;
    return o;
    function o(n) {
      return t === 126 && s[s.length - 1][1].type !== "characterEscape" ? e(n) : (r.enter("strikethroughSequenceTemporary"), h(n));
    }
    function h(n) {
      const a = k(t);
      if (n === 126)
        return u > 1 ? e(n) : (r.consume(n), u++, h);
      if (u < 2 && !l) return e(n);
      const c = r.exit("strikethroughSequenceTemporary"), p = k(n);
      return c._open = !p || p === 2 && !!a, c._close = !a || a === 2 && !!p, i(n);
    }
  }
}
export {
  j as gfmStrikethrough
};
