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 "@material/web/button/filled-button";
import "@material/web/button/outlined-button";
import "@material/web/button/text-button";
import "@material/web/divider/divider";
import "@material/web/iconbutton/icon-button";
import "@material/web/list/list";
import "@material/web/list/list-item";
import { consume } from "@lit/context";
import { mdiFile, mdiPlus } from "@mdi/js";
import { LitElement, css, html, nothing } from "lit";
import { customElement } from "lit/decorators.js";
import { clientContext, tickContext } from "../../client/client-context.js";
import { showAlertDialog, showPromptDialog } from "../../components/dialog-box/show-dialog-box.js";
import { showCommissionNodeDialog } from "../../components/dialogs/commission-node-dialog/show-commission-node-dialog.js";
import "../../components/ha-svg-icon";
import { handleAsync } from "../../util/async-handler.js";
let ServerDetails = class extends LitElement {
  constructor() {
    super(...arguments);
    this._tick = 0;
    this._onFileInput = (event) => {
      const fileElem = event.target;
      if (fileElem.files.length > 0) {
        const selectedFile = fileElem.files[0];
        const reader = new FileReader();
        reader.readAsText(selectedFile, "UTF-8");
        reader.onload = async () => {
          try {
            await this.client?.importTestNode(reader.result?.toString() ?? "");
          } catch (err) {
            showAlertDialog({
              title: "Failed to import test node",
              text: err.message
            });
          } finally {
            fileElem.value = "";
          }
        };
      }
      event.preventDefault();
    };
  }
  render() {
    if (!this.client) return html``;
    return html`
      <md-list>
        <md-list-item>
            <div slot="headline">
                <b>Open Home Foundation Matter Server ${this.client.isProduction ? "" : `(${this.client.serverBaseAddress})`}</b>
                ${this.client.connection.connected ? nothing : html` <span class="status">OFFLINE</span> `}
      </div>
        </md-list-item>
        <md-list-item>
          <div slot="supporting-text">
            <div class="left">Matter Server Version: </div>${this.client.serverInfo.sdk_version}
          </div>
          <div slot="supporting-text">
            <div class="left">FabricId: </div>${this.client.serverInfo.fabric_id}
          </div>
          <div slot="supporting-text">
            <div class="left">Compressed FabricId: </div>${this.client.serverInfo.compressed_fabric_id}
          </div>
          <div slot="supporting-text">
            <div class="left">Schema Version: </div>${this.client.serverInfo.schema_version}
          </div>
          <div slot="supporting-text">
            <div class="left">Node count: </div>${Object.keys(this.client.nodes).length}
          </div>
        </md-list-item>
        <md-list-item>
          <div class="btn-row">
            <md-outlined-button @click=${this._commissionNode}>Commission node<ha-svg-icon slot="icon" .path=${mdiPlus}></ha-svg-icon></md-outlined-button>
            <md-outlined-button @click=${handleAsync(() => this._uploadDiagnosticsDumpFile())}>Import node<ha-svg-icon slot="icon" .path=${mdiFile}></ha-svg-icon></md-outlined-button>
          </div>
        </md-list-item>
      </md-list>
      <!-- hidden file element for the upload diagnostics -->
      <input
        @change=${this._onFileInput}
        type="file"
        id="fileElem"
        accept=".json"
        style="display:none" />
      </div>
  `;
  }
  _commissionNode() {
    showCommissionNodeDialog();
  }
  async _uploadDiagnosticsDumpFile() {
    if (!await showPromptDialog({
      title: "Add test node",
      text: "Do you want to add a test node from a diagnostics dump ?",
      confirmText: "Select file"
    })) {
      return;
    }
    const fileElem = this.shadowRoot.getElementById("fileElem");
    fileElem.click();
  }
};
ServerDetails.styles = css`
        .btn-row {
            --md-outlined-button-container-shape: 0px;
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
        }

        .btn-row md-outlined-button {
            max-width: 100%;
        }

        .left {
            min-width: 120px;
            display: inline-block;
        }

        @media (min-width: 600px) {
            .left {
                min-width: 160px;
            }
        }

        .whitespace {
            height: 15px;
        }

        .status {
            color: var(--danger-color);
            font-weight: bold;
            font-size: 0.8em;
        }
    `;
__decorateClass([
  consume({ context: clientContext })
], ServerDetails.prototype, "client", 2);
__decorateClass([
  consume({ context: tickContext, subscribe: true })
], ServerDetails.prototype, "_tick", 2);
ServerDetails = __decorateClass([
  customElement("server-details")
], ServerDetails);
export {
  ServerDetails
};
//# sourceMappingURL=server-details.js.map
