import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
import { o as openWormhole } from './consumer.js';
import { _ as __ } from './default-i18n.js';
import './index2.js';
import { d as defineCustomElement$e } from './sc-alert2.js';
import { d as defineCustomElement$d } from './sc-block-ui2.js';
import { d as defineCustomElement$c } from './sc-button2.js';
import { d as defineCustomElement$b } from './sc-coupon-form2.js';
import { d as defineCustomElement$a } from './sc-form-control2.js';
import { d as defineCustomElement$9 } from './sc-format-number2.js';
import { d as defineCustomElement$8 } from './sc-icon2.js';
import { d as defineCustomElement$7 } from './sc-input2.js';
import { d as defineCustomElement$6 } from './sc-line-item2.js';
import { d as defineCustomElement$5 } from './sc-skeleton2.js';
import { d as defineCustomElement$4 } from './sc-spinner2.js';
import { d as defineCustomElement$3 } from './sc-tag2.js';
import { d as defineCustomElement$2 } from './sc-tooltip2.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$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    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"]
  }; }
  static get style() { return scOrderCouponFormCss; }
}, [1, "sc-order-coupon-form", {
    "label": [1],
    "loading": [4],
    "busy": [4],
    "error": [8],
    "order": [16],
    "forceOpen": [4, "force-open"],
    "open": [32],
    "value": [32],
    "errorMessage": [32]
  }]);
openWormhole(ScOrderCouponForm$1, ['loading', 'busy', 'order', 'error'], false);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-order-coupon-form", "sc-alert", "sc-block-ui", "sc-button", "sc-coupon-form", "sc-form-control", "sc-format-number", "sc-icon", "sc-input", "sc-line-item", "sc-skeleton", "sc-spinner", "sc-tag", "sc-tooltip"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-order-coupon-form":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScOrderCouponForm$1);
      }
      break;
    case "sc-alert":
      if (!customElements.get(tagName)) {
        defineCustomElement$e();
      }
      break;
    case "sc-block-ui":
      if (!customElements.get(tagName)) {
        defineCustomElement$d();
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "sc-coupon-form":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "sc-form-control":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sc-format-number":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-line-item":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-skeleton":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sc-tag":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-tooltip":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const ScOrderCouponForm = ScOrderCouponForm$1;
const defineCustomElement = defineCustomElement$1;

export { ScOrderCouponForm, defineCustomElement };
