var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result) __defProp(target, key, result);
  return result;
};
/**
 * @license
 * Copyright 2025-2026 Open Home Foundation
 * SPDX-License-Identifier: Apache-2.0
 */
import { consume } from "@lit/context";
import "@material/web/progress/circular-progress";
import "@material/web/textfield/outlined-text-field";
import { LitElement, html, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators.js";
import { clientContext } from "../../../client/client-context.js";
import { handleAsync } from "../../../util/async-handler.js";
import { fireEvent } from "../../../util/fire_event.js";
import { showAlertDialog } from "../../dialog-box/show-dialog-box.js";
let CommissionNodeExisting = class extends LitElement {
  constructor() {
    super(...arguments);
    this._loading = false;
  }
  firstUpdated() {
    void this._autofocusPairingCode().catch((err) => console.warn("Autofocus failed:", err));
  }
  async _autofocusPairingCode() {
    await this._pairingCodeField.updateComplete;
    this._pairingCodeField.focus();
  }
  render() {
    return html`<md-outlined-text-field label="Share code" .disabled="${this._loading}"> </md-outlined-text-field>
            <br />
            <br />
            <md-outlined-button @click=${handleAsync(() => this._commissionNode())} .disabled="${this._loading}"
                >Commission</md-outlined-button
            >${this._loading ? html` <md-circular-progress indeterminate></md-circular-progress> ` : nothing}`;
  }
  async _commissionNode() {
    this._loading = true;
    try {
      const node = await this.client.commissionWithCode(this._pairingCodeField.value, true);
      fireEvent(this, "node-commissioned", node);
    } catch (err) {
      showAlertDialog({ title: "Error commissioning node", text: err.message });
    } finally {
      this._loading = false;
    }
  }
};
__decorateClass([
  consume({ context: clientContext, subscribe: true }),
  property({ attribute: false })
], CommissionNodeExisting.prototype, "client", 2);
__decorateClass([
  state()
], CommissionNodeExisting.prototype, "_loading", 2);
__decorateClass([
  query("md-outlined-text-field[label='Share code']")
], CommissionNodeExisting.prototype, "_pairingCodeField", 2);
CommissionNodeExisting = __decorateClass([
  customElement("commission-node-existing")
], CommissionNodeExisting);
export {
  CommissionNodeExisting
};
//# sourceMappingURL=commission-node-existing.js.map
