import { toUint8 as g, bytesMatch as m, stringToBytes as P } from "./index-byte-helpers.js";
var v = function(r) {
  return typeof r == "string" ? P(r) : r;
}, c = function(r) {
  return Array.isArray(r) ? r.map(function(n) {
    return v(n);
  }) : [v(r)];
}, z = function o(r, n, u) {
  u === void 0 && (u = !1), n = c(n), r = g(r);
  var f = [];
  if (!n.length)
    return f;
  for (var i = 0; i < r.length; ) {
    var l = (r[i] << 24 | r[i + 1] << 16 | r[i + 2] << 8 | r[i + 3]) >>> 0, t = r.subarray(i + 4, i + 8);
    if (l === 0)
      break;
    var a = i + l;
    if (a > r.length) {
      if (u)
        break;
      a = r.length;
    }
    var e = r.subarray(i + 8, a);
    m(t, n[0]) && (n.length === 1 ? f.push(e) : f.push.apply(f, o(e, n.slice(1), u))), i = a;
  }
  return f;
};
export {
  z as findBox
};
