import{r as o,h as i}from"./p-9add63ef.js";import{u as r,s}from"./p-b28405ea.js";import{i as t}from"./p-b0d8cd6e.js";import{f as n}from"./p-b51de06c.js";import{c as d}from"./p-de31ba85.js";import{s as e}from"./p-830ab1a3.js";import"./p-2b28ea49.js";import"./p-dd24e53c.js";import"./p-d3366af3.js";import"./p-401e165e.js";import"./p-ec182234.js";import"./p-3f6362a4.js";import"./p-31faf2b8.js";import"./p-610295e2.js";import"./p-8dccb656.js";import"./p-259c3935.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 a=l;const p=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,a;const p=(o===null||o===void 0?void 0:o.detail)||null;try{this.error=null;r("FETCH");s.checkout=await d({id:s.checkout.id,data:{discount:{...p?{promotion_code:p}:{}}}});if(p){e(wp.i18n.sprintf(wp.i18n.__("Coupon code %1$s applied, discount is %2$s and now order total is %3$s","surecart"),p,(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=((a=(l=o===null||o===void 0?void 0:o.additional_errors)===null||l===void 0?void 0:l[0])===null||a===void 0?void 0:a.message)||(o===null||o===void 0?void 0:o.message)||wp.i18n.__("Something went wrong","surecart");r("REJECT")}}render(){var o,r,d,e,l,a,p,c,u,v;const m=(d=(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||d===void 0?void 0:d.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:"5a865ce9c95d84f59d9eae97c9b5631108d56161",ref:o=>this.couponForm=o,label:this.label||wp.i18n.__("Add Coupon Code","surecart"),collapsed:this.collapsed,placeholder:this.placeholder,loading:n()&&!((a=(l=(e=s.checkout)===null||e===void 0?void 0:e.line_items)===null||l===void 0?void 0:l.data)===null||a===void 0?void 0:a.length),busy:n(),discount:(p=s.checkout)===null||p===void 0?void 0:p.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":m,onScApplyCoupon:o=>this.handleCouponApply(o),error:this.error})}};p.style=a;export{p as sc_order_coupon_form};
//# sourceMappingURL=p-758181d4.entry.js.map