import { d as b } from "../../../../../sdk/dist/shared/chunk-QGYZ7CG5.js";
import "../../../../../sdk/dist/shared/chunk-AFVJZPLS.js";
import "@sinclair/typebox";
import "../../../../../sdk/dist/shared/chunk-A3GF4PYW.js";
import "../../../../../sdk/dist/shared/chunk-W33JMRRN.js";
const defaultFilter = () => true;
function getNavItemsFromManifest(manifest, filter = defaultFilter, pathsParts = []) {
  const groups = manifest["ui:groups"] ?? {};
  const groupsProcessed = /* @__PURE__ */ new Map();
  const items = Object.entries(manifest.properties).map(([key, prop]) => [key, b(prop)]).filter(([, prop]) => prop["ui:field"] !== "hidden").filter(([key, prop]) => filter(prop, key)).map(([key, prop]) => {
    const nextPathParts = [...pathsParts, key];
    if (prop["ui:group"]) {
      const existingGroup = groupsProcessed.get(prop["ui:group"]);
      const isObjectGroup = prop.type === "object" && !prop["ui:field"];
      if (!existingGroup) {
        groupsProcessed.set(
          prop["ui:group"],
          isObjectGroup ? [] : [
            {
              id: key,
              label: prop.title,
              path: nextPathParts.join("."),
              ...prop.metadata && { metadata: prop.metadata },
              ...prop.description ? { description: prop.description } : {},
              schema: prop
            }
          ]
        );
        const children = [];
        if (isObjectGroup) {
          for (const [childKey, childProp] of Object.entries(prop.properties)) {
            const childPath = [...nextPathParts, childKey].join(".");
            children.push({
              id: childKey,
              label: childProp.title,
              path: childPath,
              ...childProp.metadata && { metadata: childProp.metadata },
              ...childProp.description ? { description: childProp.description } : {},
              schema: childProp
            });
          }
        }
        return {
          id: prop["ui:group"],
          label: groups[prop["ui:group"]] ?? prop["ui:group"],
          ...prop.metadata && { metadata: prop.metadata },
          ...prop.description ? { description: prop.description } : {},
          path: nextPathParts.join("."),
          groupId: prop["ui:group"],
          children
        };
      }
      existingGroup.push({
        id: key,
        label: prop.title,
        path: nextPathParts.join("."),
        ...prop.metadata && { metadata: prop.metadata },
        ...prop.description ? { description: prop.description } : {},
        schema: prop
      });
      return null;
    }
    return {
      id: key,
      label: prop.title,
      path: nextPathParts.join("."),
      ...prop.metadata && { metadata: prop.metadata },
      ...prop.description ? { description: prop.description } : {},
      schema: prop
    };
  }).filter((item) => item !== null).map((prop) => {
    if (prop.groupId) {
      const children = groupsProcessed.get(prop.groupId);
      if (children?.length) {
        prop.children = children;
      }
    }
    return prop;
  });
  return items.flat();
}
export {
  getNavItemsFromManifest
};
//# sourceMappingURL=form-utils.js.map
