import{r as o,h as i}from"./p-e97fde0a.js";import{u as r,s as t}from"./p-53e7f7d7.js";import{i as n}from"./p-b0d8cd6e.js";import{f as s}from"./p-ff10bfbf.js";import{c as d}from"./p-be3a018c.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-4df6e0c5.js";import"./p-dd3464cd.js";const e=":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 l=e;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,n,s;const e=(o===null||o===void 0?void 0:o.detail)||null;try{this.error=null;r("FETCH");t.checkout=await d({id:t.checkout.id,data:{discount:{...e?{promotion_code:e}:{}}}});r("RESOLVE");await((i=this.couponForm)===null||i===void 0?void 0:i.triggerFocus())}catch(o){console.error(o);this.error=((s=(n=o===null||o===void 0?void 0:o.additional_errors)===null||n===void 0?void 0:n[0])===null||s===void 0?void 0:s.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,p,c,a,u,v;const f=(d=(r=(o=t===null||t===void 0?void 0:t.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:"65db088edebe3f3ecc89d9ab038c585c4b0b30df",ref:o=>this.couponForm=o,label:this.label||wp.i18n.__("Add Coupon Code","surecart"),collapsed:this.collapsed,placeholder:this.placeholder,loading:s()&&!((p=(l=(e=t.checkout)===null||e===void 0?void 0:e.line_items)===null||l===void 0?void 0:l.data)===null||p===void 0?void 0:p.length),busy:s(),discount:(c=t.checkout)===null||c===void 0?void 0:c.discount,"discounts-display-amount":(a=t.checkout)===null||a===void 0?void 0:a.discounts_display_amount,currency:(u=t.checkout)===null||u===void 0?void 0:u.currency,"discount-amount":(v=t.checkout)===null||v===void 0?void 0:v.discount_amount,class:{"order-coupon-form--is-rtl":n()},"button-text":this.buttonText||wp.i18n.__("Apply","surecart"),"show-interval":f,onScApplyCoupon:o=>this.handleCouponApply(o),error:this.error})}};p.style=l;export{p as sc_order_coupon_form};
//# sourceMappingURL=p-a99fcdb1.entry.js.map