import { r as s, i as n, l as m, A as v, x as h, e as g } from "./query-assigned-elements-D930kELM.mjs";
import { n as p } from "./property-DJzm_oB9.mjs";
import { CovalentListItem as u } from "./list-item.mjs";
import { s as f, c as x } from "./list-item-CK66f3gK.mjs";
import { s as b } from "./mwc-list-item.css-BfvtPwr2.mjs";
const y = ":host{font-family:var(--mdc-typography-font-family);font-size:var(--mdc-typography-body2-font-size);font-weight:600;line-height:var(--mdc-typography-body2-line-height);text-align:left;border-radius:var(--cv-list-item-border-radius, 100px);transition:border-radius .2s cubic-bezier(.4,0,.2,1),width .2s cubic-bezier(.4,0,.2,1);width:var(--cv-list-item-width, 100%);color:var(--cv-theme-on-surface-variant)}:host ::slotted(cv-icon[slot=graphic]){color:var(--cv-theme-on-surface-variant)}:host{--mdc-list-item-graphic-margin: 4px}::slotted(*){--cv-list-padding-right: 0;--cv-list-padding-left: 0;--cv-list-item-text-padding: 16px}:host([activated]){color:var(--cv-theme-on-secondary-container)}:host([activated]) ::slotted(cv-icon[slot=graphic]){color:var(--cv-theme-on-secondary-container)}:host([selected]:not([activated])) .expansion-header{transition:background-color .25s cubic-bezier(.4,0,.2,1) color .25s cubic-bezier(.4,0,.2,1);background-color:var(--cv-list-item-selected-background-color);color:var(--cv-list-item-selected-color)}:host([selected]:not([activated])) .expansion-header .mdc-deprecated-list-item__graphic{--mdc-theme-text-icon-on-background: var(--cv-list-item-selected-color)}:host([subnav]){--cv-list-item-text-padding: 16px;height:32px;font-weight:var(--mdc-typography-body2-font-weight);border-radius:var(--cv-list-item-border-radius, 100px);padding:0;padding-right:var(--cv-list-padding-right, 12px);padding-left:var(--cv-list-padding-left, 12px)}:host([graphic=avatar]) .mdc-deprecated-list-item__graphic{--mdc-theme-text-icon-on-background: var(--cv-theme-on-surface);margin-left:var(--cv-list-item-graphic-margin-left, 12px);padding-left:4px;background-color:transparent}:host([graphic=avatar]){padding:0;background-color:transparent}:host([graphic=avatar]:not([twoline])){height:48px}:host([hasChildren]){flex-direction:column;overflow:visible;height:var(--cv-list-item-height, inherit)!important;background:none;padding:0;--mdc-list-side-padding: 0;--cv-list-item-graphic-margin-left: 0}:host([hasChildren]) ::slotted(cv-list){padding-left:32px}:host([hasChildren][open]:hover:not([activated])) .expansion-header{--mdc-ripple-color: transparent}:host([hasChildren][open]:hover:not([activated])) .expansion-header:hover{--mdc-ripple-color: var(--mdc-theme-on-surface-variant)}.expansion-header{position:relative;height:48px;width:100%;border-radius:var(--cv-list-item-border-radius, 100px);overflow:hidden;display:flex;flex-shrink:0;align-items:center;background-color:var(--cv-list-item-background-color);color:var(--cv-list-item-text-color)}.expansion-header mwc-ripple{border-radius:var(--cv-list-item-border-radius, 100px);overflow:hidden}.expansion-header-inner{padding:0 16px}.expansion-icon{margin-right:var(--cv-list-item-expansion-icon-margin, 0);font-size:var(--cv-list-item-expansion-icon-size, --mdc-icon-size);color:var(--cv-list-item-text-icon-on-background, var(--mdc-theme-text-icon-on-background))}.expansion-panel{display:block;width:100%;max-height:var(--cv-list-menu-height, 0);overflow:hidden;transition:max-height .2s cubic-bezier(.4,0,1,1);--mdc-list-side-padding: 72px}:host([open][hasChildren]:not([twoline])){height:inherit;display:flex;flex-direction:column;border-radius:0}:host([open][hasChildren]:not([twoline])) .expansion-panel{transition-timing-function:cubic-bezier(0,0,.2,1);max-height:var(--cv-list-menu-height, inherit)}";
var w = Object.defineProperty, _ = Object.getOwnPropertyDescriptor, d = (e, t, i, a) => {
  for (var r = a > 1 ? void 0 : a ? _(t, i) : t, l = e.length - 1, c; l >= 0; l--)
    (c = e[l]) && (r = (a ? c(t, i, r) : c(r)) || r);
  return a && r && w(t, i, r), r;
};
let o = class extends u {
  constructor() {
    super(...arguments), this.open = !1, this.hasChildren = !1, this.activated = !1, this.lastKeySelected = 0;
  }
  _toggleOpen() {
    this.open = !this.open;
  }
  _handleKeydown(e) {
    const t = this.expansionPanelElements[0], i = t ? t == null ? void 0 : t.getFocusedItemIndex() : 0, a = (t == null ? void 0 : t.items.length) ?? 0;
    if (this.hasChildren) {
      if (e.code === "Enter") {
        e.preventDefault(), e.stopImmediatePropagation(), e.target.hasChildren ? this._toggleOpen() : this._deselectHeader(e);
        return;
      }
      if (this.open) {
        if (e.code === "ArrowUp" && i === 0 && this.lastKeySelected === 0 && !e.target.hasChildren) {
          e.preventDefault(), e.stopImmediatePropagation(), t.items[0].blur(), this.focus();
          return;
        }
        e.code === "ArrowDown" && i === -1 && (e.preventDefault(), e.stopImmediatePropagation(), t.focusItemAtIndex(0), this.lastKeySelected = 0), e.code === "ArrowUp" && i !== -1 && (e.preventDefault(), e.stopImmediatePropagation(), t.focusItemAtIndex(i), this.lastKeySelected = i), (e.code === "ArrowDown" || e.code === "ArrowUp") && i !== -1 && this.lastKeySelected < a - 1 && (e.preventDefault(), e.stopImmediatePropagation(), t.focusItemAtIndex(i), this.lastKeySelected = i);
      }
    }
  }
  _handleRequestSelected(e) {
    const t = e;
    this.hasChildren && t.detail.selected === !1 && t.detail.source === "property" && this._deselectChildren();
  }
  _deselectChildren() {
    this.expansionPanelElements.forEach((e) => {
      e.items.forEach((t) => t.selected = !1);
    });
  }
  _deselectHeader(e) {
    e.preventDefault(), e.stopImmediatePropagation(), this.fireRequestSelected(!1, "interaction"), this.activated = !1;
  }
  _updateMaxHeight(e = this.open) {
    var a;
    const t = (a = this.shadowRoot) == null ? void 0 : a.querySelector(".expansion-panel");
    let i = "0";
    e && (i = t != null && t.scrollHeight ? `${t.scrollHeight}px` : "inherit"), this.style.setProperty("--cv-list-menu-height", i);
  }
  renderExpansionItem() {
    const e = this.renderText(), t = this.graphic ? this.renderGraphic() : v, i = this.renderMeta();
    return h`
      <div
        @mousedown=${this._toggleOpen}
        @touchstart="${this._toggleOpen}"
        @keydown=${this._toggleOpen}
        class="expansion-header"
      >
        ${this.renderRipple()} ${t} ${e} ${i}
      </div>
      <div class="expansion-panel" @click=${this._deselectHeader}>
        <slot name="expansion-panel"></slot>
      </div>
    `;
  }
  connectedCallback() {
    super.connectedCallback(), this.addEventListener("keydown", this._handleKeydown), this.addEventListener("request-selected", this._handleRequestSelected);
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.removeEventListener("keydown", this._handleKeydown), this.addEventListener("request-selected", this._handleRequestSelected);
  }
  renderMeta() {
    const e = this.open ? "arrow_drop_up" : "arrow_drop_down", t = this.hasChildren ? h`<cv-icon class="expansion-icon">${e}</cv-icon>` : "";
    return h`<span class="mdc-deprecated-list-item__meta material-icons">
      ${t}
      <slot name="meta"></slot>
    </span>`;
  }
  firstUpdated() {
    super.firstUpdated(), this.hasChildren && this._updateMaxHeight();
  }
  updated(e) {
    super.updated(e), e.has("open") && this.hasChildren && this._updateMaxHeight();
  }
  render() {
    return this.hasChildren ? this.renderExpansionItem() : super.render();
  }
};
o.styles = [
  n`
      ${s(b)}
    `,
  n`
      ${s(f)}
    `,
  n`
      ${s(x)}
    `,
  n`
      ${s(y)}
    `
];
d([
  m({ slot: "expansion-panel", flatten: !0 })
], o.prototype, "expansionPanelElements", 2);
d([
  p({ type: Boolean, reflect: !0 })
], o.prototype, "open", 2);
d([
  p({ type: Boolean, reflect: !0 })
], o.prototype, "hasChildren", 2);
o = d([
  g("cv-nav-list-item")
], o);
const S = o;
export {
  o as CovalentNavRailListItem,
  S as default
};
