import { __exports as u } from "../../../../../../../../_virtual/contains.js";
import { __require as b } from "../../compile/codegen/index.js";
import { __require as q } from "../../compile/util.js";
var p;
function M() {
  if (p) return u;
  p = 1, Object.defineProperty(u, "__esModule", { value: !0 });
  const i = b(), d = q(), h = {
    keyword: "contains",
    type: "array",
    schemaType: ["object", "boolean"],
    before: "uniqueItems",
    trackErrors: !0,
    error: {
      message: ({ params: { min: n, max: e } }) => e === void 0 ? (0, i.str)`must contain at least ${n} valid item(s)` : (0, i.str)`must contain at least ${n} and no more than ${e} valid item(s)`,
      params: ({ params: { min: n, max: e } }) => e === void 0 ? (0, i._)`{minContains: ${n}}` : (0, i._)`{minContains: ${n}, maxContains: ${e}}`
    },
    code(n) {
      const { gen: e, schema: C, parentSchema: g, data: m, it: o } = n;
      let a, s;
      const { minContains: c, maxContains: y } = g;
      o.opts.next ? (a = c === void 0 ? 1 : c, s = y) : a = 1;
      const f = e.const("len", (0, i._)`${m}.length`);
      if (n.setParams({ min: a, max: s }), s === void 0 && a === 0) {
        (0, d.checkStrictMode)(o, '"minContains" == 0 without "maxContains": "contains" keyword ignored');
        return;
      }
      if (s !== void 0 && a > s) {
        (0, d.checkStrictMode)(o, '"minContains" > "maxContains" is always invalid'), n.fail();
        return;
      }
      if ((0, d.alwaysValidSchema)(o, C)) {
        let t = (0, i._)`${f} >= ${a}`;
        s !== void 0 && (t = (0, i._)`${t} && ${f} <= ${s}`), n.pass(t);
        return;
      }
      o.items = !0;
      const r = e.name("valid");
      s === void 0 && a === 1 ? $(r, () => e.if(r, () => e.break())) : a === 0 ? (e.let(r, !0), s !== void 0 && e.if((0, i._)`${m}.length > 0`, _)) : (e.let(r, !1), _()), n.result(r, () => n.reset());
      function _() {
        const t = e.name("_valid"), l = e.let("count", 0);
        $(t, () => e.if(t, () => k(l)));
      }
      function $(t, l) {
        e.forRange("i", 0, f, (v) => {
          n.subschema({
            keyword: "contains",
            dataProp: v,
            dataPropType: d.Type.Num,
            compositeRule: !0
          }, t), l();
        });
      }
      function k(t) {
        e.code((0, i._)`${t}++`), s === void 0 ? e.if((0, i._)`${t} >= ${a}`, () => e.assign(r, !0).break()) : (e.if((0, i._)`${t} > ${s}`, () => e.assign(r, !1).break()), a === 1 ? e.assign(r, !0) : e.if((0, i._)`${t} >= ${a}`, () => e.assign(r, !0)));
      }
    }
  };
  return u.default = h, u;
}
export {
  M as __require
};
//# sourceMappingURL=contains.js.map
