import { o as d } from "./plus-base-10eea8a6.mjs";
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
function f(r) {
  return d({ descriptor: (t) => ({ async get() {
    var e;
    return await this.updateComplete, (e = this.renderRoot) === null || e === void 0 ? void 0 : e.querySelector(r);
  }, enumerable: !0, configurable: !0 }) });
}
/**
 * @license
 * Copyright 2021 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
let p = class extends Event {
  constructor(t, e, o) {
    super("context-request", { bubbles: !0, composed: !0 }), this.context = t, this.callback = e, this.subscribe = o ?? !1;
  }
};
/**
 * @license
 * Copyright 2021 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
function m(r) {
  return r;
}
/**
 * @license
 * Copyright 2021 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
class b {
  get value() {
    return this.o;
  }
  set value(t) {
    this.setValue(t);
  }
  setValue(t, e = !1) {
    const o = e || !Object.is(t, this.o);
    this.o = t, o && this.updateObservers();
  }
  constructor(t) {
    this.subscriptions = /* @__PURE__ */ new Map(), this.updateObservers = () => {
      for (const [e, { disposer: o }] of this.subscriptions)
        e(this.o, o);
    }, t !== void 0 && (this.value = t);
  }
  addCallback(t, e, o) {
    if (!o)
      return void t(this.value);
    this.subscriptions.has(t) || this.subscriptions.set(t, { disposer: () => {
      this.subscriptions.delete(t);
    }, consumerHost: e });
    const { disposer: i } = this.subscriptions.get(t);
    t(this.value, i);
  }
  clearCallbacks() {
    this.subscriptions.clear();
  }
}
/**
 * @license
 * Copyright 2021 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
let v = class extends Event {
  constructor(t) {
    super("context-provider", { bubbles: !0, composed: !0 }), this.context = t;
  }
};
class u extends b {
  constructor(t, e, o) {
    var i, n;
    super(e.context !== void 0 ? e.initialValue : o), this.onContextRequest = (s) => {
      const c = s.composedPath()[0];
      s.context === this.context && c !== this.host && (s.stopPropagation(), this.addCallback(s.callback, c, s.subscribe));
    }, this.onProviderRequest = (s) => {
      const c = s.composedPath()[0];
      if (s.context !== this.context || c === this.host)
        return;
      const h = /* @__PURE__ */ new Set();
      for (const [a, { consumerHost: l }] of this.subscriptions)
        h.has(a) || (h.add(a), l.dispatchEvent(new p(this.context, a, !0)));
      s.stopPropagation();
    }, this.host = t, e.context !== void 0 ? this.context = e.context : this.context = e, this.attachListeners(), (n = (i = this.host).addController) == null || n.call(i, this);
  }
  attachListeners() {
    this.host.addEventListener("context-request", this.onContextRequest), this.host.addEventListener("context-provider", this.onProviderRequest);
  }
  hostConnected() {
    this.host.dispatchEvent(new v(this.context));
  }
}
/**
 * @license
 * Copyright 2017 Google LLC
 * SPDX-License-Identifier: BSD-3-Clause
 */
function C({ context: r }) {
  return (t, e) => {
    const o = /* @__PURE__ */ new WeakMap();
    if (typeof e == "object")
      return e.addInitializer(function() {
        o.set(this, new u(this, { context: r }));
      }), { get() {
        return t.get.call(this);
      }, set(i) {
        var n;
        return (n = o.get(this)) == null || n.setValue(i), t.set.call(this, i);
      }, init(i) {
        var n;
        return (n = o.get(this)) == null || n.setValue(i), i;
      } };
    {
      t.constructor.addInitializer((s) => {
        o.set(s, new u(s, { context: r }));
      });
      const i = Object.getOwnPropertyDescriptor(t, e);
      let n;
      if (i === void 0) {
        const s = /* @__PURE__ */ new WeakMap();
        n = { get: function() {
          return s.get(this);
        }, set: function(c) {
          o.get(this).setValue(c), s.set(this, c);
        }, configurable: !0, enumerable: !0 };
      } else {
        const s = i.set;
        n = { ...i, set: function(c) {
          o.get(this).setValue(c), s == null || s.call(this, c);
        } };
      }
      return void Object.defineProperty(t, e, n);
    }
  };
}
export {
  C as a,
  f as e,
  m as n,
  p as s
};
