import { isMap as d, isPair as l, isScalar as p, isSeq as h, parseDocument as x } from "yaml";
const f = (a) => Array.isArray(a) && typeof a[0] == "number" && typeof a[1] == "number", M = (a) => {
  try {
    return x(a);
  } catch {
    return null;
  }
}, S = (a, g) => {
  const c = M(a);
  if (!c)
    return null;
  let e = c.contents, s = null;
  for (const n of g) {
    if (d(e)) {
      const t = String(n), r = e.items.find((i) => {
        if (!l(i))
          return !1;
        const o = i.key;
        return p(o) ? String(o.value) === t : String(o) === t;
      });
      if (!r || !l(r))
        return null;
      s = r, e = r.value;
      continue;
    }
    if (h(e)) {
      const t = typeof n == "number" ? n : Number.parseInt(String(n), 10);
      if (!Number.isFinite(t) || t < 0 || t >= e.items.length)
        return null;
      s = null, e = e.items[t];
      continue;
    }
    return null;
  }
  if (s && l(s)) {
    const n = s.key?.range, t = s.value?.range;
    if (!f(n))
      return null;
    const r = Math.max(0, n[0]), i = f(t) ? Math.max(r, t[1]) : Math.max(r, n[1]);
    return { startOffset: r, endOffset: i };
  }
  const u = e?.range;
  if (!f(u))
    return null;
  const m = Math.max(0, u[0]), y = Math.max(m, u[1]);
  return { startOffset: m, endOffset: y };
};
export {
  S as getYamlNodeRangeFromPath
};
