import { __exports as t } from "../../../../../../../_virtual/code2.js";
import { __require as I } from "../compile/codegen/index.js";
import { __require as v } from "../compile/util.js";
import { __require as S } from "../compile/names.js";
var w;
function T() {
  if (w) return t;
  w = 1, Object.defineProperty(t, "__esModule", { value: !0 }), t.validateUnion = t.validateArray = t.usePattern = t.callValidateCode = t.schemaProperties = t.allSchemaProperties = t.noPropertyInData = t.propertyInData = t.isOwnProperty = t.hasPropFunc = t.reportMissingProp = t.checkMissingProp = t.checkReportMissingProp = void 0;
  const n = I(), f = v(), l = S(), k = v();
  function D(r, e) {
    const { gen: o, data: i, it: a } = r;
    o.if(m(o, i, e, a.opts.ownProperties), () => {
      r.setParams({ missingProperty: (0, n._)`${e}` }, !0), r.error();
    });
  }
  t.checkReportMissingProp = D;
  function R({ gen: r, data: e, it: { opts: o } }, i, a) {
    return (0, n.or)(...i.map((s) => (0, n.and)(m(r, e, s, o.ownProperties), (0, n._)`${a} = ${s}`)));
  }
  t.checkMissingProp = R;
  function V(r, e) {
    r.setParams({ missingProperty: e }, !0), r.error();
  }
  t.reportMissingProp = V;
  function h(r) {
    return r.scopeValue("func", {
      // eslint-disable-next-line @typescript-eslint/unbound-method
      ref: Object.prototype.hasOwnProperty,
      code: (0, n._)`Object.prototype.hasOwnProperty`
    });
  }
  t.hasPropFunc = h;
  function P(r, e, o) {
    return (0, n._)`${h(r)}.call(${e}, ${o})`;
  }
  t.isOwnProperty = P;
  function b(r, e, o, i) {
    const a = (0, n._)`${e}${(0, n.getProperty)(o)} !== undefined`;
    return i ? (0, n._)`${a} && ${P(r, e, o)}` : a;
  }
  t.propertyInData = b;
  function m(r, e, o, i) {
    const a = (0, n._)`${e}${(0, n.getProperty)(o)} === undefined`;
    return i ? (0, n.or)(a, (0, n.not)(P(r, e, o))) : a;
  }
  t.noPropertyInData = m;
  function g(r) {
    return r ? Object.keys(r).filter((e) => e !== "__proto__") : [];
  }
  t.allSchemaProperties = g;
  function q(r, e) {
    return g(e).filter((o) => !(0, f.alwaysValidSchema)(r, e[o]));
  }
  t.schemaProperties = q;
  function A({ schemaCode: r, data: e, it: { gen: o, topSchemaRef: i, schemaPath: a, errorPath: s }, it: c }, u, p, d) {
    const _ = d ? (0, n._)`${r}, ${e}, ${i}${a}` : e, y = [
      [l.default.instancePath, (0, n.strConcat)(l.default.instancePath, s)],
      [l.default.parentData, c.parentData],
      [l.default.parentDataProperty, c.parentDataProperty],
      [l.default.rootData, l.default.rootData]
    ];
    c.opts.dynamicRef && y.push([l.default.dynamicAnchors, l.default.dynamicAnchors]);
    const $ = (0, n._)`${_}, ${o.object(...y)}`;
    return p !== n.nil ? (0, n._)`${u}.call(${p}, ${$})` : (0, n._)`${u}(${$})`;
  }
  t.callValidateCode = A;
  const C = (0, n._)`new RegExp`;
  function E({ gen: r, it: { opts: e } }, o) {
    const i = e.unicodeRegExp ? "u" : "", { regExp: a } = e.code, s = a(o, i);
    return r.scopeValue("pattern", {
      key: s.toString(),
      ref: s,
      code: (0, n._)`${a.code === "new RegExp" ? C : (0, k.useFunc)(r, a)}(${o}, ${i})`
    });
  }
  t.usePattern = E;
  function O(r) {
    const { gen: e, data: o, keyword: i, it: a } = r, s = e.name("valid");
    if (a.allErrors) {
      const u = e.let("valid", !0);
      return c(() => e.assign(u, !1)), u;
    }
    return e.var(s, !0), c(() => e.break()), s;
    function c(u) {
      const p = e.const("len", (0, n._)`${o}.length`);
      e.forRange("i", 0, p, (d) => {
        r.subschema({
          keyword: i,
          dataProp: d,
          dataPropType: f.Type.Num
        }, s), e.if((0, n.not)(s), u);
      });
    }
  }
  t.validateArray = O;
  function M(r) {
    const { gen: e, schema: o, keyword: i, it: a } = r;
    if (!Array.isArray(o))
      throw new Error("ajv implementation error");
    if (o.some((p) => (0, f.alwaysValidSchema)(a, p)) && !a.opts.unevaluated)
      return;
    const c = e.let("valid", !1), u = e.name("_valid");
    e.block(() => o.forEach((p, d) => {
      const _ = r.subschema({
        keyword: i,
        schemaProp: d,
        compositeRule: !0
      }, u);
      e.assign(c, (0, n._)`${c} || ${u}`), r.mergeValidEvaluated(_, u) || e.if((0, n.not)(c));
    })), r.result(c, () => r.reset(), () => r.error(!0));
  }
  return t.validateUnion = M, t;
}
export {
  T as __require
};
//# sourceMappingURL=code.js.map
