import { Component, h, Prop, Fragment, Watch, Event } from '@stencil/core';
import { __ } from '@wordpress/i18n';
import { zones, getType } from '../../../functions/tax';
export class ScTaxIdInput {
  constructor() {
    /** Force show the field. */
    this.show = false;
    /** Type of tax id */
    this.type = 'other';
    /** Tax ID Number */
    this.number = null;
    /** The status */
    this.status = 'unknown';
    /** Other zones label */
    this.otherLabel = __('Tax ID', 'surecart');
    /** GST zone label */
    this.caGstLabel = __('GST Number', 'surecart');
    /** AU zone label */
    this.auAbnLabel = __('ABN Number', 'surecart');
    /** UK zone label */
    this.gbVatLabel = __('UK VAT', 'surecart');
    /** EU zone label */
    this.euVatLabel = __('EU VAT', 'surecart');
  }
  handleCountryChange() {
    if (this.country) {
      this.type = getType(this.country);
    }
  }
  onLabelChange() {
    zones.ca_gst.label = this.caGstLabel || zones.ca_gst.label;
    zones.au_abn.label = this.auAbnLabel || zones.au_abn.label;
    zones.gb_vat.label = this.gbVatLabel || zones.gb_vat.label;
    zones.eu_vat.label = this.euVatLabel || zones.eu_vat.label;
    zones.other.label = this.otherLabel || zones.other.label;
  }
  componentWillLoad() {
    if (this.country) {
      this.type = getType(this.country);
    }
    this.onLabelChange();
  }
  renderStatus() {
    if (this.status === 'valid') {
      return h("sc-icon", { name: "check", slot: "prefix", style: { color: 'var(--sc-color-success-500)' } });
    }
    if (this.status === 'invalid') {
      return h("sc-icon", { name: "x", slot: "prefix", style: { color: 'var(--sc-color-danger-500)' } });
    }
  }
  render() {
    var _a, _b;
    return (h(Fragment, null,
      h("sc-input", { name: "tax_identifier.number_type", value: this.type, style: { display: 'none' } }),
      h("sc-input", { label: (_a = zones === null || zones === void 0 ? void 0 : zones[(this === null || this === void 0 ? void 0 : this.type) || 'other']) === null || _a === void 0 ? void 0 : _a.label, name: "tax_identifier.number", value: this.number, onScInput: (e) => {
          e.stopImmediatePropagation();
          this.scInput.emit({
            number: e.target.value,
            number_type: this.type || 'other',
          });
        }, onScChange: (e) => {
          e.stopImmediatePropagation();
          this.scChange.emit({
            number: e.target.value,
            number_type: this.type || 'other',
          });
        } },
        this.loading && this.type === 'eu_vat' ? h("sc-spinner", { slot: "prefix", style: { '--spinner-size': '10px' } }) : this.renderStatus(),
        h("sc-dropdown", { slot: "suffix", position: "bottom-right" },
          h("sc-button", { type: "text", slot: "trigger", caret: true, loading: false, style: { color: 'var(--sc-input-label-color)' } }, (_b = zones === null || zones === void 0 ? void 0 : zones[(this === null || this === void 0 ? void 0 : this.type) || 'other']) === null || _b === void 0 ? void 0 : _b.label_small),
          h("sc-menu", null, Object.keys(zones || {}).map(name => (h("sc-menu-item", { onClick: () => {
              this.scInput.emit({
                number: this.number,
                number_type: name,
              });
              this.scChange.emit({
                number: this.number,
                number_type: name,
              });
              this.type = name;
            }, checked: this.type === name }, zones[name].label_small))))))));
  }
  static get is() { return "sc-tax-id-input"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["sc-tax-id-input.css"]
  }; }
  static get styleUrls() { return {
    "$": ["sc-tax-id-input.css"]
  }; }
  static get properties() { return {
    "country": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The country code."
      },
      "attribute": "country",
      "reflect": false
    },
    "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"
    },
    "type": {
      "type": "string",
      "mutable": true,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Type of tax id"
      },
      "attribute": "type",
      "reflect": false,
      "defaultValue": "'other'"
    },
    "number": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Tax ID Number"
      },
      "attribute": "number",
      "reflect": false,
      "defaultValue": "null"
    },
    "status": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'valid' | 'invalid' | 'unknown'",
        "resolved": "\"invalid\" | \"unknown\" | \"valid\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The status"
      },
      "attribute": "status",
      "reflect": false,
      "defaultValue": "'unknown'"
    },
    "loading": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Is this loading?"
      },
      "attribute": "loading",
      "reflect": false
    },
    "help": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Help text."
      },
      "attribute": "help",
      "reflect": false
    },
    "otherLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Other zones label"
      },
      "attribute": "other-label",
      "reflect": false,
      "defaultValue": "__('Tax ID', 'surecart')"
    },
    "caGstLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "GST zone label"
      },
      "attribute": "ca-gst-label",
      "reflect": false,
      "defaultValue": "__('GST Number', 'surecart')"
    },
    "auAbnLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "AU zone label"
      },
      "attribute": "au-abn-label",
      "reflect": false,
      "defaultValue": "__('ABN Number', 'surecart')"
    },
    "gbVatLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "UK zone label"
      },
      "attribute": "gb-vat-label",
      "reflect": false,
      "defaultValue": "__('UK VAT', 'surecart')"
    },
    "euVatLabel": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "EU zone label"
      },
      "attribute": "eu-vat-label",
      "reflect": false,
      "defaultValue": "__('EU VAT', 'surecart')"
    }
  }; }
  static get events() { return [{
      "method": "scChange",
      "name": "scChange",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Make a request to update the order."
      },
      "complexType": {
        "original": "{ number: string; number_type: string }",
        "resolved": "{ number: string; number_type: string; }",
        "references": {}
      }
    }, {
      "method": "scInput",
      "name": "scInput",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Make a request to update the order."
      },
      "complexType": {
        "original": "Partial<{ number: string; number_type: string }>",
        "resolved": "{ number?: string; number_type?: string; }",
        "references": {
          "Partial": {
            "location": "global"
          }
        }
      }
    }, {
      "method": "scInputType",
      "name": "scInputType",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Change the Type"
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }, {
      "method": "scSetState",
      "name": "scSetState",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": "Set the checkout state."
      },
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      }
    }]; }
  static get watchers() { return [{
      "propName": "country",
      "methodName": "handleCountryChange"
    }, {
      "propName": "otherLabel",
      "methodName": "onLabelChange"
    }, {
      "propName": "caGstLabel",
      "methodName": "onLabelChange"
    }, {
      "propName": "auAbnLabel",
      "methodName": "onLabelChange"
    }, {
      "propName": "gbVatLabel",
      "methodName": "onLabelChange"
    }, {
      "propName": "euVatLabel",
      "methodName": "onLabelChange"
    }]; }
}
