import { unsafeCSS, LitElement, html, nothing } from "lit";
import { customElement } from "../../decorator.js";
import compentStyle from "./system-button.css.js";
import { property } from "lit/decorators.js";
import { IconButtonVariant } from "../icon-button/icon-button.js";
import "../../icons/icon-configure.js";
import "../../icons/icon-com-microphone.js";
import "../../icons/icon-com-mic-muted-google.js";
import "../../icons/icon-wifi2-google.js";
import "../../icons/icon-wifi2-off-google.js";
import "../../icons/icon-sensor-gps-bad.js";
import "../../icons/icon-sensor-gps-low.js";
import "../../icons/icon-sensor-gps-medium.js";
import "../../icons/icon-sensor-gps-full.js";
import "../../icons/icon-sound-muted.js";
import "../../icons/icon-sound-no.js";
import "../../icons/icon-sound-low.js";
import "../../icons/icon-sound.js";
import "../button/button.js";
import "../battery-icon/battery-icon.js";
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;
};
var SystemButtonVariant = /* @__PURE__ */ ((SystemButtonVariant2) => {
  SystemButtonVariant2["condensed"] = "condensed";
  SystemButtonVariant2["expanded"] = "expanded";
  SystemButtonVariant2["actions"] = "actions";
  return SystemButtonVariant2;
})(SystemButtonVariant || {});
let ObcSystemButton = class extends LitElement {
  constructor() {
    super(...arguments);
    this.variant = "condensed";
    this.disabled = false;
    this.systemState = {
      wifi: { connected: true, strength: 3 },
      audio: { muted: false, volume: 65 },
      microphone: { muted: false, sensitivity: 80 },
      battery: { level: 78, charging: false },
      gps: { connected: false, quality: "medium" }
    };
    this.menuOpen = false;
    this.activePanel = null;
    this._handleMicrophoneActionClick = () => {
      this.activePanel = "microphone";
      this.menuOpen = true;
      this.dispatchEvent(new CustomEvent("microphone-panel-open"));
    };
    this._handleVolumeActionClick = () => {
      this.activePanel = "volume";
      this.menuOpen = true;
      this.dispatchEvent(new CustomEvent("volume-panel-open"));
    };
    this._handleSystemIconsActionClick = () => {
      this.activePanel = "system-icons";
      this.menuOpen = true;
      this.dispatchEvent(new CustomEvent("system-icons-panel-open"));
    };
  }
  _handleExpandedTypeClick() {
    this.menuOpen = !this.menuOpen;
    this.dispatchEvent(
      new CustomEvent("menu-toggle", {
        detail: { open: this.menuOpen }
      })
    );
  }
  /**
   * Updates the system state and dispatches a change event.
   * Called by the System Menu component.
   *
   * @param newState Partial system state to merge with the current state.
   * @fires system-state-change {CustomEvent<{state: SystemState}>} When the system state is updated
   */
  updateSystemState(newState) {
    this.systemState = { ...this.systemState, ...newState };
    this.dispatchEvent(
      new CustomEvent("system-state-change", {
        detail: { state: this.systemState }
      })
    );
  }
  /**
   * Closes the system menu panel.
   * Called by the System Menu component.
   */
  closeMenu() {
    this.menuOpen = false;
    this.activePanel = null;
  }
  _renderActionsButtons() {
    const buttons = [];
    let buttonCount = 0;
    if (this.systemState.microphone !== void 0) buttonCount++;
    if (this.systemState.audio !== void 0) buttonCount++;
    buttonCount++;
    let currentIndex = 0;
    if (this.systemState.microphone !== void 0) {
      const segmentPosition2 = buttonCount === 1 ? "single" : currentIndex === 0 ? "start" : currentIndex === buttonCount - 1 ? "end" : "middle";
      buttons.push(html`
        <obc-button
          .variant=${IconButtonVariant.normal}
          .segmentPosition=${segmentPosition2}
          .showLeadingIcon=${true}
          @click=${this._handleMicrophoneActionClick}
          .disabled=${this.disabled}
        >
          <span slot="leading-icon">${this._renderMicrophoneIcon()}</span>
          ${this.systemState.microphone.muted ? "Off" : "On"}
        </obc-button>
      `);
      currentIndex++;
    }
    if (this.systemState.audio !== void 0) {
      const segmentPosition2 = buttonCount === 1 ? "single" : currentIndex === 0 ? "start" : currentIndex === buttonCount - 1 ? "end" : "middle";
      buttons.push(html`
        <obc-button
          .variant=${IconButtonVariant.normal}
          .segmentPosition=${segmentPosition2}
          .showLeadingIcon=${true}
          @click=${this._handleVolumeActionClick}
          .disabled=${this.disabled}
        >
          <span slot="leading-icon">${this._renderVolumeIcon()}</span>
          ${this.systemState.audio.volume}
        </obc-button>
      `);
      currentIndex++;
    }
    const segmentPosition = buttonCount === 1 ? "single" : currentIndex === 0 ? "start" : "end";
    buttons.push(html`
      <obc-button
        .variant=${IconButtonVariant.normal}
        .segmentPosition=${segmentPosition}
        .showLeadingIcon=${true}
        @click=${this._handleSystemIconsActionClick}
        .disabled=${this.disabled}
      >
        <span slot="leading-icon" class="multiple-icons">
          ${this._renderWifiIcon()} ${this._renderGpsIcon()}
          ${this._renderBatteryIcon()}
        </span>
      </obc-button>
    `);
    return buttons;
  }
  _renderMicrophoneIcon() {
    if (this.systemState.microphone === void 0) return nothing;
    if (this.systemState.microphone.muted) {
      return html`<obi-com-mic-muted-google></obi-com-mic-muted-google>`;
    } else {
      return html`<obi-com-microphone></obi-com-microphone>`;
    }
  }
  _renderVolumeIcon() {
    if (this.systemState.audio === void 0) return nothing;
    const volume = this.systemState.audio.volume;
    const muted = this.systemState.audio.muted;
    if (muted) {
      return html`<obi-sound-muted></obi-sound-muted>`;
    }
    if (volume === 0) {
      return html`<obi-sound-no></obi-sound-no>`;
    } else if (volume <= 50) {
      return html`<obi-sound-low></obi-sound-low>`;
    } else {
      return html`<obi-sound></obi-sound>`;
    }
  }
  _renderWifiIcon() {
    if (this.systemState.wifi === void 0) return nothing;
    if (!this.systemState.wifi.connected) {
      return html`<obi-wifi2-off-google></obi-wifi2-off-google>`;
    }
    switch (this.systemState.wifi.strength) {
      case 0:
        return html`<obi-wifi2-google></obi-wifi2-google>`;
      case 1:
        return html`<obi-wifi2-google></obi-wifi2-google>`;
      case 2:
        return html`<obi-wifi2-google></obi-wifi2-google>`;
      case 3:
        return html`<obi-wifi2-google></obi-wifi2-google>`;
      case 4:
        return html`<obi-wifi2-google></obi-wifi2-google>`;
      default:
        return html`<obi-wifi2-google></obi-wifi2-google>`;
    }
  }
  _renderGpsIcon() {
    if (this.systemState.gps === void 0) return nothing;
    if (!this.systemState.gps.connected) {
      return html`<obi-sensor-gps-bad></obi-sensor-gps-bad>`;
    }
    switch (this.systemState.gps.quality) {
      case "bad":
        return html`<obi-sensor-gps-bad></obi-sensor-gps-bad>`;
      case "low":
        return html`<obi-sensor-gps-low></obi-sensor-gps-low>`;
      case "medium":
        return html`<obi-sensor-gps-medium></obi-sensor-gps-medium>`;
      case "full":
        return html`<obi-sensor-gps-full></obi-sensor-gps-full>`;
      default:
        return html`<obi-sensor-gps-medium></obi-sensor-gps-medium>`;
    }
  }
  _renderBatteryIcon() {
    if (this.systemState.battery === void 0) return nothing;
    const level = this.systemState.battery.level;
    const charging = this.systemState.battery.charging;
    const poweredNotCharging = this.systemState.battery.poweredNotCharging ?? false;
    const notification = this.systemState.battery.notification ?? false;
    return html`<obc-battery-icon
      class="icon"
      .level=${level}
      .charging=${charging}
      .poweredNotCharging=${poweredNotCharging}
      .notification=${notification}
      horizontal
    ></obc-battery-icon>`;
  }
  render() {
    switch (this.variant) {
      case "condensed":
        return html`
          <obc-icon-button
            variant=${IconButtonVariant.flat}
            .disabled=${this.disabled}
          >
            <obi-configure></obi-configure>
          </obc-icon-button>
        `;
      case "expanded":
        return html` <button
          class="expanded-visually-hidden"
          @click=${this._handleExpandedTypeClick}
          .disabled=${this.disabled}
        >
          <div class="expanded-inner-wrapper">
            <div class="expanded-icon-container">
              ${this._renderMicrophoneIcon()} ${this._renderVolumeIcon()}
              ${this._renderWifiIcon()} ${this._renderGpsIcon()}
              ${this._renderBatteryIcon()}
            </div>
          </div>
        </button>`;
      case "actions":
        return html`
          <div class="system-button--actions">
            ${this._renderActionsButtons()}
          </div>
        `;
      default:
        return html`
          <obc-icon-button variant=${IconButtonVariant.normal}>
            <obi-configure></obi-configure>
          </obc-icon-button>
        `;
    }
  }
};
ObcSystemButton.styles = unsafeCSS(compentStyle);
__decorateClass([
  property({ type: String })
], ObcSystemButton.prototype, "variant", 2);
__decorateClass([
  property({ type: Boolean })
], ObcSystemButton.prototype, "disabled", 2);
__decorateClass([
  property({ type: Object })
], ObcSystemButton.prototype, "systemState", 2);
__decorateClass([
  property({ type: Boolean })
], ObcSystemButton.prototype, "menuOpen", 2);
__decorateClass([
  property({ type: String })
], ObcSystemButton.prototype, "activePanel", 2);
ObcSystemButton = __decorateClass([
  customElement("obc-system-button")
], ObcSystemButton);
export {
  ObcSystemButton,
  SystemButtonVariant
};
//# sourceMappingURL=system-button.js.map
