import { Component, h, Prop, Event } from '@stencil/core';
import { openWormhole } from 'stencil-wormhole';
export class ScOrderTaxIdInput {
  constructor() {
    /** 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 is() { return "sc-order-tax-id-input"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["sc-order-tax-id-input.css"]
  }; }
  static get styleUrls() { return {
    "$": ["sc-order-tax-id-input.css"]
  }; }
  static get properties() { return {
    "order": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Partial<Order>",
        "resolved": "{ id?: string; status?: \"finalized\" | \"draft\" | \"paid\" | \"requires_approval\"; number?: string; amount_due?: number; trial_amount?: number; charge?: string | Charge; name?: string; email?: string; live_mode?: boolean; currency?: string; total_amount?: number; subtotal_amount?: number; tax_amount?: number; tax_inclusive_amount?: number; tax_exclusive_amount?: number; tax_status?: \"disabled\" | \"address_invalid\" | \"estimated\" | \"calculated\"; tax_label?: string; tax_percent?: number; line_items?: lineItems; metadata?: Object; payment_intent?: PaymentIntent; customer?: string | Customer; subscriptions?: { object: \"list\"; pagination: Pagination; data: Subscription[]; }; discount_amount?: number; discount?: DiscountResponse; billing_address?: string | Address; shipping_address?: string | Address; shipping_enabled?: boolean; processor_data?: ProcessorData; tax_identifier?: { number: string; number_type: string; }; url?: string; created_at?: number; constructor?: Function; toString?: () => string; toLocaleString?: () => string; valueOf?: () => Object; hasOwnProperty?: (v: PropertyKey) => boolean; isPrototypeOf?: (v: Object) => boolean; propertyIsEnumerable?: (v: PropertyKey) => boolean; }",
        "references": {
          "Partial": {
            "location": "global"
          },
          "Order": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The order"
      }
    },
    "show": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Force show the field."
      },
      "attribute": "show",
      "reflect": false,
      "defaultValue": "false"
    },
    "taxIdentifier": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "TaxIdentifier",
        "resolved": "TaxIdentifier",
        "references": {
          "TaxIdentifier": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Tax identifier"
      }
    },
    "taxProtocol": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "TaxProtocol",
        "resolved": "TaxProtocol",
        "references": {
          "TaxProtocol": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The tax protocol."
      }
    },
    "busy": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Is this busy"
      },
      "attribute": "busy",
      "reflect": false,
      "defaultValue": "false"
    }
  }; }
  static get events() { return [{
      "method": "scUpdateOrder",
      "name": "scUpdateOrder",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Make a request to update the order."
      },
      "complexType": {
        "original": "{\n    data: Partial<Order>;\n    options?: { silent?: boolean };\n  }",
        "resolved": "{ data: Partial<Order>; options?: { silent?: boolean; }; }",
        "references": {
          "Partial": {
            "location": "global"
          },
          "Order": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      }
    }]; }
}
openWormhole(ScOrderTaxIdInput, ['draft', 'order', 'tax_status', 'taxIdentifier', 'taxProtocol', 'busy'], false);
