/**
 * @license
 * Copyright 2022-2025 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class ClusterTypeModifier {
  constructor(cluster) {
    this.cluster = cluster;
  }
  /**
   * Create a new cluster with modified elements.
   */
  alter(alterations) {
    return modifyElements(this.cluster, alterations, (element, alteration) => {
      for (const property in alteration) {
        element[property] = alteration[property];
      }
    });
  }
  /**
   * Create a new cluster with different attribute defaults.
   *
   * This "sets" the values of attributes when the cluster is created
   * for the first time with no persistent state.
   */
  set(values) {
    return modifyElements(this.cluster, { attributes: values }, (element, defaultValue) => {
      element.default = defaultValue;
    });
  }
  /**
   * Create a new cluster with additional features marked "mandatory".
   *
   * This informs matter.js that an application supports these elements.
   */
  enable(flags) {
    return modifyElements(this.cluster, flags, (element, flag) => {
      if (flag === true) {
        element.optional = false;
      } else if (flag === false) {
        element.optional = true;
      }
    });
  }
}
function modifyElements(definition, modifications, modifier) {
  const result = { ...definition };
  for (const elementType of ["attributes", "commands", "events"]) {
    const mods = modifications[elementType];
    if (mods === void 0) {
      continue;
    }
    let elements = result[elementType];
    if (elements === void 0) {
      continue;
    }
    let replaced = false;
    for (const elementName in mods) {
      const mod = mods[elementName];
      if (mod === void 0) {
        continue;
      }
      const element = elements[elementName];
      if (!element) {
        continue;
      }
      if (!replaced) {
        elements = result[elementType] = { ...result[elementType] };
        replaced = true;
      }
      elements[elementName] = { ...element };
      modifier(elements[elementName], mod);
    }
  }
  return result;
}
export {
  ClusterTypeModifier
};
//# sourceMappingURL=ClusterTypeModifier.js.map
