import{__decorate as t}from"../../_virtual/_tslib.js";import'./../../external/@lit/reactive-element/reactive-element.js';import{html as e}from'./../../external/lit-html/lit-html.js';import{LitElement as i}from'./../../external/lit-element/lit-element.js';import{customElement as s}from'./../../external/@lit/reactive-element/decorators/custom-element.js';import{property as o}from'./../../external/@lit/reactive-element/decorators/property.js';import{state as n}from'./../../external/@lit/reactive-element/decorators/state.js';import{query as r}from'./../../external/@lit/reactive-element/decorators/query.js';import'./../../external/@lit/reactive-element/decorators/query-assigned-elements.js';import{queryAssignedNodes as l}from'./../../external/@lit/reactive-element/decorators/query-assigned-nodes.js';import{ifDefined as d}from'./../../external/lit-html/directives/if-defined.js';import{classMap as a}from'./../../external/lit-html/directives/class-map.js';import{debounce as h}from"../../common/helpers/events.js";import{BUTTON_TYPES as c,BUTTON_KINDS as p,BUTTON_SIZES as m,BUTTON_ICON_POSITION as y}from"./defs.js";import u from"./button.scss.js";let v=class extends i{constructor(){super(...arguments),this.internals=this.attachInternals(),this.description="",this.type=c.BUTTON,this.kind=p.PRIMARY_APP,this.href="",this.size=m.MEDIUM,this.iconPosition=y.CENTER,this.iconOnly=!1,this.disabled=!1,this.destructive=!1,this.value="",this.name=""}render(){const t={[p.PRIMARY_APP]:"primary-app",[p.PRIMARY_WEB]:"primary-web",[p.SECONDARY]:"secondary",[p.TERTIARY]:"tertiary"}[this.kind],i={button:!0,[`kd-btn--${t}${this.destructive?"-destructive":""}`]:!0,[`kd-btn--${t}`]:!this.destructive,"kd-btn--large":this.size===m.LARGE,"kd-btn--small":this.size===m.SMALL,"kd-btn--medium":this.size===m.MEDIUM,[`kd-btn--icon-${this.iconPosition}`]:!!this.iconPosition&&!this.iconOnly,"kd-btn--icon-center":this._iconEls.length&&this.iconOnly,"icon-only":this._iconEls.length&&this.iconOnly};return e`
      ${this.href&&""!==this.href?e`
            <a
              class=${a(i)}
              href=${this.href}
              ?disabled=${this.disabled}
              aria-label=${d(this.description)}
              title=${d(this.description)}
              @click=${t=>this.handleClick(t)}
            >
              <span>
                <slot @slotchange=${()=>this._handleSlotChange()}></slot>
                <slot
                  name="icon"
                  @slotchange=${()=>this._handleSlotChange()}
                ></slot>
              </span>
            </a>
          `:e`
            <button
              class=${a(i)}
              type=${this.type}
              ?disabled=${this.disabled}
              aria-label=${d(this.description)}
              title=${d(this.description)}
              name=${d(this.name)}
              value=${d(this.value)}
              formmethod=${d(this.formmethod)}
              @click=${t=>this.handleClick(t)}
            >
              <span>
                <slot @slotchange=${()=>this._handleSlotChange()}></slot>
                <slot
                  name="icon"
                  @slotchange=${()=>this._handleSlotChange()}
                ></slot>
              </span>
            </button>
          `}
    `}handleClick(t){this.internals.form&&("submit"===this.type?this.internals.form.requestSubmit(this):"reset"===this.type&&this.internals.form.reset());const e=new CustomEvent("on-click",{detail:{origEvent:t}});this.dispatchEvent(e)}_testIconOnly(){if(!this._iconEls.length)return!1;return!this._slottedEls.filter((t=>""!==t.textContent.trim())).filter((t=>!t.tagName||t.offsetParent)).length}_handleSlotChange(){this.iconOnly=this._testIconOnly(),this.requestUpdate()}connectedCallback(){super.connectedCallback(),window.addEventListener("resize",h((()=>{this.iconOnly=this._testIconOnly()})))}disconnectedCallback(){window.removeEventListener("resize",h((()=>{this.iconOnly=this._testIconOnly()}))),super.disconnectedCallback()}};v.styles=[u],v.shadowRootOptions={...i.shadowRootOptions,delegatesFocus:!0},v.formAssociated=!0,t([n()],v.prototype,"internals",void 0),t([o({type:String})],v.prototype,"description",void 0),t([o({type:String})],v.prototype,"type",void 0),t([o({type:String})],v.prototype,"kind",void 0),t([o({type:String})],v.prototype,"href",void 0),t([o({type:String})],v.prototype,"size",void 0),t([o({type:String})],v.prototype,"iconPosition",void 0),t([n()],v.prototype,"iconOnly",void 0),t([o({type:Boolean,reflect:!0})],v.prototype,"disabled",void 0),t([o({type:Boolean,reflect:!0})],v.prototype,"destructive",void 0),t([o({type:String})],v.prototype,"value",void 0),t([o({type:String})],v.prototype,"name",void 0),t([o({type:String})],v.prototype,"formmethod",void 0),t([l()],v.prototype,"_slottedEls",void 0),t([l({slot:"icon"})],v.prototype,"_iconEls",void 0),t([r(".button")],v.prototype,"_btnEl",void 0),v=t([s("kd-button")],v);export{v as Button};
//# sourceMappingURL=button.js.map
