"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 ModeUtils_exports = {};
__export(ModeUtils_exports, {
  ModeUtils: () => ModeUtils,
  UnsupportedModeError: () => UnsupportedModeError
});
module.exports = __toCommonJS(ModeUtils_exports);
var import_general = require("@matter/general");
var import_mode_base = require("@matter/types/clusters/mode-base");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class UnsupportedModeError extends import_general.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 import_general.ImplementationError(`Duplicate label in supportedModes: ${label}`);
      }
      if (modes.has(mode)) {
        throw new import_general.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: import_mode_base.ModeBase.ModeChangeStatus.UnsupportedMode,
          statusText: `Unsupported mode: ${newMode}`
        };
      }
    }
    return {
      status: import_mode_base.ModeBase.ModeChangeStatus.Success,
      statusText: ""
    };
  }
  ModeUtils2.assertModeChange = assertModeChange;
})(ModeUtils || (ModeUtils = {}));
//# sourceMappingURL=ModeUtils.js.map
