import{r as t,h as i,H as o,a as s}from"./p-e97fde0a.js";import{g as n,s as a,a as e,b as d}from"./p-3b28ad48.js";import{s as c,b as r,o as u,i as p,c as l}from"./p-863940e9.js";import"./p-f3141d53.js";import"./p-03631502.js";import"./p-9dbc54d6.js";import"./p-d3366af3.js";import"./p-401e165e.js";import"./p-830ab1a3.js";import"./p-ec182234.js";import"./p-3f6362a4.js";import"./p-95325ec5.js";import"./p-6ec14893.js";import"./p-51692a5f.js";import"./p-1f60f497.js";import"./p-123bd51b.js";import"./p-6135d661.js";import"./p-13f5e4e1.js";import"./p-93127aa7.js";const b="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=b;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,e,d;t.preventDefault();console.log(t);if((i=c[this.productId])===null||i===void 0?void 0:i.busy)return;if((s=(o=c[this.productId])===null||o===void 0?void 0:o.selectedPrice)===null||s===void 0?void 0:s.ad_hoc){r(this.productId,{dialog:this.addToCart?"ad_hoc_cart":"ad_hoc_buy"});return}if(!this.addToCart){const t=(d=(e=window===null||window===void 0?void 0:window.scData)===null||e===void 0?void 0:e.pages)===null||d===void 0?void 0:d.checkout;if(!t)return;return window.location.assign(n(this.productId,t,{no_cart:!this.addToCart}))}try{await a(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=n(this.productId,o,!this.addToCart?{no_cart:true}:{})}render(){var t,s;return i(o,{key:"f0a2bcfca4d423833c052cf222864069893a1dbc",class:{"is-busy":((t=c[this.productId])===null||t===void 0?void 0:t.busy)&&!!this.addToCart,"is-disabled":(s=c[this.productId])===null||s===void 0?void 0:s.disabled,"is-sold-out":p(this.productId)&&!l(this.productId),"is-unavailable":l(this.productId)},onClick:t=>this.handleCartClick(t)},!!this.error&&i("sc-alert",{key:"99f8fdeb43f53ec697114bdd2ea2fe2149847b71",onClick:t=>{t.stopPropagation()},type:"danger",scrollOnOpen:true,open:!!this.error,closable:false},!!e(this.error)&&i("span",{key:"96532621b9db52b646b0a1491f9cd80f42f0ec60",slot:"title",innerHTML:e(this.error)}),(d(this.error)||[]).map(((t,o)=>i("div",{innerHTML:t,key:o})))),i("slot",{key:"60ed01cfba9379cc0c6e63b1ecec78d88e3a2b5c"}))}get el(){return s(this)}};h.style=v;export{h as sc_product_buy_button};
//# sourceMappingURL=p-a1d8386c.entry.js.map