"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 NetworkServer_exports = {};
__export(NetworkServer_exports, {
  NetworkServer: () => NetworkServer
});
module.exports = __toCommonJS(NetworkServer_exports);
var import_general = require("@matter/general");
var import_protocol = require("@matter/protocol");
var import_CommissioningServer = require("../commissioning/CommissioningServer.js");
var import_NetworkBehavior = require("./NetworkBehavior.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
const logger = import_general.Logger.get("NetworkingServer");
class NetworkServer extends import_NetworkBehavior.NetworkBehavior {
  initialize() {
    if (this.state.ble === void 0) {
      this.state.ble = this.env.has(import_protocol.Ble);
    } else if (this.state.ble && !this.env.has(import_protocol.Ble)) {
      logger.warn("Disabling Bluetooth commissioning because BLE support is not installed");
      this.state.ble = false;
    }
    const discoveryCaps = this.state.discoveryCapabilities;
    switch (discoveryCaps.ble) {
      case void 0:
        discoveryCaps.ble = this.state.ble;
        break;
      case true:
        if (!this.state.ble) {
          discoveryCaps.ble = false;
        }
        break;
    }
    if (discoveryCaps.onIpNetwork === void 0) {
      discoveryCaps.onIpNetwork = true;
    }
    this.reactTo(this.endpoint.eventsOf(import_CommissioningServer.CommissioningServer).commissioned, this.#endUncommissionedMode);
    if (discoveryCaps.ble) {
      this.reactTo(this.env.get(import_protocol.FabricManager).events.added, this.#ensureMdnsAdvertiser);
    }
    return super.initialize();
  }
  #endUncommissionedMode() {
    if (this.internal.runtime) {
      this.internal.runtime.endUncommissionedMode();
    }
  }
  #ensureMdnsAdvertiser() {
    if (this.internal.runtime) {
      this.internal.runtime.ensureMdnsAdvertiser();
    }
  }
}
((NetworkServer2) => {
  class Internal extends import_NetworkBehavior.NetworkBehavior.Internal {
  }
  NetworkServer2.Internal = Internal;
  class State extends import_NetworkBehavior.NetworkBehavior.State {
    listeningAddressIpv4 = void 0;
    listeningAddressIpv6 = void 0;
    ipv4 = true;
    ble = void 0;
    discoveryCapabilities = {
      onIpNetwork: true
    };
    subscriptionOptions = void 0;
  }
  NetworkServer2.State = State;
})(NetworkServer || (NetworkServer = {}));
//# sourceMappingURL=NetworkServer.js.map
