"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 CommissioningDiscovery_exports = {};
__export(CommissioningDiscovery_exports, {
  CommissioningDiscovery: () => CommissioningDiscovery
});
module.exports = __toCommonJS(CommissioningDiscovery_exports);
var import_CommissioningClient = require("#behavior/system/commissioning/CommissioningClient.js");
var import_general = require("@matter/general");
var import_ParallelPaseDiscovery = require("./ParallelPaseDiscovery.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class CommissioningDiscovery extends import_ParallelPaseDiscovery.ParallelPaseDiscovery {
  #options;
  constructor(owner, options) {
    const opts = import_CommissioningClient.CommissioningClient.PasscodeOptions(options);
    const { discriminator } = opts;
    if (discriminator !== void 0) {
      options = { ...options, longDiscriminator: discriminator };
    }
    if (options.timeout === void 0) {
      options = { ...options, timeout: (0, import_general.Minutes)(3) };
    }
    if (options.discoveryCapabilities !== void 0 && options.scannerFilter === void 0) {
      const caps = options.discoveryCapabilities;
      options = {
        ...options,
        scannerFilter: (s) => s.type === import_general.ChannelType.UDP || !!caps.ble && s.type === import_general.ChannelType.BLE
      };
    }
    super(owner, options);
    this.#options = options;
  }
  get cleanupLabel() {
    return "Commissioning candidate cleanup";
  }
  get failureMessage() {
    return "No device could be commissioned";
  }
  onDiscovered(node) {
    if (this.paseWon) return;
    this.registerAttempt(
      (winOnPase) => node.act(
        "commission",
        (agent) => agent.commissioning.commission({
          ...this.#options,
          abort: this.abortSignal,
          continueCommissioningAfterPase: winOnPase
        })
      ),
      () => node
    );
  }
}
//# sourceMappingURL=CommissioningDiscovery.js.map
