import { _ as r } from "./tslib.es6-pPsSiLLK.mjs";
import { n as a } from "./property-DJzm_oB9.mjs";
import "./query-assigned-elements-D930kELM.mjs";
import { B as d } from "./base-element-DUJkJh_y.mjs";
/**
 * @license
 * Copyright 2018 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */
var o, e;
const l = (e = (o = window.ShadyDOM) === null || o === void 0 ? void 0 : o.inUse) !== null && e !== void 0 ? e : !1;
class n extends d {
  constructor() {
    super(...arguments), this.disabled = !1, this.containingForm = null, this.formDataListener = (t) => {
      this.disabled || this.setFormData(t.formData);
    };
  }
  findFormElement() {
    if (!this.shadowRoot || l)
      return null;
    const s = this.getRootNode().querySelectorAll("form");
    for (const i of Array.from(s))
      if (i.contains(this))
        return i;
    return null;
  }
  connectedCallback() {
    var t;
    super.connectedCallback(), this.containingForm = this.findFormElement(), (t = this.containingForm) === null || t === void 0 || t.addEventListener("formdata", this.formDataListener);
  }
  disconnectedCallback() {
    var t;
    super.disconnectedCallback(), (t = this.containingForm) === null || t === void 0 || t.removeEventListener("formdata", this.formDataListener), this.containingForm = null;
  }
  click() {
    this.formElement && !this.disabled && (this.formElement.focus(), this.formElement.click());
  }
  firstUpdated() {
    super.firstUpdated(), this.shadowRoot && this.mdcRoot.addEventListener("change", (t) => {
      this.dispatchEvent(new Event("change", t));
    });
  }
}
n.shadowRootOptions = { mode: "open", delegatesFocus: !0 };
r([
  a({ type: Boolean })
], n.prototype, "disabled", void 0);
export {
  n as F
};
