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-01ecca70.js";import{s as r,b as u,o as c,i as p,c as l}from"./p-7d44e2d5.js";import"./p-6c74654a.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-610295e2.js";import"./p-75923b89.js";import"./p-1f60f497.js";import"./p-d19e982c.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){u(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();c(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:"ec3838915186e6af63de6fc6d22d0d15794ff56f",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:"caa586154ba33147589030198e9f3b63bd1e4949",onClick:t=>{t.stopPropagation()},type:"danger",scrollOnOpen:true,open:!!this.error,closable:false},!!e(this.error)&&i("span",{key:"a126511dd87139b2ce5040f468964e3f98238e19",slot:"title",innerHTML:e(this.error)}),(d(this.error)||[]).map(((t,o)=>i("div",{innerHTML:t,key:o})))),i("slot",{key:"4084f8945a73e5348bff3f21ea0945f0e15eb1fd"}))}get el(){return s(this)}};h.style=v;export{h as sc_product_buy_button};
//# sourceMappingURL=p-9d82ea4f.entry.js.map