import{r as i,h as o,a as s}from"./p-9add63ef.js";import{o as t,s as d,b as l}from"./p-38b12af4.js";import{g as e,s as a,a as n,b as r}from"./p-666baf67.js";import"./p-2b28ea49.js";import"./p-07a2074d.js";import"./p-3f6362a4.js";import"./p-ec182234.js";import"./p-dd24e53c.js";import"./p-fb28f84f.js";import"./p-830ab1a3.js";import"./p-b28405ea.js";import"./p-d3366af3.js";import"./p-401e165e.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";const p=":host{display:block}sc-dialog{--body-spacing:var(--sc-spacing-xx-large);color:var(--sc-color-gray-600);text-decoration:none;font-size:16px}.dialog__header{display:flex;align-items:center;gap:var(--sc-spacing-medium)}.dialog__header-text{line-height:var(--sc-line-height-dense)}.dialog__image img{width:60px;height:60px;display:block}.dialog__action{font-weight:var(--sc-font-weight-bold)}.dialog__product-name{font-size:var(--sc-font-size-small)}";const c=p;const u=class{constructor(o){i(this,o);this.buttonText=undefined;this.addToCart=undefined;this.productId=undefined;this.error=undefined}async submit(){var i,o;if(!this.addToCart){const s=(o=(i=window===null||window===void 0?void 0:window.scData)===null||i===void 0?void 0:i.pages)===null||o===void 0?void 0:o.checkout;if(!s)return;return window.location.assign(e(this.productId,s))}try{await a(this.productId)}catch(i){console.error(i);this.error=i}}componentWillLoad(){t(this.productId,(()=>{setTimeout((()=>{var i;(i=this.priceInput)===null||i===void 0?void 0:i.triggerFocus()}),50)}))}render(){var i,s,t,e,a,p,c,u,v,h,m,g,f,_,b,j,w,y,x;if(!((s=(i=d[this.productId])===null||i===void 0?void 0:i.selectedPrice)===null||s===void 0?void 0:s.ad_hoc)){return null}return o("sc-dialog",{open:((t=d[this.productId])===null||t===void 0?void 0:t.dialog)===((this===null||this===void 0?void 0:this.addToCart)?"ad_hoc_cart":"ad_hoc_buy"),onScRequestClose:()=>l(this.productId,{dialog:null})},o("span",{class:"dialog__header",slot:"label"},!!((a=(e=d[this.productId])===null||e===void 0?void 0:e.product)===null||a===void 0?void 0:a.image_url)&&o("div",{class:"dialog__image"},o("img",{src:(c=(p=d[this.productId])===null||p===void 0?void 0:p.product)===null||c===void 0?void 0:c.image_url})),o("div",{class:"dialog__header-text"},o("div",{class:"dialog__action"},wp.i18n.__("Enter An Amount","surecart")),o("div",{class:"dialog__product-name"},(v=(u=d[this.productId])===null||u===void 0?void 0:u.product)===null||v===void 0?void 0:v.name))),o("sc-form",{onScSubmit:i=>{i.stopImmediatePropagation();this.submit()},onScFormSubmit:i=>i.stopImmediatePropagation()},!!this.error&&o("sc-alert",{type:"danger",scrollOnOpen:true,open:!!this.error,closable:false},!!n(this.error)&&o("span",{slot:"title",innerHTML:n(this.error)}),(r(this.error)||[]).map(((i,s)=>o("div",{innerHTML:i,key:s})))),o("sc-price-input",{ref:i=>this.priceInput=i,value:(g=(m=(h=d[this.productId])===null||h===void 0?void 0:h.adHocAmount)===null||m===void 0?void 0:m.toString)===null||g===void 0?void 0:g.call(m),"currency-code":(_=(f=d[this.productId])===null||f===void 0?void 0:f.selectedPrice)===null||_===void 0?void 0:_.currency,min:(j=(b=d[this.productId])===null||b===void 0?void 0:b.selectedPrice)===null||j===void 0?void 0:j.ad_hoc_min_amount,max:(y=(w=d[this.productId])===null||w===void 0?void 0:w.selectedPrice)===null||y===void 0?void 0:y.ad_hoc_max_amount,onScInput:i=>l(this.productId,{adHocAmount:parseInt(i.target.value)}),required:true}),o("sc-button",{type:"primary",full:true,submit:true,busy:(x=d[this.productId])===null||x===void 0?void 0:x.busy},o("slot",null,this.buttonText||wp.i18n.__("Add To Cart","surecart")))))}get el(){return s(this)}};u.style=c;export{u as sc_product_price_modal};
//# sourceMappingURL=p-b85e437a.entry.js.map