import {
  Logger
} from "/node_modules/.vite/deps/chunk-CAYODABQ.js?v=bff2a436";
import {
  ColorContextConsumer,
  ColorContextController,
  contextEvents
} from "/node_modules/.vite/deps/chunk-KBYEGRCV.js?v=bff2a436";
import {
  __classPrivateFieldGet,
  __classPrivateFieldSet,
  css,
  isServer
} from "/node_modules/.vite/deps/chunk-F6B56SAQ.js?v=bff2a436";

// node_modules/@rhds/tokens/css/color-context-provider.css.js
var color_context_provider_css_default = css`
:host([color-palette^="dark"]) { --context: dark; }
:host([color-palette^="light"]) { --context: light; }

:host([color-palette="lightest"]) {
  --rh-color-surface: var(--rh-color-surface-lightest, #ffffff);
}
:host([color-palette="lighter"]) {
  --rh-color-surface: var(--rh-color-surface-lighter, #f2f2f2);
}
:host([color-palette="light"]) {
  --rh-color-surface: var(--rh-color-surface-light, #e0e0e0);
}
:host([color-palette="dark"]) {
  --rh-color-surface: var(--rh-color-surface-dark, #383838);
}
:host([color-palette="darker"]) {
  --rh-color-surface: var(--rh-color-surface-darker, #1f1f1f);
}
:host([color-palette="darkest"]) {
  --rh-color-surface: var(--rh-color-surface-darkest, #151515);
}`;

// node_modules/@rhds/elements/lib/context/color/provider.js
var _ColorContextProvider_instances;
var _a;
var _ColorContextProvider_attribute;
var _ColorContextProvider_callbacks;
var _ColorContextProvider_mo;
var _ColorContextProvider_style;
var _ColorContextProvider_initialized;
var _ColorContextProvider_logger;
var _ColorContextProvider_consumer;
var _ColorContextProvider_local_get;
var _ColorContextProvider_isColorContextEvent;
var _ColorContextProvider_onChildContextRequestEvent;
var ColorContextProvider = class extends ColorContextController {
  get local() {
    return __classPrivateFieldGet(this, _ColorContextProvider_instances, "a", _ColorContextProvider_local_get);
  }
  get value() {
    return __classPrivateFieldGet(this, _ColorContextProvider_instances, "a", _ColorContextProvider_local_get) ?? __classPrivateFieldGet(this, _ColorContextProvider_consumer, "f").value;
  }
  constructor(host, options) {
    const { attribute = "color-palette" } = options ?? {};
    super(host, color_context_provider_css_default);
    _ColorContextProvider_instances.add(this);
    _ColorContextProvider_attribute.set(this, void 0);
    _ColorContextProvider_callbacks.set(this, /* @__PURE__ */ new Set());
    _ColorContextProvider_mo.set(this, new MutationObserver(() => this.update()));
    _ColorContextProvider_style.set(this, void 0);
    _ColorContextProvider_initialized.set(this, false);
    _ColorContextProvider_logger.set(this, void 0);
    _ColorContextProvider_consumer.set(this, void 0);
    __classPrivateFieldSet(this, _ColorContextProvider_consumer, new ColorContextConsumer(host, {
      callback: (value) => this.update(value)
    }), "f");
    __classPrivateFieldSet(this, _ColorContextProvider_logger, new Logger(host), "f");
    __classPrivateFieldSet(this, _ColorContextProvider_style, window.getComputedStyle(host), "f");
    __classPrivateFieldSet(this, _ColorContextProvider_attribute, attribute, "f");
    if (__classPrivateFieldGet(this, _ColorContextProvider_attribute, "f") !== "color-palette") {
      __classPrivateFieldGet(this, _ColorContextProvider_logger, "f").warn("color context currently supports the `color-palette` attribute only.");
    }
  }
  /**
     * When a context provider connects, it listens for context-request events
     * it also fires all previously fired context-request events from their hosts,
     * in case this context provider upgraded after and is closer to a given consumer.
     */
  async hostConnected() {
    this.host.addEventListener("context-request", (e) => __classPrivateFieldGet(this, _ColorContextProvider_instances, "m", _ColorContextProvider_onChildContextRequestEvent).call(this, e));
    __classPrivateFieldGet(this, _ColorContextProvider_mo, "f").observe(this.host, { attributes: true, attributeFilter: [__classPrivateFieldGet(this, _ColorContextProvider_attribute, "f")] });
    await this.host.updateComplete;
    for (const [host, fired] of contextEvents) {
      host.dispatchEvent(fired);
    }
    this.update();
    return true;
  }
  async hostUpdated() {
    if (!__classPrivateFieldGet(this, _ColorContextProvider_initialized, "f")) {
      this.hostConnected();
    }
    __classPrivateFieldSet(this, _ColorContextProvider_initialized, __classPrivateFieldGet(this, _ColorContextProvider_initialized, "f") || await this.hostConnected(), "f");
    if (__classPrivateFieldGet(this, _ColorContextProvider_instances, "a", _ColorContextProvider_local_get) && this.value !== __classPrivateFieldGet(this, _ColorContextProvider_consumer, "f").value) {
      __classPrivateFieldGet(this, _ColorContextProvider_consumer, "f").update(__classPrivateFieldGet(this, _ColorContextProvider_instances, "a", _ColorContextProvider_local_get));
      this.update();
    }
    if (!isServer) {
      this.update();
    }
  }
  /**
   * When a context provider disconnects, it disconnects its mutation observer
   */
  hostDisconnected() {
    __classPrivateFieldGet(this, _ColorContextProvider_callbacks, "f").forEach((x) => __classPrivateFieldGet(this, _ColorContextProvider_callbacks, "f").delete(x));
    __classPrivateFieldGet(this, _ColorContextProvider_mo, "f").disconnect();
  }
  /**
   * Calls the context callback for all consumers
   * @param [force] override theme
   */
  async update(force) {
    for (const cb of __classPrivateFieldGet(this, _ColorContextProvider_callbacks, "f")) {
      cb(force ?? this.value);
    }
  }
};
_a = ColorContextProvider, _ColorContextProvider_attribute = /* @__PURE__ */ new WeakMap(), _ColorContextProvider_callbacks = /* @__PURE__ */ new WeakMap(), _ColorContextProvider_mo = /* @__PURE__ */ new WeakMap(), _ColorContextProvider_style = /* @__PURE__ */ new WeakMap(), _ColorContextProvider_initialized = /* @__PURE__ */ new WeakMap(), _ColorContextProvider_logger = /* @__PURE__ */ new WeakMap(), _ColorContextProvider_consumer = /* @__PURE__ */ new WeakMap(), _ColorContextProvider_instances = /* @__PURE__ */ new WeakSet(), _ColorContextProvider_local_get = function _ColorContextProvider_local_get2() {
  return _a.contexts.get(this.host.getAttribute(__classPrivateFieldGet(this, _ColorContextProvider_attribute, "f")) ?? "");
}, _ColorContextProvider_isColorContextEvent = function _ColorContextProvider_isColorContextEvent2(event) {
  return event.composedPath().at(0) !== this.host && event.context === ColorContextController.context;
}, _ColorContextProvider_onChildContextRequestEvent = /**
 * Provider part of context API
 * When a child connects, claim its context-request event
 * and add its callback to the Set of children if it requests multiple updates
 * @param event context-request event
 */
async function _ColorContextProvider_onChildContextRequestEvent2(event) {
  if (__classPrivateFieldGet(this, _ColorContextProvider_instances, "m", _ColorContextProvider_isColorContextEvent).call(this, event)) {
    event.stopPropagation();
    event.callback(this.value);
    if (event.subscribe) {
      __classPrivateFieldGet(this, _ColorContextProvider_callbacks, "f").add(event.callback);
    }
  }
};
ColorContextProvider.contexts = new Map(Object.entries({
  darkest: "dark",
  darker: "dark",
  dark: "dark",
  light: "light",
  lighter: "light",
  lightest: "light"
}));
function colorContextProvider(options) {
  return function(proto, _propertyName) {
    const propertyName = _propertyName;
    const klass = proto.constructor;
    const propOpts = klass.getPropertyOptions(_propertyName);
    const attribute = typeof propOpts.attribute === "boolean" ? void 0 : propOpts.attribute;
    klass.addInitializer((instance) => {
      const controller = new ColorContextProvider(instance, {
        propertyName,
        attribute,
        ...options
      });
      instance.__DEBUG_colorContextProvider = controller;
    });
  };
}

export {
  colorContextProvider
};
/*! Bundled license information:

@rhds/tokens/css/color-context-provider.css.js:
  (**
   * Do not edit directly, this file was auto-generated.
   *
   * @license Copyright (c) 2022 Red Hat UX MIT License
   *)
*/
//# sourceMappingURL=chunk-QKIOAKEK.js.map
