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