import { __exports as d } from "../../../../../../../../_virtual/subschema.js";
import { __require as g } from "../codegen/index.js";
import { __require as x } from "../util.js";
var p;
function D() {
  if (p) return d;
  p = 1, Object.defineProperty(d, "__esModule", { value: !0 }), d.extendSubschemaMode = d.extendSubschemaData = d.getSubschema = void 0;
  const a = g(), c = x();
  function m(e, { keyword: t, schemaProp: r, schema: o, schemaPath: n, errSchemaPath: i, topSchemaRef: u }) {
    if (t !== void 0 && o !== void 0)
      throw new Error('both "keyword" and "schema" passed, only one allowed');
    if (t !== void 0) {
      const h = e.schema[t];
      return r === void 0 ? {
        schema: h,
        schemaPath: (0, a._)`${e.schemaPath}${(0, a.getProperty)(t)}`,
        errSchemaPath: `${e.errSchemaPath}/${t}`
      } : {
        schema: h[r],
        schemaPath: (0, a._)`${e.schemaPath}${(0, a.getProperty)(t)}${(0, a.getProperty)(r)}`,
        errSchemaPath: `${e.errSchemaPath}/${t}/${(0, c.escapeFragment)(r)}`
      };
    }
    if (o !== void 0) {
      if (n === void 0 || i === void 0 || u === void 0)
        throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
      return {
        schema: o,
        schemaPath: n,
        topSchemaRef: u,
        errSchemaPath: i
      };
    }
    throw new Error('either "keyword" or "schema" must be passed');
  }
  d.getSubschema = m;
  function P(e, t, { dataProp: r, dataPropType: o, data: n, dataTypes: i, propertyName: u }) {
    if (n !== void 0 && r !== void 0)
      throw new Error('both "data" and "dataProp" passed, only one allowed');
    const { gen: h } = t;
    if (r !== void 0) {
      const { errorPath: f, dataPathArr: _, opts: $ } = t, l = h.let("data", (0, a._)`${t.data}${(0, a.getProperty)(r)}`, !0);
      s(l), e.errorPath = (0, a.str)`${f}${(0, c.getErrorPath)(r, o, $.jsPropertySyntax)}`, e.parentDataProperty = (0, a._)`${r}`, e.dataPathArr = [..._, e.parentDataProperty];
    }
    if (n !== void 0) {
      const f = n instanceof a.Name ? n : h.let("data", n, !0);
      s(f), u !== void 0 && (e.propertyName = u);
    }
    i && (e.dataTypes = i);
    function s(f) {
      e.data = f, e.dataLevel = t.dataLevel + 1, e.dataTypes = [], t.definedProperties = /* @__PURE__ */ new Set(), e.parentData = t.data, e.dataNames = [...t.dataNames, f];
    }
  }
  d.extendSubschemaData = P;
  function S(e, { jtdDiscriminator: t, jtdMetadata: r, compositeRule: o, createErrors: n, allErrors: i }) {
    o !== void 0 && (e.compositeRule = o), n !== void 0 && (e.createErrors = n), i !== void 0 && (e.allErrors = i), e.jtdDiscriminator = t, e.jtdMetadata = r;
  }
  return d.extendSubschemaMode = S, d;
}
export {
  D as __require
};
//# sourceMappingURL=subschema.js.map
