import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { _ as __ } from './default-i18n.js';
import './index2.js';
import { d as defineCustomElement$h } from './sc-address2.js';
import { d as defineCustomElement$g } from './sc-block-ui2.js';
import { d as defineCustomElement$f } from './sc-button2.js';
import { d as defineCustomElement$e } from './sc-compact-address2.js';
import { d as defineCustomElement$d } from './dropdown.js';
import { d as defineCustomElement$c } from './sc-form-control2.js';
import { d as defineCustomElement$b } from './sc-icon2.js';
import { d as defineCustomElement$a } from './sc-input2.js';
import { d as defineCustomElement$9 } from './sc-menu2.js';
import { d as defineCustomElement$8 } from './sc-menu-item2.js';
import { d as defineCustomElement$7 } from './sc-menu-label2.js';
import { d as defineCustomElement$6 } from './sc-order-shipping-address2.js';
import { d as defineCustomElement$5 } from './sc-order-tax-id-input2.js';
import { d as defineCustomElement$4 } from './sc-select2.js';
import { d as defineCustomElement$3 } from './sc-spinner2.js';
import { d as defineCustomElement$2 } from './sc-tax-id-input2.js';
import { d as defineCustomElement$1 } from './sc-tooltip2.js';

const ScFormComponentsValidator = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
  }
  handleOrderChange() {
    var _a, _b;
    // bail if we don't have address invalid error or disabled.
    if (this.disabled)
      return;
    // make sure to add the address field if it's not there.
    if (((_a = this === null || this === void 0 ? void 0 : this.order) === null || _a === void 0 ? void 0 : _a.tax_status) === 'address_invalid' || ((_b = this === null || this === void 0 ? void 0 : this.order) === null || _b === void 0 ? void 0 : _b.shipping_enabled)) {
      this.addAddressField();
    }
  }
  componentWillLoad() {
    var _a, _b;
    this.hasAddress = !!this.el.querySelector('sc-order-shipping-address');
    this.hasTaxIDField = !!this.el.querySelector('sc-order-tax-id-input');
    // automatically add address field if tax is enabled.
    if ((_a = this.taxProtocol) === null || _a === void 0 ? void 0 : _a.tax_enabled) {
      this.addAddressField();
      // if eu vat is required, add the tax id field.
      if ((_b = this.taxProtocol) === null || _b === void 0 ? void 0 : _b.eu_vat_required) {
        this.addTaxIDField();
      }
    }
    // make sure to check order on load.
    this.handleOrderChange();
  }
  addAddressField() {
    if (this.hasAddress)
      return;
    const payment = this.el.querySelector('sc-payment');
    const address = document.createElement('sc-order-shipping-address');
    address.label = __('Address', 'surecart');
    payment.parentNode.insertBefore(address, payment);
    this.hasAddress = true;
  }
  addTaxIDField() {
    if (this.hasTaxIDField)
      return;
    const payment = this.el.querySelector('sc-payment');
    const taxInput = document.createElement('sc-order-tax-id-input');
    payment.parentNode.insertBefore(taxInput, payment);
    this.hasTaxIDField = true;
  }
  render() {
    return h("slot", null);
  }
  get el() { return this; }
  static get watchers() { return {
    "order": ["handleOrderChange"]
  }; }
}, [1, "sc-form-components-validator", {
    "disabled": [4],
    "order": [16],
    "taxProtocol": [16],
    "hasAddress": [32],
    "hasTaxIDField": [32]
  }]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-form-components-validator", "sc-address", "sc-block-ui", "sc-button", "sc-compact-address", "sc-dropdown", "sc-form-control", "sc-icon", "sc-input", "sc-menu", "sc-menu-item", "sc-menu-label", "sc-order-shipping-address", "sc-order-tax-id-input", "sc-select", "sc-spinner", "sc-tax-id-input", "sc-tooltip"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-form-components-validator":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScFormComponentsValidator);
      }
      break;
    case "sc-address":
      if (!customElements.get(tagName)) {
        defineCustomElement$h();
      }
      break;
    case "sc-block-ui":
      if (!customElements.get(tagName)) {
        defineCustomElement$g();
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$f();
      }
      break;
    case "sc-compact-address":
      if (!customElements.get(tagName)) {
        defineCustomElement$e();
      }
      break;
    case "sc-dropdown":
      if (!customElements.get(tagName)) {
        defineCustomElement$d();
      }
      break;
    case "sc-form-control":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "sc-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sc-menu":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sc-menu-item":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-menu-label":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-order-shipping-address":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-order-tax-id-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-select":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-tax-id-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
    case "sc-tooltip":
      if (!customElements.get(tagName)) {
        defineCustomElement$1();
      }
      break;
  } });
}
defineCustomElement();

export { ScFormComponentsValidator as S, defineCustomElement as d };
