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/text-button";
import "@material/web/dialog/dialog";
import "@material/web/select/outlined-select";
import "@material/web/select/select-option";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property, query, state } from "lit/decorators.js";
import { fireAndForget, handleAsync } from "../../../util/async-handler.js";
import { preventDefault } from "../../../util/prevent_default.js";
const LOG_LEVELS = [
  { value: "critical", label: "Critical" },
  { value: "error", label: "Error" },
  { value: "warning", label: "Warning" },
  { value: "info", label: "Info" },
  { value: "debug", label: "Debug" }
];
let LogLevelDialog = class extends LitElement {
  constructor() {
    super(...arguments);
    this._consoleLevel = "info";
    this._fileLevel = null;
    this._loading = true;
    this._applying = false;
  }
  connectedCallback() {
    super.connectedCallback();
    fireAndForget(this._loadLogLevels());
  }
  async _loadLogLevels() {
    try {
      const result = await this.client.getLogLevel();
      this._consoleLevel = result.console_loglevel;
      this._fileLevel = result.file_loglevel;
    } catch (err) {
      console.error("Failed to load log levels:", err);
    } finally {
      this._loading = false;
    }
  }
  async _apply() {
    this._applying = true;
    try {
      const consoleLevel = this._consoleSelect.value;
      const fileLevel = this._fileSelect?.value;
      const result = await this.client.setLogLevel(
        consoleLevel,
        this._fileLevel !== null ? fileLevel : void 0
      );
      this._consoleLevel = result.console_loglevel;
      this._fileLevel = result.file_loglevel;
      this._close();
    } catch (err) {
      console.error("Failed to apply log levels:", err);
      alert("Failed to apply log levels");
    } finally {
      this._applying = false;
    }
  }
  _close() {
    this.shadowRoot.querySelector("md-dialog").close();
  }
  _handleClosed() {
    this.parentNode.removeChild(this);
  }
  render() {
    return html`
            <md-dialog open @cancel=${preventDefault} @closed=${this._handleClosed}>
                <div slot="headline">Server Log Settings</div>
                <div slot="content">
                    ${this._loading ? html` <p class="loading">Loading...</p> ` : html`
                              <p class="hint">Changes are temporary and will be reset on the next server restart.</p>
                              <div class="form-field">
                                  <label>Console Log Level</label>
                                  <md-outlined-select name="console" .value=${this._consoleLevel}>
                                      ${LOG_LEVELS.map(
      (level) => html`
                                              <md-select-option
                                                  value=${level.value}
                                                  ?selected=${level.value === this._consoleLevel}
                                              >
                                                  <div slot="headline">${level.label}</div>
                                              </md-select-option>
                                          `
    )}
                                  </md-outlined-select>
                              </div>
                              ${this._fileLevel !== null ? html`
                                        <div class="form-field">
                                            <label>File Log Level</label>
                                            <md-outlined-select name="file" .value=${this._fileLevel}>
                                                ${LOG_LEVELS.map(
      (level) => html`
                                                        <md-select-option
                                                            value=${level.value}
                                                            ?selected=${level.value === this._fileLevel}
                                                        >
                                                            <div slot="headline">${level.label}</div>
                                                        </md-select-option>
                                                    `
    )}
                                            </md-outlined-select>
                                        </div>
                                    ` : nothing}
                          `}
                </div>
                <div slot="actions">
                    <md-text-button @click=${this._close}>Cancel</md-text-button>
                    <md-text-button
                        @click=${handleAsync(() => this._apply())}
                        ?disabled=${this._loading || this._applying}
                    >
                        ${this._applying ? "Applying..." : "Apply"}
                    </md-text-button>
                </div>
            </md-dialog>
        `;
  }
};
LogLevelDialog.styles = css`
        .loading {
            text-align: center;
            padding: 24px;
            color: var(--md-sys-color-on-surface-variant);
        }

        .hint {
            font-size: 0.875rem;
            color: var(--md-sys-color-on-surface-variant);
            margin: 0 0 16px 0;
            font-style: italic;
        }

        .form-field {
            margin-bottom: 16px;
        }

        .form-field label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--md-sys-color-on-surface);
        }

        md-outlined-select {
            width: 100%;
        }
    `;
__decorateClass([
  property({ attribute: false })
], LogLevelDialog.prototype, "client", 2);
__decorateClass([
  state()
], LogLevelDialog.prototype, "_consoleLevel", 2);
__decorateClass([
  state()
], LogLevelDialog.prototype, "_fileLevel", 2);
__decorateClass([
  state()
], LogLevelDialog.prototype, "_loading", 2);
__decorateClass([
  state()
], LogLevelDialog.prototype, "_applying", 2);
__decorateClass([
  query("md-outlined-select[name='console']")
], LogLevelDialog.prototype, "_consoleSelect", 2);
__decorateClass([
  query("md-outlined-select[name='file']")
], LogLevelDialog.prototype, "_fileSelect", 2);
LogLevelDialog = __decorateClass([
  customElement("log-level-dialog")
], LogLevelDialog);
export {
  LogLevelDialog
};
//# sourceMappingURL=log-level-dialog.js.map
