/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { ModeBase } from "#clusters/mode-base";
import { ImplementationError } from "#general";
class UnsupportedModeError extends ImplementationError {
}
var ModeUtils;
((ModeUtils2) => {
  function assertSupportedModes(supportedModes) {
    const labels = /* @__PURE__ */ new Set();
    const modes = /* @__PURE__ */ new Set();
    for (const { mode, label } of supportedModes) {
      if (labels.has(label)) {
        throw new ImplementationError(`Duplicate label in supportedModes: ${label}`);
      }
      if (modes.has(mode)) {
        throw new ImplementationError(`Duplicate mode in supportedModes: ${mode}`);
      }
      labels.add(label);
      modes.add(mode);
    }
  }
  ModeUtils2.assertSupportedModes = assertSupportedModes;
  function assertMode(supportedModes, newMode) {
    if (!supportedModes.some(({ mode }) => mode === newMode)) {
      throw new UnsupportedModeError(
        `Can not use unsupported mode: ${newMode}. Allowed modes are ${supportedModes.map(({ mode }) => mode).join(", ")}`
      );
    }
  }
  ModeUtils2.assertMode = assertMode;
  function assertModeChange(supportedModes, currentMode, newMode) {
    if (currentMode !== newMode) {
      try {
        assertMode(supportedModes, newMode);
      } catch (error) {
        UnsupportedModeError.accept(error);
        return {
          status: ModeBase.ModeChangeStatus.UnsupportedMode,
          statusText: `Unsupported mode: ${newMode}`
        };
      }
    }
    return {
      status: ModeBase.ModeChangeStatus.Success,
      statusText: ""
    };
  }
  ModeUtils2.assertModeChange = assertModeChange;
})(ModeUtils || (ModeUtils = {}));
export {
  ModeUtils,
  UnsupportedModeError
};
//# sourceMappingURL=ModeUtils.js.map
