/** Nav capability filter smoke test (mirrors portals.ts logic). */
function filterNavByCapabilities(nav, features) {
  if (!features) return nav;
  const isEnabled = (feature) => {
    if (!feature) return true;
    return features[feature] === true;
  };
  return nav
    .map((group) => {
      if (group.feature && !isEnabled(group.feature)) return null;
      if (group.items) {
        const items = group.items.filter((i) => isEnabled(i.feature));
        if (items.length === 0 && !group.href) return null;
        return { ...group, items };
      }
      return group;
    })
    .filter(Boolean);
}

const sampleNav = [
  { id: "dashboard", href: "/experience", items: undefined },
  {
    id: "builder",
    feature: null,
    items: [
      { href: "/x", feature: "page_builder" },
      { href: "/experience/components", feature: null },
    ],
  },
];

const out = filterNavByCapabilities(sampleNav, { page_builder: false });
if (out.length !== 2) throw new Error(`expected 2 groups, got ${out.length}`);
const builder = out.find((g) => g.id === "builder");
if (!builder?.items?.length) throw new Error("builder group should keep non-gated items");
console.log("experience nav-filter OK");
