import{__decorate as t}from"tslib";import{html as e}from"lit";import{property as i,customElement as s}from"lit/decorators.js";import{s as n}from"./nile-inline-sidebar-item.css.esm.js";import{N as r}from"../internal/nile-element.esm.js";import{classMap as o}from"lit/directives/class-map.js";import"../internal/accessibility/a11y.state.enum.esm.js";import"../internal/accessibility/a11y.property.enum.esm.js";import"../internal/accessibility/role.enum.esm.js";let l=class extends r{constructor(){super(...arguments),this.active=!1,this.disabled=!1,this.tooltip=!1,this.variant="minimal",this._handleHostKeyDown=t=>{"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),this._select(t))}}static get styles(){return[n]}firstUpdated(t){super.firstUpdated(t),this.syncBodyAndHeaderStates()}updated(t){super.updated(t),(t.has("disabled")||t.has("active"))&&this.syncBodyAndHeaderStates()}syncBodyAndHeaderStates(){const t=[this.querySelector('[slot="body"]'),this.querySelector('[slot="header"]')],e={disabled:this.disabled,active:this.active};t.forEach((t=>{t&&Object.entries(e).forEach((([e,i])=>{e in t&&(t[e]=i)}))}))}connectedCallback(){super.connectedCallback(),this.hasAttribute("tabindex")||this.setAttribute("tabindex",this.disabled?"-1":"0"),this.hasAttribute("role")||this.setAttribute("role","menuitem"),this.addEventListener("keydown",this._handleHostKeyDown)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("keydown",this._handleHostKeyDown)}_select(t){if(this.disabled)return t.preventDefault(),void t.stopPropagation();const e=this.closest("nile-inline-sidebar");if(e){e.querySelectorAll("nile-inline-sidebar-item").forEach((t=>t.active=t===this))}const i=this.textContent?.trim()||"";this.dispatchEvent(new CustomEvent("nile-click",{detail:{item:this,href:this.href,text:i},bubbles:!0,composed:!0})),this.href&&(window.location.href=this.href)}handleClick(t){this._select(t)}render(){return e`
      <div
        class=${o({item:!0,"item--rich":"rich"===this.variant})}
        @click=${this.handleClick}
        role="menuitem"
        style=${"rich"===this.variant?"border-radius: 4px 0 0 4px;":""}
        aria-disabled=${this.disabled}
      >
        ${"minimal"===this.variant?this.href?e`<a href=${this.href} @click=${t=>t.preventDefault()}><slot></slot></a>`:e`<slot></slot>`:this.href?e`<a
                href=${this.href}
                @click=${t=>t.preventDefault()}
              >
                <div class="header-content" part="header-content">
                  <slot name="header"></slot>
                </div>
                <div class="body-content" part="body-content">
                  <slot name="body"></slot>
                </div>
              </a>`:e`
                <div class="header-content" part="header-content">
                  <slot name="header"></slot>
                </div>
                <div class="body-content" part="body-content">
                  <slot name="body"></slot>
                </div>
              `}
      </div>
    `}};t([i({type:Boolean,reflect:!0})],l.prototype,"active",void 0),t([i({type:Boolean,reflect:!0})],l.prototype,"disabled",void 0),t([i({type:String})],l.prototype,"href",void 0),t([i({type:Boolean,reflect:!0})],l.prototype,"tooltip",void 0),t([i({type:String,reflect:!0,attribute:!0})],l.prototype,"variant",void 0),t([i({type:String,reflect:!0})],l.prototype,"panel",void 0),l=t([s("nile-inline-sidebar-item")],l);export{l as N};
