import{r as t,h as i,H as o,a as s}from"./p-9add63ef.js";import{g as a,s as n,a as d,b as e}from"./p-666baf67.js";import{s as r,b as c,o as u,i as p,c as b}from"./p-38b12af4.js";import"./p-b28405ea.js";import"./p-2b28ea49.js";import"./p-dd24e53c.js";import"./p-d3366af3.js";import"./p-401e165e.js";import"./p-830ab1a3.js";import"./p-ec182234.js";import"./p-3f6362a4.js";import"./p-31faf2b8.js";import"./p-610295e2.js";import"./p-efd935a6.js";import"./p-78468e45.js";import"./p-de31ba85.js";import"./p-8dccb656.js";import"./p-259c3935.js";import"./p-07a2074d.js";import"./p-fb28f84f.js";const l="sc-product-buy-button{position:relative}sc-product-buy-button a.wp-block-button__link{position:relative;text-decoration:none}sc-product-buy-button .sc-block-button--sold-out,sc-product-buy-button .sc-block-button--unavailable{display:none !important}sc-product-buy-button.is-unavailable a{display:none !important}sc-product-buy-button.is-unavailable .sc-block-button--unavailable{display:initial !important}sc-product-buy-button.is-sold-out a{display:none !important}sc-product-buy-button.is-sold-out .sc-block-button--sold-out{display:initial !important}sc-product-buy-button sc-spinner::part(base){--indicator-color:currentColor;--spinner-size:12px;position:absolute;top:calc(50% - var(--spinner-size) + var(--spinner-size) / 4);left:calc(50% - var(--spinner-size) + var(--spinner-size) / 4)}sc-product-buy-button [data-text],sc-product-buy-button [data-loader]{transition:opacity var(--sc-transition-fast) ease-in-out, visibility var(--sc-transition-fast) ease-in-out}sc-product-buy-button [data-loader]{opacity:0;visibility:hidden}sc-product-buy-button.is-disabled{pointer-events:none}sc-product-buy-button.is-busy [data-text]{opacity:0;visibility:hidden}sc-product-buy-button.is-busy [data-loader]{opacity:1;visibility:visible}sc-product-buy-button sc-alert{margin-bottom:var(--sc-spacing-medium)}sc-product-buy-button.is-out-of-stock [data-text]{opacity:0.6}";const v=l;const h=class{constructor(i){t(this,i);this.addToCart=undefined;this.productId=undefined;this.formId=undefined;this.mode="live";this.checkoutLink=undefined;this.error=undefined}async handleCartClick(t){var i,o,s,d,e;t.preventDefault();console.log(t);if((i=r[this.productId])===null||i===void 0?void 0:i.busy)return;if((s=(o=r[this.productId])===null||o===void 0?void 0:o.selectedPrice)===null||s===void 0?void 0:s.ad_hoc){c(this.productId,{dialog:this.addToCart?"ad_hoc_cart":"ad_hoc_buy"});return}if(!this.addToCart){const t=(e=(d=window===null||window===void 0?void 0:window.scData)===null||d===void 0?void 0:d.pages)===null||e===void 0?void 0:e.checkout;if(!t)return;return window.location.assign(a(this.productId,t,{no_cart:!this.addToCart}))}try{await n(this.productId)}catch(t){console.error(t);this.error=t}}componentDidLoad(){this.link=this.el.querySelector("a");this.updateProductLink();u(this.productId,(()=>this.updateProductLink()))}updateProductLink(){var t,i;const o=(i=(t=window===null||window===void 0?void 0:window.scData)===null||t===void 0?void 0:t.pages)===null||i===void 0?void 0:i.checkout;if(!o||!this.link)return;this.link.href=a(this.productId,o,!this.addToCart?{no_cart:true}:{})}render(){var t,s;return i(o,{key:"8aea1a81f802ca0eb4415359db962396e58f7db2",class:{"is-busy":((t=r[this.productId])===null||t===void 0?void 0:t.busy)&&!!this.addToCart,"is-disabled":(s=r[this.productId])===null||s===void 0?void 0:s.disabled,"is-sold-out":p(this.productId)&&!b(this.productId),"is-unavailable":b(this.productId)},onClick:t=>this.handleCartClick(t)},!!this.error&&i("sc-alert",{key:"4209dd9bc56d54c33c9c7bb052101ad25d57a7fb",onClick:t=>{t.stopPropagation()},type:"danger",scrollOnOpen:true,open:!!this.error,closable:false},!!d(this.error)&&i("span",{key:"476d72435c03b9b30c0c3c66edfcaa1fdaa2aa24",slot:"title",innerHTML:d(this.error)}),(e(this.error)||[]).map(((t,o)=>i("div",{innerHTML:t,key:o})))),i("slot",{key:"0db31ac0ca82fbba425cfe5273e1a8565c97631a"}))}get el(){return s(this)}};h.style=v;export{h as sc_product_buy_button};
//# sourceMappingURL=p-dae5c4e2.entry.js.map