import{r as o,h as i}from"./p-e97fde0a.js";import{u as r,s}from"./p-53e7f7d7.js";import{i as t}from"./p-b0d8cd6e.js";import{f as n}from"./p-ff10bfbf.js";import{c as e}from"./p-75e76c8c.js";import{s as d}from"./p-830ab1a3.js";import"./p-03631502.js";import"./p-9dbc54d6.js";import"./p-d3366af3.js";import"./p-401e165e.js";import"./p-ec182234.js";import"./p-3f6362a4.js";import"./p-95325ec5.js";import"./p-4df6e0c5.js";import"./p-dd3464cd.js";const l=":host{display:block}.coupon-form{position:relative}.form{opacity:0;visibility:hidden;height:0;transition:opacity var(--sc-transition-fast) ease-in-out}.coupon-form--is-open .form{opacity:1;visibility:visible;height:auto;margin-top:var(--sc-spacing-small);display:grid;gap:var(--sc-spacing-small)}.coupon-form--is-open .trigger{color:var(--sc-input-label-color)}.coupon-form--is-open .trigger:hover{text-decoration:none}.trigger{cursor:pointer;font-size:var(--sc-font-size-small);color:var(--sc-color-gray-500);user-select:none}.trigger:hover{text-decoration:underline}.order-coupon-form--is-rtl .trigger,.order-coupon-form--is-rtl .trigger:hover{text-align:right}";const p=l;const a=class{constructor(i){o(this,i);this.label=undefined;this.loading=undefined;this.collapsed=undefined;this.placeholder=undefined;this.buttonText=undefined;this.open=undefined;this.value=undefined;this.error=undefined}async handleCouponApply(o){var i,t,n,l,p;const a=(o===null||o===void 0?void 0:o.detail)||null;try{this.error=null;r("FETCH");s.checkout=await e({id:s.checkout.id,data:{discount:{...a?{promotion_code:a}:{}}}});if(a){d(wp.i18n.sprintf(wp.i18n.__("Coupon code %1$s applied, discount is %2$s and now order total is %3$s","surecart"),a,(i=s.checkout)===null||i===void 0?void 0:i.discounts_display_amount,(t=s.checkout)===null||t===void 0?void 0:t.total_display_amount),"assertive")}r("RESOLVE");await((n=this.couponForm)===null||n===void 0?void 0:n.triggerFocus())}catch(o){console.error(o);this.error=((p=(l=o===null||o===void 0?void 0:o.additional_errors)===null||l===void 0?void 0:l[0])===null||p===void 0?void 0:p.message)||(o===null||o===void 0?void 0:o.message)||wp.i18n.__("Something went wrong","surecart");r("REJECT")}}render(){var o,r,e,d,l,p,a,c,u,v;const f=(e=(r=(o=s===null||s===void 0?void 0:s.checkout)===null||o===void 0?void 0:o.line_items)===null||r===void 0?void 0:r.data)===null||e===void 0?void 0:e.some((o=>{var i;return(i=o===null||o===void 0?void 0:o.price)===null||i===void 0?void 0:i.recurring_interval}));return i("sc-coupon-form",{key:"a6899ee676c036b0e1e8925f098eed882a2ebe32",ref:o=>this.couponForm=o,label:this.label||wp.i18n.__("Add Coupon Code","surecart"),collapsed:this.collapsed,placeholder:this.placeholder,loading:n()&&!((p=(l=(d=s.checkout)===null||d===void 0?void 0:d.line_items)===null||l===void 0?void 0:l.data)===null||p===void 0?void 0:p.length),busy:n(),discount:(a=s.checkout)===null||a===void 0?void 0:a.discount,"discounts-display-amount":(c=s.checkout)===null||c===void 0?void 0:c.discounts_display_amount,currency:(u=s.checkout)===null||u===void 0?void 0:u.currency,"discount-amount":(v=s.checkout)===null||v===void 0?void 0:v.discount_amount,class:{"order-coupon-form--is-rtl":t()},"button-text":this.buttonText||wp.i18n.__("Apply","surecart"),"show-interval":f,onScApplyCoupon:o=>this.handleCouponApply(o),error:this.error})}};a.style=p;export{a as sc_order_coupon_form};
//# sourceMappingURL=p-1b0554bf.entry.js.map