import {
  __decorateClass,
  __privateAdd,
  __privateGet
} from "../../chunks/chunk.QU3DSPNU.js";
var _handleClick, _handleKeyDown;
import { property, state } from "lit/decorators.js";
import { GdsElement } from "../../gds-element.js";
import { GdsToggleControlBase } from "../../primitives/toggle-controls-base/toggle-control-base.component.js";
import { gdsCustomElement, html } from "../../scoping.js";
import rbcbToggleStyles from "../../shared-styles/rbcb-toggle.style.js";
import { radioToggle } from "../../shared-styles/rbcb-toggle.template.js";
import RadioStyles from "./radio.styles.js";
let GdsRadio = class extends GdsElement {
  constructor() {
    super();
    this.label = "";
    this.supportingText = "";
    this.value = "";
    this.checked = false;
    this.disabled = false;
    this.invalid = false;
    this._isFocused = false;
    __privateAdd(this, _handleClick, (e) => {
      if (this.disabled || !this.label) return;
      e.preventDefault();
      this.checked = true;
      this.focus();
      this.dispatchStandardEvent("input", { bubbles: true });
    });
    __privateAdd(this, _handleKeyDown, (e) => {
      if (this.disabled) return;
      if (e.key === "Enter" || e.key === " ") {
        e.preventDefault();
        this.checked = true;
        this.dispatchStandardEvent("input", { bubbles: true });
      }
    });
    this.addEventListener("keydown", __privateGet(this, _handleKeyDown));
    this.addEventListener("focus", () => this._isFocused = true);
    this.addEventListener("blur", () => this._isFocused = false);
  }
  connectedCallback() {
    super.connectedCallback();
    this.setAttribute("role", "radio");
    this._updateAriaState();
    this.addEventListener("click", __privateGet(this, _handleClick));
  }
  _updateAriaState() {
    this.setAttribute("aria-checked", this.checked.toString());
    this.setAttribute("aria-disabled", this.disabled.toString());
    this.setAttribute("tabindex", this.disabled ? "-1" : "0");
    this.setAttribute(
      "aria-description",
      this.errorMessage ? this.errorMessage : ""
    );
    this.toggleAttribute("aria-invalid", this.invalid);
  }
  updated(changedProperties) {
    super.updated(changedProperties);
    if (changedProperties.has("checked") || changedProperties.has("disabled") || changedProperties.has("invalid")) {
      this._updateAriaState();
    }
  }
  render() {
    return html`
      <gds-toggle-control-base type="radio">
        <label slot="label" @click=${__privateGet(this, _handleClick)}> ${this.label} </label>
        <span slot="supporting-text"> ${this.supportingText} </span>
        ${radioToggle({
      checked: this.checked,
      disabled: this.disabled,
      indeterminate: false,
      invalid: this.invalid
    })}
      </gds-toggle-control-base>
    `;
  }
};
_handleClick = new WeakMap();
_handleKeyDown = new WeakMap();
GdsRadio.styles = [rbcbToggleStyles, RadioStyles];
__decorateClass([
  property()
], GdsRadio.prototype, "label", 2);
__decorateClass([
  property({ attribute: "supporting-text" })
], GdsRadio.prototype, "supportingText", 2);
__decorateClass([
  property({ type: String })
], GdsRadio.prototype, "value", 2);
__decorateClass([
  property({ type: Boolean, reflect: true })
], GdsRadio.prototype, "checked", 2);
__decorateClass([
  property({ type: Boolean, reflect: true })
], GdsRadio.prototype, "disabled", 2);
__decorateClass([
  property({ type: Boolean })
], GdsRadio.prototype, "invalid", 2);
__decorateClass([
  property({ type: String })
], GdsRadio.prototype, "errorMessage", 2);
__decorateClass([
  state()
], GdsRadio.prototype, "_isFocused", 2);
GdsRadio = __decorateClass([
  gdsCustomElement("gds-radio", { dependsOn: [GdsToggleControlBase] })
], GdsRadio);
export {
  GdsRadio
};
