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-a8950b71.js";import{s as r,b as c,o as u,i as p,c as l}from"./p-863940e9.js";import"./p-53e7f7d7.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-4df6e0c5.js";import"./p-d7c7b076.js";import"./p-1f60f497.js";import"./p-be3a018c.js";import"./p-dd3464cd.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=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=(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:"5aeb7e1cb84d33f5eb914168be277d02397e1af8",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)&&!l(this.productId),"is-unavailable":l(this.productId)},onClick:t=>this.handleCartClick(t)},!!this.error&&i("sc-alert",{key:"09881cc0ca0689de423624131c7dcfb648641a7b",onClick:t=>{t.stopPropagation()},type:"danger",scrollOnOpen:true,open:!!this.error,closable:false},!!e(this.error)&&i("span",{key:"a4600aa6606a8326d81df8f0e6b07f59bb2605c7",slot:"title",innerHTML:e(this.error)}),(d(this.error)||[]).map(((t,o)=>i("div",{innerHTML:t,key:o})))),i("slot",{key:"0d1ea96966d67f039a2954e16f545e96aebb1d44"}))}get el(){return s(this)}};h.style=v;export{h as sc_product_buy_button};
//# sourceMappingURL=p-c96f897c.entry.js.map