@foxy.io/elements 1.35.0-beta.3 → 1.36.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/dist/cdn/foxy-access-recovery-form.js +1 -1
  2. package/dist/cdn/foxy-address-card.js +5 -5
  3. package/dist/cdn/foxy-address-form.js +1 -1
  4. package/dist/cdn/foxy-admin-subscription-card.js +1 -1
  5. package/dist/cdn/foxy-admin-subscription-form.js +1 -1
  6. package/dist/cdn/foxy-api-browser.js +1 -1
  7. package/dist/cdn/foxy-applied-coupon-code-card.js +1 -1
  8. package/dist/cdn/foxy-applied-coupon-code-form.js +1 -1
  9. package/dist/cdn/foxy-applied-tax-card.js +1 -1
  10. package/dist/cdn/foxy-attribute-card.js +1 -1
  11. package/dist/cdn/foxy-attribute-form.js +1 -1
  12. package/dist/cdn/foxy-billing-address-card.js +1 -1
  13. package/dist/cdn/foxy-cancellation-form.js +1 -1
  14. package/dist/cdn/foxy-cart-card.js +1 -1
  15. package/dist/cdn/foxy-cart-form.js +1 -1
  16. package/dist/cdn/foxy-client-card.js +1 -1
  17. package/dist/cdn/foxy-client-form.js +1 -1
  18. package/dist/cdn/foxy-collection-page.js +1 -1
  19. package/dist/cdn/foxy-collection-pages.js +1 -1
  20. package/dist/cdn/foxy-copy-to-clipboard.js +1 -1
  21. package/dist/cdn/foxy-coupon-card.js +1 -1
  22. package/dist/cdn/foxy-coupon-code-card.js +1 -1
  23. package/dist/cdn/foxy-coupon-code-form.js +1 -1
  24. package/dist/cdn/foxy-coupon-codes-form.js +1 -1
  25. package/dist/cdn/foxy-coupon-detail-card.js +1 -1
  26. package/dist/cdn/foxy-coupon-form.js +1 -1
  27. package/dist/cdn/foxy-custom-field-card.js +1 -1
  28. package/dist/cdn/foxy-custom-field-form.js +1 -1
  29. package/dist/cdn/foxy-customer-card.js +1 -1
  30. package/dist/cdn/foxy-customer-form.js +1 -1
  31. package/dist/cdn/foxy-customer-portal-settings-form.js +1 -1
  32. package/dist/cdn/foxy-customer-portal-settings.js +1 -1
  33. package/dist/cdn/foxy-customer-portal.js +1 -1
  34. package/dist/cdn/foxy-customer.js +1 -1
  35. package/dist/cdn/foxy-customers-table.js +1 -1
  36. package/dist/cdn/foxy-discount-builder.js +1 -1
  37. package/dist/cdn/foxy-discount-card.js +1 -1
  38. package/dist/cdn/foxy-discount-detail-card.js +1 -1
  39. package/dist/cdn/foxy-donation.js +1 -1
  40. package/dist/cdn/foxy-downloadable-card.js +1 -1
  41. package/dist/cdn/foxy-downloadable-form.js +1 -1
  42. package/dist/cdn/foxy-email-template-card.js +1 -1
  43. package/dist/cdn/foxy-email-template-form.js +1 -1
  44. package/dist/cdn/foxy-error-entry-card.js +1 -1
  45. package/dist/cdn/foxy-experimental-add-to-cart-builder.js +2 -2
  46. package/dist/cdn/foxy-filter-attribute-card.js +1 -1
  47. package/dist/cdn/foxy-filter-attribute-form.js +1 -1
  48. package/dist/cdn/foxy-form-dialog.js +1 -1
  49. package/dist/cdn/foxy-generate-codes-form.js +1 -1
  50. package/dist/cdn/foxy-gift-card-card.js +1 -1
  51. package/dist/cdn/foxy-gift-card-code-card.js +1 -1
  52. package/dist/cdn/foxy-gift-card-code-form.js +1 -1
  53. package/dist/cdn/foxy-gift-card-code-log-card.js +1 -1
  54. package/dist/cdn/foxy-gift-card-codes-form.js +1 -1
  55. package/dist/cdn/foxy-gift-card-form.js +1 -1
  56. package/dist/cdn/foxy-i18n-editor.js +1 -1
  57. package/dist/cdn/foxy-i18n.js +1 -1
  58. package/dist/cdn/foxy-integration-card.js +1 -1
  59. package/dist/cdn/foxy-integration-form.js +1 -1
  60. package/dist/cdn/foxy-item-card.js +1 -1
  61. package/dist/cdn/foxy-item-category-card.js +1 -1
  62. package/dist/cdn/foxy-item-category-form.js +1 -1
  63. package/dist/cdn/foxy-item-form.js +1 -1
  64. package/dist/cdn/foxy-item-option-card.js +1 -1
  65. package/dist/cdn/foxy-item-option-form.js +1 -1
  66. package/dist/cdn/foxy-items-form.js +1 -1
  67. package/dist/cdn/foxy-native-integration-card.js +1 -1
  68. package/dist/cdn/foxy-native-integration-form.js +1 -1
  69. package/dist/cdn/foxy-pagination.js +1 -1
  70. package/dist/cdn/foxy-passkey-card.js +1 -1
  71. package/dist/cdn/foxy-passkey-form.js +1 -1
  72. package/dist/cdn/foxy-payment-card-embed.js +1 -1
  73. package/dist/cdn/foxy-payment-card.js +1 -1
  74. package/dist/cdn/foxy-payment-method-card.js +1 -1
  75. package/dist/cdn/foxy-payments-api-fraud-protection-card.js +1 -1
  76. package/dist/cdn/foxy-payments-api-fraud-protection-form.js +1 -1
  77. package/dist/cdn/foxy-payments-api-payment-method-card.js +1 -1
  78. package/dist/cdn/foxy-payments-api-payment-method-form.js +1 -1
  79. package/dist/cdn/foxy-payments-api-payment-preset-card.js +1 -1
  80. package/dist/cdn/foxy-payments-api-payment-preset-form.js +1 -1
  81. package/dist/cdn/foxy-query-builder.js +1 -1
  82. package/dist/cdn/foxy-report-form.js +15 -15
  83. package/dist/cdn/foxy-reports-table.js +1 -1
  84. package/dist/cdn/foxy-shipment-card.js +1 -1
  85. package/dist/cdn/foxy-shipping-container-card.js +1 -1
  86. package/dist/cdn/foxy-shipping-drop-type-card.js +1 -1
  87. package/dist/cdn/foxy-shipping-method-card.js +1 -1
  88. package/dist/cdn/foxy-shipping-service-card.js +1 -1
  89. package/dist/cdn/foxy-sign-in-form.js +1 -1
  90. package/dist/cdn/foxy-spinner.js +1 -1
  91. package/dist/cdn/foxy-store-card.js +1 -1
  92. package/dist/cdn/foxy-store-form.js +1 -1
  93. package/dist/cdn/foxy-store-shipping-method-form.js +1 -1
  94. package/dist/cdn/foxy-subscription-card.js +1 -1
  95. package/dist/cdn/foxy-subscription-form.js +1 -1
  96. package/dist/cdn/foxy-subscription-settings-form.js +1 -1
  97. package/dist/cdn/foxy-subscriptions-table.js +1 -1
  98. package/dist/cdn/foxy-table.js +1 -1
  99. package/dist/cdn/foxy-tax-card.js +1 -1
  100. package/dist/cdn/foxy-tax-form.js +1 -1
  101. package/dist/cdn/foxy-template-config-form.js +1 -1
  102. package/dist/cdn/foxy-template-form.js +1 -1
  103. package/dist/cdn/foxy-template-set-card.js +1 -1
  104. package/dist/cdn/foxy-template-set-form.js +1 -1
  105. package/dist/cdn/foxy-transaction-card.js +1 -1
  106. package/dist/cdn/foxy-transaction.js +1 -1
  107. package/dist/cdn/foxy-transactions-table.js +7 -7
  108. package/dist/cdn/foxy-update-payment-method-form.js +1 -1
  109. package/dist/cdn/foxy-user-card.js +1 -1
  110. package/dist/cdn/foxy-user-form.js +1 -1
  111. package/dist/cdn/foxy-user-invitation-card.js +1 -1
  112. package/dist/cdn/foxy-user-invitation-form.js +1 -1
  113. package/dist/cdn/foxy-users-table.js +1 -1
  114. package/dist/cdn/foxy-webhook-card.js +1 -1
  115. package/dist/cdn/foxy-webhook-form.js +1 -1
  116. package/dist/cdn/foxy-webhook-log-card.js +1 -1
  117. package/dist/cdn/foxy-webhook-status-card.js +1 -1
  118. package/dist/cdn/{shared-3149ab8d.js → shared-01bb183b.js} +1 -1
  119. package/dist/cdn/{shared-e14930ce.js → shared-0453e29f.js} +1 -1
  120. package/dist/cdn/{shared-6cb26d12.js → shared-0b00883f.js} +1 -1
  121. package/dist/cdn/{shared-6b06d5c1.js → shared-0b1b1c14.js} +1 -1
  122. package/dist/cdn/{shared-d9f38239.js → shared-0d8e7067.js} +1 -1
  123. package/dist/cdn/{shared-602ed877.js → shared-0fcc7a6c.js} +1 -1
  124. package/dist/cdn/{shared-2256b8b1.js → shared-10b54c49.js} +1 -1
  125. package/dist/cdn/{shared-0e59bad9.js → shared-1482d5dd.js} +1 -1
  126. package/dist/cdn/{shared-2868b35f.js → shared-1ea59bd6.js} +1 -1
  127. package/dist/cdn/{shared-a4d773a3.js → shared-21100e1b.js} +1 -1
  128. package/dist/cdn/{shared-7439665e.js → shared-2503aefc.js} +1 -1
  129. package/dist/cdn/{shared-bf7baab5.js → shared-25f9729f.js} +1 -1
  130. package/dist/cdn/{shared-84ada96e.js → shared-28682c2b.js} +1 -1
  131. package/dist/cdn/{shared-56271b15.js → shared-2879b67f.js} +1 -1
  132. package/dist/cdn/{shared-f0a38941.js → shared-2e8361e1.js} +1 -1
  133. package/dist/cdn/{shared-831f5042.js → shared-3aaf64e6.js} +1 -1
  134. package/dist/cdn/{shared-a81a1cc3.js → shared-3c4f3814.js} +1 -1
  135. package/dist/cdn/{shared-303cf36c.js → shared-421f9892.js} +1 -1
  136. package/dist/cdn/{shared-4bcb2368.js → shared-4a4cf3e3.js} +1 -1
  137. package/dist/cdn/{shared-c5972323.js → shared-4b84e1b4.js} +1 -1
  138. package/dist/cdn/{shared-35a2aabc.js → shared-4cf87721.js} +1 -1
  139. package/dist/cdn/{shared-2b25aedd.js → shared-4d609ecc.js} +1 -1
  140. package/dist/cdn/{shared-2565fed8.js → shared-4e8a5b95.js} +1 -1
  141. package/dist/cdn/{shared-8d92dd6e.js → shared-5f43aa36.js} +1 -1
  142. package/dist/cdn/{shared-37dc0b85.js → shared-60150977.js} +1 -1
  143. package/dist/cdn/{shared-acdf3166.js → shared-61ef8001.js} +1 -1
  144. package/dist/cdn/shared-62240936.js +1 -0
  145. package/dist/cdn/{shared-9c82e27f.js → shared-6a45a781.js} +2 -2
  146. package/dist/cdn/{shared-0e1d094b.js → shared-6b76afc2.js} +1 -1
  147. package/dist/cdn/{shared-927f1a51.js → shared-6d11190a.js} +1 -1
  148. package/dist/cdn/{shared-61e50856.js → shared-76dcc864.js} +1 -1
  149. package/dist/cdn/{shared-a5bd0da6.js → shared-775a58a9.js} +1 -1
  150. package/dist/cdn/{shared-afa402dc.js → shared-788e1a9b.js} +1 -1
  151. package/dist/cdn/{shared-40bed8c1.js → shared-843aec9a.js} +1 -1
  152. package/dist/cdn/{shared-2eebd7bc.js → shared-85475a4e.js} +1 -1
  153. package/dist/cdn/{shared-481eb635.js → shared-8612d84d.js} +1 -1
  154. package/dist/cdn/{shared-4fdc63d9.js → shared-86aa139c.js} +1 -1
  155. package/dist/cdn/{shared-544b7d4b.js → shared-87dbd821.js} +1 -1
  156. package/dist/cdn/{shared-59d9d6ca.js → shared-89d09114.js} +1 -1
  157. package/dist/cdn/{shared-50f2497c.js → shared-9092b247.js} +1 -1
  158. package/dist/cdn/{shared-21254863.js → shared-92490909.js} +1 -1
  159. package/dist/cdn/{shared-059d1e79.js → shared-95d2e9c3.js} +1 -1
  160. package/dist/cdn/{shared-5741ba29.js → shared-97807c4d.js} +1 -1
  161. package/dist/cdn/shared-9d7ae4aa.js +1 -0
  162. package/dist/cdn/{shared-7f68743e.js → shared-a2e51632.js} +1 -1
  163. package/dist/cdn/{shared-2ca4d459.js → shared-a33244f7.js} +1 -1
  164. package/dist/cdn/{shared-3023dfb2.js → shared-b927be75.js} +3 -3
  165. package/dist/cdn/{shared-db92bb31.js → shared-c1a3337f.js} +1 -1
  166. package/dist/cdn/{shared-247297ce.js → shared-c1ade7a9.js} +1 -1
  167. package/dist/cdn/{shared-120413cd.js → shared-c52295d5.js} +1 -1
  168. package/dist/cdn/{shared-2676836d.js → shared-cbd1fab7.js} +1 -1
  169. package/dist/cdn/{shared-751c9f1e.js → shared-cc76a917.js} +1 -1
  170. package/dist/cdn/{shared-ebd077b5.js → shared-cd652fd0.js} +1 -1
  171. package/dist/cdn/{shared-900fd54f.js → shared-d2340faa.js} +1 -1
  172. package/dist/cdn/{shared-37c52c4c.js → shared-d279baa5.js} +1 -1
  173. package/dist/cdn/{shared-349a42e1.js → shared-e0d1856d.js} +1 -1
  174. package/dist/cdn/{shared-64d48bc6.js → shared-e5417c6e.js} +1 -1
  175. package/dist/cdn/{shared-6fa216e7.js → shared-e622d8cf.js} +1 -1
  176. package/dist/cdn/{shared-939f50c2.js → shared-f20eefdd.js} +1 -1
  177. package/dist/cdn/{shared-d4e7383e.js → shared-f316780a.js} +1 -1
  178. package/dist/cdn/{shared-aa54bc96.js → shared-f72d82a9.js} +1 -1
  179. package/dist/cdn/{shared-cdb5ad48.js → shared-f92b9842.js} +1 -1
  180. package/dist/cdn/{shared-19ebb715.js → shared-fa4ab526.js} +5 -5
  181. package/dist/cdn/{shared-639dbd3f.js → shared-fea2714e.js} +1 -1
  182. package/dist/cdn/translations/native-integration-form/en.json +344 -214
  183. package/dist/cdn/translations/tax-card/en.json +6 -4
  184. package/dist/cdn/translations/tax-form/en.json +161 -32
  185. package/dist/elements/internal/InternalForm/InternalForm.js +2 -2
  186. package/dist/elements/internal/InternalForm/InternalForm.js.map +1 -1
  187. package/dist/elements/public/NativeIntegrationForm/NativeIntegrationForm.d.ts +4 -5
  188. package/dist/elements/public/NativeIntegrationForm/NativeIntegrationForm.js +415 -292
  189. package/dist/elements/public/NativeIntegrationForm/NativeIntegrationForm.js.map +1 -1
  190. package/dist/elements/public/NativeIntegrationForm/defaults.d.ts +9 -68
  191. package/dist/elements/public/NativeIntegrationForm/defaults.js +18 -18
  192. package/dist/elements/public/NativeIntegrationForm/defaults.js.map +1 -1
  193. package/dist/elements/public/NativeIntegrationForm/index.d.ts +4 -3
  194. package/dist/elements/public/NativeIntegrationForm/index.js +4 -3
  195. package/dist/elements/public/NativeIntegrationForm/index.js.map +1 -1
  196. package/dist/elements/public/TaxCard/TaxCard.js +4 -0
  197. package/dist/elements/public/TaxCard/TaxCard.js.map +1 -1
  198. package/dist/elements/public/TaxForm/TaxForm.d.ts +31 -51
  199. package/dist/elements/public/TaxForm/TaxForm.js +260 -634
  200. package/dist/elements/public/TaxForm/TaxForm.js.map +1 -1
  201. package/dist/elements/public/TaxForm/index.d.ts +9 -9
  202. package/dist/elements/public/TaxForm/index.js +9 -9
  203. package/dist/elements/public/TaxForm/index.js.map +1 -1
  204. package/dist/mixins/themeable.js +4 -0
  205. package/dist/mixins/themeable.js.map +1 -1
  206. package/package.json +1 -1
  207. package/dist/cdn/shared-139024d1.js +0 -1
  208. package/dist/cdn/shared-3b1fc10b.js +0 -1
  209. package/dist/cdn/shared-433b15f9.js +0 -1
  210. package/dist/cdn/shared-d9393c31.js +0 -1
@@ -1,19 +1,13 @@
1
- import { Checkbox, Dropdown, Metadata } from "../../private/index.js";
2
- import { Nucleon } from '@foxy.io/sdk/core';
3
- import { ScopedElementsMixin } from '@open-wc/scoped-elements';
4
- import { html } from 'lit-html';
5
- import { ConfigurableMixin } from "../../../mixins/configurable.js";
6
- import { NucleonElement } from "../NucleonElement/NucleonElement.js";
7
- import { ThemeableMixin } from "../../../mixins/themeable.js";
8
1
  import { TranslatableMixin } from "../../../mixins/translatable.js";
9
- import { classMap } from "../../../utils/class-map.js";
2
+ import { BooleanSelector } from '@foxy.io/sdk/core';
3
+ import { InternalForm } from "../../internal/InternalForm/InternalForm.js";
10
4
  import { ifDefined } from 'lit-html/directives/if-defined';
11
- import { interpret } from 'xstate';
5
+ import { html } from 'lit-html';
6
+ const NS = 'tax-form';
7
+ const Base = TranslatableMixin(InternalForm, NS);
12
8
  // prettier-ignore
13
9
  const defaultLiveRateCountries = ['US', 'CA', 'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GB', 'GR', 'HR', 'HU', 'IE', 'IM', 'IT', 'LT', 'LU', 'LV', 'MC', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'];
14
10
  const taxJarLiveRateCountries = [...defaultLiveRateCountries, 'AU'];
15
- const NS = 'tax-form';
16
- const Base = ConfigurableMixin(ThemeableMixin(ScopedElementsMixin(TranslatableMixin(NucleonElement, NS))));
17
11
  /**
18
12
  * Form element for creating or editing taxes (`fx:tax`).
19
13
  *
@@ -23,673 +17,305 @@ const Base = ConfigurableMixin(ThemeableMixin(ScopedElementsMixin(TranslatableMi
23
17
  export class TaxForm extends Base {
24
18
  constructor() {
25
19
  super(...arguments);
26
- this.__previousCountry = undefined;
27
- this.__countries = '';
28
- this.__regions = '';
29
- this.__countriesService = interpret(Nucleon.machine.withConfig({
30
- services: {
31
- sendGet: async () => {
32
- const response = await new TaxForm.API(this).fetch(this.countries);
33
- if (!response.ok)
34
- throw new Error(await response.text());
35
- return await response.json();
36
- },
37
- },
38
- }));
39
- this.__regionsService = interpret(Nucleon.machine.withConfig({
40
- services: {
41
- sendGet: async () => {
42
- var _a;
43
- const url = new URL(this.regions);
44
- url.searchParams.set('country_code', (_a = this.form.country) !== null && _a !== void 0 ? _a : 'US');
45
- const response = await new TaxForm.API(this).fetch(url.toString());
46
- if (!response.ok)
47
- throw new Error(await response.text());
48
- return await response.json();
49
- },
50
- },
51
- }));
52
- }
53
- static get scopedElements() {
54
- return {
55
- 'vaadin-number-field': customElements.get('vaadin-number-field'),
56
- 'vaadin-text-field': customElements.get('vaadin-text-field'),
57
- 'vaadin-combo-box': customElements.get('vaadin-combo-box'),
58
- 'vaadin-button': customElements.get('vaadin-button'),
59
- 'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),
60
- 'foxy-internal-sandbox': customElements.get('foxy-internal-sandbox'),
61
- 'foxy-spinner': customElements.get('foxy-spinner'),
62
- 'foxy-i18n': customElements.get('foxy-i18n'),
63
- 'x-metadata': Metadata,
64
- 'x-checkbox': Checkbox,
65
- 'x-dropdown': Dropdown,
20
+ /** URL of the `fx:native_integrations` collection for the store. */
21
+ this.nativeIntegrations = null;
22
+ /** URL of the `fx:countries` property helper resource. */
23
+ this.countries = null;
24
+ /** URL of the `fx:regions` property helper resource. */
25
+ this.regions = null;
26
+ this.__serviceProviderGetValue = () => {
27
+ return this.form.service_provider || (this.form.is_live ? 'default' : 'none');
66
28
  };
29
+ this.__serviceProviderSetValue = (newValue) => {
30
+ const newProvider = ['none', 'default'].includes(newValue) ? '' : newValue;
31
+ this.edit({
32
+ service_provider: newProvider,
33
+ use_origin_rates: false,
34
+ is_live: newValue !== 'none',
35
+ });
36
+ this.edit({
37
+ exempt_all_customer_tax_ids: this.__isExemptAllCustomerTaxIdsHidden,
38
+ apply_to_shipping: this.__isApplyToShippingHidden,
39
+ });
40
+ };
41
+ this.__countrySetValue = (newValue) => {
42
+ this.edit({ country: newValue, region: '', city: '' });
43
+ this.edit({ apply_to_shipping: this.__isApplyToShippingHidden });
44
+ };
45
+ this.__regionSetValue = (newValue) => {
46
+ this.edit({ region: newValue, city: '' });
47
+ };
48
+ this.__typeSetValue = (newValue) => {
49
+ this.edit({
50
+ type: newValue,
51
+ country: '',
52
+ region: '',
53
+ city: '',
54
+ // @ts-expect-error SDK types are not up to date.
55
+ service_provider: newValue === 'custom_tax_endpoint' ? 'custom_tax' : '',
56
+ apply_to_shipping: false,
57
+ use_origin_rates: false,
58
+ exempt_all_customer_tax_ids: false,
59
+ is_live: false,
60
+ rate: 0,
61
+ });
62
+ };
63
+ this.__typeOptions = JSON.stringify([
64
+ { label: 'option_custom_tax_endpoint', value: 'custom_tax_endpoint' },
65
+ { label: 'option_global', value: 'global' },
66
+ { label: 'option_union', value: 'union' },
67
+ { label: 'option_country', value: 'country' },
68
+ { label: 'option_region', value: 'region' },
69
+ { label: 'option_local', value: 'local' },
70
+ ]);
67
71
  }
68
72
  static get properties() {
69
73
  return {
70
74
  ...super.properties,
71
- countries: { type: String, noAccessor: true },
72
- regions: { type: String, noAccessor: true },
75
+ nativeIntegrations: { attribute: 'native-integrations' },
76
+ countries: {},
77
+ regions: {},
73
78
  };
74
79
  }
75
80
  static get v8n() {
76
81
  return [
77
- ({ name: v }) => !!v || 'name_required',
78
- ({ name: v }) => !v || v.length <= 30 || 'name_too_long',
79
- ({ country: c, type: t }) => t !== 'country' || !!c || 'country_required',
80
- ({ country: c, type: t }) => t !== 'region' || !!c || 'country_required',
81
- ({ country: c, use_origin_rates: r }) => !r || !!c || 'country_required',
82
- ({ country: v }) => !v || !!v.match(/[A-Z]{2}/) || 'country_invalid',
83
- ({ region: v, type: t }) => t != 'region' || !!v || 'region_required',
84
- ({ region: v }) => !v || v.length <= 20 || 'region_too_long',
85
- ({ city: v }) => !v || v.length <= 50 || 'city_too_long',
86
- ({ city: c, type: t }) => t != 'local' || !!c || 'city_required',
87
- ({ rate: v }) => !v || v <= 100 || 'rate_invalid',
82
+ ({ name: v }) => !!v || 'name:v8n_required',
83
+ ({ name: v }) => !v || v.length <= 30 || 'name:v8n_too_long',
84
+ ({ country: c, type: t }) => t !== 'country' || !!c || 'country:v8n_required',
85
+ ({ country: c, type: t }) => t !== 'region' || !!c || 'country:v8n_required',
86
+ ({ country: c, use_origin_rates: r }) => !r || !!c || 'country:v8n_required',
87
+ ({ region: v, type: t }) => t != 'region' || !!v || 'region:v8n_required',
88
+ ({ region: v }) => !v || v.length <= 20 || 'region:v8n_too_long',
89
+ ({ city: v }) => !v || v.length <= 50 || 'city:v8n_too_long',
90
+ ({ city: c, type: t }) => t != 'local' || !!c || 'city:v8n_required',
91
+ ({ rate: v }) => v === void 0 || v > 0 || 'rate:v8n_invalid',
88
92
  ];
89
93
  }
90
- /** URI of the `fx:countries` hAPI resource. */
91
- get countries() {
92
- return this.__countries;
93
- }
94
- set countries(value) {
95
- this.__countries = value;
96
- if (value) {
97
- this.__countriesService.send({ type: 'FETCH' });
98
- }
99
- else {
100
- this.__countriesService.send({ type: 'SET_DATA', data: null });
101
- }
102
- }
103
- /** URI of the `fx:regions` hAPI resource. */
104
- get regions() {
105
- return this.__regions;
94
+ get readonlySelector() {
95
+ const alwaysMatch = [super.readonlySelector.toString()];
96
+ alwaysMatch.unshift('native-integrations');
97
+ return new BooleanSelector(alwaysMatch.join(' ').trim());
106
98
  }
107
- set regions(value) {
108
- this.__regions = value;
109
- if (value) {
110
- this.__regionsService.send({ type: 'FETCH' });
99
+ get hiddenSelector() {
100
+ var _a, _b, _c;
101
+ const alwaysMatch = [super.hiddenSelector.toString()];
102
+ if (this.__nativeIntegrationsUrl === void 0)
103
+ alwaysMatch.unshift('native-integrations');
104
+ if (this.__isCountryHidden)
105
+ alwaysMatch.unshift('group-three:country');
106
+ if (this.__isRegionHidden) {
107
+ alwaysMatch.unshift('group-three:region-select', 'group-three:region-input');
111
108
  }
112
- else {
113
- this.__regionsService.send({ type: 'SET_DATA', data: null });
109
+ if (this.__isCityHidden)
110
+ alwaysMatch.unshift('group-three:city');
111
+ if (this.__isProviderHidden)
112
+ alwaysMatch.unshift('group-one:service-provider');
113
+ if (this.__isRateHidden)
114
+ alwaysMatch.unshift('group-one:rate');
115
+ if (this.__isApplyToShippingHidden)
116
+ alwaysMatch.unshift('group-two:apply-to-shipping');
117
+ if (this.__isUseOriginRatesHidden)
118
+ alwaysMatch.unshift('group-two:use-origin-rates');
119
+ if (this.__isExemptAllCustomerTaxIdsHidden) {
120
+ alwaysMatch.unshift('group-two:exempt-all-customer-tax-ids');
114
121
  }
115
- }
116
- connectedCallback() {
117
- super.connectedCallback();
118
- this.__countriesService.onTransition(({ changed }) => changed && this.requestUpdate());
119
- this.__countriesService.onChange(() => this.requestUpdate());
120
- this.__countriesService.start();
121
- this.__regionsService.onTransition(({ changed }) => changed && this.requestUpdate());
122
- this.__regionsService.onChange(() => this.requestUpdate());
123
- this.__regionsService.start();
124
- }
125
- render() {
126
- var _a, _b;
122
+ const regions = Object.values((_c = (_b = (_a = this.__regionsLoader) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.values) !== null && _c !== void 0 ? _c : {});
123
+ alwaysMatch.unshift(`group-three:region-${regions.length ? 'input' : 'select'}`);
124
+ return new BooleanSelector(alwaysMatch.join(' ').trim());
125
+ }
126
+ renderBody() {
127
+ var _a, _b, _c, _d, _e, _f, _g;
128
+ const countries = Object.values((_c = (_b = (_a = this.__countriesLoader) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.values) !== null && _c !== void 0 ? _c : {});
129
+ const countryOptions = countries.map(c => ({ rawLabel: c.default, value: c.cc2 }));
130
+ const regions = Object.values((_f = (_e = (_d = this.__regionsLoader) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.values) !== null && _f !== void 0 ? _f : {});
131
+ const regionOptions = regions.map(r => ({ rawLabel: r.default, value: r.code }));
127
132
  return html `
128
- <div class="relative space-y-m">
129
- ${this.__isNameHidden ? null : this.__renderName()}
130
- ${this.__isTypeHidden ? null : this.__renderType()}
131
- ${this.__isCountryHidden ? null : this.__renderCountry()}
132
- ${this.__isRegionHidden ? null : this.__renderRegion()}
133
- ${this.__isCityHidden ? null : this.__renderCity()}
134
- ${this.__isProviderHidden ? null : this.__renderProvider()}
135
- ${this.__isRateHidden ? null : this.__renderRate()}
136
- ${this.__isApplyToShippingHidden ? null : this.__renderApplyToShipping()}
137
- ${this.__isUseOriginRatesHidden ? null : this.__renderUseOriginRates()}
138
- ${this.__isExemptAllCustomerTaxIdsHidden ? null : this.__renderExemptAllCustomerTaxIds()}
139
- ${this.__isTimestampsHidden ? null : this.__renderTimestamps()}
140
- ${this.__isCreateHidden ? null : this.__renderCreate()}
141
- ${this.__isDeleteHidden ? null : this.__renderDelete()}
133
+ ${this.renderHeader()}
142
134
 
143
- <div
144
- data-testid="spinner"
145
- class=${classMap({
146
- 'transition duration-500 ease-in-out absolute inset-0 flex': true,
147
- 'opacity-0 pointer-events-none': this.in('idle'),
148
- })}
135
+ <foxy-internal-summary-control infer="group-one">
136
+ <foxy-internal-text-control layout="summary-item" infer="name"></foxy-internal-text-control>
137
+
138
+ <foxy-internal-select-control
139
+ options=${this.__typeOptions}
140
+ layout="summary-item"
141
+ infer="type"
142
+ .setValue=${this.__typeSetValue}
149
143
  >
150
- <foxy-spinner
151
- layout="vertical"
152
- class="m-auto p-m bg-base shadow-xs rounded-t-l rounded-b-l"
153
- state=${this.in('fail') ? 'error' : this.in('busy') ? 'busy' : 'empty'}
154
- lang=${this.lang}
155
- ns="${this.ns} ${(_b = (_a = customElements.get('foxy-spinner')) === null || _a === void 0 ? void 0 : _a.defaultNS) !== null && _b !== void 0 ? _b : ''}"
156
- >
157
- </foxy-spinner>
158
- </div>
159
- </div>
160
- `;
161
- }
162
- updated(changes) {
163
- super.updated(changes);
164
- if (this.form.country !== this.__previousCountry) {
165
- this.__previousCountry = this.form.country;
166
- this.__regionsService.send({ type: 'FETCH' });
167
- }
168
- // vaadin's combo box doesn't seem to validate on its own
169
- this.renderRoot.querySelectorAll('vaadin-combo-box').forEach(e => e.validate());
170
- }
171
- disconnectedCallback() {
172
- super.disconnectedCallback();
173
- this.__countriesService.stop();
174
- this.__regionsService.stop();
175
- }
176
- get __isNameHidden() {
177
- return this.hiddenSelector.matches('name', true);
178
- }
179
- get __isTypeHidden() {
180
- return this.hiddenSelector.matches('type', true);
181
- }
182
- get __isCountryHidden() {
183
- if (this.hiddenSelector.matches('country', true))
184
- return true;
185
- if (this.form.type === 'union')
186
- return !this.form.use_origin_rates;
187
- return !['country', 'region', 'local'].includes(this.form.type);
188
- }
189
- get __isRegionHidden() {
190
- if (this.hiddenSelector.matches('region', true))
191
- return true;
192
- return this.form.type !== 'local' && this.form.type !== 'region';
193
- }
194
- get __isCityHidden() {
195
- if (this.hiddenSelector.matches('city', true))
196
- return true;
197
- return this.form.type !== 'local';
198
- }
199
- get __isProviderHidden() {
200
- if (this.hiddenSelector.matches('provider', true))
201
- return true;
202
- return !this.form.type || this.form.type === 'global' || this.form.type === 'local';
203
- }
204
- get __isRateHidden() {
205
- if (this.hiddenSelector.matches('rate', true))
206
- return true;
207
- return !this.form.type || this.form.is_live === true;
208
- }
209
- get __isApplyToShippingHidden() {
210
- if (this.hiddenSelector.matches('apply-to-shipping', true))
211
- return true;
212
- if (this.form.type === undefined)
213
- return true;
214
- return !!this.form.is_live && defaultLiveRateCountries.includes(this.form.country);
215
- }
216
- get __isUseOriginRatesHidden() {
217
- if (this.hiddenSelector.matches('use-origin-rates', true))
218
- return true;
219
- return this.form.type !== 'union' || !this.form.is_live || !!this.form.service_provider;
220
- }
221
- get __isExemptAllCustomerTaxIdsHidden() {
222
- if (this.hiddenSelector.matches('exempt-all-customer-tax-ids', true))
223
- return true;
224
- const provider = this.form.service_provider;
225
- return provider === undefined || provider === 'onesource' || provider === 'avalara';
226
- }
227
- get __isTimestampsHidden() {
228
- if (this.hiddenSelector.matches('timestamps', true))
229
- return true;
230
- return !this.data;
231
- }
232
- get __isCreateHidden() {
233
- if (this.hiddenSelector.matches('create', true))
234
- return true;
235
- return !!this.data;
236
- }
237
- get __isDeleteHidden() {
238
- if (this.hiddenSelector.matches('delete', true))
239
- return true;
240
- return !this.data;
241
- }
242
- __getErrorMessage(prefix) {
243
- const error = this.errors.find(err => err.startsWith(prefix));
244
- return error ? this.t(error.replace(prefix, 'v8n')).toString() : '';
245
- }
246
- __getValidator(prefix) {
247
- return () => !this.errors.some(err => err.startsWith(prefix));
248
- }
249
- __renderName() {
250
- return html `
251
- <div>
252
- ${this.renderTemplateOrSlot('name:before')}
144
+ </foxy-internal-select-control>
253
145
 
254
- <vaadin-text-field
255
- data-testid="name"
256
- class="w-full"
257
- label=${this.t('name')}
258
- value=${ifDefined(this.form.name)}
259
- .checkValidity=${this.__getValidator('name')}
260
- .errorMessage=${this.__getErrorMessage('name')}
261
- ?disabled=${!this.in('idle') || this.disabledSelector.matches('name', true)}
262
- ?readonly=${this.readonlySelector.matches('name', true)}
263
- required
264
- @keydown=${this.__submitOnEnter}
265
- @input=${(evt) => {
266
- const newName = evt.currentTarget.value;
267
- this.edit({ name: newName });
268
- }}
146
+ <foxy-internal-select-control
147
+ options=${JSON.stringify(this.__serviceProviderOptions)}
148
+ layout="summary-item"
149
+ infer="service-provider"
150
+ .getValue=${this.__serviceProviderGetValue}
151
+ .setValue=${this.__serviceProviderSetValue}
269
152
  >
270
- </vaadin-text-field>
153
+ </foxy-internal-select-control>
271
154
 
272
- ${this.renderTemplateOrSlot('name:after')}
273
- </div>
274
- `;
275
- }
276
- __renderType() {
277
- if (!this.form.type)
278
- this.edit({ type: 'global' });
279
- return html `
280
- <div>
281
- ${this.renderTemplateOrSlot('type:before')}
155
+ <foxy-internal-number-control layout="summary-item" suffix="%" infer="rate" min="0">
156
+ </foxy-internal-number-control>
157
+ </foxy-internal-summary-control>
282
158
 
283
- <x-dropdown
284
- data-testid="type"
285
- label=${this.t('type')}
286
- value=${ifDefined(this.form.type)}
287
- class="w-full"
288
- .items=${['global', 'union', 'country', 'region', 'local']}
289
- .getText=${(value) => this.t(`tax_${value}`)}
290
- ?disabled=${!this.in('idle') || this.disabledSelector.matches('type', true)}
291
- ?readonly=${this.readonlySelector.matches('type', true)}
292
- @change=${(evt) => {
293
- this.edit({
294
- type: evt.detail,
295
- country: '',
296
- region: '',
297
- city: '',
298
- service_provider: '',
299
- apply_to_shipping: false,
300
- use_origin_rates: false,
301
- exempt_all_customer_tax_ids: false,
302
- is_live: false,
303
- rate: 0,
304
- });
305
- }}
306
- >
307
- </x-dropdown>
159
+ <foxy-internal-async-list-control
160
+ infer="native-integrations"
161
+ first=${ifDefined(this.__nativeIntegrationsUrl)}
162
+ item="foxy-native-integration-card"
163
+ >
164
+ </foxy-internal-async-list-control>
308
165
 
309
- ${this.renderTemplateOrSlot('type:after')}
310
- </div>
311
- `;
312
- }
313
- __renderCountry() {
314
- var _a, _b, _c;
315
- const isLoadingItems = !!((_a = this.__countriesService.state) === null || _a === void 0 ? void 0 : _a.matches('busy'));
316
- const isLoadingData = this.in('busy');
317
- const isLoading = isLoadingItems || isLoadingData;
318
- const isFail = this.in('fail');
319
- const json = (_b = this.__countriesService.state) === null || _b === void 0 ? void 0 : _b.context.data;
320
- const items = Object.values((_c = json === null || json === void 0 ? void 0 : json.values) !== null && _c !== void 0 ? _c : {});
321
- return html `
322
- <div>
323
- ${this.renderTemplateOrSlot('country:before')}
166
+ <foxy-internal-summary-control infer="group-two">
167
+ <foxy-internal-switch-control infer="exempt-all-customer-tax-ids">
168
+ </foxy-internal-switch-control>
169
+ <foxy-internal-switch-control infer="apply-to-shipping"></foxy-internal-switch-control>
170
+ <foxy-internal-switch-control infer="use-origin-rates"></foxy-internal-switch-control>
171
+ </foxy-internal-summary-control>
324
172
 
325
- <vaadin-combo-box
326
- item-value-path="cc2"
327
- item-label-path="default"
328
- item-id-path="cc2"
329
- data-testid="country"
330
- label="${this.t('country')}${isLoadingItems ? ` • ${this.t('loading_busy')}` : ''}"
331
- value=${ifDefined(isLoadingItems ? undefined : this.form.country)}
332
- class="w-full"
333
- .checkValidity=${this.__getValidator('country')}
334
- .errorMessage=${this.__getErrorMessage('country')}
335
- .items=${items}
336
- ?allow-custom-value=${items.length === 0}
337
- ?disabled=${isFail || isLoading || this.disabledSelector.matches('country', true)}
338
- ?readonly=${this.readonlySelector.matches('country', true)}
339
- required
340
- @change=${(evt) => {
341
- this.edit({
342
- country: evt.currentTarget.value,
343
- region: '',
344
- city: '',
345
- is_live: false,
346
- service_provider: '',
347
- });
348
- if (this.__isApplyToShippingHidden)
349
- this.edit({ apply_to_shipping: false });
350
- this.__regionsService.send({ type: 'FETCH' });
351
- }}
173
+ <foxy-internal-summary-control infer="group-three">
174
+ <foxy-internal-select-control
175
+ options=${JSON.stringify(countryOptions)}
176
+ layout="summary-item"
177
+ infer="country"
178
+ .setValue=${this.__countrySetValue}
352
179
  >
353
- </vaadin-combo-box>
180
+ </foxy-internal-select-control>
354
181
 
355
- ${this.renderTemplateOrSlot('country:after')}
356
- </div>
357
- `;
358
- }
359
- __renderRegion() {
360
- var _a, _b, _c;
361
- const isLoadingItems = !!((_a = this.__regionsService.state) === null || _a === void 0 ? void 0 : _a.matches('busy'));
362
- const isLoadingData = this.in('busy');
363
- const isLoading = isLoadingItems || isLoadingData;
364
- const isFail = this.in('fail');
365
- const json = (_b = this.__regionsService.state) === null || _b === void 0 ? void 0 : _b.context.data;
366
- const items = Object.values((_c = json === null || json === void 0 ? void 0 : json.values) !== null && _c !== void 0 ? _c : {});
367
- return html `
368
- <div>
369
- ${this.renderTemplateOrSlot('region:before')}
182
+ <foxy-internal-select-control
183
+ property="region"
184
+ options=${JSON.stringify(regionOptions)}
185
+ layout="summary-item"
186
+ infer="region-select"
187
+ .setValue=${this.__regionSetValue}
188
+ >
189
+ </foxy-internal-select-control>
370
190
 
371
- <vaadin-combo-box
372
- item-value-path="code"
373
- item-label-path="default"
374
- item-id-path="code"
375
- data-testid="region"
376
- label="${this.t('region')}${isLoadingItems ? ` • ${this.t('loading_busy')}` : ''}"
377
- value=${ifDefined(isLoadingItems ? undefined : this.form.region)}
378
- class="w-full"
379
- .checkValidity=${this.__getValidator('region')}
380
- .errorMessage=${this.__getErrorMessage('region')}
381
- .items=${items}
382
- ?allow-custom-value=${items.length === 0}
383
- ?disabled=${isFail || isLoading || this.disabledSelector.matches('region', true)}
384
- ?readonly=${this.readonlySelector.matches('region', true)}
385
- required
386
- @change=${(evt) => {
387
- const newRegion = evt.currentTarget.value;
388
- this.edit({ region: newRegion, city: '' });
389
- }}
191
+ <foxy-internal-text-control
192
+ property="region"
193
+ layout="summary-item"
194
+ infer="region-input"
195
+ .setValue=${this.__regionSetValue}
390
196
  >
391
- </vaadin-combo-box>
197
+ </foxy-internal-text-control>
392
198
 
393
- ${this.renderTemplateOrSlot('region:after')}
394
- </div>
395
- `;
396
- }
397
- __renderCity() {
398
- return html `
399
- <div>
400
- ${this.renderTemplateOrSlot('city:before')}
199
+ <foxy-internal-text-control layout="summary-item" infer="city"></foxy-internal-text-control>
200
+ </foxy-internal-summary-control>
401
201
 
402
- <vaadin-text-field
403
- data-testid="city"
404
- class="w-full"
405
- label=${this.t('city')}
406
- value=${ifDefined(this.form.city)}
407
- .checkValidity=${this.__getValidator('city')}
408
- .errorMessage=${this.__getErrorMessage('city')}
409
- ?disabled=${!this.in('idle') || this.disabledSelector.matches('city', true)}
410
- ?readonly=${this.readonlySelector.matches('city', true)}
411
- required
412
- @keydown=${this.__submitOnEnter}
413
- @input=${(evt) => {
414
- const newCity = evt.currentTarget.value;
415
- this.edit({ city: newCity });
416
- }}
417
- >
418
- </vaadin-text-field>
202
+ ${super.renderBody()}
203
+
204
+ <foxy-nucleon
205
+ infer=""
206
+ class="hidden"
207
+ href=${ifDefined((_g = this.countries) !== null && _g !== void 0 ? _g : void 0)}
208
+ id="countriesLoader"
209
+ @update=${() => this.requestUpdate()}
210
+ >
211
+ </foxy-nucleon>
419
212
 
420
- ${this.renderTemplateOrSlot('city:after')}
421
- </div>
213
+ <foxy-nucleon
214
+ infer=""
215
+ class="hidden"
216
+ href=${ifDefined(this.__regionsUrl)}
217
+ id="regionsLoader"
218
+ @update=${() => this.requestUpdate()}
219
+ >
220
+ </foxy-nucleon>
422
221
  `;
423
222
  }
424
- __renderProvider() {
425
- const items = [
426
- { label: this.t('tax_rate_provider_none'), value: 'none' },
427
- { label: 'Avalara AvaTax 15', value: 'avalara' },
428
- { label: 'Thomson Reuters ONESOURCE', value: 'onesource' },
223
+ get __serviceProviderOptions() {
224
+ const options = [
225
+ { label: 'option_none', value: 'none' },
226
+ { label: 'option_avalara', value: 'avalara' },
227
+ { label: 'option_onesource', value: 'onesource' },
429
228
  ];
430
- if (this.form.type === 'union' || defaultLiveRateCountries.includes(this.form.country)) {
431
- items.push({ label: this.t('tax_rate_provider_default'), value: 'default' });
229
+ if (this.form.type === 'union' ||
230
+ !this.form.country ||
231
+ defaultLiveRateCountries.includes(this.form.country)) {
232
+ options.unshift({ label: 'option_default', value: 'default' });
432
233
  }
433
- if (taxJarLiveRateCountries.includes(this.form.country)) {
434
- items.push({ label: 'TaxJar', value: 'taxjar' });
234
+ if (this.form.type === 'union' ||
235
+ !this.form.country ||
236
+ taxJarLiveRateCountries.includes(this.form.country)) {
237
+ options.push({ label: 'option_taxjar', value: 'taxjar' });
435
238
  }
436
- return html `
437
- <div>
438
- ${this.renderTemplateOrSlot('provider:before')}
439
-
440
- <x-dropdown
441
- data-testid="provider"
442
- label=${this.t('tax_rate_provider')}
443
- value=${this.form.service_provider || (this.form.is_live ? 'default' : 'none')}
444
- class="w-full"
445
- .items=${items.map(item => item.value)}
446
- .getText=${(value) => { var _a; return (_a = items.find(item => item.value === value)) === null || _a === void 0 ? void 0 : _a.label; }}
447
- ?disabled=${!this.in('idle') || this.disabledSelector.matches('provider', true)}
448
- ?readonly=${this.readonlySelector.matches('provider', true)}
449
- @change=${(evt) => {
450
- const newValue = evt.detail;
451
- const newProvider = ['none', 'default'].includes(newValue) ? '' : newValue;
452
- this.edit({
453
- service_provider: newProvider,
454
- is_live: newValue !== 'none',
455
- });
456
- if (this.__isExemptAllCustomerTaxIdsHidden) {
457
- this.edit({ exempt_all_customer_tax_ids: false });
239
+ return options;
240
+ }
241
+ get __nativeIntegrationsUrl() {
242
+ var _a;
243
+ try {
244
+ const url = new URL((_a = this.nativeIntegrations) !== null && _a !== void 0 ? _a : '');
245
+ const provider = this.form.service_provider;
246
+ if (provider) {
247
+ url.searchParams.set('provider', provider);
248
+ return url.toString();
458
249
  }
459
- if (this.__isApplyToShippingHidden)
460
- this.edit({ apply_to_shipping: false });
461
- if (this.__isUseOriginRatesHidden)
462
- this.edit({ use_origin_rates: false });
463
- }}
464
- >
465
- </x-dropdown>
466
-
467
- ${this.renderTemplateOrSlot('provider:after')}
468
- </div>
469
- `;
250
+ }
251
+ catch (_b) {
252
+ // do nothing
253
+ }
470
254
  }
471
- __renderRate() {
472
- return html `
473
- <div>
474
- ${this.renderTemplateOrSlot('rate:before')}
475
-
476
- <vaadin-number-field
477
- data-testid="rate"
478
- class="w-full"
479
- label=${this.t('tax_rate')}
480
- value=${ifDefined(this.form.rate)}
481
- min="0"
482
- .checkValidity=${this.__getValidator('rate')}
483
- .errorMessage=${this.__getErrorMessage('rate')}
484
- ?disabled=${!this.in('idle') || this.disabledSelector.matches('rate', true)}
485
- ?readonly=${this.readonlySelector.matches('rate', true)}
486
- required
487
- @keydown=${this.__submitOnEnter}
488
- @change=${(evt) => {
489
- const newRate = parseFloat(evt.currentTarget.value);
490
- if (!isNaN(newRate))
491
- this.edit({ rate: newRate });
492
- }}
493
- >
494
- </vaadin-number-field>
495
-
496
- ${this.renderTemplateOrSlot('rate:after')}
497
- </div>
498
- `;
255
+ get __regionsUrl() {
256
+ var _a;
257
+ try {
258
+ const regionsURL = new URL((_a = this.regions) !== null && _a !== void 0 ? _a : '');
259
+ const country = this.form.country;
260
+ if (country)
261
+ regionsURL.searchParams.set('country_code', country);
262
+ return regionsURL.toString();
263
+ }
264
+ catch (_b) {
265
+ // do nothing
266
+ }
499
267
  }
500
- __renderApplyToShipping() {
501
- return html `
502
- <div>
503
- ${this.renderTemplateOrSlot('apply-to-shipping:before')}
504
-
505
- <x-checkbox
506
- data-testid="apply-to-shipping"
507
- class="leading-s"
508
- ?disabled=${!this.in('idle') || this.disabledSelector.matches('apply-to-shipping', true)}
509
- ?readonly=${this.readonlySelector.matches('apply-to-shipping', true)}
510
- ?checked=${!!this.form.apply_to_shipping}
511
- @change=${(evt) => this.edit({ apply_to_shipping: evt.detail })}
512
- >
513
- <foxy-i18n
514
- class="block text-m text-body"
515
- lang=${this.lang}
516
- key="tax_apply_to_shipping"
517
- ns=${this.ns}
518
- >
519
- </foxy-i18n>
520
-
521
- <foxy-i18n
522
- class="block text-s text-secondary"
523
- lang=${this.lang}
524
- key="tax_apply_to_shipping_explainer"
525
- ns=${this.ns}
526
- >
527
- </foxy-i18n>
528
- </x-checkbox>
529
-
530
- ${this.renderTemplateOrSlot('apply-to-shipping:after')}
531
- </div>
532
- `;
268
+ get __countriesLoader() {
269
+ return this.renderRoot.querySelector('#countriesLoader');
533
270
  }
534
- __renderUseOriginRates() {
535
- return html `
536
- <div>
537
- ${this.renderTemplateOrSlot('use-origin-rates:before')}
538
-
539
- <x-checkbox
540
- data-testid="use-origin-rates"
541
- class="leading-s"
542
- ?disabled=${!this.in('idle') || this.disabledSelector.matches('use-origin-rates', true)}
543
- ?readonly=${this.readonlySelector.matches('use-origin-rates', true)}
544
- ?checked=${!!this.form.use_origin_rates}
545
- @change=${(evt) => this.edit({ use_origin_rates: evt.detail })}
546
- >
547
- <foxy-i18n
548
- class="block text-m text-body"
549
- lang=${this.lang}
550
- key="tax_use_origin_rates"
551
- ns=${this.ns}
552
- >
553
- </foxy-i18n>
554
-
555
- <foxy-i18n
556
- class="block text-s text-secondary"
557
- lang=${this.lang}
558
- key="tax_use_origin_rates_explainer"
559
- ns=${this.ns}
560
- >
561
- </foxy-i18n>
562
- </x-checkbox>
563
-
564
- ${this.renderTemplateOrSlot('use-origin-rates:after')}
565
- </div>
566
- `;
271
+ get __regionsLoader() {
272
+ return this.renderRoot.querySelector('#regionsLoader');
567
273
  }
568
- __renderExemptAllCustomerTaxIds() {
569
- const scope = 'exempt-all-customer-tax-ids';
570
- return html `
571
- <div>
572
- ${this.renderTemplateOrSlot(`${scope}:before`)}
573
-
574
- <x-checkbox
575
- data-testid="${scope}"
576
- class="leading-s"
577
- ?disabled=${!this.in('idle') || this.disabledSelector.matches(scope, true)}
578
- ?readonly=${this.readonlySelector.matches(scope, true)}
579
- ?checked=${!!this.form.exempt_all_customer_tax_ids}
580
- @change=${(evt) => {
581
- this.edit({ exempt_all_customer_tax_ids: evt.detail });
582
- }}
583
- >
584
- <foxy-i18n
585
- class="block text-m text-body"
586
- lang=${this.lang}
587
- key="tax_exempt_all_customer_tax_ids"
588
- ns=${this.ns}
589
- >
590
- </foxy-i18n>
591
-
592
- <foxy-i18n
593
- class="block text-s text-secondary"
594
- lang=${this.lang}
595
- key="tax_exempt_all_customer_tax_ids_explainer"
596
- ns=${this.ns}
597
- >
598
- </foxy-i18n>
599
- </x-checkbox>
600
-
601
- ${this.renderTemplateOrSlot(`${scope}:after`)}
602
- </div>
603
- `;
274
+ get __isExemptAllCustomerTaxIdsHidden() {
275
+ const type = this.form.type;
276
+ if (type === 'custom_tax_endpoint')
277
+ return true;
278
+ if (type === 'country' || type === 'region' || type === 'local')
279
+ return !!this.form.is_live;
280
+ const provider = this.form.service_provider;
281
+ return !provider || provider === 'onesource' || provider === 'avalara' || provider === 'taxjar';
604
282
  }
605
- __renderTimestamps() {
606
- return html `
607
- <div>
608
- ${this.renderTemplateOrSlot('timestamps:before')}
609
-
610
- <x-metadata
611
- data-testid="timestamps"
612
- .items=${['date_modified', 'date_created'].map(field => {
613
- var _a;
614
- return ({
615
- name: this.t(field),
616
- value: ((_a = this.data) === null || _a === void 0 ? void 0 : _a[field]) ? this.t('date', { value: new Date(this.data[field]) })
617
- : '',
618
- });
619
- })}
620
- >
621
- </x-metadata>
622
-
623
- ${this.renderTemplateOrSlot('timestamps:after')}
624
- </div>
625
- `;
283
+ get __isApplyToShippingHidden() {
284
+ const type = this.form.type;
285
+ if (!type || type === 'custom_tax_endpoint')
286
+ return true;
287
+ if (type === 'union')
288
+ return false;
289
+ if (type === 'country' && this.form.is_live)
290
+ return true;
291
+ if (type === 'region' && this.form.is_live)
292
+ return true;
293
+ return !!this.form.is_live && defaultLiveRateCountries.includes(this.form.country);
626
294
  }
627
- __renderCreate() {
628
- const isCleanTemplateInvalid = this.in({ idle: { template: { clean: 'invalid' } } });
629
- const isDirtyTemplateInvalid = this.in({ idle: { template: { dirty: 'invalid' } } });
630
- const isCleanSnapshotInvalid = this.in({ idle: { snapshot: { clean: 'invalid' } } });
631
- const isDirtySnapshotInvalid = this.in({ idle: { snapshot: { dirty: 'invalid' } } });
632
- const isTemplateInvalid = isCleanTemplateInvalid || isDirtyTemplateInvalid;
633
- const isSnaphotInvalid = isCleanSnapshotInvalid || isDirtySnapshotInvalid;
634
- const isInvalid = isTemplateInvalid || isSnaphotInvalid;
635
- const isIdle = this.in('idle');
636
- return html `
637
- <div>
638
- ${this.renderTemplateOrSlot('create:before')}
639
-
640
- <vaadin-button
641
- data-testid="create"
642
- class="w-full"
643
- theme="primary success"
644
- ?disabled=${!isIdle || isInvalid || this.disabledSelector.matches('create', true)}
645
- @click=${this.submit}
646
- >
647
- <foxy-i18n ns=${this.ns} key="create" lang=${this.lang}></foxy-i18n>
648
- </vaadin-button>
649
-
650
- ${this.renderTemplateOrSlot('create:after')}
651
- </div>
652
- `;
295
+ get __isUseOriginRatesHidden() {
296
+ return this.form.type !== 'union' || !this.form.is_live || !!this.form.service_provider;
653
297
  }
654
- __renderDelete() {
655
- return html `
656
- <div>
657
- <foxy-internal-confirm-dialog
658
- data-testid="confirm"
659
- message="delete_prompt"
660
- confirm="delete"
661
- cancel="cancel"
662
- header="delete"
663
- theme="primary error"
664
- lang=${this.lang}
665
- ns=${this.ns}
666
- id="confirm"
667
- @hide=${(evt) => !evt.detail.cancelled && this.delete()}
668
- >
669
- </foxy-internal-confirm-dialog>
670
-
671
- ${this.renderTemplateOrSlot('delete:before')}
672
-
673
- <vaadin-button
674
- data-testid="delete"
675
- theme="error"
676
- class="w-full"
677
- ?disabled=${!this.in('idle') || this.disabledSelector.matches('delete', true)}
678
- @click=${(evt) => {
679
- const confirm = this.renderRoot.querySelector('#confirm');
680
- confirm.show(evt.currentTarget);
681
- }}
682
- >
683
- <foxy-i18n ns=${this.ns} key="delete" lang=${this.lang}></foxy-i18n>
684
- </vaadin-button>
685
-
686
- ${this.renderTemplateOrSlot('delete:after')}
687
- </div>
688
- `;
298
+ get __isProviderHidden() {
299
+ const type = this.form.type;
300
+ return !type || type === 'global' || type === 'local' || type === 'custom_tax_endpoint';
689
301
  }
690
- __submitOnEnter(evt) {
691
- if (evt.key === 'Enter')
692
- this.submit();
302
+ get __isCountryHidden() {
303
+ if (this.form.type === 'union') {
304
+ return (!this.form.service_provider || this.form.is_live) && !this.form.use_origin_rates;
305
+ }
306
+ else {
307
+ return !['country', 'region', 'local'].includes(this.form.type);
308
+ }
309
+ }
310
+ get __isRegionHidden() {
311
+ return this.form.type !== 'local' && this.form.type !== 'region';
312
+ }
313
+ get __isCityHidden() {
314
+ return this.form.type !== 'local';
315
+ }
316
+ get __isRateHidden() {
317
+ const type = this.form.type;
318
+ return !type || type === 'custom_tax_endpoint' || this.form.is_live === true;
693
319
  }
694
320
  }
695
321
  //# sourceMappingURL=TaxForm.js.map