import{r as i,c as e,h as t,F as s,H as r}from"./p-e97fde0a.js";import{i as o}from"./p-4df6e0c5.js";import{g as l}from"./p-2f193d80.js";import{f as c}from"./p-ff10bfbf.js";import{o as a}from"./p-53e7f7d7.js";import"./p-3f6362a4.js";import"./p-2805073a.js";import"./p-401e165e.js";import"./p-95325ec5.js";import"./p-03631502.js";import"./p-9dbc54d6.js";import"./p-d3366af3.js";import"./p-830ab1a3.js";import"./p-ec182234.js";const n=":host{display:block}sc-form{width:100%}.selected-price{display:flex;align-items:center;gap:var(--sc-spacing-small);flex-wrap:wrap}.selected-price__wrap{display:flex;align-items:baseline;flex-wrap:wrap;gap:var(--sc-spacing-xx-small);color:var(--sc-selected-price-color, var(--sc-color-gray-800));line-height:1}.selected-price__price{font-size:var(--sc-font-size-xxx-large);font-weight:var(--sc-font-weight-bold);white-space:nowrap}.selected-price__interval{font-weight:var(--sc-font-weight-bold);opacity:0.65;white-space:nowrap}.selected-price__scratch-price{opacity:0.65;font-weight:var(--sc-font-weight-normal);text-decoration:line-through}";const p=n;const d=class{constructor(t){i(this,t);this.scUpdateLineItem=e(this,"scUpdateLineItem",7);this.productId=undefined;this.showInput=undefined;this.adHocAmount=undefined}lineItem(){return l(this.productId)}componentWillLoad(){a("checkout",(()=>{var i,e,t;this.adHocAmount=((i=this.lineItem())===null||i===void 0?void 0:i.ad_hoc_amount)||((t=(e=this.lineItem())===null||e===void 0?void 0:e.price)===null||t===void 0?void 0:t.amount)}))}updatePrice(){var i,e,t;this.showInput=false;if(!this.adHocAmount&&this.adHocAmount!==0)return;if(this.adHocAmount===((i=this.lineItem())===null||i===void 0?void 0:i.ad_hoc_amount))return;this.scUpdateLineItem.emit({price_id:(t=(e=this.lineItem())===null||e===void 0?void 0:e.price)===null||t===void 0?void 0:t.id,quantity:1,ad_hoc_amount:this.adHocAmount})}handleShowInputChange(i){if(i){setTimeout((()=>{this.input.triggerFocus()}),50)}}onSubmit(i){i.preventDefault();i.stopImmediatePropagation();this.updatePrice()}render(){var i,e,l,a,n,p;const d=(i=this.lineItem())===null||i===void 0?void 0:i.price;const u=(e=this.lineItem())===null||e===void 0?void 0:e.variant;if(!d)return t(r,{style:{display:"none"}});return t("div",{class:{"selected-price":true}},this.showInput?t("sc-form",{onScSubmit:i=>this.onSubmit(i),onScFormSubmit:i=>{i.preventDefault();i.stopImmediatePropagation()}},t("sc-price-input",{ref:i=>this.input=i,size:"large","currency-code":(d===null||d===void 0?void 0:d.currency)||"usd",min:d===null||d===void 0?void 0:d.ad_hoc_min_amount,max:d===null||d===void 0?void 0:d.ad_hoc_max_amount,placeholder:"0.00",required:true,value:(a=(l=this.adHocAmount)===null||l===void 0?void 0:l.toString)===null||a===void 0?void 0:a.call(l),onScInput:i=>this.adHocAmount=parseFloat(i.target.value),onKeyDown:i=>{if(i.key==="Enter"){this.onSubmit(i)}}},t("sc-button",{slot:"suffix",type:"link",submit:true},wp.i18n.__("Update","surecart")))):t(s,null,t("div",{class:"selected-price__wrap"},t("span",{class:"selected-price__price","aria-label":wp.i18n.__("Product price","surecart")},(d===null||d===void 0?void 0:d.scratch_amount)>d.amount&&t(s,null,t("span",{class:"selected-price__scratch-price",part:"price__scratch"},d===null||d===void 0?void 0:d.scratch_display_amount," ")),((n=this.lineItem())===null||n===void 0?void 0:n.ad_hoc_amount)!==null?(p=this.lineItem())===null||p===void 0?void 0:p.ad_hoc_display_amount:(u===null||u===void 0?void 0:u.display_amount)||(d===null||d===void 0?void 0:d.display_amount)),t("span",{class:"selected-price__interval","aria-label":wp.i18n.__("Price interval","surecart")},o(d,{labels:{interval:"/",period:wp.i18n.__("for","surecart")}}))),(d===null||d===void 0?void 0:d.ad_hoc)&&!c()&&t("sc-button",{class:"selected-price__change-amount",type:"primary",size:"small",onClick:()=>this.showInput=true},t("sc-icon",{name:"edit",slot:"prefix"}),wp.i18n.__("Change Amount","surecart"))))}static get watchers(){return{showInput:["handleShowInputChange"]}}};d.style=p;export{d as sc_product_selected_price};
//# sourceMappingURL=p-f703b170.entry.js.map