import{proxyCustomElement,HTMLElement,h,Host}from"@stencil/core/internal/client";import{a as store,d as onChange,s as state}from"./mutations2.js";const scCartButtonCss=":host{display:inline-block;vertical-align:middle;line-height:1}::slotted(*){display:block !important;line-height:1}.cart__button{padding:0 4px;height:100%;display:grid;align-items:center}.cart__content{position:relative}.cart__count{box-sizing:border-box;position:absolute;inset:-12px -16px auto auto;text-align:center;font-size:10px;font-weight:bold;border-radius:var(--sc-cart-icon-counter-border-radius, 9999px);color:var(--sc-cart-icon-counter-color, var(--sc-color-primary-text, var(--sc-color-white)));background:var(--sc-cart-icon-counter-background, var(--sc-color-primary-500));box-shadow:var(--sc-cart-icon-box-shadow, var(--sc-shadow-x-large));padding:2px 6px;line-height:14px;min-width:14px;z-index:1}.cart__icon{font-size:var(--sc-cart-icon-size, 1.1em);cursor:pointer}.cart__icon sc-icon{display:block}",ScCartButtonStyle0=scCartButtonCss,ScCartButton$1=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),this.open=null,this.count=0,this.formId=void 0,this.mode="live",this.cartMenuAlwaysShown=!0,this.showEmptyCount=!1}getItemsCount(){var t,e;const o=null===(e=null===(t=null==state?void 0:state.checkout)||void 0===t?void 0:t.line_items)||void 0===e?void 0:e.data;let n=0;return(o||[]).forEach((t=>{n+=null==t?void 0:t.quantity})),n}componentDidLoad(){this.link=this.el.closest("a"),this.link.addEventListener("click",(t=>(t.preventDefault(),t.stopImmediatePropagation(),store.state.cart={...store.state.cart,open:!store.state.cart.open},!1))),this.handleParentLinkDisplay(),onChange(this.mode,(()=>this.handleParentLinkDisplay()))}handleParentLinkDisplay(){this.link.style.display=this.cartMenuAlwaysShown||this.getItemsCount()?null:"none"}render(){return h(Host,{key:"cd0d572b879518e3f2e72139e75d4a54baf5b559",tabindex:0,role:"button","aria-label":wp.i18n.sprintf(wp.i18n.__("Open Cart Menu Icon with %d items.","surecart"),this.getItemsCount()),onKeyDown:t=>{"Enter"!==(null==t?void 0:t.code)&&"Space"!==(null==t?void 0:t.code)||(store.state.cart={...store.state.cart,open:!store.state.cart.open},t.preventDefault())}},h("div",{key:"c0cb1233fdf40add265db4d0f0aa0921f28b6111",class:"cart__button",part:"base"},h("div",{key:"4a0a381b4d639e62704b691363a531e91c1d8ccf",class:"cart__content"},(this.showEmptyCount||!!this.getItemsCount())&&h("span",{key:"608efaf88f387271cadced0041077f4f27e13ff5",class:"cart__count",part:"count"},this.getItemsCount()),h("div",{key:"e370398ae5e678bb4f130bf707d820a2c3dcf95e",class:"cart__icon"},h("slot",{key:"d024190b50c2b48c591de22cb34514c640bc18ad"})))))}get el(){return this}static get style(){return ScCartButtonStyle0}},[1,"sc-cart-button",{formId:[513,"form-id"],mode:[1],cartMenuAlwaysShown:[4,"cart-menu-always-shown"],showEmptyCount:[4,"show-empty-count"],open:[32],count:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-cart-button"].forEach((t=>{"sc-cart-button"===t&&(customElements.get(t)||customElements.define(t,ScCartButton$1))}))}const ScCartButton=ScCartButton$1,defineCustomElement=defineCustomElement$1;export{ScCartButton,defineCustomElement};