import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
import { o as openWormhole } from './consumer.js';
import { d as defineCustomElement$a } from './sc-button2.js';
import { d as defineCustomElement$9 } from './dropdown.js';
import { d as defineCustomElement$8 } from './sc-form-control2.js';
import { d as defineCustomElement$7 } from './sc-icon2.js';
import { d as defineCustomElement$6 } from './sc-input2.js';
import { d as defineCustomElement$5 } from './sc-menu2.js';
import { d as defineCustomElement$4 } from './sc-menu-item2.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 scOrderTaxIdInputCss = ":host{display:block}";

const ScOrderTaxIdInput = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
    this.scUpdateOrder = createEvent(this, "scUpdateOrder", 7);
    /** Force show the field. */
    this.show = false;
    /** Is this busy */
    this.busy = false;
  }
  getStatus() {
    var _a, _b, _c;
    if (((_a = this.taxIdentifier) === null || _a === void 0 ? void 0 : _a.number_type) !== 'eu_vat') {
      return 'unknown';
    }
    if (((_b = this.taxProtocol) === null || _b === void 0 ? void 0 : _b.eu_vat_unverified_behavior) === 'apply_reverse_charge') {
      return 'unknown';
    }
    return ((_c = this.taxIdentifier) === null || _c === void 0 ? void 0 : _c.eu_vat_verified) ? 'valid' : 'invalid';
  }
  maybeUpdateOrder(tax_identifier) {
    var _a;
    if (((_a = this.taxProtocol) === null || _a === void 0 ? void 0 : _a.eu_vat_unverified_behavior) === 'apply_reverse_charge') {
      return;
    }
    this.scUpdateOrder.emit({
      data: { tax_identifier },
    });
  }
  render() {
    var _a, _b, _c, _d, _e, _f;
    return (h("sc-tax-id-input", { show: this.show, number: (_b = (_a = this.order) === null || _a === void 0 ? void 0 : _a.tax_identifier) === null || _b === void 0 ? void 0 : _b.number, type: (_d = (_c = this.order) === null || _c === void 0 ? void 0 : _c.tax_identifier) === null || _d === void 0 ? void 0 : _d.number_type, country: (_f = (_e = this === null || this === void 0 ? void 0 : this.order) === null || _e === void 0 ? void 0 : _e.shipping_address) === null || _f === void 0 ? void 0 : _f.country, status: this.getStatus(), loading: this.busy, onScChange: e => {
        e.stopImmediatePropagation();
        this.maybeUpdateOrder(e.detail);
      } }));
  }
  static get style() { return scOrderTaxIdInputCss; }
}, [1, "sc-order-tax-id-input", {
    "order": [16],
    "show": [4],
    "taxIdentifier": [16],
    "taxProtocol": [16],
    "busy": [4]
  }]);
openWormhole(ScOrderTaxIdInput, ['draft', 'order', 'tax_status', 'taxIdentifier', 'taxProtocol', 'busy'], false);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-order-tax-id-input", "sc-button", "sc-dropdown", "sc-form-control", "sc-icon", "sc-input", "sc-menu", "sc-menu-item", "sc-spinner", "sc-tax-id-input", "sc-tooltip"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-order-tax-id-input":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScOrderTaxIdInput);
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sc-dropdown":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sc-form-control":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-menu":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-menu-item":
      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 { ScOrderTaxIdInput as S, defineCustomElement as d };
