"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var NamedComponents_exports = {};
__export(NamedComponents_exports, {
  NamedComponents: () => NamedComponents
});
module.exports = __toCommonJS(NamedComponents_exports);
var import_general = require("@matter/general");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
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"}`,
        (0, import_general.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"}`,
        (0, import_general.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 };
}
//# sourceMappingURL=NamedComponents.js.map
