import { __exports as t } from "../../../../../../../_virtual/util.js";
import { __require as V } from "./codegen/index.js";
import { __require as q } from "./codegen/code.js";
var R;
function T() {
  if (R) return t;
  R = 1, Object.defineProperty(t, "__esModule", { value: !0 }), t.checkStrictMode = t.getErrorPath = t.Type = t.useFunc = t.setEvaluated = t.evaluatedPropsToName = t.mergeEvaluated = t.eachItem = t.unescapeJsonPointer = t.escapeJsonPointer = t.escapeFragment = t.unescapeFragment = t.schemaRefOrVal = t.schemaHasRulesButRef = t.schemaHasRules = t.checkUnknownRules = t.alwaysValidSchema = t.toHash = void 0;
  const u = V(), k = q();
  function N(e) {
    const r = {};
    for (const n of e)
      r[n] = !0;
    return r;
  }
  t.toHash = N;
  function v(e, r) {
    return typeof r == "boolean" ? r : Object.keys(r).length === 0 ? !0 : (d(e, r), !$(r, e.self.RULES.all));
  }
  t.alwaysValidSchema = v;
  function d(e, r = e.schema) {
    const { opts: n, self: s } = e;
    if (!n.strictSchema || typeof r == "boolean")
      return;
    const i = s.RULES.keywords;
    for (const a in r)
      i[a] || y(e, `unknown keyword: "${a}"`);
  }
  t.checkUnknownRules = d;
  function $(e, r) {
    if (typeof e == "boolean")
      return !e;
    for (const n in e)
      if (r[n])
        return !0;
    return !1;
  }
  t.schemaHasRules = $;
  function w(e, r) {
    if (typeof e == "boolean")
      return !e;
    for (const n in e)
      if (n !== "$ref" && r.all[n])
        return !0;
    return !1;
  }
  t.schemaHasRulesButRef = w;
  function E({ topSchemaRef: e, schemaPath: r }, n, s, i) {
    if (!i) {
      if (typeof n == "number" || typeof n == "boolean")
        return n;
      if (typeof n == "string")
        return (0, u._)`${n}`;
    }
    return (0, u._)`${e}${r}${(0, u.getProperty)(s)}`;
  }
  t.schemaRefOrVal = E;
  function b(e) {
    return m(decodeURIComponent(e));
  }
  t.unescapeFragment = b;
  function S(e) {
    return encodeURIComponent(o(e));
  }
  t.escapeFragment = S;
  function o(e) {
    return typeof e == "number" ? `${e}` : e.replace(/~/g, "~0").replace(/\//g, "~1");
  }
  t.escapeJsonPointer = o;
  function m(e) {
    return e.replace(/~1/g, "/").replace(/~0/g, "~");
  }
  t.unescapeJsonPointer = m;
  function F(e, r) {
    if (Array.isArray(e))
      for (const n of e)
        r(n);
    else
      r(e);
  }
  t.eachItem = F;
  function _({ mergeNames: e, mergeToName: r, mergeValues: n, resultToName: s }) {
    return (i, a, c, U) => {
      const p = c === void 0 ? a : c instanceof u.Name ? (a instanceof u.Name ? e(i, a, c) : r(i, a, c), c) : a instanceof u.Name ? (r(i, c, a), a) : n(a, c);
      return U === u.Name && !(p instanceof u.Name) ? s(i, p) : p;
    };
  }
  t.mergeEvaluated = {
    props: _({
      mergeNames: (e, r, n) => e.if((0, u._)`${n} !== true && ${r} !== undefined`, () => {
        e.if((0, u._)`${r} === true`, () => e.assign(n, !0), () => e.assign(n, (0, u._)`${n} || {}`).code((0, u._)`Object.assign(${n}, ${r})`));
      }),
      mergeToName: (e, r, n) => e.if((0, u._)`${n} !== true`, () => {
        r === !0 ? e.assign(n, !0) : (e.assign(n, (0, u._)`${n} || {}`), f(e, n, r));
      }),
      mergeValues: (e, r) => e === !0 ? !0 : { ...e, ...r },
      resultToName: g
    }),
    items: _({
      mergeNames: (e, r, n) => e.if((0, u._)`${n} !== true && ${r} !== undefined`, () => e.assign(n, (0, u._)`${r} === true ? true : ${n} > ${r} ? ${n} : ${r}`)),
      mergeToName: (e, r, n) => e.if((0, u._)`${n} !== true`, () => e.assign(n, r === !0 ? !0 : (0, u._)`${n} > ${r} ? ${n} : ${r}`)),
      mergeValues: (e, r) => e === !0 ? !0 : Math.max(e, r),
      resultToName: (e, r) => e.var("items", r)
    })
  };
  function g(e, r) {
    if (r === !0)
      return e.var("props", !0);
    const n = e.var("props", (0, u._)`{}`);
    return r !== void 0 && f(e, n, r), n;
  }
  t.evaluatedPropsToName = g;
  function f(e, r, n) {
    Object.keys(n).forEach((s) => e.assign((0, u._)`${r}${(0, u.getProperty)(s)}`, !0));
  }
  t.setEvaluated = f;
  const h = {};
  function H(e, r) {
    return e.scopeValue("func", {
      ref: r,
      code: h[r.code] || (h[r.code] = new k._Code(r.code))
    });
  }
  t.useFunc = H;
  var l;
  (function(e) {
    e[e.Num = 0] = "Num", e[e.Str = 1] = "Str";
  })(l || (t.Type = l = {}));
  function P(e, r, n) {
    if (e instanceof u.Name) {
      const s = r === l.Num;
      return n ? s ? (0, u._)`"[" + ${e} + "]"` : (0, u._)`"['" + ${e} + "']"` : s ? (0, u._)`"/" + ${e}` : (0, u._)`"/" + ${e}.replace(/~/g, "~0").replace(/\\//g, "~1")`;
    }
    return n ? (0, u.getProperty)(e).toString() : "/" + o(e);
  }
  t.getErrorPath = P;
  function y(e, r, n = e.opts.strictSchema) {
    if (n) {
      if (r = `strict mode: ${r}`, n === !0)
        throw new Error(r);
      e.self.logger.warn(r);
    }
  }
  return t.checkStrictMode = y, t;
}
export {
  T as __require
};
//# sourceMappingURL=util.js.map
