/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { describeList } from "@matter/general";
function NamedComponents(cluster, inferredComponents) {
  let base = { mandatory: [], optional: [] };
  const components = [];
  const namedComponentMap = {};
  const featureNames = Object.fromEntries(cluster.features.map((f) => [f.name, f.title || f.name]));
  for (const component of inferredComponents) {
    let name;
    const contributorDocumentation = Array();
    const allOf = component.condition?.allOf;
    if (allOf) {
      const names = allOf.map((f) => featureNames[f]);
      name = names.join("And");
      contributorDocumentation.push(
        `it supports feature${allOf.length === 1 ? "" : "s"}`,
        describeList("and", ...names)
      );
    }
    const anyOf = component.condition?.anyOf;
    if (anyOf) {
      const names = anyOf.map((f) => featureNames[f]);
      const members = Array();
      if (name) {
        members.push(name);
      }
      members.push(...anyOf);
      name = names.join("Or");
      if (contributorDocumentation.length) {
        contributorDocumentation.push("and it");
      }
      contributorDocumentation.push(
        `it supports feature${anyOf.length === 1 ? "" : "s"}`,
        describeList("or", ...names)
      );
    }
    const not = component.condition?.not;
    if (not) {
      name = `${name || ""}Not${featureNames[not]}`;
      if (contributorDocumentation.length) {
        contributorDocumentation.push("and it");
      }
      contributorDocumentation.push("doesn't support feature", not);
    }
    if (!name) {
      base = component;
    } else {
      contributorDocumentation.unshift(`A ${cluster.name}Cluster supports these elements if`);
      let namedComponent = namedComponentMap[name];
      if (!namedComponent) {
        namedComponent = {
          name,
          documentation: `${contributorDocumentation.join(" ")}.`,
          ...component
        };
        namedComponentMap[name] = namedComponent;
        components.push(namedComponent);
      }
    }
  }
  return { base, components };
}
export {
  NamedComponents
};
//# sourceMappingURL=NamedComponents.js.map
