import { isSpace as g } from "../common/utils.js";
function B(o, r, C, q) {
  let l = o.bMarks[r] + o.tShift[r], k = o.eMarks[r];
  const A = o.lineMax;
  if (o.sCount[r] - o.blkIndent >= 4 || o.src.charCodeAt(l) !== 62)
    return !1;
  if (q)
    return !0;
  const b = [], i = [], h = [], f = [], s = o.md.block.ruler.getRules("blockquote"), T = o.parentType;
  o.parentType = "blockquote";
  let M = !1, n;
  for (n = r; n < C; n++) {
    const u = o.sCount[n] < o.blkIndent;
    if (l = o.bMarks[n] + o.tShift[n], k = o.eMarks[n], l >= k)
      break;
    if (o.src.charCodeAt(l++) === 62 && !u) {
      let c = o.sCount[n] + 1, e, p;
      o.src.charCodeAt(l) === 32 ? (l++, c++, p = !1, e = !0) : o.src.charCodeAt(l) === 9 ? (e = !0, (o.bsCount[n] + c) % 4 === 3 ? (l++, c++, p = !1) : p = !0) : e = !1;
      let d = c;
      for (b.push(o.bMarks[n]), o.bMarks[n] = l; l < k; ) {
        const I = o.src.charCodeAt(l);
        if (g(I))
          I === 9 ? d += 4 - (d + o.bsCount[n] + (p ? 1 : 0)) % 4 : d++;
        else
          break;
        l++;
      }
      M = l >= k, i.push(o.bsCount[n]), o.bsCount[n] = o.sCount[n] + 1 + (e ? 1 : 0), h.push(o.sCount[n]), o.sCount[n] = d - c, f.push(o.tShift[n]), o.tShift[n] = l - o.bMarks[n];
      continue;
    }
    if (M)
      break;
    let S = !1;
    for (let c = 0, e = s.length; c < e; c++)
      if (s[c](o, n, C, !0)) {
        S = !0;
        break;
      }
    if (S) {
      o.lineMax = n, o.blkIndent !== 0 && (b.push(o.bMarks[n]), i.push(o.bsCount[n]), f.push(o.tShift[n]), h.push(o.sCount[n]), o.sCount[n] -= o.blkIndent);
      break;
    }
    b.push(o.bMarks[n]), i.push(o.bsCount[n]), f.push(o.tShift[n]), h.push(o.sCount[n]), o.sCount[n] = -1;
  }
  const y = o.blkIndent;
  o.blkIndent = 0;
  const x = o.push("blockquote_open", "blockquote", 1);
  x.markup = ">";
  const m = [r, 0];
  x.map = m, o.md.block.tokenize(o, r, n);
  const _ = o.push("blockquote_close", "blockquote", -1);
  _.markup = ">", o.lineMax = A, o.parentType = T, m[1] = o.line;
  for (let u = 0; u < f.length; u++)
    o.bMarks[u + r] = b[u], o.tShift[u + r] = f[u], o.sCount[u + r] = h[u], o.bsCount[u + r] = i[u];
  return o.blkIndent = y, !0;
}
export {
  B as default
};
