@foxy.io/elements 1.12.0-beta.6 → 1.13.0-beta.2

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 (71) hide show
  1. package/dist/cdn/foxy-address-form.js +1 -1
  2. package/dist/cdn/foxy-applied-tax-card.js +1 -1
  3. package/dist/cdn/foxy-attribute-form.js +1 -1
  4. package/dist/cdn/foxy-cancellation-form.js +1 -1
  5. package/dist/cdn/foxy-custom-field-card.js +1 -1
  6. package/dist/cdn/foxy-custom-field-form.js +1 -1
  7. package/dist/cdn/foxy-customer-form.js +1 -1
  8. package/dist/cdn/foxy-customer-portal-settings.js +1 -1
  9. package/dist/cdn/foxy-customer-portal.js +1 -1
  10. package/dist/cdn/foxy-customer.js +1 -1
  11. package/dist/cdn/foxy-discount-card.js +1 -1
  12. package/dist/cdn/foxy-donation.js +1 -1
  13. package/dist/cdn/foxy-form-dialog.js +1 -1
  14. package/dist/cdn/foxy-items-form.js +1 -1
  15. package/dist/cdn/foxy-payment-method-card.js +1 -1
  16. package/dist/cdn/foxy-subscription-form.js +1 -1
  17. package/dist/cdn/foxy-tax-card.js +1 -0
  18. package/dist/cdn/foxy-tax-form.js +1 -0
  19. package/dist/cdn/foxy-user-form.js +1 -1
  20. package/dist/cdn/foxy-users-table.js +1 -1
  21. package/dist/cdn/{shared-452674bd.js → shared-036a8b21.js} +1 -1
  22. package/dist/cdn/{shared-0dcff074.js → shared-296637c5.js} +1 -1
  23. package/dist/cdn/{shared-f2d6922d.js → shared-4a990126.js} +1 -1
  24. package/dist/cdn/shared-67157a25.js +1 -0
  25. package/dist/cdn/shared-b0b1d248.js +1 -0
  26. package/dist/cdn/translations/country/zh-cn.json +248 -0
  27. package/dist/cdn/translations/country/zh-hk.json +245 -0
  28. package/dist/cdn/translations/customer-portal/de.json +35 -0
  29. package/dist/cdn/translations/shared/de.json +16 -0
  30. package/dist/cdn/translations/shared/en.json +16 -0
  31. package/dist/cdn/translations/shared/es.json +18 -2
  32. package/dist/elements/private/Dialog/DialogWindow.js +1 -1
  33. package/dist/elements/private/Dialog/DialogWindow.js.map +1 -1
  34. package/dist/elements/public/AddressForm/AddressForm.d.ts +4 -4
  35. package/dist/elements/public/AddressForm/AddressForm.js +4 -4
  36. package/dist/elements/public/AddressForm/AddressForm.js.map +1 -1
  37. package/dist/elements/public/AddressForm/types.d.ts +6 -6
  38. package/dist/elements/public/AddressForm/types.js.map +1 -1
  39. package/dist/elements/public/CustomFieldCard/TwoLineCard.js +10 -2
  40. package/dist/elements/public/CustomFieldCard/TwoLineCard.js.map +1 -1
  41. package/dist/elements/public/Customer/types.d.ts +8 -8
  42. package/dist/elements/public/Customer/types.js.map +1 -1
  43. package/dist/elements/public/CustomerPortal/types.d.ts +8 -8
  44. package/dist/elements/public/CustomerPortal/types.js.map +1 -1
  45. package/dist/elements/public/TaxCard/TaxCard.d.ts +24 -0
  46. package/dist/elements/public/TaxCard/TaxCard.js +52 -0
  47. package/dist/elements/public/TaxCard/TaxCard.js.map +1 -0
  48. package/dist/elements/public/TaxCard/index.d.ts +5 -0
  49. package/dist/elements/public/TaxCard/index.js +7 -0
  50. package/dist/elements/public/TaxCard/index.js.map +1 -0
  51. package/dist/elements/public/TaxCard/types.d.ts +3 -0
  52. package/dist/elements/public/TaxCard/types.js +2 -0
  53. package/dist/elements/public/TaxCard/types.js.map +1 -0
  54. package/dist/elements/public/TaxForm/TaxForm.d.ts +105 -0
  55. package/dist/elements/public/TaxForm/TaxForm.js +701 -0
  56. package/dist/elements/public/TaxForm/TaxForm.js.map +1 -0
  57. package/dist/elements/public/TaxForm/index.d.ts +10 -0
  58. package/dist/elements/public/TaxForm/index.js +12 -0
  59. package/dist/elements/public/TaxForm/index.js.map +1 -0
  60. package/dist/elements/public/TaxForm/types.d.ts +33 -0
  61. package/dist/elements/public/TaxForm/types.js +2 -0
  62. package/dist/elements/public/TaxForm/types.js.map +1 -0
  63. package/dist/elements/public/index.d.ts +2 -0
  64. package/dist/elements/public/index.defined.d.ts +2 -0
  65. package/dist/elements/public/index.defined.js +2 -0
  66. package/dist/elements/public/index.defined.js.map +1 -1
  67. package/dist/elements/public/index.js +2 -0
  68. package/dist/elements/public/index.js.map +1 -1
  69. package/package.json +1 -1
  70. package/dist/cdn/shared-7888de8c.js +0 -1
  71. package/dist/cdn/shared-dea02a36.js +0 -1
@@ -0,0 +1,701 @@
1
+ import { Checkbox, Dropdown, PropertyTable } 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
+ import { TranslatableMixin } from "../../../mixins/translatable.js";
9
+ import { classMap } from "../../../utils/class-map.js";
10
+ import { ifDefined } from 'lit-html/directives/if-defined';
11
+ import { interpret } from 'xstate';
12
+ // prettier-ignore
13
+ 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
+ const taxJarLiveRateCountries = [...defaultLiveRateCountries, 'AU'];
15
+ const NS = 'tax-form';
16
+ const Base = ConfigurableMixin(ThemeableMixin(ScopedElementsMixin(TranslatableMixin(NucleonElement, NS))));
17
+ /**
18
+ * Form element for creating or editing taxes (`fx:tax`).
19
+ *
20
+ * @slot name:before
21
+ * @slot name:after
22
+ *
23
+ * @slot type:before
24
+ * @slot type:after
25
+ *
26
+ * @slot country:before
27
+ * @slot country:after
28
+ *
29
+ * @slot region:before
30
+ * @slot region:after
31
+ *
32
+ * @slot city:before
33
+ * @slot city:after
34
+ *
35
+ * @slot provider:before
36
+ * @slot provider:after
37
+ *
38
+ * @slot rate:before
39
+ * @slot rate:after
40
+ *
41
+ * @slot apply-to-shipping:before
42
+ * @slot apply-to-shipping:after
43
+ *
44
+ * @slot use-origin-rates:before
45
+ * @slot use-origin-rates:after
46
+ *
47
+ * @slot exempt-all-customer-tax-ids:before
48
+ * @slot exempt-all-customer-tax-ids:after
49
+ *
50
+ * @slot timestamps:before
51
+ * @slot timestamps:after
52
+ *
53
+ * @slot delete:before
54
+ * @slot delete:after
55
+ *
56
+ * @slot create:before
57
+ * @slot create:after
58
+ *
59
+ * @element foxy-tax-form
60
+ * @since 1.13.0
61
+ */
62
+ export class TaxForm extends Base {
63
+ constructor() {
64
+ super(...arguments);
65
+ this.templates = {};
66
+ this.__countries = '';
67
+ this.__regions = '';
68
+ this.__countriesService = interpret(Nucleon.machine.withConfig({
69
+ services: {
70
+ sendGet: async () => {
71
+ const response = await new TaxForm.API(this).fetch(this.countries);
72
+ if (!response.ok)
73
+ throw new Error(await response.text());
74
+ return await response.json();
75
+ },
76
+ },
77
+ }));
78
+ this.__regionsService = interpret(Nucleon.machine.withConfig({
79
+ services: {
80
+ sendGet: async () => {
81
+ var _a;
82
+ const url = new URL(this.regions);
83
+ url.searchParams.set('country_code', (_a = this.form.country) !== null && _a !== void 0 ? _a : 'US');
84
+ const response = await new TaxForm.API(this).fetch(url.toString());
85
+ if (!response.ok)
86
+ throw new Error(await response.text());
87
+ return await response.json();
88
+ },
89
+ },
90
+ }));
91
+ }
92
+ static get scopedElements() {
93
+ return {
94
+ 'vaadin-integer-field': customElements.get('vaadin-integer-field'),
95
+ 'vaadin-text-field': customElements.get('vaadin-text-field'),
96
+ 'vaadin-combo-box': customElements.get('vaadin-combo-box'),
97
+ 'vaadin-button': customElements.get('vaadin-button'),
98
+ 'foxy-internal-confirm-dialog': customElements.get('foxy-internal-confirm-dialog'),
99
+ 'foxy-spinner': customElements.get('foxy-spinner'),
100
+ 'foxy-i18n': customElements.get('foxy-i18n'),
101
+ 'x-property-table': PropertyTable,
102
+ 'x-checkbox': Checkbox,
103
+ 'x-dropdown': Dropdown,
104
+ };
105
+ }
106
+ static get properties() {
107
+ return {
108
+ ...super.properties,
109
+ countries: { type: String, noAccessor: true },
110
+ regions: { type: String, noAccessor: true },
111
+ };
112
+ }
113
+ static get v8n() {
114
+ return [
115
+ ({ name: v }) => !!v || 'name_required',
116
+ ({ name: v }) => !v || v.length <= 30 || 'name_too_long',
117
+ ({ country: c, type: t }) => t !== 'country' || !!c || 'country_required',
118
+ ({ country: c, type: t }) => t !== 'region' || !!c || 'country_required',
119
+ ({ country: c, use_origin_rates: r }) => !r || !!c || 'country_required',
120
+ ({ country: v }) => !v || !!v.match(/[A-Z]{2}/) || 'country_invalid',
121
+ ({ region: v, type: t }) => t != 'region' || !!v || 'region_required',
122
+ ({ region: v }) => !v || v.length <= 20 || 'region_too_long',
123
+ ({ city: v }) => !v || v.length <= 50 || 'city_too_long',
124
+ ({ city: c, type: t }) => t != 'local' || !!c || 'city_required',
125
+ ({ rate: v }) => !v || v <= 100 || 'rate_invalid',
126
+ ];
127
+ }
128
+ /** URI of the `fx:countries` hAPI resource. */
129
+ get countries() {
130
+ return this.__countries;
131
+ }
132
+ set countries(value) {
133
+ this.__countries = value;
134
+ if (value) {
135
+ this.__countriesService.send({ type: 'FETCH' });
136
+ }
137
+ else {
138
+ this.__countriesService.send({ type: 'SET_DATA', data: null });
139
+ }
140
+ }
141
+ /** URI of the `fx:regions` hAPI resource. */
142
+ get regions() {
143
+ return this.__regions;
144
+ }
145
+ set regions(value) {
146
+ this.__regions = value;
147
+ if (value) {
148
+ this.__regionsService.send({ type: 'FETCH' });
149
+ }
150
+ else {
151
+ this.__regionsService.send({ type: 'SET_DATA', data: null });
152
+ }
153
+ }
154
+ connectedCallback() {
155
+ super.connectedCallback();
156
+ this.__countriesService.onTransition(({ changed }) => changed && this.requestUpdate());
157
+ this.__countriesService.onChange(() => this.requestUpdate());
158
+ this.__countriesService.start();
159
+ this.__regionsService.onTransition(({ changed }) => changed && this.requestUpdate());
160
+ this.__regionsService.onChange(() => this.requestUpdate());
161
+ this.__regionsService.start();
162
+ }
163
+ render() {
164
+ var _a, _b;
165
+ return html `
166
+ <div class="relative space-y-m">
167
+ ${this.__isNameHidden ? null : this.__renderName()}
168
+ ${this.__isTypeHidden ? null : this.__renderType()}
169
+ ${this.__isCountryHidden ? null : this.__renderCountry()}
170
+ ${this.__isRegionHidden ? null : this.__renderRegion()}
171
+ ${this.__isCityHidden ? null : this.__renderCity()}
172
+ ${this.__isProviderHidden ? null : this.__renderProvider()}
173
+ ${this.__isRateHidden ? null : this.__renderRate()}
174
+ ${this.__isApplyToShippingHidden ? null : this.__renderApplyToShipping()}
175
+ ${this.__isUseOriginRatesHidden ? null : this.__renderUseOriginRates()}
176
+ ${this.__isExemptAllCustomerTaxIdsHidden ? null : this.__renderExemptAllCustomerTaxIds()}
177
+ ${this.__isTimestampsHidden ? null : this.__renderTimestamps()}
178
+ ${this.__isCreateHidden ? null : this.__renderCreate()}
179
+ ${this.__isDeleteHidden ? null : this.__renderDelete()}
180
+
181
+ <div
182
+ class=${classMap({
183
+ 'transition duration-500 ease-in-out absolute inset-0 flex': true,
184
+ 'opacity-0 pointer-events-none': !this.in('busy') && !this.in('fail'),
185
+ })}
186
+ >
187
+ <foxy-spinner
188
+ layout="vertical"
189
+ class="m-auto p-m bg-base shadow-xs rounded-t-l rounded-b-l"
190
+ state=${this.in('fail') ? 'error' : this.in('busy') ? 'busy' : 'empty'}
191
+ lang=${this.lang}
192
+ ns="${this.ns} ${(_b = (_a = customElements.get('foxy-spinner')) === null || _a === void 0 ? void 0 : _a.defaultNS) !== null && _b !== void 0 ? _b : ''}"
193
+ >
194
+ </foxy-spinner>
195
+ </div>
196
+ </div>
197
+ `;
198
+ }
199
+ updated(changes) {
200
+ super.updated(changes);
201
+ // vaadin's combo box doesn't seem to validate on its own
202
+ this.renderRoot.querySelectorAll('vaadin-combo-box').forEach(e => e.validate());
203
+ }
204
+ disconnectedCallback() {
205
+ super.disconnectedCallback();
206
+ this.__countriesService.stop();
207
+ this.__regionsService.stop();
208
+ }
209
+ get __isNameHidden() {
210
+ return this.hiddenSelector.matches('name', true);
211
+ }
212
+ get __isTypeHidden() {
213
+ return this.hiddenSelector.matches('type', true);
214
+ }
215
+ get __isCountryHidden() {
216
+ if (this.hiddenSelector.matches('country', true))
217
+ return true;
218
+ if (this.form.type === 'union')
219
+ return !this.form.use_origin_rates;
220
+ return !['country', 'region', 'local'].includes(this.form.type);
221
+ }
222
+ get __isRegionHidden() {
223
+ if (this.hiddenSelector.matches('region', true))
224
+ return true;
225
+ return this.form.type !== 'local' && this.form.type !== 'region';
226
+ }
227
+ get __isCityHidden() {
228
+ if (this.hiddenSelector.matches('city', true))
229
+ return true;
230
+ return this.form.type !== 'local';
231
+ }
232
+ get __isProviderHidden() {
233
+ if (this.hiddenSelector.matches('provider', true))
234
+ return true;
235
+ return !this.form.type || this.form.type === 'global' || this.form.type === 'local';
236
+ }
237
+ get __isRateHidden() {
238
+ if (this.hiddenSelector.matches('rate', true))
239
+ return true;
240
+ return !this.form.type || this.form.is_live === true;
241
+ }
242
+ get __isApplyToShippingHidden() {
243
+ if (this.hiddenSelector.matches('apply-to-shipping', true))
244
+ return true;
245
+ if (this.form.type === undefined)
246
+ return true;
247
+ return !!this.form.is_live && defaultLiveRateCountries.includes(this.form.country);
248
+ }
249
+ get __isUseOriginRatesHidden() {
250
+ if (this.hiddenSelector.matches('use-origin-rates', true))
251
+ return true;
252
+ return this.form.type !== 'union' || !this.form.is_live || !!this.form.service_provider;
253
+ }
254
+ get __isExemptAllCustomerTaxIdsHidden() {
255
+ if (this.hiddenSelector.matches('exempt-all-customer-tax-ids', true))
256
+ return true;
257
+ const provider = this.form.service_provider;
258
+ return provider === undefined || provider === 'onesource' || provider === 'avalara';
259
+ }
260
+ get __isTimestampsHidden() {
261
+ if (this.hiddenSelector.matches('timestamps', true))
262
+ return true;
263
+ return !this.data;
264
+ }
265
+ get __isCreateHidden() {
266
+ if (this.hiddenSelector.matches('create', true))
267
+ return true;
268
+ return !!this.data;
269
+ }
270
+ get __isDeleteHidden() {
271
+ if (this.hiddenSelector.matches('delete', true))
272
+ return true;
273
+ return !this.data;
274
+ }
275
+ __getErrorMessage(prefix) {
276
+ const error = this.errors.find(err => err.startsWith(prefix));
277
+ return error ? this.t(error.replace(prefix, 'v8n')).toString() : '';
278
+ }
279
+ __getValidator(prefix) {
280
+ return () => !this.errors.some(err => err.startsWith(prefix));
281
+ }
282
+ __renderName() {
283
+ return html `
284
+ <div>
285
+ ${this.renderTemplateOrSlot('name:before')}
286
+
287
+ <vaadin-text-field
288
+ class="w-full"
289
+ label=${this.t('name')}
290
+ value=${ifDefined(this.form.name)}
291
+ .checkValidity=${this.__getValidator('name')}
292
+ .errorMessage=${this.__getErrorMessage('name')}
293
+ ?disabled=${this.in('busy') || this.disabledSelector.matches('name', true)}
294
+ ?readonly=${this.readonlySelector.matches('name', true)}
295
+ required
296
+ @input=${(evt) => {
297
+ const newName = evt.currentTarget.value;
298
+ this.edit({ name: newName });
299
+ }}
300
+ >
301
+ </vaadin-text-field>
302
+
303
+ ${this.renderTemplateOrSlot('name:after')}
304
+ </div>
305
+ `;
306
+ }
307
+ __renderType() {
308
+ if (!this.form.type)
309
+ this.edit({ type: 'global' });
310
+ return html `
311
+ <div>
312
+ ${this.renderTemplateOrSlot('type:before')}
313
+
314
+ <x-dropdown
315
+ label=${this.t('type')}
316
+ value=${ifDefined(this.form.type)}
317
+ class="w-full"
318
+ .items=${['global', 'union', 'country', 'region', 'local']}
319
+ .getText=${(value) => this.t(`tax_${value}`)}
320
+ ?disabled=${this.in('busy') || this.disabledSelector.matches('type', true)}
321
+ ?readonly=${this.readonlySelector.matches('type', true)}
322
+ @change=${(evt) => {
323
+ this.edit({
324
+ type: evt.detail,
325
+ country: '',
326
+ region: '',
327
+ city: '',
328
+ service_provider: '',
329
+ apply_to_shipping: false,
330
+ use_origin_rates: false,
331
+ exempt_all_customer_tax_ids: false,
332
+ is_live: false,
333
+ rate: 0,
334
+ });
335
+ }}
336
+ >
337
+ </x-dropdown>
338
+
339
+ ${this.renderTemplateOrSlot('type:after')}
340
+ </div>
341
+ `;
342
+ }
343
+ __renderCountry() {
344
+ var _a;
345
+ const isLoadingItems = this.__countriesService.state.matches('busy');
346
+ const isLoadingData = this.in('busy');
347
+ const isLoading = isLoadingItems || isLoadingData;
348
+ const json = this.__countriesService.state.context.data;
349
+ const items = Object.values((_a = json === null || json === void 0 ? void 0 : json.values) !== null && _a !== void 0 ? _a : {});
350
+ return html `
351
+ <div>
352
+ ${this.renderTemplateOrSlot('country:before')}
353
+
354
+ <vaadin-combo-box
355
+ item-value-path="cc2"
356
+ item-label-path="default"
357
+ item-id-path="cc2"
358
+ label="${this.t('country')}${isLoadingItems ? ` • ${this.t('loading_busy')}` : ''}"
359
+ value=${ifDefined(this.form.country)}
360
+ class="w-full"
361
+ .checkValidity=${this.__getValidator('country')}
362
+ .errorMessage=${this.__getErrorMessage('country')}
363
+ .items=${items}
364
+ ?allow-custom-value=${items.length === 0}
365
+ ?disabled=${isLoading || this.disabledSelector.matches('country', true)}
366
+ ?readonly=${this.readonlySelector.matches('country', true)}
367
+ required
368
+ @change=${(evt) => {
369
+ this.edit({
370
+ country: evt.currentTarget.value,
371
+ region: '',
372
+ city: '',
373
+ is_live: false,
374
+ service_provider: '',
375
+ });
376
+ if (this.__isApplyToShippingHidden)
377
+ this.edit({ apply_to_shipping: false });
378
+ this.__regionsService.send({ type: 'FETCH' });
379
+ }}
380
+ >
381
+ </vaadin-combo-box>
382
+
383
+ ${this.renderTemplateOrSlot('country:after')}
384
+ </div>
385
+ `;
386
+ }
387
+ __renderRegion() {
388
+ var _a;
389
+ const isLoadingItems = this.__regionsService.state.matches('busy');
390
+ const isLoadingData = this.in('busy');
391
+ const isLoading = isLoadingItems || isLoadingData;
392
+ const json = this.__regionsService.state.context.data;
393
+ const items = Object.values((_a = json === null || json === void 0 ? void 0 : json.values) !== null && _a !== void 0 ? _a : {});
394
+ return html `
395
+ <div>
396
+ ${this.renderTemplateOrSlot('region:before')}
397
+
398
+ <vaadin-combo-box
399
+ item-value-path="code"
400
+ item-label-path="default"
401
+ item-id-path="code"
402
+ label="${this.t('region')}${isLoadingItems ? ` • ${this.t('loading_busy')}` : ''}"
403
+ value=${ifDefined(this.form.region)}
404
+ class="w-full"
405
+ .checkValidity=${this.__getValidator('region')}
406
+ .errorMessage=${this.__getErrorMessage('region')}
407
+ .items=${items}
408
+ ?allow-custom-value=${items.length === 0}
409
+ ?disabled=${isLoading || this.disabledSelector.matches('region', true)}
410
+ ?readonly=${this.readonlySelector.matches('region', true)}
411
+ required
412
+ @change=${(evt) => {
413
+ const newRegion = evt.currentTarget.value;
414
+ this.edit({ region: newRegion, city: '' });
415
+ }}
416
+ >
417
+ </vaadin-combo-box>
418
+
419
+ ${this.renderTemplateOrSlot('region:after')}
420
+ </div>
421
+ `;
422
+ }
423
+ __renderCity() {
424
+ return html `
425
+ <div>
426
+ ${this.renderTemplateOrSlot('city:before')}
427
+
428
+ <vaadin-text-field
429
+ class="w-full"
430
+ label=${this.t('city')}
431
+ value=${ifDefined(this.form.city)}
432
+ .checkValidity=${this.__getValidator('city')}
433
+ .errorMessage=${this.__getErrorMessage('city')}
434
+ ?disabled=${this.in('busy') || this.disabledSelector.matches('city', true)}
435
+ ?readonly=${this.readonlySelector.matches('city', true)}
436
+ required
437
+ @input=${(evt) => {
438
+ const newCity = evt.currentTarget.value;
439
+ this.edit({ city: newCity });
440
+ }}
441
+ >
442
+ </vaadin-text-field>
443
+
444
+ ${this.renderTemplateOrSlot('city:after')}
445
+ </div>
446
+ `;
447
+ }
448
+ __renderProvider() {
449
+ const items = [
450
+ { label: this.t('tax_rate_provider_none'), value: 'none' },
451
+ { label: 'Avalara AvaTax 15', value: 'avalara' },
452
+ { label: 'Thomson Reuters ONESOURCE', value: 'onesource' },
453
+ ];
454
+ if (this.form.type === 'union' || defaultLiveRateCountries.includes(this.form.country)) {
455
+ items.push({ label: this.t('tax_rate_provider_default'), value: 'default' });
456
+ }
457
+ if (taxJarLiveRateCountries.includes(this.form.country)) {
458
+ items.push({ label: 'TaxJar', value: 'taxjar' });
459
+ }
460
+ return html `
461
+ <div>
462
+ ${this.renderTemplateOrSlot('provider:before')}
463
+
464
+ <x-dropdown
465
+ label=${this.t('tax_rate_provider')}
466
+ value=${this.form.service_provider || (this.form.is_live ? 'default' : 'none')}
467
+ class="w-full"
468
+ .items=${items.map(item => item.value)}
469
+ .getText=${(value) => { var _a; return (_a = items.find(item => item.value === value)) === null || _a === void 0 ? void 0 : _a.label; }}
470
+ ?disabled=${this.in('busy') || this.disabledSelector.matches('provider', true)}
471
+ ?readonly=${this.readonlySelector.matches('provider', true)}
472
+ @change=${(evt) => {
473
+ const newValue = evt.detail;
474
+ const newProvider = ['none', 'default'].includes(newValue) ? '' : newValue;
475
+ this.edit({
476
+ service_provider: newProvider,
477
+ is_live: newValue !== 'none',
478
+ });
479
+ if (this.__isExemptAllCustomerTaxIdsHidden) {
480
+ this.edit({ exempt_all_customer_tax_ids: false });
481
+ }
482
+ if (this.__isApplyToShippingHidden)
483
+ this.edit({ apply_to_shipping: false });
484
+ if (this.__isUseOriginRatesHidden)
485
+ this.edit({ use_origin_rates: false });
486
+ }}
487
+ >
488
+ </x-dropdown>
489
+
490
+ ${this.renderTemplateOrSlot('provider:after')}
491
+ </div>
492
+ `;
493
+ }
494
+ __renderRate() {
495
+ return html `
496
+ <div>
497
+ ${this.renderTemplateOrSlot('rate:before')}
498
+
499
+ <vaadin-integer-field
500
+ class="w-full"
501
+ label=${this.t('tax_rate')}
502
+ value=${ifDefined(this.form.rate)}
503
+ min="0"
504
+ prevent-invalid-input
505
+ has-controls
506
+ .checkValidity=${this.__getValidator('rate')}
507
+ .errorMessage=${this.__getErrorMessage('rate')}
508
+ ?disabled=${this.in('busy') || this.disabledSelector.matches('rate', true)}
509
+ ?readonly=${this.readonlySelector.matches('rate', true)}
510
+ required
511
+ @change=${(evt) => {
512
+ const newRate = parseInt(evt.currentTarget.value);
513
+ this.edit({ rate: newRate });
514
+ }}
515
+ >
516
+ </vaadin-integer-field>
517
+
518
+ ${this.renderTemplateOrSlot('rate:after')}
519
+ </div>
520
+ `;
521
+ }
522
+ __renderApplyToShipping() {
523
+ return html `
524
+ <div>
525
+ ${this.renderTemplateOrSlot('apply-to-shipping:before')}
526
+
527
+ <x-checkbox
528
+ class="leading-s"
529
+ ?disabled=${this.disabledSelector.matches('apply-to-shipping', true)}
530
+ ?readonly=${this.readonlySelector.matches('apply-to-shipping', true)}
531
+ ?checked=${!!this.form.apply_to_shipping}
532
+ @change=${(evt) => this.edit({ apply_to_shipping: evt.detail })}
533
+ >
534
+ <foxy-i18n
535
+ class="block text-m text-body"
536
+ lang=${this.lang}
537
+ key="tax_apply_to_shipping"
538
+ ns=${this.ns}
539
+ >
540
+ </foxy-i18n>
541
+
542
+ <foxy-i18n
543
+ class="block text-s text-secondary"
544
+ lang=${this.lang}
545
+ key="tax_apply_to_shipping_explainer"
546
+ ns=${this.ns}
547
+ >
548
+ </foxy-i18n>
549
+ </x-checkbox>
550
+
551
+ ${this.renderTemplateOrSlot('apply-to-shipping:after')}
552
+ </div>
553
+ `;
554
+ }
555
+ __renderUseOriginRates() {
556
+ return html `
557
+ <div>
558
+ ${this.renderTemplateOrSlot('use-origin-rates:before')}
559
+
560
+ <x-checkbox
561
+ class="leading-s"
562
+ ?disabled=${this.disabledSelector.matches('use-origin-rates', true)}
563
+ ?readonly=${this.readonlySelector.matches('use-origin-rates', true)}
564
+ ?checked=${!!this.form.use_origin_rates}
565
+ @change=${(evt) => this.edit({ use_origin_rates: evt.detail })}
566
+ >
567
+ <foxy-i18n
568
+ class="block text-m text-body"
569
+ lang=${this.lang}
570
+ key="tax_use_origin_rates"
571
+ ns=${this.ns}
572
+ >
573
+ </foxy-i18n>
574
+
575
+ <foxy-i18n
576
+ class="block text-s text-secondary"
577
+ lang=${this.lang}
578
+ key="tax_use_origin_rates_explainer"
579
+ ns=${this.ns}
580
+ >
581
+ </foxy-i18n>
582
+ </x-checkbox>
583
+
584
+ ${this.renderTemplateOrSlot('use-origin-rates:after')}
585
+ </div>
586
+ `;
587
+ }
588
+ __renderExemptAllCustomerTaxIds() {
589
+ return html `
590
+ <div>
591
+ ${this.renderTemplateOrSlot('exempt-all-customer-tax-ids:before')}
592
+
593
+ <x-checkbox
594
+ class="leading-s"
595
+ ?disabled=${this.disabledSelector.matches('exempt-all-customer-tax-ids', true)}
596
+ ?readonly=${this.readonlySelector.matches('exempt-all-customer-tax-ids', true)}
597
+ ?checked=${!!this.form.exempt_all_customer_tax_ids}
598
+ @change=${(evt) => {
599
+ this.edit({ exempt_all_customer_tax_ids: evt.detail });
600
+ }}
601
+ >
602
+ <foxy-i18n
603
+ class="block text-m text-body"
604
+ lang=${this.lang}
605
+ key="tax_exempt_all_customer_tax_ids"
606
+ ns=${this.ns}
607
+ >
608
+ </foxy-i18n>
609
+
610
+ <foxy-i18n
611
+ class="block text-s text-secondary"
612
+ lang=${this.lang}
613
+ key="tax_exempt_all_customer_tax_ids_explainer"
614
+ ns=${this.ns}
615
+ >
616
+ </foxy-i18n>
617
+ </x-checkbox>
618
+
619
+ ${this.renderTemplateOrSlot('exempt-all-customer-tax-ids:after')}
620
+ </div>
621
+ `;
622
+ }
623
+ __renderTimestamps() {
624
+ return html `
625
+ <div>
626
+ ${this.renderTemplateOrSlot('timestamps:before')}
627
+
628
+ <x-property-table
629
+ .items=${['date_modified', 'date_created'].map(field => ({
630
+ name: this.t(field),
631
+ value: this.data ? this.t('date', { value: new Date(this.data[field]) }) : '',
632
+ }))}
633
+ >
634
+ </x-property-table>
635
+
636
+ ${this.renderTemplateOrSlot('timestamps:after')}
637
+ </div>
638
+ `;
639
+ }
640
+ __renderCreate() {
641
+ const isCleanTemplateInvalid = this.in({ idle: { template: { clean: 'invalid' } } });
642
+ const isDirtyTemplateInvalid = this.in({ idle: { template: { dirty: 'invalid' } } });
643
+ const isCleanSnapshotInvalid = this.in({ idle: { snapshot: { clean: 'invalid' } } });
644
+ const isDirtySnapshotInvalid = this.in({ idle: { snapshot: { dirty: 'invalid' } } });
645
+ const isTemplateInvalid = isCleanTemplateInvalid || isDirtyTemplateInvalid;
646
+ const isSnaphotInvalid = isCleanSnapshotInvalid || isDirtySnapshotInvalid;
647
+ const isInvalid = isTemplateInvalid || isSnaphotInvalid;
648
+ const isBusy = this.in('busy');
649
+ return html `
650
+ <div>
651
+ ${this.renderTemplateOrSlot('create:before')}
652
+
653
+ <vaadin-button
654
+ class="w-full"
655
+ theme="primary success"
656
+ ?disabled=${isBusy || isInvalid || this.disabledSelector.matches('create', true)}
657
+ @click=${this.submit}
658
+ >
659
+ <foxy-i18n ns=${this.ns} key="create" lang=${this.lang}></foxy-i18n>
660
+ </vaadin-button>
661
+
662
+ ${this.renderTemplateOrSlot('create:after')}
663
+ </div>
664
+ `;
665
+ }
666
+ __renderDelete() {
667
+ return html `
668
+ <div>
669
+ <foxy-internal-confirm-dialog
670
+ message="delete_prompt"
671
+ confirm="delete"
672
+ cancel="cancel"
673
+ header="delete"
674
+ theme="primary error"
675
+ lang=${this.lang}
676
+ ns=${this.ns}
677
+ id="confirm"
678
+ @hide=${(evt) => !evt.detail.cancelled && this.delete()}
679
+ >
680
+ </foxy-internal-confirm-dialog>
681
+
682
+ ${this.renderTemplateOrSlot('delete:before')}
683
+
684
+ <vaadin-button
685
+ theme="primary error"
686
+ class="w-full"
687
+ ?disabled=${this.in('busy') || this.disabledSelector.matches('delete', true)}
688
+ @click=${(evt) => {
689
+ const confirm = this.renderRoot.querySelector('#confirm');
690
+ confirm.show(evt.currentTarget);
691
+ }}
692
+ >
693
+ <foxy-i18n ns=${this.ns} key="delete" lang=${this.lang}></foxy-i18n>
694
+ </vaadin-button>
695
+
696
+ ${this.renderTemplateOrSlot('delete:after')}
697
+ </div>
698
+ `;
699
+ }
700
+ }
701
+ //# sourceMappingURL=TaxForm.js.map