import { r as registerInstance, c as createEvent, h } from './index-f1d2a96f.js';
import { o as openWormhole } from './consumer-7a54eb9f.js';
import { _ as __ } from './default-i18n-91ef32a0.js';
import './index-0a61debd.js';
import './_commonjsHelpers-9943807e.js';

const scOrderCouponFormCss = ":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}";

const ScOrderCouponForm = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
    this.scApplyCoupon = createEvent(this, "scApplyCoupon", 7);
  }
  handleErrorsChange() {
    var _a;
    const error = (((_a = this === null || this === void 0 ? void 0 : this.error) === null || _a === void 0 ? void 0 : _a.additional_errors) || []).find(error => { var _a; return ((_a = error === null || error === void 0 ? void 0 : error.data) === null || _a === void 0 ? void 0 : _a.attribute) === 'discount.promotion_code'; });
    this.errorMessage = (error === null || error === void 0 ? void 0 : error.message) ? error === null || error === void 0 ? void 0 : error.message : '';
  }
  render() {
    var _a, _b, _c, _d;
    return (h("sc-coupon-form", { label: this.label, loading: this.loading && !((_a = this.order) === null || _a === void 0 ? void 0 : _a.id), busy: this.busy, error: this.errorMessage, discount: (_b = this === null || this === void 0 ? void 0 : this.order) === null || _b === void 0 ? void 0 : _b.discount, currency: (_c = this === null || this === void 0 ? void 0 : this.order) === null || _c === void 0 ? void 0 : _c.currency, "discount-amount": (_d = this === null || this === void 0 ? void 0 : this.order) === null || _d === void 0 ? void 0 : _d.discount_amount }, h("slot", null, __('Apply Coupon', 'surecart'))));
  }
  static get watchers() { return {
    "error": ["handleErrorsChange"]
  }; }
};
openWormhole(ScOrderCouponForm, ['loading', 'busy', 'order', 'error'], false);
ScOrderCouponForm.style = scOrderCouponFormCss;

export { ScOrderCouponForm as sc_order_coupon_form };
