import { mergeAllOfSchemas as y } from "./merge-all-of-schemas.js";
const d = ["oneOf", "anyOf", "allOf", "not"];
function b(e) {
  var O;
  if (!e || typeof e != "object")
    return e;
  let r = { ...e };
  const o = d.find((t) => r == null ? void 0 : r[t]);
  if (!o || o === "not")
    return r;
  const s = r == null ? void 0 : r[o];
  if (!Array.isArray(s))
    return r;
  const i = { ...r };
  delete i[o], delete i.nullable;
  const u = Object.keys(i).length > 0, c = (o === "oneOf" || o === "anyOf") && (s.some((t) => t.allOf) || u), p = s.map((t) => {
    if (t.allOf && Array.isArray(t.allOf)) {
      let l = y(t.allOf);
      return c && (l = y(t.allOf, i)), Object.keys(t).forEach((n) => {
        !d.includes(n) && !(n in l) && (l[n] = t[n]);
      }), l;
    }
    return c && !t.allOf ? { ...i, ...t } : t;
  });
  p.some((t) => t.type === "null") && (r.nullable = !0);
  const f = p.filter((t) => t.type !== "null");
  return f.length === 1 && (r != null && r[o]) ? (r = { ...r, ...f[0] }, r == null || delete r[o], r) : c ? (r = {
    [o]: f
  }, r.nullable && (r.nullable = !0), r) : (Array.isArray(r == null ? void 0 : r[o]) && ((O = r == null ? void 0 : r[o]) == null ? void 0 : O.length) > 1 && (r[o] = f), r);
}
export {
  d as compositions,
  b as optimizeValueForDisplay
};
