import {
  __decorateClass,
  __privateAdd,
  __privateGet,
  __privateMethod
} from "../../chunks/chunk.QU3DSPNU.js";
var _fullscreenStyles, _GdsSpinner_instances, getWrapperClasses_fn;
import { localized, msg } from "@lit/localize";
import { css } from "lit";
import { property, state } from "lit/decorators.js";
import { classMap } from "lit/directives/class-map.js";
import { when } from "lit/directives/when.js";
import { GdsElement } from "../../gds-element.js";
import { gdsCustomElement, html } from "../../scoping.js";
import { tokens } from "../../tokens.style.js";
import { watch } from "../../utils/decorators/watch.js";
import { GlobalStylesRegistry } from "../../utils/global-styles.js";
import {
  withLayoutChildProps,
  withMarginProps,
  withPositioningProps
} from "../../utils/mixins/declarative-layout-mixins.js";
import styles from "./spinner.styles.js";
let GdsSpinner = class extends withMarginProps(
  withPositioningProps(withLayoutChildProps(GdsElement))
) {
  constructor() {
    super(...arguments);
    __privateAdd(this, _GdsSpinner_instances);
    /**
     * Global styles for fullscreen mode
     */
    __privateAdd(this, _fullscreenStyles, css`
    html {
      overflow: hidden !important;
      overscroll-behavior: none !important;
    }
  `);
    this.label = msg("Loading...");
    this.labelPosition = "bottom";
    this.showLabel = false;
    this.cover = false;
    this.fullscreen = false;
    this.size = "md";
    this._isAnimating = false;
  }
  /**
   * Sets up accessibility attributes and initializes the spinner
   */
  connectedCallback() {
    super.connectedCallback();
    this.setAttribute("role", "status");
    this.setAttribute("aria-live", "polite");
    this._isAnimating = true;
    this.dispatchCustomEvent("gds-spinner-connected");
  }
  /**
   * Cleans up document styles if fullscreen mode was used
   */
  disconnectedCallback() {
    super.disconnectedCallback();
    if (this.fullscreen) {
      this.fullscreen = false;
      this._toggleRootStyles();
    }
    this._isAnimating = false;
  }
  _updateAriaLabel() {
    this.setAttribute("aria-label", this.label);
  }
  /**
   * Renders the spinner component
   */
  render() {
    return html`
      <div part="wrapper" class=${classMap(__privateMethod(this, _GdsSpinner_instances, getWrapperClasses_fn).call(this))}>
        <span part="spinner" class="spinner"></span>
        ${when(
      this.showLabel,
      () => html`<span part="label" class="spinner-label">${this.label}</span>`
    )}
      </div>
    `;
  }
  _toggleRootStyles() {
    const registry = GlobalStylesRegistry.instance;
    const key = `gds-spinner-fullscreen-${this.id || "default"}`;
    if (this.fullscreen) {
      registry.injectGlobalStyles(key, __privateGet(this, _fullscreenStyles));
    } else {
      registry.clearGlobalStyles(key);
    }
  }
};
_fullscreenStyles = new WeakMap();
_GdsSpinner_instances = new WeakSet();
/**
 * Generates CSS classes for the wrapper element based on component state
 */
getWrapperClasses_fn = function() {
  return {
    "spinner-wrapper": true,
    "spinner-fullscreen": this.fullscreen,
    "spinner-cover": this.cover,
    "spinner-backdrop": this.cover || this.fullscreen,
    "spinner-animating": this._isAnimating,
    [`spinner-label-${this.labelPosition}`]: this.labelPosition
  };
};
/** All styles are defined in the external styles file */
GdsSpinner.styles = [tokens, styles];
__decorateClass([
  property({ type: String })
], GdsSpinner.prototype, "label", 2);
__decorateClass([
  property({ type: String, reflect: true, attribute: "label-position" })
], GdsSpinner.prototype, "labelPosition", 2);
__decorateClass([
  property({ type: Boolean, reflect: true })
], GdsSpinner.prototype, "showLabel", 2);
__decorateClass([
  property({ type: Boolean, reflect: true })
], GdsSpinner.prototype, "cover", 2);
__decorateClass([
  property({ type: Boolean, reflect: true })
], GdsSpinner.prototype, "fullscreen", 2);
__decorateClass([
  property({ type: String, reflect: true })
], GdsSpinner.prototype, "size", 2);
__decorateClass([
  state()
], GdsSpinner.prototype, "_isAnimating", 2);
__decorateClass([
  watch("label")
], GdsSpinner.prototype, "_updateAriaLabel", 1);
__decorateClass([
  watch("fullscreen")
], GdsSpinner.prototype, "_toggleRootStyles", 1);
GdsSpinner = __decorateClass([
  gdsCustomElement("gds-spinner"),
  localized()
], GdsSpinner);
export {
  GdsSpinner
};
