import { __exports as f } from "../../../../../../../../_virtual/dependencies.js";
import { __require as P } from "../../compile/codegen/index.js";
import { __require as D } from "../../compile/util.js";
import { __require as q } from "../code.js";
var _;
function j() {
  return _ ? f : (_ = 1, function(n) {
    Object.defineProperty(n, "__esModule", { value: !0 }), n.validateSchemaDeps = n.validatePropertyDeps = n.error = void 0;
    const u = P(), y = D(), a = q();
    n.error = {
      message: ({ params: { property: e, depsCount: o, deps: r } }) => {
        const s = o === 1 ? "property" : "properties";
        return (0, u.str)`must have ${s} ${r} when property ${e} is present`;
      },
      params: ({ params: { property: e, depsCount: o, deps: r, missingProperty: s } }) => (0, u._)`{property: ${e},
    missingProperty: ${s},
    depsCount: ${o},
    deps: ${r}}`
      // TODO change to reference
    };
    const h = {
      keyword: "dependencies",
      type: "object",
      schemaType: "object",
      error: n.error,
      code(e) {
        const [o, r] = g(e);
        l(e, o), m(e, r);
      }
    };
    function g({ schema: e }) {
      const o = {}, r = {};
      for (const s in e) {
        if (s === "__proto__")
          continue;
        const p = Array.isArray(e[s]) ? o : r;
        p[s] = e[s];
      }
      return [o, r];
    }
    function l(e, o = e.schema) {
      const { gen: r, data: s, it: p } = e;
      if (Object.keys(o).length === 0)
        return;
      const c = r.let("missing");
      for (const i in o) {
        const t = o[i];
        if (t.length === 0)
          continue;
        const d = (0, a.propertyInData)(r, s, i, p.opts.ownProperties);
        e.setParams({
          property: i,
          depsCount: t.length,
          deps: t.join(", ")
        }), p.allErrors ? r.if(d, () => {
          for (const v of t)
            (0, a.checkReportMissingProp)(e, v);
        }) : (r.if((0, u._)`${d} && (${(0, a.checkMissingProp)(e, t, c)})`), (0, a.reportMissingProp)(e, c), r.else());
      }
    }
    n.validatePropertyDeps = l;
    function m(e, o = e.schema) {
      const { gen: r, data: s, keyword: p, it: c } = e, i = r.name("valid");
      for (const t in o)
        (0, y.alwaysValidSchema)(c, o[t]) || (r.if(
          (0, a.propertyInData)(r, s, t, c.opts.ownProperties),
          () => {
            const d = e.subschema({ keyword: p, schemaProp: t }, i);
            e.mergeValidEvaluated(d, i);
          },
          () => r.var(i, !0)
          // TODO var
        ), e.ok(i));
    }
    n.validateSchemaDeps = m, n.default = h;
  }(f), f);
}
export {
  j as __require
};
//# sourceMappingURL=dependencies.js.map
