import { unsafeCSS, LitElement, nothing, html } from "lit";
import { property } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import "../icon-button/icon-button.js";
import componentStyle from "./toggle-switch.css.js";
import { customElement } from "../../decorator.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;
};
let ObcToggleSwitch = class extends LitElement {
  constructor() {
    super(...arguments);
    this.label = "Label";
    this.checked = false;
    this.disabled = false;
    this.hasDescription = false;
    this.description = "";
    this.hasBottomDivider = false;
    this.hasIcon = false;
    this.externalControl = false;
  }
  /**
   * Handles input events to change the toggle state.
   * Prevents changes if the toggle is disabled.
   * @param e {InputEvent}
   * @fires input - Dispatched when the value of the input changes
   */
  _tryChange(e) {
    if (this.disabled) {
      e.preventDefault();
      return;
    }
    const nextChecked = !this.checked;
    if (!this.externalControl) {
      this.checked = nextChecked;
    }
    e.stopPropagation();
    this.dispatchEvent(
      new CustomEvent("input", {
        detail: { checked: nextChecked }
      })
    );
    if (this.externalControl) {
      e.target.checked = this.checked;
    }
  }
  render() {
    return html`
      <label
        class=${classMap({
      checked: this.checked,
      disabled: this.disabled,
      "has-description": this.hasDescription
    })}
      >
        <div class="icon-label-container">
          ${this.hasIcon ? html`<div class="icon-container"><slot name="icon"></slot></div>` : nothing}
          <div class="label-container">
            <span class="label">${this.label}</span>
            ${this.hasDescription ? html`<span class="description">${this.description}</span>` : nothing}
          </div>
        </div>
        <div class="switch">
          <div class="presenter ${classMap({ checked: this.checked })}">
            <div class="knob"></div>
            <input
              type="checkbox"
              .checked=${this.checked}
              ?disabled=${this.disabled}
              @input=${this._tryChange}
            />
          </div>
        </div>
        ${this.hasBottomDivider ? html`<div class="bottom-divider"></div>` : nothing}
      </label>
    `;
  }
};
ObcToggleSwitch.styles = unsafeCSS(componentStyle);
__decorateClass([
  property({ type: String })
], ObcToggleSwitch.prototype, "label", 2);
__decorateClass([
  property({ type: Boolean })
], ObcToggleSwitch.prototype, "checked", 2);
__decorateClass([
  property({ type: Boolean })
], ObcToggleSwitch.prototype, "disabled", 2);
__decorateClass([
  property({ type: Boolean })
], ObcToggleSwitch.prototype, "hasDescription", 2);
__decorateClass([
  property({ type: String })
], ObcToggleSwitch.prototype, "description", 2);
__decorateClass([
  property({ type: Boolean })
], ObcToggleSwitch.prototype, "hasBottomDivider", 2);
__decorateClass([
  property({ type: Boolean })
], ObcToggleSwitch.prototype, "hasIcon", 2);
__decorateClass([
  property({ type: Boolean })
], ObcToggleSwitch.prototype, "externalControl", 2);
ObcToggleSwitch = __decorateClass([
  customElement("obc-toggle-switch")
], ObcToggleSwitch);
export {
  ObcToggleSwitch
};
//# sourceMappingURL=toggle-switch.js.map
