"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 PaseDiscovery_exports = {};
__export(PaseDiscovery_exports, {
  PaseDiscovery: () => PaseDiscovery
});
module.exports = __toCommonJS(PaseDiscovery_exports);
var import_general = require("@matter/general");
var import_protocol = require("@matter/protocol");
var import_ParallelPaseDiscovery = require("./ParallelPaseDiscovery.js");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
class PaseDiscovery extends import_ParallelPaseDiscovery.ParallelPaseDiscovery {
  #options;
  constructor(owner, options) {
    if (options.timeout === void 0) {
      options = { ...options, timeout: (0, import_general.Seconds)(60) };
    }
    super(owner, options);
    this.#options = options;
  }
  get cleanupLabel() {
    return "PASE candidate cleanup";
  }
  get failureMessage() {
    return "No PASE session could be established";
  }
  onDiscovered(node) {
    if (this.paseWon) return;
    this.registerAttempt(
      (winOnPase) => node.act("establish-pase", (agent) => {
        const addresses = agent.commissioning.state.addresses;
        if (!addresses?.length) {
          return;
        }
        const commissioner = node.env.get(import_protocol.ControllerCommissioner);
        const establishOptions = {
          addresses: addresses.map(import_general.ServerAddress),
          discoveryData: agent.commissioning.descriptor,
          passcode: this.#options.passcode,
          timeout: this.#options.timeout,
          abort: this.abortSignal,
          continueAfterPase: winOnPase
        };
        return commissioner.establishPase(establishOptions);
      }),
      (result) => result?.paseSession
    );
  }
}
//# sourceMappingURL=PaseDiscovery.js.map
