@salla.sa/twilight-components 1.6.0 → 1.6.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 (62) hide show
  1. package/dist/cjs/Helper-8ae6a805.js +28 -0
  2. package/dist/cjs/arrow-right-3d137e4c.js +13 -0
  3. package/dist/cjs/cancel-ae668d91.js +13 -0
  4. package/dist/cjs/check-circle2-1aac98d1.js +13 -0
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/cjs/mail-2db058ee.js +13 -0
  7. package/dist/cjs/salla-add-product-button_13.cjs.entry.js +2870 -0
  8. package/dist/cjs/salla-infinite-scroll.cjs.entry.js +93 -0
  9. package/dist/cjs/salla-list-tile_2.cjs.entry.js +80 -0
  10. package/dist/cjs/salla-loyalty.cjs.entry.js +229 -0
  11. package/dist/cjs/salla-product-size-guide.cjs.entry.js +52 -0
  12. package/dist/cjs/salla-quantity-input.cjs.entry.js +101 -0
  13. package/dist/cjs/salla-rating-modal.cjs.entry.js +169 -0
  14. package/dist/cjs/salla-social-share.cjs.entry.js +1447 -0
  15. package/dist/cjs/salla-swiper.cjs.entry.js +5023 -0
  16. package/dist/cjs/salla-tab-content_3.cjs.entry.js +159 -0
  17. package/dist/cjs/star2-8288e6e1.js +13 -0
  18. package/dist/cjs/twilight-components.cjs.js +1 -1
  19. package/dist/collection/components/salla-login-modal/salla-login-modal.js +4 -3
  20. package/dist/components/salla-login-modal.js +4 -3
  21. package/dist/esm/Helper-e1d414a5.js +26 -0
  22. package/dist/esm/arrow-right-1c3e04f2.js +11 -0
  23. package/dist/esm/cancel-41a92070.js +11 -0
  24. package/dist/esm/check-circle2-f6e5f685.js +11 -0
  25. package/dist/esm/loader.js +1 -1
  26. package/dist/esm/mail-9d5204c6.js +11 -0
  27. package/dist/esm/salla-add-product-button_13.entry.js +2854 -0
  28. package/dist/esm/salla-infinite-scroll.entry.js +89 -0
  29. package/dist/esm/salla-list-tile_2.entry.js +75 -0
  30. package/dist/esm/salla-loyalty.entry.js +225 -0
  31. package/dist/esm/salla-product-size-guide.entry.js +48 -0
  32. package/dist/esm/salla-quantity-input.entry.js +97 -0
  33. package/dist/esm/salla-rating-modal.entry.js +165 -0
  34. package/dist/esm/salla-social-share.entry.js +1443 -0
  35. package/dist/esm/salla-swiper.entry.js +5019 -0
  36. package/dist/esm/salla-tab-content_3.entry.js +153 -0
  37. package/dist/esm/star2-b134fc74.js +11 -0
  38. package/dist/esm/twilight-components.js +1 -1
  39. package/dist/twilight-components/p-14f0ff17.entry.js +4 -0
  40. package/dist/twilight-components/p-2749c9d3.entry.js +4 -0
  41. package/dist/twilight-components/p-335abbbb.entry.js +4 -0
  42. package/dist/twilight-components/p-4cafb11b.entry.js +4 -0
  43. package/dist/twilight-components/p-5e63e308.entry.js +4 -0
  44. package/dist/twilight-components/p-648e74e5.entry.js +4 -0
  45. package/dist/twilight-components/p-897b2018.js +4 -0
  46. package/dist/twilight-components/p-93708e1e.js +4 -0
  47. package/dist/twilight-components/p-9d236cf4.entry.js +4 -0
  48. package/dist/twilight-components/p-9d2ca9c8.js +4 -0
  49. package/dist/twilight-components/p-af7d5660.js +4 -0
  50. package/dist/twilight-components/p-bdbd2386.entry.js +4 -0
  51. package/dist/twilight-components/p-cac3db69.entry.js +4 -0
  52. package/dist/twilight-components/p-d914a212.js +4 -0
  53. package/dist/twilight-components/p-dace8e6d.js +4 -0
  54. package/dist/twilight-components/p-f9253fda.entry.js +4 -0
  55. package/dist/twilight-components/twilight-components.esm.js +1 -1
  56. package/package.json +2 -2
  57. package/dist/cjs/salla-add-product-button.cjs.entry.js +0 -104
  58. package/dist/cjs/salla-button_24.cjs.entry.js +0 -10087
  59. package/dist/esm/salla-add-product-button.entry.js +0 -100
  60. package/dist/esm/salla-button_24.entry.js +0 -10060
  61. package/dist/twilight-components/p-30b2c5b0.entry.js +0 -4
  62. package/dist/twilight-components/p-76cb2574.entry.js +0 -4
@@ -0,0 +1,2854 @@
1
+ /*!
2
+ * Crafted with ❤ by Salla
3
+ */
4
+ import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-4e30ffd0.js';
5
+ import { H as Helper } from './Helper-e1d414a5.js';
6
+ import { e as email } from './mail-9d5204c6.js';
7
+ import { A as ArrowRightIcon } from './arrow-right-1c3e04f2.js';
8
+ import { C as Cancel } from './cancel-41a92070.js';
9
+ import { C as CheckCircle2 } from './check-circle2-f6e5f685.js';
10
+ import { S as Star2 } from './star2-b134fc74.js';
11
+ import { S as Search } from './search-19ea3313.js';
12
+
13
+ const sallaAddProductButtonCss = ":host{display:block}salla-add-product-button[width=wide]{width:100%}";
14
+
15
+ const SallaAddProductButton = class {
16
+ constructor(hostRef) {
17
+ registerInstance(this, hostRef);
18
+ this.success = createEvent(this, "success", 7);
19
+ this.failed = createEvent(this, "failed", 7);
20
+ this.hostAttributes = {};
21
+ this.hasLabel = false;
22
+ /**
23
+ * Channels.
24
+ */
25
+ this.channels = null;
26
+ /**
27
+ * Product Quantity
28
+ */
29
+ this.quantity = 0;
30
+ /**
31
+ * Donating amount.
32
+ */
33
+ this.donatingAmount = 0;
34
+ /**
35
+ * Product Status.Defaults to `sale`
36
+ */
37
+ this.productStatus = 'sale';
38
+ /**
39
+ * Product type. Defaults to `product`
40
+ */
41
+ this.productType = 'product';
42
+ }
43
+ getLabel() {
44
+ if (this.productStatus === 'sale') {
45
+ return salla.lang.get('pages.cart.add_to_cart');
46
+ }
47
+ if (this.productType !== 'donating') {
48
+ return salla.lang.get('pages.products.out_of_stock');
49
+ }
50
+ // donating
51
+ return salla.lang.get('pages.products.donation_exceed');
52
+ }
53
+ addProductToCart(event) {
54
+ // we want to ignore the click action when the type of button is submit a form
55
+ if (this.hostAttributes['type'] === 'submit') {
56
+ return false;
57
+ }
58
+ event.preventDefault();
59
+ /**
60
+ * by default the quick add is just an alias for add item function
61
+ * but its work only when the id is the only value is passed via the object
62
+ * so we will filter the object entities to remove null and zero values in case we don't want the normal add item action
63
+ */
64
+ const data = Object.entries({
65
+ id: this.productId,
66
+ donating_amount: this.donatingAmount,
67
+ quantity: this.quantity
68
+ }).reduce((a, [k, v]) => (v ? (a[k] = v, a) : a), {});
69
+ return salla.cart.quickAdd(data)
70
+ .then((response) => {
71
+ return this.success.emit(response);
72
+ })
73
+ .catch((error) => {
74
+ return this.failed.emit(error);
75
+ });
76
+ }
77
+ getBtnAttributes() {
78
+ for (let i = 0; i < this.host.attributes.length; i++) {
79
+ if (!['id', 'class'].includes(this.host.attributes[i].name)) {
80
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
81
+ }
82
+ }
83
+ return this.hostAttributes;
84
+ }
85
+ componentWillLoad() {
86
+ this.hasLabel = !!this.host.innerHTML.replace('<!---->', '').trim();
87
+ }
88
+ render() {
89
+ return (h(Host, null, this.productStatus === 'out-and-notify' && this.channels ?
90
+ h("salla-product-availability", Object.assign({}, this.getBtnAttributes()), h("slot", null)) :
91
+ h("salla-button", Object.assign({ ref: el => this.btn = el, onClick: event => this.addProductToCart(event), type: "button", fill: this.productStatus === 'sale' ? 'solid' : 'outline', color: this.productStatus === 'sale' ? 'primary' : 'light', "loader-position": "center" }, this.getBtnAttributes(), { disabled: this.productStatus !== 'sale' }), h("slot", null))));
92
+ }
93
+ componentDidRender() {
94
+ //if label not passed, get label
95
+ if (this.hasLabel) {
96
+ return;
97
+ }
98
+ this.btn.setText(this.getLabel() || 'اضافة للسلة');
99
+ salla.lang.onLoaded(() => {
100
+ this.btn.setText(this.getLabel() || 'اضافة للسلة');
101
+ });
102
+ }
103
+ get host() { return getElement(this); }
104
+ };
105
+ SallaAddProductButton.style = sallaAddProductButtonCss;
106
+
107
+ const sallaButtonCss = "";
108
+
109
+ const SallaButton = class {
110
+ constructor(hostRef) {
111
+ registerInstance(this, hostRef);
112
+ this.hostAttributes = {};
113
+ /**
114
+ * Button Type
115
+ */
116
+ this.shape = 'btn';
117
+ /**
118
+ * Button Color
119
+ */
120
+ this.color = 'primary';
121
+ /**
122
+ * Button Fill
123
+ */
124
+ this.fill = 'solid';
125
+ /**
126
+ * Button Size
127
+ */
128
+ this.size = 'medium';
129
+ /**
130
+ * Button Width
131
+ */
132
+ this.width = 'normal';
133
+ /**
134
+ * Is the button currently loading
135
+ */
136
+ this.loading = false;
137
+ /**
138
+ * Is the button currently disabled
139
+ */
140
+ this.disabled = false;
141
+ /**
142
+ * If there is need to change loader position, pass the position
143
+ */
144
+ this.loaderPosition = 'after';
145
+ }
146
+ /**
147
+ * Run loading animation
148
+ */
149
+ async load() {
150
+ if (this.loaderPosition == 'center')
151
+ this.text.classList.add('s-button-hide');
152
+ this.host.setAttribute('loading', '');
153
+ return this.host;
154
+ }
155
+ /**
156
+ * Stop loading animation
157
+ */
158
+ async stop() {
159
+ this.host.removeAttribute('loading');
160
+ this.host.querySelector('button').removeAttribute('loading');
161
+ if (this.loaderPosition == 'center')
162
+ this.text.classList.remove('s-button-hide');
163
+ return this.host;
164
+ }
165
+ /**
166
+ * Changing the body of the button
167
+ * @param html
168
+ */
169
+ async setText(html) {
170
+ this.text.innerHTML = html;
171
+ return this.host;
172
+ }
173
+ /**
174
+ * Add `disabled` attribute
175
+ */
176
+ async disable() {
177
+ this.host.setAttribute('disabled', '');
178
+ return this.host;
179
+ }
180
+ /**
181
+ * Remove `disabled` attribute
182
+ */
183
+ async enable() {
184
+ this.host.removeAttribute('disabled');
185
+ return this.host;
186
+ }
187
+ getBtnAttributes() {
188
+ for (let i = 0; i < this.host.attributes.length; i++) {
189
+ if (!['color', 'fill', 'size', 'width', 'id'].includes(this.host.attributes[i].name)) {
190
+ this.hostAttributes[this.host.attributes[i].name] = this.host.attributes[i].value;
191
+ }
192
+ }
193
+ this.hostAttributes.type = this.hostAttributes.type || 'button';
194
+ this.hostAttributes.class +=
195
+ ' s-button-element s-button-' + this.shape
196
+ + ' s-button-' + (this.fill == "none" ? 'fill-none' : this.fill)
197
+ + (this.size != "medium" ? ' s-button-' + this.size : '')
198
+ + (this.width != "normal" ? ' s-button-' + this.width : '')
199
+ + (this.shape == "link" ? ' s-button-' + this.color + '-link' : '')
200
+ + (this.shape != "link" && this.fill != 'outline' ? ' s-button-' + this.color : '')
201
+ + (this.fill == 'outline' ? ' s-button-' + this.color + '-outline' : '')
202
+ + (this.disabled ? ' s-button-disabled ' : '')
203
+ + (this.shape == 'icon' ? ' s-button-loader-center' : ' s-button-loader-' + this.loaderPosition);
204
+ return this.hostAttributes;
205
+ }
206
+ button() {
207
+ return (h("button", Object.assign({}, this.getBtnAttributes(), { disabled: this.disabled }), h("span", { class: "s-button-text", ref: el => this.text = el }, h("slot", null)), this.loading ? h("span", { class: "s-button-loader" }) : ''));
208
+ }
209
+ render() {
210
+ return (h(Host, { class: "s-button-wrap" }, this.href ? h("a", { href: this.href }, this.button()) : this.button()));
211
+ }
212
+ get host() { return getElement(this); }
213
+ };
214
+ SallaButton.style = sallaButtonCss;
215
+
216
+ const sallaLoadingCss = ".s-loading{animation:spin 1s linear infinite;fill:var(--color-primary)}.s-loading-container{display:flex;justify-content:center;align-items:center}@keyframes spin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}";
217
+
218
+ const SallaLoading = class {
219
+ constructor(hostRef) {
220
+ registerInstance(this, hostRef);
221
+ /**
222
+ * Sets the diameter of the circle in pixels, Defaults to `32`
223
+ */
224
+ this.size = 32;
225
+ /**
226
+ * Sets the stroke of the circle (border) in pixels, Defaults to `4`
227
+ */
228
+ this.width = 2;
229
+ /**
230
+ * Spinner content color.
231
+ */
232
+ this.color = undefined; // TODO: Should be replaced with primary color (variable)
233
+ /**
234
+ * Spinner background color.
235
+ */
236
+ this.bgColor = "#e5e7eb";
237
+ }
238
+ render() {
239
+ return (h(Host, { class: "s-loading-container" }, h("svg", { "aria-hidden": "true", style: { width: `${this.size}px`, height: `${this.size}px`, fill: this.color, color: this.bgColor }, class: "s-loading", viewBox: "0 0 100 101", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, h("path", { d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z", fill: "currentColor" }), h("path", { d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z", fill: "currentFill" }))));
240
+ }
241
+ };
242
+ SallaLoading.style = sallaLoadingCss;
243
+
244
+ const sallaLocalizationModalCss = ".s-localization-modal-select{background-image:url(\"data:image/svg+xml;utf8,<svg fill='gray' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>\")}.iti__flag{width:20px}.iti__flag.iti__be{width:18px}.iti__flag.iti__ch{width:15px}.iti__flag.iti__mc{width:19px}.iti__flag.iti__ne{width:18px}.iti__flag.iti__np{width:13px}.iti__flag.iti__va{width:15px}@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi){.iti__flag{background-size:5652px 15px}}.iti__flag.iti__ac{height:10px;background-position:0px 0px}.iti__flag.iti__ad{height:14px;background-position:-22px 0px}.iti__flag.iti__ae{height:10px;background-position:-44px 0px}.iti__flag.iti__af{height:14px;background-position:-66px 0px}.iti__flag.iti__ag{height:14px;background-position:-88px 0px}.iti__flag.iti__ai{height:10px;background-position:-110px 0px}.iti__flag.iti__al{height:15px;background-position:-132px 0px}.iti__flag.iti__am{height:10px;background-position:-154px 0px}.iti__flag.iti__ao{height:14px;background-position:-176px 0px}.iti__flag.iti__aq{height:14px;background-position:-198px 0px}.iti__flag.iti__ar{height:13px;background-position:-220px 0px}.iti__flag.iti__as{height:10px;background-position:-242px 0px}.iti__flag.iti__at{height:14px;background-position:-264px 0px}.iti__flag.iti__au{height:10px;background-position:-286px 0px}.iti__flag.iti__aw{height:14px;background-position:-308px 0px}.iti__flag.iti__ax{height:13px;background-position:-330px 0px}.iti__flag.iti__az{height:10px;background-position:-352px 0px}.iti__flag.iti__ba{height:10px;background-position:-374px 0px}.iti__flag.iti__bb{height:14px;background-position:-396px 0px}.iti__flag.iti__bd{height:12px;background-position:-418px 0px}.iti__flag.iti__be{height:15px;background-position:-440px 0px}.iti__flag.iti__bf{height:14px;background-position:-460px 0px}.iti__flag.iti__bg{height:12px;background-position:-482px 0px}.iti__flag.iti__bh{height:12px;background-position:-504px 0px}.iti__flag.iti__bi{height:12px;background-position:-526px 0px}.iti__flag.iti__bj{height:14px;background-position:-548px 0px}.iti__flag.iti__bl{height:14px;background-position:-570px 0px}.iti__flag.iti__bm{height:10px;background-position:-592px 0px}.iti__flag.iti__bn{height:10px;background-position:-614px 0px}.iti__flag.iti__bo{height:14px;background-position:-636px 0px}.iti__flag.iti__bq{height:14px;background-position:-658px 0px}.iti__flag.iti__br{height:14px;background-position:-680px 0px}.iti__flag.iti__bs{height:10px;background-position:-702px 0px}.iti__flag.iti__bt{height:14px;background-position:-724px 0px}.iti__flag.iti__bv{height:15px;background-position:-746px 0px}.iti__flag.iti__bw{height:14px;background-position:-768px 0px}.iti__flag.iti__by{height:10px;background-position:-790px 0px}.iti__flag.iti__bz{height:14px;background-position:-812px 0px}.iti__flag.iti__ca{height:10px;background-position:-834px 0px}.iti__flag.iti__cc{height:10px;background-position:-856px 0px}.iti__flag.iti__cd{height:15px;background-position:-878px 0px}.iti__flag.iti__cf{height:14px;background-position:-900px 0px}.iti__flag.iti__cg{height:14px;background-position:-922px 0px}.iti__flag.iti__ch{height:15px;background-position:-944px 0px}.iti__flag.iti__ci{height:14px;background-position:-961px 0px}.iti__flag.iti__ck{height:10px;background-position:-983px 0px}.iti__flag.iti__cl{height:14px;background-position:-1005px 0px}.iti__flag.iti__cm{height:14px;background-position:-1027px 0px}.iti__flag.iti__cn{height:14px;background-position:-1049px 0px}.iti__flag.iti__co{height:14px;background-position:-1071px 0px}.iti__flag.iti__cp{height:14px;background-position:-1093px 0px}.iti__flag.iti__cr{height:12px;background-position:-1115px 0px}.iti__flag.iti__cu{height:10px;background-position:-1137px 0px}.iti__flag.iti__cv{height:12px;background-position:-1159px 0px}.iti__flag.iti__cw{height:14px;background-position:-1181px 0px}.iti__flag.iti__cx{height:10px;background-position:-1203px 0px}.iti__flag.iti__cy{height:14px;background-position:-1225px 0px}.iti__flag.iti__cz{height:14px;background-position:-1247px 0px}.iti__flag.iti__de{height:12px;background-position:-1269px 0px}.iti__flag.iti__dg{height:10px;background-position:-1291px 0px}.iti__flag.iti__dj{height:14px;background-position:-1313px 0px}.iti__flag.iti__dk{height:15px;background-position:-1335px 0px}.iti__flag.iti__dm{height:10px;background-position:-1357px 0px}.iti__flag.iti__do{height:14px;background-position:-1379px 0px}.iti__flag.iti__dz{height:14px;background-position:-1401px 0px}.iti__flag.iti__ea{height:14px;background-position:-1423px 0px}.iti__flag.iti__ec{height:14px;background-position:-1445px 0px}.iti__flag.iti__ee{height:13px;background-position:-1467px 0px}.iti__flag.iti__eg{height:14px;background-position:-1489px 0px}.iti__flag.iti__eh{height:10px;background-position:-1511px 0px}.iti__flag.iti__er{height:10px;background-position:-1533px 0px}.iti__flag.iti__es{height:14px;background-position:-1555px 0px}.iti__flag.iti__et{height:10px;background-position:-1577px 0px}.iti__flag.iti__eu{height:14px;background-position:-1599px 0px}.iti__flag.iti__fi{height:12px;background-position:-1621px 0px}.iti__flag.iti__fj{height:10px;background-position:-1643px 0px}.iti__flag.iti__fk{height:10px;background-position:-1665px 0px}.iti__flag.iti__fm{height:11px;background-position:-1687px 0px}.iti__flag.iti__fo{height:15px;background-position:-1709px 0px}.iti__flag.iti__fr{height:14px;background-position:-1731px 0px}.iti__flag.iti__ga{height:15px;background-position:-1753px 0px}.iti__flag.iti__gb{height:10px;background-position:-1775px 0px}.iti__flag.iti__gd{height:12px;background-position:-1797px 0px}.iti__flag.iti__ge{height:14px;background-position:-1819px 0px}.iti__flag.iti__gf{height:14px;background-position:-1841px 0px}.iti__flag.iti__gg{height:14px;background-position:-1863px 0px}.iti__flag.iti__gh{height:14px;background-position:-1885px 0px}.iti__flag.iti__gi{height:10px;background-position:-1907px 0px}.iti__flag.iti__gl{height:14px;background-position:-1929px 0px}.iti__flag.iti__gm{height:14px;background-position:-1951px 0px}.iti__flag.iti__gn{height:14px;background-position:-1973px 0px}.iti__flag.iti__gp{height:14px;background-position:-1995px 0px}.iti__flag.iti__gq{height:14px;background-position:-2017px 0px}.iti__flag.iti__gr{height:14px;background-position:-2039px 0px}.iti__flag.iti__gs{height:10px;background-position:-2061px 0px}.iti__flag.iti__gt{height:13px;background-position:-2083px 0px}.iti__flag.iti__gu{height:11px;background-position:-2105px 0px}.iti__flag.iti__gw{height:10px;background-position:-2127px 0px}.iti__flag.iti__gy{height:12px;background-position:-2149px 0px}.iti__flag.iti__hk{height:14px;background-position:-2171px 0px}.iti__flag.iti__hm{height:10px;background-position:-2193px 0px}.iti__flag.iti__hn{height:10px;background-position:-2215px 0px}.iti__flag.iti__hr{height:10px;background-position:-2237px 0px}.iti__flag.iti__ht{height:12px;background-position:-2259px 0px}.iti__flag.iti__hu{height:10px;background-position:-2281px 0px}.iti__flag.iti__ic{height:14px;background-position:-2303px 0px}.iti__flag.iti__id{height:14px;background-position:-2325px 0px}.iti__flag.iti__ie{height:10px;background-position:-2347px 0px}.iti__flag.iti__il{height:15px;background-position:-2369px 0px}.iti__flag.iti__im{height:10px;background-position:-2391px 0px}.iti__flag.iti__in{height:14px;background-position:-2413px 0px}.iti__flag.iti__io{height:10px;background-position:-2435px 0px}.iti__flag.iti__iq{height:14px;background-position:-2457px 0px}.iti__flag.iti__ir{height:12px;background-position:-2479px 0px}.iti__flag.iti__is{height:15px;background-position:-2501px 0px}.iti__flag.iti__it{height:14px;background-position:-2523px 0px}.iti__flag.iti__je{height:12px;background-position:-2545px 0px}.iti__flag.iti__jm{height:10px;background-position:-2567px 0px}.iti__flag.iti__jo{height:10px;background-position:-2589px 0px}.iti__flag.iti__jp{height:14px;background-position:-2611px 0px}.iti__flag.iti__ke{height:14px;background-position:-2633px 0px}.iti__flag.iti__kg{height:12px;background-position:-2655px 0px}.iti__flag.iti__kh{height:13px;background-position:-2677px 0px}.iti__flag.iti__ki{height:10px;background-position:-2699px 0px}.iti__flag.iti__km{height:12px;background-position:-2721px 0px}.iti__flag.iti__kn{height:14px;background-position:-2743px 0px}.iti__flag.iti__kp{height:10px;background-position:-2765px 0px}.iti__flag.iti__kr{height:14px;background-position:-2787px 0px}.iti__flag.iti__kw{height:10px;background-position:-2809px 0px}.iti__flag.iti__ky{height:10px;background-position:-2831px 0px}.iti__flag.iti__kz{height:10px;background-position:-2853px 0px}.iti__flag.iti__la{height:14px;background-position:-2875px 0px}.iti__flag.iti__lb{height:14px;background-position:-2897px 0px}.iti__flag.iti__lc{height:10px;background-position:-2919px 0px}.iti__flag.iti__li{height:12px;background-position:-2941px 0px}.iti__flag.iti__lk{height:10px;background-position:-2963px 0px}.iti__flag.iti__lr{height:11px;background-position:-2985px 0px}.iti__flag.iti__ls{height:14px;background-position:-3007px 0px}.iti__flag.iti__lt{height:12px;background-position:-3029px 0px}.iti__flag.iti__lu{height:12px;background-position:-3051px 0px}.iti__flag.iti__lv{height:10px;background-position:-3073px 0px}.iti__flag.iti__ly{height:10px;background-position:-3095px 0px}.iti__flag.iti__ma{height:14px;background-position:-3117px 0px}.iti__flag.iti__mc{height:15px;background-position:-3139px 0px}.iti__flag.iti__md{height:10px;background-position:-3160px 0px}.iti__flag.iti__me{height:10px;background-position:-3182px 0px}.iti__flag.iti__mf{height:14px;background-position:-3204px 0px}.iti__flag.iti__mg{height:14px;background-position:-3226px 0px}.iti__flag.iti__mh{height:11px;background-position:-3248px 0px}.iti__flag.iti__mk{height:10px;background-position:-3270px 0px}.iti__flag.iti__ml{height:14px;background-position:-3292px 0px}.iti__flag.iti__mm{height:14px;background-position:-3314px 0px}.iti__flag.iti__mn{height:10px;background-position:-3336px 0px}.iti__flag.iti__mo{height:14px;background-position:-3358px 0px}.iti__flag.iti__mp{height:10px;background-position:-3380px 0px}.iti__flag.iti__mq{height:14px;background-position:-3402px 0px}.iti__flag.iti__mr{height:14px;background-position:-3424px 0px}.iti__flag.iti__ms{height:10px;background-position:-3446px 0px}.iti__flag.iti__mt{height:14px;background-position:-3468px 0px}.iti__flag.iti__mu{height:14px;background-position:-3490px 0px}.iti__flag.iti__mv{height:14px;background-position:-3512px 0px}.iti__flag.iti__mw{height:14px;background-position:-3534px 0px}.iti__flag.iti__mx{height:12px;background-position:-3556px 0px}.iti__flag.iti__my{height:10px;background-position:-3578px 0px}.iti__flag.iti__mz{height:14px;background-position:-3600px 0px}.iti__flag.iti__na{height:14px;background-position:-3622px 0px}.iti__flag.iti__nc{height:10px;background-position:-3644px 0px}.iti__flag.iti__ne{height:15px;background-position:-3666px 0px}.iti__flag.iti__nf{height:10px;background-position:-3686px 0px}.iti__flag.iti__ng{height:10px;background-position:-3708px 0px}.iti__flag.iti__ni{height:12px;background-position:-3730px 0px}.iti__flag.iti__nl{height:14px;background-position:-3752px 0px}.iti__flag.iti__no{height:15px;background-position:-3774px 0px}.iti__flag.iti__np{height:15px;background-position:-3796px 0px}.iti__flag.iti__nr{height:10px;background-position:-3811px 0px}.iti__flag.iti__nu{height:10px;background-position:-3833px 0px}.iti__flag.iti__nz{height:10px;background-position:-3855px 0px}.iti__flag.iti__om{height:10px;background-position:-3877px 0px}.iti__flag.iti__pa{height:14px;background-position:-3899px 0px}.iti__flag.iti__pe{height:14px;background-position:-3921px 0px}.iti__flag.iti__pf{height:14px;background-position:-3943px 0px}.iti__flag.iti__pg{height:15px;background-position:-3965px 0px}.iti__flag.iti__ph{height:10px;background-position:-3987px 0px}.iti__flag.iti__pk{height:14px;background-position:-4009px 0px}.iti__flag.iti__pl{height:13px;background-position:-4031px 0px}.iti__flag.iti__pm{height:14px;background-position:-4053px 0px}.iti__flag.iti__pn{height:10px;background-position:-4075px 0px}.iti__flag.iti__pr{height:14px;background-position:-4097px 0px}.iti__flag.iti__ps{height:10px;background-position:-4119px 0px}.iti__flag.iti__pt{height:14px;background-position:-4141px 0px}.iti__flag.iti__pw{height:13px;background-position:-4163px 0px}.iti__flag.iti__py{height:11px;background-position:-4185px 0px}.iti__flag.iti__qa{height:8px;background-position:-4207px 0px}.iti__flag.iti__re{height:14px;background-position:-4229px 0px}.iti__flag.iti__ro{height:14px;background-position:-4251px 0px}.iti__flag.iti__rs{height:14px;background-position:-4273px 0px}.iti__flag.iti__ru{height:14px;background-position:-4295px 0px}.iti__flag.iti__rw{height:14px;background-position:-4317px 0px}.iti__flag.iti__sa{height:14px;background-position:-4339px 0px}.iti__flag.iti__sb{height:10px;background-position:-4361px 0px}.iti__flag.iti__sc{height:10px;background-position:-4383px 0px}.iti__flag.iti__sd{height:10px;background-position:-4405px 0px}.iti__flag.iti__se{height:13px;background-position:-4427px 0px}.iti__flag.iti__sg{height:14px;background-position:-4449px 0px}.iti__flag.iti__sh{height:10px;background-position:-4471px 0px}.iti__flag.iti__si{height:10px;background-position:-4493px 0px}.iti__flag.iti__sj{height:15px;background-position:-4515px 0px}.iti__flag.iti__sk{height:14px;background-position:-4537px 0px}.iti__flag.iti__sl{height:14px;background-position:-4559px 0px}.iti__flag.iti__sm{height:15px;background-position:-4581px 0px}.iti__flag.iti__sn{height:14px;background-position:-4603px 0px}.iti__flag.iti__so{height:14px;background-position:-4625px 0px}.iti__flag.iti__sr{height:14px;background-position:-4647px 0px}.iti__flag.iti__ss{height:10px;background-position:-4669px 0px}.iti__flag.iti__st{height:10px;background-position:-4691px 0px}.iti__flag.iti__sv{height:12px;background-position:-4713px 0px}.iti__flag.iti__sx{height:14px;background-position:-4735px 0px}.iti__flag.iti__sy{height:14px;background-position:-4757px 0px}.iti__flag.iti__sz{height:14px;background-position:-4779px 0px}.iti__flag.iti__ta{height:10px;background-position:-4801px 0px}.iti__flag.iti__tc{height:10px;background-position:-4823px 0px}.iti__flag.iti__td{height:14px;background-position:-4845px 0px}.iti__flag.iti__tf{height:14px;background-position:-4867px 0px}.iti__flag.iti__tg{height:13px;background-position:-4889px 0px}.iti__flag.iti__th{height:14px;background-position:-4911px 0px}.iti__flag.iti__tj{height:10px;background-position:-4933px 0px}.iti__flag.iti__tk{height:10px;background-position:-4955px 0px}.iti__flag.iti__tl{height:10px;background-position:-4977px 0px}.iti__flag.iti__tm{height:14px;background-position:-4999px 0px}.iti__flag.iti__tn{height:14px;background-position:-5021px 0px}.iti__flag.iti__to{height:10px;background-position:-5043px 0px}.iti__flag.iti__tr{height:14px;background-position:-5065px 0px}.iti__flag.iti__tt{height:12px;background-position:-5087px 0px}.iti__flag.iti__tv{height:10px;background-position:-5109px 0px}.iti__flag.iti__tw{height:14px;background-position:-5131px 0px}.iti__flag.iti__tz{height:14px;background-position:-5153px 0px}.iti__flag.iti__ua{height:14px;background-position:-5175px 0px}.iti__flag.iti__ug{height:14px;background-position:-5197px 0px}.iti__flag.iti__um{height:11px;background-position:-5219px 0px}.iti__flag.iti__un{height:14px;background-position:-5241px 0px}.iti__flag.iti__us{height:11px;background-position:-5263px 0px}.iti__flag.iti__uy{height:14px;background-position:-5285px 0px}.iti__flag.iti__uz{height:10px;background-position:-5307px 0px}.iti__flag.iti__va{height:15px;background-position:-5329px 0px}.iti__flag.iti__vc{height:14px;background-position:-5346px 0px}.iti__flag.iti__ve{height:14px;background-position:-5368px 0px}.iti__flag.iti__vg{height:10px;background-position:-5390px 0px}.iti__flag.iti__vi{height:14px;background-position:-5412px 0px}.iti__flag.iti__vn{height:14px;background-position:-5434px 0px}.iti__flag.iti__vu{height:12px;background-position:-5456px 0px}.iti__flag.iti__wf{height:14px;background-position:-5478px 0px}.iti__flag.iti__ws{height:10px;background-position:-5500px 0px}.iti__flag.iti__xk{height:15px;background-position:-5522px 0px}.iti__flag.iti__ye{height:14px;background-position:-5544px 0px}.iti__flag.iti__yt{height:14px;background-position:-5566px 0px}.iti__flag.iti__za{height:14px;background-position:-5588px 0px}.iti__flag.iti__zm{height:14px;background-position:-5610px 0px}.iti__flag.iti__zw{height:10px;background-position:-5632px 0px}.iti__flag{height:15px;box-shadow:0px 0px 1px 0px #888;background-image:url(\"https://cdn.salla.network/images/flags.png\");background-repeat:no-repeat;background-color:#f5f7f9;background-position:20px 0}@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi){.iti__flag{background-image:url(\"https://cdn.salla.network/images/flags@2x.png\")}}.iti__flag.iti__np{background-color:transparent}";
245
+
246
+ const SallaLocalizationModal = class {
247
+ constructor(hostRef) {
248
+ registerInstance(this, hostRef);
249
+ var _a, _b;
250
+ this.translationLoaded = false;
251
+ this.languages = [];
252
+ this.currencies = [];
253
+ this.isLoading = true;
254
+ /**
255
+ * Current language (existing or newly selected)
256
+ */
257
+ this.language = salla.config.get('user.language_code');
258
+ /**
259
+ * Current currency (existing or newly selected)
260
+ */
261
+ this.currency = salla.config.get('user.currency_code');
262
+ Helper.setHost(this.host);
263
+ salla.event.on('localization::open', () => this.open());
264
+ salla.lang.onLoaded(() => {
265
+ this.translationLoaded = true;
266
+ });
267
+ /**
268
+ * letting developer to insert his own slot like:
269
+ * <salla-localization>
270
+ * <div slot="language">...{name}....</div>
271
+ * <div slot="currency">...{name}....</div>
272
+ * </salla-localization>
273
+ * Because scoped templates not supported in stencil );
274
+ * we made a workaround to pass language & currency attributes, then replace names in rendering
275
+ */
276
+ this.languageSlot = ((_a = Helper.getElement('[slot="language"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<label class="s-localization-modal-label" for="lang-{code}"><span>{name}</span><div class="s-localization-modal-flag flag iti__flag iti__{country_code}"></div></label>';
277
+ this.currencySlot = ((_b = Helper.getElement('[slot="currency"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || '<label class="s-localization-modal-label" for="currency-{code}"><span>{name}</span><small class="s-localization-modal-currency">{code}</small></label>';
278
+ }
279
+ /**
280
+ * open the component
281
+ */
282
+ async open() {
283
+ return await this.modal.open()
284
+ .then(() => this.getLanguages())
285
+ .then(() => this.getCurrencies())
286
+ .then(() => this.isLoading = false);
287
+ }
288
+ /**
289
+ * Hide the component
290
+ */
291
+ async close() {
292
+ return this.modal.close();
293
+ }
294
+ async getLanguages() {
295
+ this.language = this.language || salla.config.get('user.language_code');
296
+ return this.languages.length > 1 ? null : await salla.config.languages().then(data => this.languages = data);
297
+ }
298
+ async getCurrencies() {
299
+ this.currency = this.currency || salla.config.get('user.currency_code');
300
+ return this.currencies.length > 1 ? null : await salla.config.currencies().then(data => this.currencies = Object.values(data || {}));
301
+ }
302
+ onChangeCurrency(event) {
303
+ this.currency = event.target.value;
304
+ }
305
+ onChangeLanguage(event) {
306
+ this.language = event.target.value;
307
+ }
308
+ /**
309
+ * Change currency and language to the selected ones.
310
+ */
311
+ async submit() {
312
+ let url;
313
+ this.btn.load()
314
+ .then(() => {
315
+ if (!this.currency) {
316
+ salla.log('There is no currency!');
317
+ return;
318
+ }
319
+ if (this.currency === salla.config.get('user.currency_code', 'SAR')) {
320
+ return;
321
+ }
322
+ url = window.location.href;
323
+ return salla.currency.api.change(this.currency);
324
+ })
325
+ .then(() => this.language === salla.config.get('user.language_code', 'ar') || (url = salla.helpers.addParamToUrl('lang', this.language)))
326
+ .then(() => this.btn.stop())
327
+ .then(() => this.close())
328
+ .then(() => url && (window.location.href = url));
329
+ }
330
+ render() {
331
+ return (h("salla-modal", { isLoading: this.isLoading, class: "s-hidden", ref: modal => this.modal = modal, width: "xs" }, h("div", { slot: 'loading' }, h("div", { class: "s-localization-modal-skeleton" }, h("salla-skeleton", { width: '25%', height: '15px' }), h("div", { class: "s-localization-modal-skeleton-content" }, [...Array(4)].map(() => h("div", { class: "s-localization-modal-skeleton-item" }, h("div", { class: "s-localization-modal-skeleton-item-flex" }, h("salla-skeleton", { type: 'circle', height: '16px', width: '16px' }), h("salla-skeleton", { height: '10px', width: '100px' })), h("salla-skeleton", { height: '15px', width: '20px' })))), h("salla-skeleton", { width: '25%', height: '15px' }), h("div", { class: "s-localization-modal-skeleton-content" }, [...Array(4)].map(() => h("div", { class: "s-localization-modal-skeleton-item" }, h("div", { class: "s-localization-modal-skeleton-item-flex" }, h("salla-skeleton", { type: 'circle', height: '16px', width: '16px' }), h("salla-skeleton", { height: '10px', width: '100px' })), h("salla-skeleton", { height: '15px', width: '20px' })))), h("salla-skeleton", { height: '40px', width: '100%' }))), !this.isLoading ?
332
+ h("div", { class: "s-localization-modal-inner" }, this.languages.length > 1 ?
333
+ h("div", { class: "s-localization-modal-section" }, h("label", { class: "s-localization-modal-title" }, salla.lang.get('common.titles.language')), h("div", { class: "s-localization-modal-section-inner" }, this.languages.length < 6 ?
334
+ this.languages.map(lang => h("div", { class: "s-localization-modal-item" }, h("input", { class: "s-localization-modal-input", type: "radio", checked: this.language == lang.iso_code, onChange: () => this.language = lang.iso_code, name: "language", id: 'lang-' + lang.code.toLowerCase(), value: lang.code }), h("div", { class: "s-localization-modal-label-slot", id: "language-slot", innerHTML: this.languageSlot
335
+ .replace(/\{name\}/g, lang.name)
336
+ .replace(/\{code\}/g, lang.code)
337
+ .replace(/\{country_code\}/g, lang.country_code) }))) :
338
+ h("select", { class: "s-localization-modal-select", name: "language", onChange: e => this.onChangeLanguage(e) }, this.languages.map(lang => h("option", { value: lang.code, selected: this.language == lang.code }, lang.name)))))
339
+ : '', this.currencies.length > 1 ?
340
+ h("div", { class: "s-localization-modal-section" }, h("label", { class: "s-localization-modal-title" }, salla.lang.get('common.titles.currency')), h("div", { class: "s-localization-modal-section-inner" }, this.currencies.length < 6 ?
341
+ this.currencies.map(currency => h("div", { class: "s-localization-modal-item" }, h("input", { class: "s-localization-modal-input", type: "radio", name: "currency", checked: this.currency == currency.code, onChange: () => this.currency = currency.code, id: 'currency-' + currency.code, value: currency.code }), h("div", { class: "s-localization-modal-label-slot", id: "currency-slot", innerHTML: this.currencySlot
342
+ .replace(/\{name\}/g, currency.name)
343
+ .replace(/\{code\}/g, currency.code)
344
+ .replace(/\{country_code\}/g, currency.country_code) }))) :
345
+ h("select", { class: "s-localization-modal-select", name: "currency", onChange: e => this.onChangeCurrency(e) }, this.currencies.map(currency => h("option", { value: currency.code, selected: this.currency == currency.code }, currency.name)))))
346
+ : '', h("salla-button", { width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.ok')))
347
+ : ''));
348
+ }
349
+ /**
350
+ * to reduce dom levels we will move slot data into the parent dom
351
+ */
352
+ componentDidRender() {
353
+ this.host.querySelectorAll('#currency-slot').forEach(el => el.replaceWith(el.firstChild));
354
+ this.host.querySelectorAll('#language-slot').forEach(el => el.replaceWith(el.firstChild));
355
+ }
356
+ get host() { return getElement(this); }
357
+ };
358
+ SallaLocalizationModal.style = sallaLocalizationModalCss;
359
+
360
+ const UserIcon = `<!-- Generated by IcoMoon.io -->
361
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
362
+ <title>user</title>
363
+ <path d="M16 16c4.412 0 8-3.588 8-8s-3.588-8-8-8-8 3.588-8 8 3.588 8 8 8zM16 2.667c2.941 0 5.333 2.392 5.333 5.333s-2.392 5.333-5.333 5.333-5.333-2.392-5.333-5.333 2.392-5.333 5.333-5.333zM16 18.667c-7.476 0-13.333 3.66-13.333 8.333v3.667c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-3.667c0-3.019 4.984-5.667 10.667-5.667s10.667 2.648 10.667 5.667v3.667c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-3.667c0-4.673-5.857-8.333-13.333-8.333z"></path>
364
+ </svg>
365
+ `;
366
+
367
+ const PhoneIcon = `<!-- Generated by IcoMoon.io -->
368
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
369
+ <title>phone</title>
370
+ <path d="M30.823 21.713l-3.883-3.883c-1.569-1.568-4.12-1.568-5.689 0l-2.568 2.568c-3.063-1.499-5.583-4.019-7.081-7.083l2.568-2.567c0.759-0.76 1.177-1.771 1.177-2.845s-0.419-2.084-1.179-2.844l-3.881-3.881c-1.52-1.521-4.171-1.521-5.689 0l-1.845 1.847c-2.22 2.219-3.183 5.407-2.573 8.527 1.98 10.144 10.125 18.292 20.269 20.271 0.616 0.121 1.236 0.18 1.849 0.18 2.492 0 4.896-0.972 6.677-2.752l1.847-1.847c1.568-1.571 1.568-4.121 0.001-5.691zM28.936 25.517l-1.845 1.847c-1.592 1.592-3.883 2.283-6.132 1.841-9.089-1.776-16.388-9.075-18.163-18.165-0.439-2.247 0.249-4.539 1.841-6.129l1.847-1.847c0.256-0.257 0.596-0.397 0.959-0.397s0.703 0.14 0.959 0.397l3.883 3.883c0.256 0.256 0.397 0.596 0.397 0.959s-0.141 0.703-0.397 0.96l-3.22 3.217c-0.383 0.384-0.496 0.959-0.287 1.457 1.813 4.339 5.343 7.868 9.683 9.684 0.497 0.207 1.073 0.095 1.457-0.288l3.22-3.22c0.529-0.529 1.389-0.528 1.917 0l3.881 3.883c0.528 0.529 0.528 1.389 0 1.919z"></path>
371
+ </svg>
372
+ `;
373
+
374
+ const KeyboardArrowRightIcon = `<!-- Generated by IcoMoon.io -->
375
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
376
+ <title>keyboard_arrow_right</title>
377
+ <path d="M11.438 22.479l6.125-6.125-6.125-6.125 1.875-1.875 8 8-8 8z"></path>
378
+ </svg>
379
+ `;
380
+
381
+ const sallaLoginModalCss = "";
382
+
383
+ const SallaLoginModal = class {
384
+ constructor(hostRef) {
385
+ registerInstance(this, hostRef);
386
+ /**
387
+ * Does the merchant allow to login using email
388
+ */
389
+ this.isEmailAllowed = true;
390
+ /**
391
+ * Does the merchant/current location for visitor allow to login using mobile, By default outside KSA is `false`
392
+ */
393
+ this.isMobileAllowed = true;
394
+ /**
395
+ * Does the merchant require registration with email & mobile
396
+ */
397
+ this.isEmailRequired = false;
398
+ this.regType = 'phone';
399
+ this.translationLoaded = false;
400
+ this.typing = (e, submitMethod) => {
401
+ const error = e.target.nextElementSibling;
402
+ e.target.classList.remove('s-has-error');
403
+ (error === null || error === void 0 ? void 0 : error.classList.contains('s-login-modal-error-message')) && (error.innerText = '');
404
+ e.key == 'Enter' && submitMethod();
405
+ };
406
+ this.loginBySMS = async () => {
407
+ const { phone, countryCode } = await this.loginTelInput.getValues();
408
+ const isPhoneValid = await this.loginTelInput.isValid();
409
+ if (!isPhoneValid) {
410
+ return;
411
+ }
412
+ this.login(this.smsBtn, { type: 'mobile', phone: phone, country_code: countryCode });
413
+ };
414
+ this.loginByEmail = () => {
415
+ if (!Helper.isValidEmail(this.loginEmail.value)) {
416
+ this.validateField(this.loginEmail, this.emailErrorMsg);
417
+ return;
418
+ }
419
+ this.login(this.emailBtn, { type: 'email', email: this.loginEmail.value });
420
+ };
421
+ this.newUser = async () => {
422
+ var _a;
423
+ const { phone: regPhone, countryCode } = this.regType == "email" ? await this.regTelInput.getValues() : await this.loginTelInput.getValues(), emailValue = this.regEmail.value || ((_a = this.loginEmail) === null || _a === void 0 ? void 0 : _a.value);
424
+ await this.newUserValidation();
425
+ await this.regBtn.load();
426
+ await this.regBtn.disable();
427
+ let data = {
428
+ first_name: this.firstName.value,
429
+ last_name: this.lastName.value,
430
+ phone: regPhone || this.loginTelInput.phone,
431
+ country_code: countryCode,
432
+ verified_by: this.regType,
433
+ };
434
+ emailValue && (data = Object.assign(Object.assign({}, data), { email: emailValue }));
435
+ this.verifyTab.getCode()
436
+ .then(code => salla.auth.api.register(Object.assign(Object.assign({}, data), { code })))
437
+ .then(() => salla.auth.canRedirect && window.location.reload())
438
+ .catch((error) => {
439
+ salla.logger.error(error);
440
+ this.regBtn.stop() && this.regBtn.enable();
441
+ });
442
+ };
443
+ this.title = this.host.title || salla.lang.get('blocks.header.login');
444
+ this.host.removeAttribute('title');
445
+ this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
446
+ this.firstNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.first_name') });
447
+ this.lastNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.last_name') });
448
+ salla.lang.onLoaded(() => {
449
+ this.translationLoaded = true;
450
+ this.title = salla.lang.get('blocks.header.login');
451
+ this.updateTranslations();
452
+ });
453
+ salla.event.on('login::open', (event) => this.open(event));
454
+ salla.event.on('twilight::initiated', () => {
455
+ this.isEmailAllowed = salla.config.get('store.settings.auth.email_allowed', this.isEmailAllowed);
456
+ this.isMobileAllowed = salla.config.get('store.settings.auth.mobile_allowed', this.isMobileAllowed);
457
+ this.isEmailRequired = salla.config.get('store.settings.auth.is_email_required', this.isEmailRequired);
458
+ });
459
+ }
460
+ /**
461
+ * @param {CustomEvent|{details:{case:'new_customer'|'authenticated', redirect_url:string|null}}} event
462
+ */
463
+ onVerified(event) {
464
+ var _a, _b;
465
+ salla.log('verified', event);
466
+ //there is a case when force login is activated & is new user, it will return case inside error key., so cover it.
467
+ let verifyCase = ((_a = event.detail) === null || _a === void 0 ? void 0 : _a.data.case) || ((_b = event.detail) === null || _b === void 0 ? void 0 : _b.error.case);
468
+ if (!verifyCase) {
469
+ salla.log('verified but without case!');
470
+ return;
471
+ }
472
+ if (verifyCase === "new_customer") {
473
+ return this.showTab(this.registrationTab);
474
+ }
475
+ if (!salla.auth.canRedirect()) {
476
+ salla.log('Will not auto redirect or reload, due to `salla.auth.canRedirect()`');
477
+ return;
478
+ }
479
+ if (event.detail.data.redirect_url) {
480
+ return window.location.href = event.detail.data.redirect_url;
481
+ }
482
+ window.location.reload();
483
+ }
484
+ updateTranslations() {
485
+ var _a;
486
+ this.emailErrorMsg = salla.lang.get('common.elements.email_is_valid');
487
+ this.firstNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.first_name') });
488
+ this.lastNameErrorMsg = salla.lang.get('common.errors.field_required', { attribute: salla.lang.get('pages.profile.last_name') });
489
+ (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
490
+ }
491
+ /**
492
+ * Open login component
493
+ */
494
+ // @ts-ignore
495
+ async open(event = null) {
496
+ // todo :: support change the settings from event details
497
+ // if(event && event.hasOwnProperty('isEmailAllowed')){
498
+ // this.isEmailAllowed = event?.isEmailAllowed;
499
+ // }
500
+ //
501
+ // if(event && event.hasOwnProperty('isMobileAllowed')){
502
+ // this.isMobileAllowed = event?.isMobileAllowed;
503
+ // }
504
+ if (this.isEmailAllowed && this.isMobileAllowed) {
505
+ this.showTab(this.homeTab);
506
+ }
507
+ else if (this.isEmailAllowed) {
508
+ this.showTab(this.emailTab);
509
+ }
510
+ else if (this.isMobileAllowed) {
511
+ this.showTab(this.mobileTab);
512
+ }
513
+ return this.modal.open();
514
+ }
515
+ showTab(tab, evt) {
516
+ var _a;
517
+ evt === null || evt === void 0 ? void 0 : evt.preventDefault();
518
+ let tabs = [this.homeTab, this.mobileTab, this.emailTab, this.verifyTab, this.registrationTab];
519
+ tabs.map(el => Helper.toggleElementClassIf(el, 'visible', 's-hidden', () => el == tab));
520
+ setTimeout(() => tabs.map(el => Helper.toggleElementClassIf(el, 's-login-modal-active', 's-login-modal-unactive', () => el == tab)), 200);
521
+ //we should have only one salla-login, so it's okay to get it from document
522
+ //todo:: use better way for resize the modal
523
+ setTimeout(() => { var _a; return (_a = this.modal.querySelector('.s-login-modal-wrapper')) === null || _a === void 0 ? void 0 : _a.setAttribute('style', 'height:' + (tab === null || tab === void 0 ? void 0 : tab.scrollHeight) + 'px'); });
524
+ if ([this.mobileTab, this.emailTab].includes(tab)) {
525
+ this.regType = tab === this.mobileTab ? 'phone' : 'email';
526
+ }
527
+ let isRegistrationTab = tab == this.registrationTab;
528
+ // focus the first input in tab
529
+ // tab.querySelector('input')?.focus();
530
+ (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(isRegistrationTab ? salla.lang.get('common.titles.registration') : this.title);
531
+ if (!isRegistrationTab) {
532
+ Helper.toggleElementClassIf(this.regMobileBlock, 's-hidden', 's-show', () => this.regType === 'phone')
533
+ .toggleElementClassIf(this.regEmailBlock, 's-hidden', 's-show', () => this.regType === 'email');
534
+ }
535
+ return this;
536
+ }
537
+ login(btn, data) {
538
+ btn.load()
539
+ .then(() => btn.disable())
540
+ .then(() => salla.auth.api.login(data))
541
+ .then(() => this.showTab(this.verifyTab))
542
+ .then(() => this.verifyTab.open(data))
543
+ .finally(() => btn.stop() && btn.enable());
544
+ }
545
+ async newUserValidation() {
546
+ const isLogByPhone = this.regType == "phone", isLogByEmail = this.regType == "email", emailValue = this.regEmail.value || (isLogByEmail && this.loginEmail.value), isEmailValid = Helper.isValidEmail(emailValue), isFirstNameValid = this.firstName.value.length > 0, isLastNameValid = this.lastName.value.length > 0, isPhoneValid = await this.regTelInput.isValid() || isLogByPhone && await this.loginTelInput.isValid(), emailValidation = (emailValue && isEmailValid) || (!emailValue && !this.isEmailRequired);
547
+ if (emailValidation && isPhoneValid && isFirstNameValid && isLastNameValid)
548
+ return;
549
+ !isEmailValid && this.validateField(this.regEmail, this.emailErrorMsg);
550
+ !isFirstNameValid && this.validateField(this.firstName, this.firstNameErrorMsg);
551
+ !isLastNameValid && this.validateField(this.lastName, this.lastNameErrorMsg);
552
+ throw ('Please insert required fields');
553
+ }
554
+ // eslint-disable-next-line @stencil/own-methods-must-be-private
555
+ validateField(field, errorMsg) {
556
+ field.classList.add('s-has-error');
557
+ field.nextElementSibling['innerText'] = '* ' + errorMsg;
558
+ }
559
+ render() {
560
+ return (h("salla-modal", { class: "s-login-modal", "modal-title": this.title, ref: modal => this.modal = modal, width: "xs" }, h("span", { slot: 'icon', class: "s-login-modal-header-icon", innerHTML: UserIcon }), h("div", { class: "s-login-modal-wrapper" }, this.isEmailAllowed && this.isMobileAllowed ?
561
+ h("div", { class: "s-login-modal-tab", ref: tab => this.homeTab = tab }, h("p", { class: "s-login-modal-sub-title" }, salla.lang.get('blocks.header.select_login_way')), h("slot", { name: "before-login-type" }), h("a", { href: "#", class: "s-login-modal-main-btn", onClick: (evt) => this.showTab(this.mobileTab, evt) }, h("span", { class: "s-login-modal-main-btn-icon", innerHTML: PhoneIcon }), h("span", { class: "s-login-modal-main-btn-text" }, salla.lang.get('blocks.header.sms')), h("span", { class: "s-login-modal-main-btn-arrow", innerHTML: KeyboardArrowRightIcon })), h("a", { href: "#", class: "s-login-modal-main-btn", onClick: (evt) => this.showTab(this.emailTab, evt) }, h("span", { class: "s-login-modal-main-btn-icon", innerHTML: email }), h("span", { class: "s-login-modal-main-btn-text" }, salla.lang.get('common.elements.email')), h("span", { class: "s-login-modal-main-btn-arrow", innerHTML: KeyboardArrowRightIcon })), h("slot", { name: "after-login-type" }))
562
+ : '', this.isMobileAllowed ?
563
+ h("div", { class: "s-login-modal-tab", ref: tab => this.mobileTab = tab }, h("slot", { name: "before-login-mobile" }), h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.mobile')), h("salla-tel-input", { ref: el => this.loginTelInput = el, onKeyDown: e => this.typing(e, this.loginBySMS) }), h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.loginBySMS(), ref: b => this.smsBtn = b }, salla.lang.get('blocks.header.enter')), this.isEmailAllowed ?
564
+ h("a", { href: "#", onClick: () => this.showTab(this.emailTab), class: "s-login-modal-link" }, salla.lang.get('blocks.header.login_by_email')) : '', h("slot", { name: "after-login-mobile" })) : '', this.isEmailAllowed ?
565
+ h("div", { class: "s-login-modal-tab", ref: tab => this.emailTab = tab }, h("slot", { name: "before-login-email" }), h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.email')), h("input", { type: "email", ref: el => this.loginEmail = el, onKeyDown: e => this.typing(e, this.loginByEmail), placeholder: "your@email.com", class: "s-login-modal-input s-ltr" }), h("span", { class: "s-login-modal-error-message" }), h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.loginByEmail(), ref: b => this.emailBtn = b }, salla.lang.get('blocks.header.enter')), this.isMobileAllowed ?
566
+ h("a", { href: "#", onClick: () => this.showTab(this.mobileTab), class: "s-login-modal-link" }, salla.lang.get('blocks.header.login_by_sms'))
567
+ : '', h("slot", { name: "after-login-email" })) : '', h("salla-verify", { display: "inline", ref: tab => this.verifyTab = tab, autoReload: false }, h("a", { onClick: () => this.showTab(this.regType == 'phone' ? this.mobileTab : this.emailTab), class: "s-verify-back", innerHTML: ArrowRightIcon, slot: "after-footer", href: "#" })), h("div", { ref: tab => this.registrationTab = tab }, h("slot", { name: "before-registration" }), h("div", null, h("label", { class: "s-login-modal-label" }, salla.lang.get('blocks.header.your_name')), h("input", { type: "text", class: "s-login-modal-input", ref: el => this.firstName = el, onKeyDown: e => this.typing(e, this.newUser), placeholder: salla.lang.get('pages.profile.first_name') }), h("span", { class: "s-login-modal-error-message" })), h("div", null, h("label", { class: "s-login-modal-label" }, salla.lang.get('pages.profile.last_name')), h("input", { type: "text", class: "s-login-modal-input", ref: el => this.lastName = el, onKeyDown: e => this.typing(e, this.newUser), placeholder: salla.lang.get('pages.profile.last_name') }), h("span", { class: "s-login-modal-error-message" })), h("div", { ref: el => this.regMobileBlock = el, class: "mb-1.5" }, h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.mobile')), h("salla-tel-input", { ref: el => this.regTelInput = el, onKeyDown: e => this.typing(e, this.newUser) })), h("div", { ref: el => this.regEmailBlock = el, class: "mb-1.5" }, h("label", { class: "s-login-modal-label" }, salla.lang.get('common.elements.email')), h("input", { type: "email", ref: el => this.regEmail = el, onKeyDown: e => this.typing(e, this.newUser), placeholder: "your@email.com", class: "s-login-modal-input s-ltr" }), h("span", { class: "s-login-modal-error-message" })), h("salla-button", { "loader-position": 'center', width: "wide", onClick: () => this.newUser(), ref: b => this.regBtn = b }, salla.lang.get('blocks.header.register')), h("slot", { name: "after-registration" })))));
568
+ }
569
+ get host() { return getElement(this); }
570
+ };
571
+ SallaLoginModal.style = sallaLoginModalCss;
572
+
573
+ const AlertEngineIcon = `<!-- Generated by IcoMoon.io -->
574
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
575
+ <title>alert-engine</title>
576
+ <path d="M16 18.673c-0.736 0-1.333 0.604-1.333 1.34s0.597 1.333 1.333 1.333 1.333-0.597 1.333-1.333v-0.013c0-0.736-0.597-1.327-1.333-1.327zM2.667 16c0-3.092 1.083-6.105 3.047-8.484 0.469-0.568 0.389-1.408-0.179-1.877-0.568-0.468-1.408-0.388-1.877 0.179-2.359 2.857-3.657 6.473-3.657 10.183s1.299 7.325 3.657 10.183c0.264 0.319 0.645 0.484 1.029 0.484 0.299 0 0.6-0.1 0.848-0.305 0.568-0.469 0.648-1.309 0.179-1.877-1.964-2.379-3.047-5.392-3.047-8.484zM16 10.667c-0.736 0-1.333 0.597-1.333 1.333v4c0 0.736 0.597 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-4c0-0.736-0.597-1.333-1.333-1.333zM16 5.333c-5.881 0-10.667 4.785-10.667 10.667s4.785 10.667 10.667 10.667 10.667-4.785 10.667-10.667-4.785-10.667-10.667-10.667zM16 24c-4.412 0-8-3.588-8-8s3.588-8 8-8 8 3.588 8 8-3.588 8-8 8zM28.343 5.817c-0.469-0.567-1.307-0.647-1.877-0.179-0.568 0.469-0.648 1.309-0.179 1.877 1.964 2.379 3.047 5.392 3.047 8.484s-1.083 6.105-3.047 8.484c-0.469 0.568-0.389 1.408 0.179 1.877 0.249 0.205 0.549 0.305 0.848 0.305 0.384 0 0.765-0.165 1.028-0.484 2.36-2.857 3.659-6.473 3.659-10.183s-1.299-7.325-3.657-10.183z"></path>
577
+ </svg>
578
+ `;
579
+
580
+ const sallaModalCss = "";
581
+
582
+ const SallaModal = class {
583
+ constructor(hostRef) {
584
+ registerInstance(this, hostRef);
585
+ /**
586
+ * Sets the modal to be closable. Defaults to `true`
587
+ */
588
+ this.isClosable = true; //todo::rename unclude. Suggestion => persistent
589
+ /**
590
+ * The size of the modal
591
+ */
592
+ this.width = 'md';
593
+ /**
594
+ * The position of the modal
595
+ */
596
+ this.position = 'middle';
597
+ /**
598
+ * open the modal on rendering
599
+ */
600
+ this.visible = false;
601
+ /**
602
+ * open the modal on rendering
603
+ */
604
+ this.hasSkeleton = false;
605
+ /**
606
+ * Show loading in the middle
607
+ */
608
+ this.isLoading = false;
609
+ /**
610
+ * Show subtitle before the title or not, defaults to `false` (after the title)
611
+ */
612
+ this.subTitleFirst = false; //todo:: choose better name
613
+ /**
614
+ * Avoid padding in the modal body or not, defaults to `false`
615
+ */
616
+ this.noPadding = false; //todo:: choose better name
617
+ /**
618
+ * Set modal sub title.
619
+ */
620
+ this.subTitle = '';
621
+ /**
622
+ * Align modal content to center, defaults to `false`
623
+ */
624
+ this.centered = false;
625
+ /**
626
+ * Set the style of the header icon.
627
+ */
628
+ this.iconStyle = undefined;
629
+ Helper.setHost(this.host);
630
+ salla.event.on('modal::open', target => target == this.host.id && this.open());
631
+ salla.event.on('modal::close', target => target == this.host.id && this.close());
632
+ this.modalTitle = this.host.getAttribute('modal-title');
633
+ // close modal on Escape button clicked
634
+ Helper.onKeyUp(document.body, e => e.keyCode === 27 && this.closeModal());
635
+ }
636
+ handleVisible(newValue) {
637
+ if (!newValue) {
638
+ salla.event.dispatch('modalClosed');
639
+ this.toggleModal(false);
640
+ return;
641
+ }
642
+ salla.event.dispatch('modalOpened');
643
+ this.host.classList.remove('s-hidden');
644
+ setTimeout(() => this.toggleModal(true)); //small amont of time to running toggle After adding hidden
645
+ }
646
+ /**
647
+ * Open the modal
648
+ */
649
+ async open() {
650
+ this.host.setAttribute('visible', '');
651
+ return this.host;
652
+ }
653
+ /**
654
+ * close the modal
655
+ */
656
+ async close() {
657
+ this.host.removeAttribute('visible');
658
+ return this.host;
659
+ }
660
+ /**
661
+ * Change the Modal Title
662
+ * @param {string} modalTitle
663
+ */
664
+ async setTitle(modalTitle) {
665
+ this.modalTitle = modalTitle;
666
+ return this.host;
667
+ }
668
+ /**
669
+ * Start loading
670
+ */
671
+ async loading() {
672
+ this.isLoading = true;
673
+ return this.host;
674
+ }
675
+ /**
676
+ * Stop the loading
677
+ */
678
+ async stopLoading() {
679
+ this.isLoading = false;
680
+ return this.host;
681
+ }
682
+ toggleModal(isOpen) {
683
+ const body = this.host.querySelector('.s-modal-body');
684
+ Helper.toggleElementClassIf(body, 's-modal-entering', 's-modal-leaving', () => isOpen)
685
+ .toggleElementClassIf(this.overlay, 's-modal-entering', 's-modal-overlay-leaving', () => isOpen)
686
+ .toggleElementClassIf(document.body, 'modal-is-open', 'modal-is-closed', () => isOpen);
687
+ if (!isOpen) {
688
+ setTimeout(() => this.host.classList.add('s-hidden'), 350);
689
+ }
690
+ }
691
+ closeModal() {
692
+ if (!this.isClosable) {
693
+ return;
694
+ }
695
+ this.host.removeAttribute('visible');
696
+ }
697
+ iconBlockClasses() {
698
+ return {
699
+ 's-modal-icon': true,
700
+ 's-modal-bg-error': this.iconStyle == 'error',
701
+ 's-modal-bg-success': this.iconStyle == 'success',
702
+ 's-modal-bg-normal': !this.iconStyle,
703
+ 's-modal-bg-primary': this.iconStyle == 'primary'
704
+ };
705
+ }
706
+ getWidth() {
707
+ return this.isLoading ? (this.hasSkeleton ? 'md' : 'xs') : this.width;
708
+ }
709
+ //todo:: pref for each modal
710
+ render() {
711
+ this.host.id = this.host.id || 'salla-modal';
712
+ if (this.isLoading) {
713
+ return (h(Host, { class: 'salla-modal s-modal s-modal-container s-hidden', "aria-modal": "true", role: "dialog" }, h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), h("div", { class: "s-modal-wrapper" }, h("span", { class: 's-modal-spacer s-modal-align-' + this.position }, "\u200B"), h("div", { class: 's-modal-body ' + 's-modal-align-' + this.position + ' s-modal-' + this.getWidth() + (this.noPadding ? ' s-modal-nopadding' : ' s-modal-padding') }, h("slot", { name: "loading" }, h("salla-loading", null)), h("div", { class: "s-hidden" }, h("slot", null))))));
714
+ }
715
+ return (h(Host, { class: 'salla-modal s-modal s-modal-container s-hidden', "aria-modal": "true", role: "dialog" }, h("div", { class: "s-modal-overlay", ref: el => this.overlay = el, onClick: () => this.closeModal() }), h("div", { class: "s-modal-wrapper" }, h("span", { class: 's-modal-spacer s-modal-align-' + this.position }, "\u200B"), h("div", { class: 's-modal-body ' + 's-modal-align-' + this.position + ' s-modal-' + this.getWidth() + (this.noPadding ? ' s-modal-nopadding' : ' s-modal-padding') }, h("div", { class: { 's-modal-header': true, 's-modal-is-center': this.centered } }, this.isClosable ?
716
+ h("button", { class: "s-modal-close", onClick: () => this.closeModal(), type: "button" }, h("span", { innerHTML: Cancel }))
717
+ : '', this.modalTitle || this.subTitle ?
718
+ h("div", { class: "s-modal-header-inner" }, h("slot", { name: 'icon' }, !!this.iconStyle ?
719
+ h("div", { class: this.iconBlockClasses(), innerHTML: this.iconStyle == 'error' ? AlertEngineIcon : CheckCircle2 })
720
+ : ''), h("div", { class: "s-modal-header-content" }, h("div", { class: { 's-modal-title': true, 's-modal-title-below': this.subTitleFirst }, innerHTML: this.modalTitle }), h("p", { class: { 's-modal-sub-title': true }, innerHTML: this.subTitle })))
721
+ : ""), h("slot", null), h("slot", { name: "footer" })))));
722
+ }
723
+ //move the modal as root dom, because we need the model to be outside the forms
724
+ componentDidLoad() {
725
+ document.body.append(this.host);
726
+ }
727
+ get host() { return getElement(this); }
728
+ static get watchers() { return {
729
+ "visible": ["handleVisible"]
730
+ }; }
731
+ };
732
+ SallaModal.style = sallaModalCss;
733
+
734
+ const SpecialDiscountIcon = `<!-- Generated by IcoMoon.io -->
735
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
736
+ <title>special-discount</title>
737
+ <path d="M20.667 19.333c-0.737 0-1.333 0.596-1.333 1.333v0.013c0 0.737 0.596 1.327 1.333 1.327s1.333-0.603 1.333-1.34-0.596-1.333-1.333-1.333zM11.333 12.673c0.737 0 1.333-0.603 1.333-1.34s-0.596-1.333-1.333-1.333-1.333 0.596-1.333 1.333v0.013c0 0.736 0.596 1.327 1.333 1.327zM30.307 16l0.947-4.244c0.107-0.473-0.055-0.969-0.417-1.291l-3.259-2.876-1.732-3.987c-0.193-0.444-0.612-0.749-1.095-0.796l-4.327-0.417-3.748-2.204c-0.416-0.248-0.933-0.248-1.353 0l-3.744 2.204-4.329 0.417c-0.483 0.047-0.901 0.352-1.095 0.796l-1.732 3.987-3.259 2.877c-0.363 0.321-0.525 0.816-0.417 1.289l0.947 4.244-0.947 4.244c-0.107 0.473 0.055 0.969 0.417 1.291l3.259 2.876 1.732 3.987c0.193 0.444 0.612 0.749 1.095 0.796l4.325 0.416 3.749 2.207c0.208 0.123 0.441 0.184 0.676 0.184s0.468-0.061 0.676-0.185l3.747-2.205 4.328-0.416c0.483-0.045 0.903-0.351 1.095-0.796l1.732-3.985 3.259-2.877c0.363-0.321 0.525-0.816 0.417-1.291zM28.48 20.056l-2.892 2.552c-0.145 0.131-0.261 0.291-0.34 0.469l-1.536 3.536-3.84 0.369c-0.195 0.019-0.381 0.080-0.551 0.179l-3.321 1.959-3.324-1.959c-0.168-0.099-0.356-0.16-0.549-0.179l-3.839-0.369-1.536-3.537c-0.077-0.18-0.195-0.339-0.34-0.469l-2.892-2.551 0.84-3.765c0.043-0.192 0.043-0.389 0-0.581l-0.84-3.765 2.892-2.551c0.145-0.131 0.263-0.289 0.34-0.469l1.536-3.539 3.84-0.369c0.195-0.019 0.381-0.080 0.549-0.179l3.323-1.957 3.325 1.957c0.167 0.099 0.355 0.16 0.548 0.179l3.839 0.369 1.536 3.539c0.077 0.18 0.195 0.339 0.34 0.469l2.892 2.551-0.84 3.765c-0.043 0.192-0.043 0.389 0 0.581zM20.391 9.724l-10.667 10.667c-0.521 0.521-0.521 1.364 0 1.885 0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391l10.667-10.667c0.521-0.521 0.521-1.364 0-1.885s-1.364-0.521-1.885 0z"></path>
738
+ </svg>
739
+ `;
740
+
741
+ const KeyboardArrowLeftIcon = `<!-- Generated by IcoMoon.io -->
742
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
743
+ <title>keyboard_arrow_left</title>
744
+ <path d="M20.563 22.104l-1.875 1.875-8-8 8-8 1.875 1.875-6.125 6.125z"></path>
745
+ </svg>
746
+ `;
747
+
748
+ const Tag = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
749
+ <title>tag</title>
750
+ <path d="M28 0h-9.344c-1.059 0-2.056 0.411-2.809 1.153l-14.673 14.456c-1.56 1.56-1.561 4.097-0.001 5.657l9.56 9.56c0.755 0.755 1.76 1.172 2.828 1.173h0.003c1.068 0 2.072-0.416 2.833-1.179l14.451-14.668c0.743-0.753 1.153-1.751 1.153-2.809v-9.344c0-2.205-1.795-4-4-4zM29.333 13.344c0 0.353-0.137 0.685-0.385 0.937l-14.444 14.661c-0.252 0.252-0.587 0.391-0.941 0.391-0.001 0-0.001 0-0.001 0-0.356-0.001-0.691-0.139-0.943-0.392l-9.561-9.56c-0.52-0.52-0.52-1.365-0.005-1.88l14.667-14.449c0.253-0.248 0.585-0.385 0.937-0.385h9.344c0.736 0 1.333 0.597 1.333 1.333zM24 6.673c-0.737 0-1.333 0.604-1.333 1.341s0.596 1.333 1.333 1.333 1.333-0.596 1.333-1.333v-0.015c0-0.737-0.596-1.327-1.333-1.327z"></path>
751
+ </svg>
752
+ `;
753
+
754
+ const sallaOfferModalCss = "";
755
+
756
+ const SallaOfferModal = class {
757
+ constructor(hostRef) {
758
+ registerInstance(this, hostRef);
759
+ var _a, _b;
760
+ this.offer = null;
761
+ this.translationLoaded = false;
762
+ Helper.setHost(this.host);
763
+ salla.lang.onLoaded(() => {
764
+ this.translationLoaded = true;
765
+ });
766
+ this.categorySlot = ((_a = Helper.getElement('[slot="category"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || `<span class="s-offer-modal-badge-icon">{tagIcon}</span><span class="s-offer-modal-badge-text">{name}</span>`;
767
+ this.productSlot = ((_b = Helper.getElement('[slot="product"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || this.defaultProductSlot();
768
+ salla.product.event.onOfferExisted(offer => {
769
+ if (salla.storage.get('remember-offer-' + offer.id)) {
770
+ salla.log('User selected to don\'t show this offer again.');
771
+ return;
772
+ }
773
+ this.open(offer.product_id);
774
+ });
775
+ }
776
+ /**
777
+ * Show the available offers for the product
778
+ * @param product_id
779
+ */
780
+ async open(product_id) {
781
+ //TODO:: make sure there is only one offer
782
+ return salla.product.offers(product_id)
783
+ .then(response => this.showOffer(response.data[0]));
784
+ }
785
+ /**
786
+ * Show offer details
787
+ * @param {Offer} offer
788
+ */
789
+ async showOffer(offer) {
790
+ this.offer = offer;
791
+ this.offer_name = offer.name;
792
+ this.offer_message = offer.message;
793
+ this.modal.setTitle(this.offer_name);
794
+ return this.modal.open();
795
+ }
796
+ rememberMe(event) {
797
+ salla.storage.set('remember-offer-' + this.offer.id, event.target.checked);
798
+ }
799
+ //todo:: pass event then use sallaButton from it
800
+ addItem() {
801
+ // this here, is sallaButton
802
+ this['load']();
803
+ return salla.cart.api
804
+ .quickAdd(this['dataset'].id)
805
+ .finally(() => this['stop']());
806
+ }
807
+ defaultProductSlot() {
808
+ return '<a href={url} class="s-offer-modal-product-image-wrap"><img class="s-offer-modal-product-image" src="{image}" /></a>' +
809
+ '<div class="s-offer-modal-product-info">' +
810
+ ' <a href={url} class="s-offer-modal-product-name">{name}</a>' +
811
+ ' <div class="s-offer-modal-product-price">{price}</div>' +
812
+ '</div>';
813
+ }
814
+ render() {
815
+ var _a, _b;
816
+ return h("salla-modal", { "sub-title-first": true, "sub-title": this.offer_message, ref: modal => this.modal = modal, "is-loading": this.offer === null }, h("span", { slot: 'icon', class: "s-offer-modal-header-icon", innerHTML: SpecialDiscountIcon }), this.offer !== null
817
+ ? [h("div", { class: "s-offer-modal-scrolled-slider-wrap" }, h("div", { class: "s-offer-modal-body s-offer-modal-scrolled-slider" }, ((_a = this.offer.get.categories) === null || _a === void 0 ? void 0 : _a.length) > 0
818
+ ? this.offer.get.categories.map(category => h("a", { href: category.urls.customer, class: "s-offer-modal-badge s-offer-modal-slider-item", innerHTML: this.categorySlot
819
+ .replace(/\{tagIcon\}/g, Tag)
820
+ .replace(/\{name\}/g, category.name)
821
+ .replace(/\{url\}/g, category.urls.customer) }))
822
+ : (_b = this.offer.get.products) === null || _b === void 0 ? void 0 : _b.map(product => h("div", { class: { "s-offer-modal-product": true, "s-offer-modal-slider-item": true, "s-offer-modal-not-available": !product.is_available }, id: 'product_' + product.id, innerHTML: this.productSlot
823
+ .replace(/\{name\}/g, product.name)
824
+ .replace(/\{url\}/g, product.url)
825
+ .replace(/\{image\}/g, product.thumbnail)
826
+ .replace(/\{price\}/g, product.has_special_price
827
+ ? salla.money(product.price) + '<span class="s-offer-modal-product-old-price">' + salla.money(product.regular_price) + '</span>'
828
+ : salla.money(product.price)) }, h("div", { class: "s-offer-modal-btn-wrap" }, h("salla-button", { width: "wide", fill: 'outline', "data-id": product.id, disabled: !product.is_available, "loader-position": "center", onClick: this.addItem }, product.is_available ? salla.lang.get('pages.cart.add_to_cart') : salla.lang.get('pages.products.out_of_stock')))))), h("div", { class: "s-offer-modal-slider-nav" }, h("button", { class: "s-offer-modal-nav-btn s-offer-modal-prev-btn" }, h("span", { class: "s-offer-modal-nav-btn-icon", innerHTML: KeyboardArrowLeftIcon })), h("button", { class: "s-offer-modal-nav-btn s-offer-modal-next-btn" }, h("span", { class: "s-offer-modal-nav-btn-icon", innerHTML: KeyboardArrowRightIcon })))), h("div", { class: "s-offer-modal-footer", slot: "footer" }, this.offer.formatted_date ?
829
+ h("p", { class: "s-offer-modal-expiry" }, salla.lang.get('pages.products.offer_expires_in'), " ", this.offer.formatted_date)
830
+ : '', h("label", { class: "s-offer-modal-remember-label" }, h("input", { type: "checkbox", onChange: e => this.rememberMe(e), class: "s-offer-modal-remember-input" }), "\u00A0 ", salla.lang.get('common.elements.remember_my_choice'))),
831
+ ] : '');
832
+ }
833
+ componentDidRender() {
834
+ // Sooo mini Slider
835
+ if (this.offer && window.screen.width > 639) {
836
+ let sliderWrap = this.modal.querySelector('.s-offer-modal-scrolled-slider-wrap'), slider = this.modal.querySelector('.s-offer-modal-scrolled-slider'), navButtons = this.modal.querySelectorAll('.s-offer-modal-nav-btn'), nexBtn = this.modal.querySelector('.s-offer-modal-next-btn'), prevBtn = this.modal.querySelector('.s-offer-modal-prev-btn'), items = this.modal.querySelectorAll('.s-offer-modal-slider-item'), sliderNavMargin = 20, // space before displaying the next/prev btns.
837
+ current = 0, // current slide
838
+ slidesToScroll = 3, itemsLength = items.length;
839
+ console.log('items[0]:', items[0]);
840
+ let itemSize = items[0].offsetWidth, sliderSize = itemsLength * itemSize, sliderWrapperSize = sliderWrap.offsetWidth, sliderInvisibleSize = sliderSize - sliderWrapperSize, isRTL = document.body.classList.contains('rtl') ? true : false;
841
+ if (sliderInvisibleSize > sliderNavMargin)
842
+ nexBtn.classList.add('s-offer-modal-btn-is-active');
843
+ window.onresize = function () {
844
+ sliderWrapperSize = sliderWrap.offsetWidth;
845
+ sliderInvisibleSize = sliderSize - sliderWrapperSize;
846
+ };
847
+ slider.addEventListener('scroll', function () {
848
+ let sliderPosition = Math.abs(slider.scrollLeft);
849
+ let sliderEndOffset = sliderInvisibleSize - sliderNavMargin;
850
+ // show & hide the navigation btns depending on scroll position
851
+ if (sliderPosition <= sliderNavMargin) {
852
+ nexBtn.classList.add('s-offer-modal-btn-is-active');
853
+ prevBtn.classList.remove('s-offer-modal-btn-is-active');
854
+ }
855
+ else if (sliderPosition < sliderEndOffset) {
856
+ // show both btns in the middle
857
+ nexBtn.classList.add('s-offer-modal-btn-is-active');
858
+ prevBtn.classList.add('s-offer-modal-btn-is-active');
859
+ }
860
+ else if (sliderPosition >= sliderEndOffset) {
861
+ nexBtn.classList.remove('s-offer-modal-btn-is-active');
862
+ prevBtn.classList.add('s-offer-modal-btn-is-active');
863
+ }
864
+ });
865
+ // Navigation
866
+ navButtons.forEach(btn => {
867
+ btn.addEventListener('click', function () {
868
+ btn.classList.contains('s-offer-modal-next-btn') ? current++ : current--;
869
+ slider.scrollTo({
870
+ top: 0,
871
+ left: itemSize * slidesToScroll * current * (isRTL ? -1 : 1),
872
+ behavior: 'smooth'
873
+ });
874
+ });
875
+ });
876
+ }
877
+ }
878
+ get host() { return getElement(this); }
879
+ };
880
+ SallaOfferModal.style = sallaOfferModalCss;
881
+
882
+ const BellRingIcon = `<!-- Generated by IcoMoon.io -->
883
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
884
+ <title>bell-ring</title>
885
+ <path d="M2.667 13.333v-4c0-2.592 0.748-5.107 2.161-7.271 0.404-0.616 0.231-1.443-0.387-1.845-0.616-0.401-1.443-0.228-1.845 0.388-1.699 2.599-2.596 5.617-2.596 8.728v4c0 0.736 0.596 1.333 1.333 1.333s1.333-0.596 1.333-1.333zM25.333 15.647v-6.313c0-5.147-4.188-9.333-9.333-9.333s-9.333 4.187-9.333 9.333v6.312l-5.157 9.027c-0.236 0.413-0.235 0.92 0.004 1.331 0.239 0.412 0.679 0.664 1.153 0.664h8c0 2.941 2.392 5.333 5.333 5.333s5.333-2.392 5.333-5.333h8c0.475 0 0.915-0.252 1.153-0.664 0.239-0.411 0.24-0.917 0.004-1.331zM16 29.333c-1.471 0-2.667-1.196-2.667-2.667h5.333c0 1.472-1.196 2.667-2.667 2.667zM4.965 24l4.193-7.339c0.113-0.2 0.175-0.429 0.175-0.661v-6.667c0-3.676 2.991-6.667 6.667-6.667s6.667 2.991 6.667 6.667v6.667c0 0.232 0.061 0.46 0.176 0.661l4.192 7.339zM29.403 0.603c-0.403-0.616-1.232-0.789-1.845-0.387-0.617 0.403-0.791 1.229-0.387 1.845 1.415 2.165 2.163 4.68 2.163 7.272v4c0 0.736 0.596 1.333 1.333 1.333s1.333-0.597 1.333-1.333v-4c0-3.112-0.899-6.132-2.597-8.731z"></path>
886
+ </svg>
887
+ `;
888
+
889
+ const sallaProductAvailabilityCss = "";
890
+
891
+ const SallaProductAvailability = class {
892
+ constructor(hostRef) {
893
+ registerInstance(this, hostRef);
894
+ this.isUser = Helper.isUser();
895
+ this.translationLoaded = false;
896
+ /**
897
+ * product id that can visitor subscribe to its availability notification
898
+ */
899
+ this.productId = salla.config.get('page.id');
900
+ /**
901
+ * is current user already subscribed
902
+ */
903
+ this.isSubscribed = false;
904
+ // @Method()
905
+ this.submit = async () => {
906
+ if (this.isUser) {
907
+ return salla.api.product.availabilitySubscribe(this.productId)
908
+ .then(() => this.isSubscribed = true);
909
+ }
910
+ let data = { id: this.productId };
911
+ if (this.channels_.includes('sms')) {
912
+ let { phone, countryCode } = await this.mobileInput.getValues();
913
+ data['country_code'] = countryCode;
914
+ data['phone'] = phone;
915
+ }
916
+ if (this.channels_.includes('email')) {
917
+ this.email.value !== '' && (data['email'] = this.email.value);
918
+ }
919
+ await this.validateform();
920
+ return this.btn.load()
921
+ .then(() => this.btn.disable())
922
+ .then(() => salla.api.product.availabilitySubscribe(data))
923
+ .then(() => {
924
+ this.isSubscribed = true;
925
+ salla.storage.set(`product-${this.productId}-subscribed`, true);
926
+ }) //no need to wait until finishing alert animation
927
+ .then(() => this.btn.stop())
928
+ .then(() => this.modal.close())
929
+ .catch(() => this.btn.stop() && this.btn.enable());
930
+ };
931
+ // helpers
932
+ this.typing = (e, submitMethod) => {
933
+ const error = e.target.nextElementSibling;
934
+ e.target.classList.remove('s-has-error');
935
+ (error === null || error === void 0 ? void 0 : error.classList.contains('s-product-availability-error-msg')) && (error.innerText = '');
936
+ e.key == 'Enter' && submitMethod();
937
+ };
938
+ salla.lang.onLoaded(() => {
939
+ var _a;
940
+ this.translationLoaded = true;
941
+ this.title_ = this.host.title || salla.lang.get('pages.products.notify_availability_title');
942
+ (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title_);
943
+ });
944
+ if (this.isUser)
945
+ return;
946
+ this.channelsWatcher(this.channels);
947
+ this.title_ = this.host.title || salla.lang.get('pages.products.notify_availability_title');
948
+ this.host.removeAttribute('title');
949
+ this.isVisitorSubscribed = salla.storage.get(`product-${this.productId}-subscribed`);
950
+ }
951
+ channelsWatcher(newValue) {
952
+ this.channels_ = !!newValue ? newValue.split(',') : [];
953
+ }
954
+ async validateform() {
955
+ try {
956
+ if (this.channels_.includes('email')) {
957
+ const isEmailValid = Helper.isValidEmail(this.email.value);
958
+ if (isEmailValid)
959
+ return;
960
+ !isEmailValid && this.validateField(this.email, salla.lang.get('common.elements.email_is_valid'));
961
+ }
962
+ if (this.channels_.includes('sms')) {
963
+ const isPhoneValid = await this.mobileInput.isValid();
964
+ if (isPhoneValid)
965
+ return;
966
+ }
967
+ }
968
+ catch (error) {
969
+ throw ('Please insert required fields');
970
+ }
971
+ }
972
+ validateField(field, errorMsg) {
973
+ field.classList.add('s-has-error');
974
+ field.nextElementSibling['innerText'] = '* ' + errorMsg;
975
+ }
976
+ render() {
977
+ return (h(Host, { class: "s-product-availability-wrap" }, this.isSubscribed || this.isVisitorSubscribed
978
+ ? h("div", { class: "s-product-availability-subscribed" }, h("span", { innerHTML: BellRingIcon, class: "s-product-availability-subs-icon" }), " ", salla.lang.get('pages.products.notify_availability_success'))
979
+ :
980
+ h("salla-button", { width: "wide", onClick: () => this.isUser ? this.submit() : this.modal.open() }, salla.lang.get('pages.products.notify_availability')), this.isUser || this.isSubscribed || this.isVisitorSubscribed ? '' : this.renderModal()));
981
+ }
982
+ renderModal() {
983
+ return (h("salla-modal", { ref: modal => this.modal = modal, "modal-title": this.title_, subTitle: salla.lang.get('pages.products.notify_availability_subtitle'), width: "sm" }, h("span", { slot: 'icon', innerHTML: BellRingIcon }), h("div", { class: "s-product-availability-body" }, this.channels_.includes('email') ? [
984
+ h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.email')),
985
+ h("input", { class: "s-product-availability-input", onKeyDown: e => this.typing(e, this.submit), placeholder: salla.lang.get('common.elements.email_placeholder') || 'your@email.com', ref: el => this.email = el, type: "email" }),
986
+ h("span", { class: "s-product-availability-error-msg" })
987
+ ] : '', this.channels_.includes('sms') ? [
988
+ h("label", { class: "s-product-availability-label" }, salla.lang.get('common.elements.mobile')),
989
+ h("salla-tel-input", { ref: el => this.mobileInput = el, onKeyDown: e => this.typing(e, this.submit) })
990
+ ] : ''), h("div", { slot: "footer", class: "s-product-availability-footer" }, h("salla-button", { class: "modal-cancel-btn", width: "wide", color: "light", fill: "outline", onClick: () => this.modal.close() }, salla.lang.get('common.elements.cancel')), h("salla-button", { class: "submit-btn", "loader-position": 'center', width: "wide", ref: btn => this.btn = btn, onClick: () => this.submit() }, salla.lang.get('common.elements.submit')))));
991
+ }
992
+ get host() { return getElement(this); }
993
+ static get watchers() { return {
994
+ "channels": ["channelsWatcher"]
995
+ }; }
996
+ };
997
+ SallaProductAvailability.style = sallaProductAvailabilityCss;
998
+
999
+ const sallaRatingStarsCss = "";
1000
+
1001
+ const SallaRatingStars = class {
1002
+ constructor(hostRef) {
1003
+ registerInstance(this, hostRef);
1004
+ /**
1005
+ * Sets input name.
1006
+ */
1007
+ this.name = 'rating';
1008
+ /**
1009
+ * Sets the height and width of the component. Defaults to medium.
1010
+ */
1011
+ this.size = 'medium';
1012
+ }
1013
+ initiateRating() {
1014
+ this.host.addEventListener('click', () => {
1015
+ if (!this.startsElem)
1016
+ return;
1017
+ // Get the selected star - activeElement is not supported in safari
1018
+ let activeStars = this.startsElem.querySelectorAll('.s-rating-stars-hovered');
1019
+ let selected = activeStars[activeStars.length - 1];
1020
+ if (!selected)
1021
+ return;
1022
+ let selectedIndex = selected.getAttribute('data-star');
1023
+ this.startsElem.querySelector('.rating_hidden_input').value = selectedIndex;
1024
+ // Loop through each star, and add or remove the `.selected` class to toggle highlighting
1025
+ this.startsElem.querySelectorAll('.s-rating-stars-btn-star')
1026
+ .forEach((star, index) => Helper.toggleElementClassIf(star, 's-rating-stars-selected', 's-rating-stars-unselected', () => index < parseInt(selectedIndex)));
1027
+ // update aria-pressed attr status
1028
+ this.startsElem.querySelectorAll('[aria-pressed]').forEach(star => star.removeAttribute('aria-pressed'));
1029
+ selected.setAttribute('aria-pressed', 'true');
1030
+ });
1031
+ }
1032
+ highlightSelectedStars() {
1033
+ var _a, _b;
1034
+ let hoveredClass = 's-rating-stars-hovered', stars = (_a = this.startsElem) === null || _a === void 0 ? void 0 : _a.querySelectorAll('.s-rating-stars-btn-star');
1035
+ stars === null || stars === void 0 ? void 0 : stars.forEach((star, index) => {
1036
+ star.addEventListener('mouseover', () => {
1037
+ for (let i = 0; i <= index; i++) {
1038
+ stars[i].classList.add(hoveredClass);
1039
+ }
1040
+ });
1041
+ star.addEventListener('mouseout', () => star.classList.remove(hoveredClass));
1042
+ });
1043
+ (_b = this.startsElem) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseout', () => stars.forEach(star => star.classList.remove(hoveredClass)));
1044
+ }
1045
+ createStars(n) {
1046
+ let stars = [];
1047
+ for (let i = 0; i < 5; i++) {
1048
+ stars.push(h("span", { class: {
1049
+ 's-rating-stars-btn-star': true,
1050
+ ['s-rating-stars-' + this.size]: true,
1051
+ 's-rating-stars-selected': i < n
1052
+ }, innerHTML: Star2 }));
1053
+ }
1054
+ return stars;
1055
+ }
1056
+ render() {
1057
+ return (h(Host, null, this.value ?
1058
+ h("div", { class: "s-rating-stars-wrapper" }, " ", this.createStars(this.value), " ")
1059
+ :
1060
+ h("div", { class: "s-rating-stars-element", ref: (el) => this.startsElem = el }, h("input", { type: "hidden", class: "rating_hidden_input", name: this.name, value: "" }), [1, 2, 3, 4, 5].map(star => h("button", { class: `s-rating-stars-btn-star s-rating-stars-` + this.size, "data-star": star }, h("span", { innerHTML: Star2 }))))));
1061
+ }
1062
+ componentDidLoad() {
1063
+ this.initiateRating();
1064
+ this.highlightSelectedStars();
1065
+ }
1066
+ get host() { return getElement(this); }
1067
+ };
1068
+ SallaRatingStars.style = sallaRatingStarsCss;
1069
+
1070
+ const sallaSearchCss = "";
1071
+
1072
+ const SallaSearch = class {
1073
+ constructor(hostRef) {
1074
+ registerInstance(this, hostRef);
1075
+ var _a;
1076
+ this.inputValue = '';
1077
+ this.translationLoaded = false;
1078
+ this.loading = false;
1079
+ this.typing = false;
1080
+ this.debounce = setTimeout(() => '', 1000);
1081
+ /**
1082
+ * Set the component display without modal window. Defaults to `false`
1083
+ */
1084
+ this.inline = false;
1085
+ /**
1086
+ * Adds a border radius to the input. Half of the height.
1087
+ */
1088
+ this.oval = false;
1089
+ /**
1090
+ * Sets the height of the input
1091
+ */
1092
+ this.height = 60;
1093
+ Helper.setHost(this.host);
1094
+ this.productSlot = ((_a = Helper.getElement('[slot="product"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || this.getDefaultProductSlot();
1095
+ salla.event.on('search::open', () => this.open());
1096
+ salla.lang.onLoaded(() => {
1097
+ this.translationLoaded = true;
1098
+ });
1099
+ salla.event.on('modalClosed', () => this.onModalClose());
1100
+ }
1101
+ async open() {
1102
+ if (!this.inline) {
1103
+ await this.modal.open().then(() => setTimeout(() => this.searchInput.focus(), 300));
1104
+ }
1105
+ }
1106
+ onModalClose() {
1107
+ this.searchInput.value = '';
1108
+ this.results = undefined;
1109
+ this.afterSearching();
1110
+ this.container.classList.remove('s-search-no-results');
1111
+ }
1112
+ handleKeyDown(ev) {
1113
+ if (ev.key === 'Enter') {
1114
+ window.location.href = salla.url.get('/search?q=' + encodeURI(this.search_term));
1115
+ }
1116
+ }
1117
+ getDefaultProductSlot() {
1118
+ return '<div class="s-search-product-image-container">' +
1119
+ ' <img class="s-search-product-image" src="{image}" alt="{name}"/>' +
1120
+ '</div>' +
1121
+ '<div class="s-search-product-details">' +
1122
+ ' <div class="s-search-product-title">{name}</div> <div class="s-search-product-price">{price} <span class="s-search-product-regular-price">{regular_price}</span></div>' +
1123
+ '</div>';
1124
+ }
1125
+ debounceSearch(event) {
1126
+ this.typing = true;
1127
+ clearTimeout(this.debounce);
1128
+ this.debounce = setTimeout(() => {
1129
+ this.typing = false;
1130
+ this.search_term = event.target.value;
1131
+ }, 500);
1132
+ }
1133
+ handelSearch(val) {
1134
+ this.inputValue = val;
1135
+ if (val.length > 2) {
1136
+ this.search(val);
1137
+ }
1138
+ else {
1139
+ this.results = undefined;
1140
+ this.afterSearching();
1141
+ }
1142
+ }
1143
+ search(val) {
1144
+ Helper.hideElement(this.noResults);
1145
+ //run loading spinner or stop it
1146
+ this.loading = true;
1147
+ salla.product.search(val)
1148
+ .then(response => this.results = response)
1149
+ .catch(err => err !== 'Query is same as previous one!' ? this.results = undefined : null)
1150
+ .finally(() => this.afterSearching(/*isEmpty*/ false));
1151
+ }
1152
+ afterSearching(isEmpty = true) {
1153
+ var _a;
1154
+ this.noResults.style.display = isEmpty || ((_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length) > 0 ? 'none' : 'block';
1155
+ Helper.toggleElementClassIf(this.container, 's-search-container-open', 's-search-no-results', () => { var _a; return (_a = this.results) === null || _a === void 0 ? void 0 : _a.data.length; });
1156
+ this.loading = false;
1157
+ salla.product.api.previousQuery = ''; //avoid having error 'Query is same as previous one!' after reopen modal;
1158
+ this.inputValue.length < 3 ? this.container.classList.remove('s-search-no-results') : '';
1159
+ }
1160
+ render() {
1161
+ var _a;
1162
+ const searchContent = h("div", { class: { 's-search-container': true, 's-search-inline': this.inline }, ref: container => this.container = container }, h("input", { type: "text", autocomplete: "off", class: "s-search-input", placeholder: salla.lang.get('blocks.header.search_placeholder'), onInput: e => this.debounceSearch(e), onKeyDown: e => this.handleKeyDown(e), ref: input => this.searchInput = input, style: { height: this.height + 'px', borderRadius: this.oval ? this.height / 2 + 'px' : '' } }), h("span", { class: "s-search-icon-wrap" }, h("span", { class: "s-search-icon", innerHTML: this.loading ? '<i class="s-search-spinner-loader"></i>' : Search })), h("div", { class: "s-search-results" }, (_a = this.results) === null || _a === void 0 ? void 0 :
1163
+ _a.data.map(item => h("a", { href: item.url, class: { "s-search-product": true, 's-search-product-not-available': !item.is_available }, innerHTML: this.productSlot
1164
+ .replace(/\{name\}/g, item.name)
1165
+ .replace(/\{price\}/g, salla.money(item.price))
1166
+ .replace(/\{regular_price\}/g, item.has_special_price ? salla.money(item.regular_price) : '')
1167
+ .replace(/\{image\}/g, item.thumbnail) })), h("p", { ref: el => this.noResults = el, class: "s-search-no-results-placeholder" }, salla.lang.get('common.elements.no_options'))));
1168
+ return (this.inline ?
1169
+ h("div", { class: "s-search-modal" }, searchContent)
1170
+ :
1171
+ h("salla-modal", { position: "top", class: "s-search-modal", ref: modal => this.modal = modal }, searchContent));
1172
+ }
1173
+ /**
1174
+ * Run it one time after load
1175
+ */
1176
+ componentDidLoad() {
1177
+ this.afterSearching();
1178
+ }
1179
+ get host() { return getElement(this); }
1180
+ static get watchers() { return {
1181
+ "search_term": ["handelSearch"]
1182
+ }; }
1183
+ };
1184
+ SallaSearch.style = sallaSearchCss;
1185
+
1186
+ const sallaSkeletonCss = ":host{display:block}";
1187
+
1188
+ const SallaSkeleton = class {
1189
+ constructor(hostRef) {
1190
+ registerInstance(this, hostRef);
1191
+ /**
1192
+ * Set the shape type of the skeleton is it circle or normal
1193
+ */
1194
+ this.type = 'normal';
1195
+ /**
1196
+ * Set the skeleton width
1197
+ */
1198
+ this.width = '100%';
1199
+ /**
1200
+ * Set the skeleton height
1201
+ */
1202
+ this.height = '100%';
1203
+ }
1204
+ render() {
1205
+ const classes = {
1206
+ 's-skeleton-item': true,
1207
+ 's-skeleton-item-circular': this.type == 'circle',
1208
+ };
1209
+ return (h(Host, { class: "s-skeleton-wrapper", style: { width: this.width, height: this.height } }, h("div", { class: classes }, "\u00A0")));
1210
+ }
1211
+ };
1212
+ SallaSkeleton.style = sallaSkeletonCss;
1213
+
1214
+ function createCommonjsModule(fn, basedir, module) {
1215
+ return module = {
1216
+ path: basedir,
1217
+ exports: {},
1218
+ require: function (path, base) {
1219
+ return commonjsRequire();
1220
+ }
1221
+ }, fn(module, module.exports), module.exports;
1222
+ }
1223
+
1224
+ function commonjsRequire () {
1225
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
1226
+ }
1227
+
1228
+ var intlTelInput$1 = createCommonjsModule(function (module) {
1229
+ /*
1230
+ * International Telephone Input v17.0.18
1231
+ * https://github.com/jackocnr/intl-tel-input.git
1232
+ * Licensed under the MIT license
1233
+ */
1234
+
1235
+ // wrap in UMD
1236
+ (function(factory) {
1237
+ if (module.exports) module.exports = factory(); else window.intlTelInput = factory();
1238
+ })(function(undefined$1) {
1239
+ return function() {
1240
+ // Array of country objects for the flag dropdown.
1241
+ // Here is the criteria for the plugin to support a given country/territory
1242
+ // - It has an iso2 code: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
1243
+ // - It has it's own country calling code (it is not a sub-region of another country): https://en.wikipedia.org/wiki/List_of_country_calling_codes
1244
+ // - It has a flag in the region-flags project: https://github.com/behdad/region-flags/tree/gh-pages/png
1245
+ // - It is supported by libphonenumber (it must be listed on this page): https://github.com/googlei18n/libphonenumber/blob/master/resources/ShortNumberMetadata.xml
1246
+ // Each country array has the following information:
1247
+ // [
1248
+ // Country name,
1249
+ // iso2 code,
1250
+ // International dial code,
1251
+ // Order (if >1 country with same dial code),
1252
+ // Area codes
1253
+ // ]
1254
+ var allCountries = [ [ "Afghanistan (‫افغانستان‬‎)", "af", "93" ], [ "Albania (Shqipëri)", "al", "355" ], [ "Algeria (‫الجزائر‬‎)", "dz", "213" ], [ "American Samoa", "as", "1", 5, [ "684" ] ], [ "Andorra", "ad", "376" ], [ "Angola", "ao", "244" ], [ "Anguilla", "ai", "1", 6, [ "264" ] ], [ "Antigua and Barbuda", "ag", "1", 7, [ "268" ] ], [ "Argentina", "ar", "54" ], [ "Armenia (Հայաստան)", "am", "374" ], [ "Aruba", "aw", "297" ], [ "Ascension Island", "ac", "247" ], [ "Australia", "au", "61", 0 ], [ "Austria (Österreich)", "at", "43" ], [ "Azerbaijan (Azərbaycan)", "az", "994" ], [ "Bahamas", "bs", "1", 8, [ "242" ] ], [ "Bahrain (‫البحرين‬‎)", "bh", "973" ], [ "Bangladesh (বাংলাদেশ)", "bd", "880" ], [ "Barbados", "bb", "1", 9, [ "246" ] ], [ "Belarus (Беларусь)", "by", "375" ], [ "Belgium (België)", "be", "32" ], [ "Belize", "bz", "501" ], [ "Benin (Bénin)", "bj", "229" ], [ "Bermuda", "bm", "1", 10, [ "441" ] ], [ "Bhutan (འབྲུག)", "bt", "975" ], [ "Bolivia", "bo", "591" ], [ "Bosnia and Herzegovina (Босна и Херцеговина)", "ba", "387" ], [ "Botswana", "bw", "267" ], [ "Brazil (Brasil)", "br", "55" ], [ "British Indian Ocean Territory", "io", "246" ], [ "British Virgin Islands", "vg", "1", 11, [ "284" ] ], [ "Brunei", "bn", "673" ], [ "Bulgaria (България)", "bg", "359" ], [ "Burkina Faso", "bf", "226" ], [ "Burundi (Uburundi)", "bi", "257" ], [ "Cambodia (កម្ពុជា)", "kh", "855" ], [ "Cameroon (Cameroun)", "cm", "237" ], [ "Canada", "ca", "1", 1, [ "204", "226", "236", "249", "250", "289", "306", "343", "365", "387", "403", "416", "418", "431", "437", "438", "450", "506", "514", "519", "548", "579", "581", "587", "604", "613", "639", "647", "672", "705", "709", "742", "778", "780", "782", "807", "819", "825", "867", "873", "902", "905" ] ], [ "Cape Verde (Kabu Verdi)", "cv", "238" ], [ "Caribbean Netherlands", "bq", "599", 1, [ "3", "4", "7" ] ], [ "Cayman Islands", "ky", "1", 12, [ "345" ] ], [ "Central African Republic (République centrafricaine)", "cf", "236" ], [ "Chad (Tchad)", "td", "235" ], [ "Chile", "cl", "56" ], [ "China (中国)", "cn", "86" ], [ "Christmas Island", "cx", "61", 2, [ "89164" ] ], [ "Cocos (Keeling) Islands", "cc", "61", 1, [ "89162" ] ], [ "Colombia", "co", "57" ], [ "Comoros (‫جزر القمر‬‎)", "km", "269" ], [ "Congo (DRC) (Jamhuri ya Kidemokrasia ya Kongo)", "cd", "243" ], [ "Congo (Republic) (Congo-Brazzaville)", "cg", "242" ], [ "Cook Islands", "ck", "682" ], [ "Costa Rica", "cr", "506" ], [ "Côte d’Ivoire", "ci", "225" ], [ "Croatia (Hrvatska)", "hr", "385" ], [ "Cuba", "cu", "53" ], [ "Curaçao", "cw", "599", 0 ], [ "Cyprus (Κύπρος)", "cy", "357" ], [ "Czech Republic (Česká republika)", "cz", "420" ], [ "Denmark (Danmark)", "dk", "45" ], [ "Djibouti", "dj", "253" ], [ "Dominica", "dm", "1", 13, [ "767" ] ], [ "Dominican Republic (República Dominicana)", "do", "1", 2, [ "809", "829", "849" ] ], [ "Ecuador", "ec", "593" ], [ "Egypt (‫مصر‬‎)", "eg", "20" ], [ "El Salvador", "sv", "503" ], [ "Equatorial Guinea (Guinea Ecuatorial)", "gq", "240" ], [ "Eritrea", "er", "291" ], [ "Estonia (Eesti)", "ee", "372" ], [ "Eswatini", "sz", "268" ], [ "Ethiopia", "et", "251" ], [ "Falkland Islands (Islas Malvinas)", "fk", "500" ], [ "Faroe Islands (Føroyar)", "fo", "298" ], [ "Fiji", "fj", "679" ], [ "Finland (Suomi)", "fi", "358", 0 ], [ "France", "fr", "33" ], [ "French Guiana (Guyane française)", "gf", "594" ], [ "French Polynesia (Polynésie française)", "pf", "689" ], [ "Gabon", "ga", "241" ], [ "Gambia", "gm", "220" ], [ "Georgia (საქართველო)", "ge", "995" ], [ "Germany (Deutschland)", "de", "49" ], [ "Ghana (Gaana)", "gh", "233" ], [ "Gibraltar", "gi", "350" ], [ "Greece (Ελλάδα)", "gr", "30" ], [ "Greenland (Kalaallit Nunaat)", "gl", "299" ], [ "Grenada", "gd", "1", 14, [ "473" ] ], [ "Guadeloupe", "gp", "590", 0 ], [ "Guam", "gu", "1", 15, [ "671" ] ], [ "Guatemala", "gt", "502" ], [ "Guernsey", "gg", "44", 1, [ "1481", "7781", "7839", "7911" ] ], [ "Guinea (Guinée)", "gn", "224" ], [ "Guinea-Bissau (Guiné Bissau)", "gw", "245" ], [ "Guyana", "gy", "592" ], [ "Haiti", "ht", "509" ], [ "Honduras", "hn", "504" ], [ "Hong Kong (香港)", "hk", "852" ], [ "Hungary (Magyarország)", "hu", "36" ], [ "Iceland (Ísland)", "is", "354" ], [ "India (भारत)", "in", "91" ], [ "Indonesia", "id", "62" ], [ "Iran (‫ایران‬‎)", "ir", "98" ], [ "Iraq (‫العراق‬‎)", "iq", "964" ], [ "Ireland", "ie", "353" ], [ "Isle of Man", "im", "44", 2, [ "1624", "74576", "7524", "7924", "7624" ] ], [ "Israel (‫ישראל‬‎)", "il", "972" ], [ "Italy (Italia)", "it", "39", 0 ], [ "Jamaica", "jm", "1", 4, [ "876", "658" ] ], [ "Japan (日本)", "jp", "81" ], [ "Jersey", "je", "44", 3, [ "1534", "7509", "7700", "7797", "7829", "7937" ] ], [ "Jordan (‫الأردن‬‎)", "jo", "962" ], [ "Kazakhstan (Казахстан)", "kz", "7", 1, [ "33", "7" ] ], [ "Kenya", "ke", "254" ], [ "Kiribati", "ki", "686" ], [ "Kosovo", "xk", "383" ], [ "Kuwait (‫الكويت‬‎)", "kw", "965" ], [ "Kyrgyzstan (Кыргызстан)", "kg", "996" ], [ "Laos (ລາວ)", "la", "856" ], [ "Latvia (Latvija)", "lv", "371" ], [ "Lebanon (‫لبنان‬‎)", "lb", "961" ], [ "Lesotho", "ls", "266" ], [ "Liberia", "lr", "231" ], [ "Libya (‫ليبيا‬‎)", "ly", "218" ], [ "Liechtenstein", "li", "423" ], [ "Lithuania (Lietuva)", "lt", "370" ], [ "Luxembourg", "lu", "352" ], [ "Macau (澳門)", "mo", "853" ], [ "North Macedonia (Македонија)", "mk", "389" ], [ "Madagascar (Madagasikara)", "mg", "261" ], [ "Malawi", "mw", "265" ], [ "Malaysia", "my", "60" ], [ "Maldives", "mv", "960" ], [ "Mali", "ml", "223" ], [ "Malta", "mt", "356" ], [ "Marshall Islands", "mh", "692" ], [ "Martinique", "mq", "596" ], [ "Mauritania (‫موريتانيا‬‎)", "mr", "222" ], [ "Mauritius (Moris)", "mu", "230" ], [ "Mayotte", "yt", "262", 1, [ "269", "639" ] ], [ "Mexico (México)", "mx", "52" ], [ "Micronesia", "fm", "691" ], [ "Moldova (Republica Moldova)", "md", "373" ], [ "Monaco", "mc", "377" ], [ "Mongolia (Монгол)", "mn", "976" ], [ "Montenegro (Crna Gora)", "me", "382" ], [ "Montserrat", "ms", "1", 16, [ "664" ] ], [ "Morocco (‫المغرب‬‎)", "ma", "212", 0 ], [ "Mozambique (Moçambique)", "mz", "258" ], [ "Myanmar (Burma) (မြန်မာ)", "mm", "95" ], [ "Namibia (Namibië)", "na", "264" ], [ "Nauru", "nr", "674" ], [ "Nepal (नेपाल)", "np", "977" ], [ "Netherlands (Nederland)", "nl", "31" ], [ "New Caledonia (Nouvelle-Calédonie)", "nc", "687" ], [ "New Zealand", "nz", "64" ], [ "Nicaragua", "ni", "505" ], [ "Niger (Nijar)", "ne", "227" ], [ "Nigeria", "ng", "234" ], [ "Niue", "nu", "683" ], [ "Norfolk Island", "nf", "672" ], [ "North Korea (조선 민주주의 인민 공화국)", "kp", "850" ], [ "Northern Mariana Islands", "mp", "1", 17, [ "670" ] ], [ "Norway (Norge)", "no", "47", 0 ], [ "Oman (‫عُمان‬‎)", "om", "968" ], [ "Pakistan (‫پاکستان‬‎)", "pk", "92" ], [ "Palau", "pw", "680" ], [ "Palestine (‫فلسطين‬‎)", "ps", "970" ], [ "Panama (Panamá)", "pa", "507" ], [ "Papua New Guinea", "pg", "675" ], [ "Paraguay", "py", "595" ], [ "Peru (Perú)", "pe", "51" ], [ "Philippines", "ph", "63" ], [ "Poland (Polska)", "pl", "48" ], [ "Portugal", "pt", "351" ], [ "Puerto Rico", "pr", "1", 3, [ "787", "939" ] ], [ "Qatar (‫قطر‬‎)", "qa", "974" ], [ "Réunion (La Réunion)", "re", "262", 0 ], [ "Romania (România)", "ro", "40" ], [ "Russia (Россия)", "ru", "7", 0 ], [ "Rwanda", "rw", "250" ], [ "Saint Barthélemy", "bl", "590", 1 ], [ "Saint Helena", "sh", "290" ], [ "Saint Kitts and Nevis", "kn", "1", 18, [ "869" ] ], [ "Saint Lucia", "lc", "1", 19, [ "758" ] ], [ "Saint Martin (Saint-Martin (partie française))", "mf", "590", 2 ], [ "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)", "pm", "508" ], [ "Saint Vincent and the Grenadines", "vc", "1", 20, [ "784" ] ], [ "Samoa", "ws", "685" ], [ "San Marino", "sm", "378" ], [ "São Tomé and Príncipe (São Tomé e Príncipe)", "st", "239" ], [ "Saudi Arabia (‫المملكة العربية السعودية‬‎)", "sa", "966" ], [ "Senegal (Sénégal)", "sn", "221" ], [ "Serbia (Србија)", "rs", "381" ], [ "Seychelles", "sc", "248" ], [ "Sierra Leone", "sl", "232" ], [ "Singapore", "sg", "65" ], [ "Sint Maarten", "sx", "1", 21, [ "721" ] ], [ "Slovakia (Slovensko)", "sk", "421" ], [ "Slovenia (Slovenija)", "si", "386" ], [ "Solomon Islands", "sb", "677" ], [ "Somalia (Soomaaliya)", "so", "252" ], [ "South Africa", "za", "27" ], [ "South Korea (대한민국)", "kr", "82" ], [ "South Sudan (‫جنوب السودان‬‎)", "ss", "211" ], [ "Spain (España)", "es", "34" ], [ "Sri Lanka (ශ්‍රී ලංකාව)", "lk", "94" ], [ "Sudan (‫السودان‬‎)", "sd", "249" ], [ "Suriname", "sr", "597" ], [ "Svalbard and Jan Mayen", "sj", "47", 1, [ "79" ] ], [ "Sweden (Sverige)", "se", "46" ], [ "Switzerland (Schweiz)", "ch", "41" ], [ "Syria (‫سوريا‬‎)", "sy", "963" ], [ "Taiwan (台灣)", "tw", "886" ], [ "Tajikistan", "tj", "992" ], [ "Tanzania", "tz", "255" ], [ "Thailand (ไทย)", "th", "66" ], [ "Timor-Leste", "tl", "670" ], [ "Togo", "tg", "228" ], [ "Tokelau", "tk", "690" ], [ "Tonga", "to", "676" ], [ "Trinidad and Tobago", "tt", "1", 22, [ "868" ] ], [ "Tunisia (‫تونس‬‎)", "tn", "216" ], [ "Turkey (Türkiye)", "tr", "90" ], [ "Turkmenistan", "tm", "993" ], [ "Turks and Caicos Islands", "tc", "1", 23, [ "649" ] ], [ "Tuvalu", "tv", "688" ], [ "U.S. Virgin Islands", "vi", "1", 24, [ "340" ] ], [ "Uganda", "ug", "256" ], [ "Ukraine (Україна)", "ua", "380" ], [ "United Arab Emirates (‫الإمارات العربية المتحدة‬‎)", "ae", "971" ], [ "United Kingdom", "gb", "44", 0 ], [ "United States", "us", "1", 0 ], [ "Uruguay", "uy", "598" ], [ "Uzbekistan (Oʻzbekiston)", "uz", "998" ], [ "Vanuatu", "vu", "678" ], [ "Vatican City (Città del Vaticano)", "va", "39", 1, [ "06698" ] ], [ "Venezuela", "ve", "58" ], [ "Vietnam (Việt Nam)", "vn", "84" ], [ "Wallis and Futuna (Wallis-et-Futuna)", "wf", "681" ], [ "Western Sahara (‫الصحراء الغربية‬‎)", "eh", "212", 1, [ "5288", "5289" ] ], [ "Yemen (‫اليمن‬‎)", "ye", "967" ], [ "Zambia", "zm", "260" ], [ "Zimbabwe", "zw", "263" ], [ "Åland Islands", "ax", "358", 1, [ "18" ] ] ];
1255
+ // loop over all of the countries above, restructuring the data to be objects with named keys
1256
+ for (var i = 0; i < allCountries.length; i++) {
1257
+ var c = allCountries[i];
1258
+ allCountries[i] = {
1259
+ name: c[0],
1260
+ iso2: c[1],
1261
+ dialCode: c[2],
1262
+ priority: c[3] || 0,
1263
+ areaCodes: c[4] || null
1264
+ };
1265
+ }
1266
+ function _classCallCheck(instance, Constructor) {
1267
+ if (!(instance instanceof Constructor)) {
1268
+ throw new TypeError("Cannot call a class as a function");
1269
+ }
1270
+ }
1271
+ function _defineProperties(target, props) {
1272
+ for (var i = 0; i < props.length; i++) {
1273
+ var descriptor = props[i];
1274
+ descriptor.enumerable = descriptor.enumerable || false;
1275
+ descriptor.configurable = true;
1276
+ if ("value" in descriptor) descriptor.writable = true;
1277
+ Object.defineProperty(target, descriptor.key, descriptor);
1278
+ }
1279
+ }
1280
+ function _createClass(Constructor, protoProps, staticProps) {
1281
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1282
+ if (staticProps) _defineProperties(Constructor, staticProps);
1283
+ return Constructor;
1284
+ }
1285
+ var intlTelInputGlobals = {
1286
+ getInstance: function getInstance(input) {
1287
+ var id = input.getAttribute("data-intl-tel-input-id");
1288
+ return window.intlTelInputGlobals.instances[id];
1289
+ },
1290
+ instances: {},
1291
+ // using a global like this allows us to mock it in the tests
1292
+ documentReady: function documentReady() {
1293
+ return document.readyState === "complete";
1294
+ }
1295
+ };
1296
+ if (typeof window === "object") window.intlTelInputGlobals = intlTelInputGlobals;
1297
+ // these vars persist through all instances of the plugin
1298
+ var id = 0;
1299
+ var defaults = {
1300
+ // whether or not to allow the dropdown
1301
+ allowDropdown: true,
1302
+ // if there is just a dial code in the input: remove it on blur
1303
+ autoHideDialCode: true,
1304
+ // add a placeholder in the input with an example number for the selected country
1305
+ autoPlaceholder: "polite",
1306
+ // modify the parentClass
1307
+ customContainer: "",
1308
+ // modify the auto placeholder
1309
+ customPlaceholder: null,
1310
+ // append menu to specified element
1311
+ dropdownContainer: null,
1312
+ // don't display these countries
1313
+ excludeCountries: [],
1314
+ // format the input value during initialisation and on setNumber
1315
+ formatOnDisplay: true,
1316
+ // geoIp lookup function
1317
+ geoIpLookup: null,
1318
+ // inject a hidden input with this name, and on submit, populate it with the result of getNumber
1319
+ hiddenInput: "",
1320
+ // initial country
1321
+ initialCountry: "",
1322
+ // localized country names e.g. { 'de': 'Deutschland' }
1323
+ localizedCountries: null,
1324
+ // don't insert international dial codes
1325
+ nationalMode: true,
1326
+ // display only these countries
1327
+ onlyCountries: [],
1328
+ // number type to use for placeholders
1329
+ placeholderNumberType: "MOBILE",
1330
+ // the countries at the top of the list. defaults to united states and united kingdom
1331
+ preferredCountries: [ "us", "gb" ],
1332
+ // display the country dial code next to the selected flag so it's not part of the typed number
1333
+ separateDialCode: false,
1334
+ // specify the path to the libphonenumber script to enable validation/formatting
1335
+ utilsScript: ""
1336
+ };
1337
+ // https://en.wikipedia.org/wiki/List_of_North_American_Numbering_Plan_area_codes#Non-geographic_area_codes
1338
+ var regionlessNanpNumbers = [ "800", "822", "833", "844", "855", "866", "877", "880", "881", "882", "883", "884", "885", "886", "887", "888", "889" ];
1339
+ // utility function to iterate over an object. can't use Object.entries or native forEach because
1340
+ // of IE11
1341
+ var forEachProp = function forEachProp(obj, callback) {
1342
+ var keys = Object.keys(obj);
1343
+ for (var i = 0; i < keys.length; i++) {
1344
+ callback(keys[i], obj[keys[i]]);
1345
+ }
1346
+ };
1347
+ // run a method on each instance of the plugin
1348
+ var forEachInstance = function forEachInstance(method) {
1349
+ forEachProp(window.intlTelInputGlobals.instances, function(key) {
1350
+ window.intlTelInputGlobals.instances[key][method]();
1351
+ });
1352
+ };
1353
+ // this is our plugin class that we will create an instance of
1354
+ // eslint-disable-next-line no-unused-vars
1355
+ var Iti = /*#__PURE__*/
1356
+ function() {
1357
+ function Iti(input, options) {
1358
+ var _this = this;
1359
+ _classCallCheck(this, Iti);
1360
+ this.id = id++;
1361
+ this.telInput = input;
1362
+ this.activeItem = null;
1363
+ this.highlightedItem = null;
1364
+ // process specified options / defaults
1365
+ // alternative to Object.assign, which isn't supported by IE11
1366
+ var customOptions = options || {};
1367
+ this.options = {};
1368
+ forEachProp(defaults, function(key, value) {
1369
+ _this.options[key] = customOptions.hasOwnProperty(key) ? customOptions[key] : value;
1370
+ });
1371
+ this.hadInitialPlaceholder = Boolean(input.getAttribute("placeholder"));
1372
+ }
1373
+ _createClass(Iti, [ {
1374
+ key: "_init",
1375
+ value: function _init() {
1376
+ var _this2 = this;
1377
+ // if in nationalMode, disable options relating to dial codes
1378
+ if (this.options.nationalMode) this.options.autoHideDialCode = false;
1379
+ // if separateDialCode then doesn't make sense to A) insert dial code into input
1380
+ // (autoHideDialCode), and B) display national numbers (because we're displaying the country
1381
+ // dial code next to them)
1382
+ if (this.options.separateDialCode) {
1383
+ this.options.autoHideDialCode = this.options.nationalMode = false;
1384
+ }
1385
+ // we cannot just test screen size as some smartphones/website meta tags will report desktop
1386
+ // resolutions
1387
+ // Note: for some reason jasmine breaks if you put this in the main Plugin function with the
1388
+ // rest of these declarations
1389
+ // Note: to target Android Mobiles (and not Tablets), we must find 'Android' and 'Mobile'
1390
+ this.isMobile = /Android.+Mobile|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
1391
+ if (this.isMobile) {
1392
+ // trigger the mobile dropdown css
1393
+ document.body.classList.add("iti-mobile");
1394
+ // on mobile, we want a full screen dropdown, so we must append it to the body
1395
+ if (!this.options.dropdownContainer) this.options.dropdownContainer = document.body;
1396
+ }
1397
+ // these promises get resolved when their individual requests complete
1398
+ // this way the dev can do something like iti.promise.then(...) to know when all requests are
1399
+ // complete
1400
+ if (typeof Promise !== "undefined") {
1401
+ var autoCountryPromise = new Promise(function(resolve, reject) {
1402
+ _this2.resolveAutoCountryPromise = resolve;
1403
+ _this2.rejectAutoCountryPromise = reject;
1404
+ });
1405
+ var utilsScriptPromise = new Promise(function(resolve, reject) {
1406
+ _this2.resolveUtilsScriptPromise = resolve;
1407
+ _this2.rejectUtilsScriptPromise = reject;
1408
+ });
1409
+ this.promise = Promise.all([ autoCountryPromise, utilsScriptPromise ]);
1410
+ } else {
1411
+ // prevent errors when Promise doesn't exist
1412
+ this.resolveAutoCountryPromise = this.rejectAutoCountryPromise = function() {};
1413
+ this.resolveUtilsScriptPromise = this.rejectUtilsScriptPromise = function() {};
1414
+ }
1415
+ // in various situations there could be no country selected initially, but we need to be able
1416
+ // to assume this variable exists
1417
+ this.selectedCountryData = {};
1418
+ // process all the data: onlyCountries, excludeCountries, preferredCountries etc
1419
+ this._processCountryData();
1420
+ // generate the markup
1421
+ this._generateMarkup();
1422
+ // set the initial state of the input value and the selected flag
1423
+ this._setInitialState();
1424
+ // start all of the event listeners: autoHideDialCode, input keydown, selectedFlag click
1425
+ this._initListeners();
1426
+ // utils script, and auto country
1427
+ this._initRequests();
1428
+ }
1429
+ }, {
1430
+ key: "_processCountryData",
1431
+ value: function _processCountryData() {
1432
+ // process onlyCountries or excludeCountries array if present
1433
+ this._processAllCountries();
1434
+ // process the countryCodes map
1435
+ this._processCountryCodes();
1436
+ // process the preferredCountries
1437
+ this._processPreferredCountries();
1438
+ // translate countries according to localizedCountries option
1439
+ if (this.options.localizedCountries) this._translateCountriesByLocale();
1440
+ // sort countries by name
1441
+ if (this.options.onlyCountries.length || this.options.localizedCountries) {
1442
+ this.countries.sort(this._countryNameSort);
1443
+ }
1444
+ }
1445
+ }, {
1446
+ key: "_addCountryCode",
1447
+ value: function _addCountryCode(iso2, countryCode, priority) {
1448
+ if (countryCode.length > this.countryCodeMaxLen) {
1449
+ this.countryCodeMaxLen = countryCode.length;
1450
+ }
1451
+ if (!this.countryCodes.hasOwnProperty(countryCode)) {
1452
+ this.countryCodes[countryCode] = [];
1453
+ }
1454
+ // bail if we already have this country for this countryCode
1455
+ for (var i = 0; i < this.countryCodes[countryCode].length; i++) {
1456
+ if (this.countryCodes[countryCode][i] === iso2) return;
1457
+ }
1458
+ // check for undefined as 0 is falsy
1459
+ var index = priority !== undefined$1 ? priority : this.countryCodes[countryCode].length;
1460
+ this.countryCodes[countryCode][index] = iso2;
1461
+ }
1462
+ }, {
1463
+ key: "_processAllCountries",
1464
+ value: function _processAllCountries() {
1465
+ if (this.options.onlyCountries.length) {
1466
+ var lowerCaseOnlyCountries = this.options.onlyCountries.map(function(country) {
1467
+ return country.toLowerCase();
1468
+ });
1469
+ this.countries = allCountries.filter(function(country) {
1470
+ return lowerCaseOnlyCountries.indexOf(country.iso2) > -1;
1471
+ });
1472
+ } else if (this.options.excludeCountries.length) {
1473
+ var lowerCaseExcludeCountries = this.options.excludeCountries.map(function(country) {
1474
+ return country.toLowerCase();
1475
+ });
1476
+ this.countries = allCountries.filter(function(country) {
1477
+ return lowerCaseExcludeCountries.indexOf(country.iso2) === -1;
1478
+ });
1479
+ } else {
1480
+ this.countries = allCountries;
1481
+ }
1482
+ }
1483
+ }, {
1484
+ key: "_translateCountriesByLocale",
1485
+ value: function _translateCountriesByLocale() {
1486
+ for (var i = 0; i < this.countries.length; i++) {
1487
+ var iso = this.countries[i].iso2.toLowerCase();
1488
+ if (this.options.localizedCountries.hasOwnProperty(iso)) {
1489
+ this.countries[i].name = this.options.localizedCountries[iso];
1490
+ }
1491
+ }
1492
+ }
1493
+ }, {
1494
+ key: "_countryNameSort",
1495
+ value: function _countryNameSort(a, b) {
1496
+ return a.name.localeCompare(b.name);
1497
+ }
1498
+ }, {
1499
+ key: "_processCountryCodes",
1500
+ value: function _processCountryCodes() {
1501
+ this.countryCodeMaxLen = 0;
1502
+ // here we store just dial codes
1503
+ this.dialCodes = {};
1504
+ // here we store "country codes" (both dial codes and their area codes)
1505
+ this.countryCodes = {};
1506
+ // first: add dial codes
1507
+ for (var i = 0; i < this.countries.length; i++) {
1508
+ var c = this.countries[i];
1509
+ if (!this.dialCodes[c.dialCode]) this.dialCodes[c.dialCode] = true;
1510
+ this._addCountryCode(c.iso2, c.dialCode, c.priority);
1511
+ }
1512
+ // next: add area codes
1513
+ // this is a second loop over countries, to make sure we have all of the "root" countries
1514
+ // already in the map, so that we can access them, as each time we add an area code substring
1515
+ // to the map, we also need to include the "root" country's code, as that also matches
1516
+ for (var _i = 0; _i < this.countries.length; _i++) {
1517
+ var _c = this.countries[_i];
1518
+ // area codes
1519
+ if (_c.areaCodes) {
1520
+ var rootCountryCode = this.countryCodes[_c.dialCode][0];
1521
+ // for each area code
1522
+ for (var j = 0; j < _c.areaCodes.length; j++) {
1523
+ var areaCode = _c.areaCodes[j];
1524
+ // for each digit in the area code to add all partial matches as well
1525
+ for (var k = 1; k < areaCode.length; k++) {
1526
+ var partialDialCode = _c.dialCode + areaCode.substr(0, k);
1527
+ // start with the root country, as that also matches this dial code
1528
+ this._addCountryCode(rootCountryCode, partialDialCode);
1529
+ this._addCountryCode(_c.iso2, partialDialCode);
1530
+ }
1531
+ // add the full area code
1532
+ this._addCountryCode(_c.iso2, _c.dialCode + areaCode);
1533
+ }
1534
+ }
1535
+ }
1536
+ }
1537
+ }, {
1538
+ key: "_processPreferredCountries",
1539
+ value: function _processPreferredCountries() {
1540
+ this.preferredCountries = [];
1541
+ for (var i = 0; i < this.options.preferredCountries.length; i++) {
1542
+ var countryCode = this.options.preferredCountries[i].toLowerCase();
1543
+ var countryData = this._getCountryData(countryCode, false, true);
1544
+ if (countryData) this.preferredCountries.push(countryData);
1545
+ }
1546
+ }
1547
+ }, {
1548
+ key: "_createEl",
1549
+ value: function _createEl(name, attrs, container) {
1550
+ var el = document.createElement(name);
1551
+ if (attrs) forEachProp(attrs, function(key, value) {
1552
+ return el.setAttribute(key, value);
1553
+ });
1554
+ if (container) container.appendChild(el);
1555
+ return el;
1556
+ }
1557
+ }, {
1558
+ key: "_generateMarkup",
1559
+ value: function _generateMarkup() {
1560
+ // if autocomplete does not exist on the element and its form, then
1561
+ // prevent autocomplete as there's no safe, cross-browser event we can react to, so it can
1562
+ // easily put the plugin in an inconsistent state e.g. the wrong flag selected for the
1563
+ // autocompleted number, which on submit could mean wrong number is saved (esp in nationalMode)
1564
+ if (!this.telInput.hasAttribute("autocomplete") && !(this.telInput.form && this.telInput.form.hasAttribute("autocomplete"))) {
1565
+ this.telInput.setAttribute("autocomplete", "off");
1566
+ }
1567
+ // containers (mostly for positioning)
1568
+ var parentClass = "iti";
1569
+ if (this.options.allowDropdown) parentClass += " iti--allow-dropdown";
1570
+ if (this.options.separateDialCode) parentClass += " iti--separate-dial-code";
1571
+ if (this.options.customContainer) {
1572
+ parentClass += " ";
1573
+ parentClass += this.options.customContainer;
1574
+ }
1575
+ var wrapper = this._createEl("div", {
1576
+ "class": parentClass
1577
+ });
1578
+ this.telInput.parentNode.insertBefore(wrapper, this.telInput);
1579
+ this.flagsContainer = this._createEl("div", {
1580
+ "class": "iti__flag-container"
1581
+ }, wrapper);
1582
+ wrapper.appendChild(this.telInput);
1583
+ // selected flag (displayed to left of input)
1584
+ this.selectedFlag = this._createEl("div", {
1585
+ "class": "iti__selected-flag",
1586
+ role: "combobox",
1587
+ "aria-controls": "iti-".concat(this.id, "__country-listbox"),
1588
+ "aria-owns": "iti-".concat(this.id, "__country-listbox"),
1589
+ "aria-expanded": "false"
1590
+ }, this.flagsContainer);
1591
+ this.selectedFlagInner = this._createEl("div", {
1592
+ "class": "iti__flag"
1593
+ }, this.selectedFlag);
1594
+ if (this.options.separateDialCode) {
1595
+ this.selectedDialCode = this._createEl("div", {
1596
+ "class": "iti__selected-dial-code"
1597
+ }, this.selectedFlag);
1598
+ }
1599
+ if (this.options.allowDropdown) {
1600
+ // make element focusable and tab navigable
1601
+ this.selectedFlag.setAttribute("tabindex", "0");
1602
+ this.dropdownArrow = this._createEl("div", {
1603
+ "class": "iti__arrow"
1604
+ }, this.selectedFlag);
1605
+ // country dropdown: preferred countries, then divider, then all countries
1606
+ this.countryList = this._createEl("ul", {
1607
+ "class": "iti__country-list iti__hide",
1608
+ id: "iti-".concat(this.id, "__country-listbox"),
1609
+ role: "listbox",
1610
+ "aria-label": "List of countries"
1611
+ });
1612
+ if (this.preferredCountries.length) {
1613
+ this._appendListItems(this.preferredCountries, "iti__preferred", true);
1614
+ this._createEl("li", {
1615
+ "class": "iti__divider",
1616
+ role: "separator",
1617
+ "aria-disabled": "true"
1618
+ }, this.countryList);
1619
+ }
1620
+ this._appendListItems(this.countries, "iti__standard");
1621
+ // create dropdownContainer markup
1622
+ if (this.options.dropdownContainer) {
1623
+ this.dropdown = this._createEl("div", {
1624
+ "class": "iti iti--container"
1625
+ });
1626
+ this.dropdown.appendChild(this.countryList);
1627
+ } else {
1628
+ this.flagsContainer.appendChild(this.countryList);
1629
+ }
1630
+ }
1631
+ if (this.options.hiddenInput) {
1632
+ var hiddenInputName = this.options.hiddenInput;
1633
+ var name = this.telInput.getAttribute("name");
1634
+ if (name) {
1635
+ var i = name.lastIndexOf("[");
1636
+ // if input name contains square brackets, then give the hidden input the same name,
1637
+ // replacing the contents of the last set of brackets with the given hiddenInput name
1638
+ if (i !== -1) hiddenInputName = "".concat(name.substr(0, i), "[").concat(hiddenInputName, "]");
1639
+ }
1640
+ this.hiddenInput = this._createEl("input", {
1641
+ type: "hidden",
1642
+ name: hiddenInputName
1643
+ });
1644
+ wrapper.appendChild(this.hiddenInput);
1645
+ }
1646
+ }
1647
+ }, {
1648
+ key: "_appendListItems",
1649
+ value: function _appendListItems(countries, className, preferred) {
1650
+ // we create so many DOM elements, it is faster to build a temp string
1651
+ // and then add everything to the DOM in one go at the end
1652
+ var tmp = "";
1653
+ // for each country
1654
+ for (var i = 0; i < countries.length; i++) {
1655
+ var c = countries[i];
1656
+ var idSuffix = preferred ? "-preferred" : "";
1657
+ // open the list item
1658
+ tmp += "<li class='iti__country ".concat(className, "' tabIndex='-1' id='iti-").concat(this.id, "__item-").concat(c.iso2).concat(idSuffix, "' role='option' data-dial-code='").concat(c.dialCode, "' data-country-code='").concat(c.iso2, "' aria-selected='false'>");
1659
+ // add the flag
1660
+ tmp += "<div class='iti__flag-box'><div class='iti__flag iti__".concat(c.iso2, "'></div></div>");
1661
+ // and the country name and dial code
1662
+ tmp += "<span class='iti__country-name'>".concat(c.name, "</span>");
1663
+ tmp += "<span class='iti__dial-code'>+".concat(c.dialCode, "</span>");
1664
+ // close the list item
1665
+ tmp += "</li>";
1666
+ }
1667
+ this.countryList.insertAdjacentHTML("beforeend", tmp);
1668
+ }
1669
+ }, {
1670
+ key: "_setInitialState",
1671
+ value: function _setInitialState() {
1672
+ // fix firefox bug: when first load page (with input with value set to number with intl dial
1673
+ // code) and initialising plugin removes the dial code from the input, then refresh page,
1674
+ // and we try to init plugin again but this time on number without dial code so get grey flag
1675
+ var attributeValue = this.telInput.getAttribute("value");
1676
+ var inputValue = this.telInput.value;
1677
+ var useAttribute = attributeValue && attributeValue.charAt(0) === "+" && (!inputValue || inputValue.charAt(0) !== "+");
1678
+ var val = useAttribute ? attributeValue : inputValue;
1679
+ var dialCode = this._getDialCode(val);
1680
+ var isRegionlessNanp = this._isRegionlessNanp(val);
1681
+ var _this$options = this.options, initialCountry = _this$options.initialCountry, nationalMode = _this$options.nationalMode, autoHideDialCode = _this$options.autoHideDialCode, separateDialCode = _this$options.separateDialCode;
1682
+ // if we already have a dial code, and it's not a regionlessNanp, we can go ahead and set the
1683
+ // flag, else fall back to the default country
1684
+ if (dialCode && !isRegionlessNanp) {
1685
+ this._updateFlagFromNumber(val);
1686
+ } else if (initialCountry !== "auto") {
1687
+ // see if we should select a flag
1688
+ if (initialCountry) {
1689
+ this._setFlag(initialCountry.toLowerCase());
1690
+ } else {
1691
+ if (dialCode && isRegionlessNanp) {
1692
+ // has intl dial code, is regionless nanp, and no initialCountry, so default to US
1693
+ this._setFlag("us");
1694
+ } else {
1695
+ // no dial code and no initialCountry, so default to first in list
1696
+ this.defaultCountry = this.preferredCountries.length ? this.preferredCountries[0].iso2 : this.countries[0].iso2;
1697
+ if (!val) {
1698
+ this._setFlag(this.defaultCountry);
1699
+ }
1700
+ }
1701
+ }
1702
+ // if empty and no nationalMode and no autoHideDialCode then insert the default dial code
1703
+ if (!val && !nationalMode && !autoHideDialCode && !separateDialCode) {
1704
+ this.telInput.value = "+".concat(this.selectedCountryData.dialCode);
1705
+ }
1706
+ }
1707
+ // NOTE: if initialCountry is set to auto, that will be handled separately
1708
+ // format - note this wont be run after _updateDialCode as that's only called if no val
1709
+ if (val) this._updateValFromNumber(val);
1710
+ }
1711
+ }, {
1712
+ key: "_initListeners",
1713
+ value: function _initListeners() {
1714
+ this._initKeyListeners();
1715
+ if (this.options.autoHideDialCode) this._initBlurListeners();
1716
+ if (this.options.allowDropdown) this._initDropdownListeners();
1717
+ if (this.hiddenInput) this._initHiddenInputListener();
1718
+ }
1719
+ }, {
1720
+ key: "_initHiddenInputListener",
1721
+ value: function _initHiddenInputListener() {
1722
+ var _this3 = this;
1723
+ this._handleHiddenInputSubmit = function() {
1724
+ _this3.hiddenInput.value = _this3.getNumber();
1725
+ };
1726
+ if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleHiddenInputSubmit);
1727
+ }
1728
+ }, {
1729
+ key: "_getClosestLabel",
1730
+ value: function _getClosestLabel() {
1731
+ var el = this.telInput;
1732
+ while (el && el.tagName !== "LABEL") {
1733
+ el = el.parentNode;
1734
+ }
1735
+ return el;
1736
+ }
1737
+ }, {
1738
+ key: "_initDropdownListeners",
1739
+ value: function _initDropdownListeners() {
1740
+ var _this4 = this;
1741
+ // hack for input nested inside label (which is valid markup): clicking the selected-flag to
1742
+ // open the dropdown would then automatically trigger a 2nd click on the input which would
1743
+ // close it again
1744
+ this._handleLabelClick = function(e) {
1745
+ // if the dropdown is closed, then focus the input, else ignore the click
1746
+ if (_this4.countryList.classList.contains("iti__hide")) _this4.telInput.focus(); else e.preventDefault();
1747
+ };
1748
+ var label = this._getClosestLabel();
1749
+ if (label) label.addEventListener("click", this._handleLabelClick);
1750
+ // toggle country dropdown on click
1751
+ this._handleClickSelectedFlag = function() {
1752
+ // only intercept this event if we're opening the dropdown
1753
+ // else let it bubble up to the top ("click-off-to-close" listener)
1754
+ // we cannot just stopPropagation as it may be needed to close another instance
1755
+ if (_this4.countryList.classList.contains("iti__hide") && !_this4.telInput.disabled && !_this4.telInput.readOnly) {
1756
+ _this4._showDropdown();
1757
+ }
1758
+ };
1759
+ this.selectedFlag.addEventListener("click", this._handleClickSelectedFlag);
1760
+ // open dropdown list if currently focused
1761
+ this._handleFlagsContainerKeydown = function(e) {
1762
+ var isDropdownHidden = _this4.countryList.classList.contains("iti__hide");
1763
+ if (isDropdownHidden && [ "ArrowUp", "Up", "ArrowDown", "Down", " ", "Enter" ].indexOf(e.key) !== -1) {
1764
+ // prevent form from being submitted if "ENTER" was pressed
1765
+ e.preventDefault();
1766
+ // prevent event from being handled again by document
1767
+ e.stopPropagation();
1768
+ _this4._showDropdown();
1769
+ }
1770
+ // allow navigation from dropdown to input on TAB
1771
+ if (e.key === "Tab") _this4._closeDropdown();
1772
+ };
1773
+ this.flagsContainer.addEventListener("keydown", this._handleFlagsContainerKeydown);
1774
+ }
1775
+ }, {
1776
+ key: "_initRequests",
1777
+ value: function _initRequests() {
1778
+ var _this5 = this;
1779
+ // if the user has specified the path to the utils script, fetch it on window.load, else resolve
1780
+ if (this.options.utilsScript && !window.intlTelInputUtils) {
1781
+ // if the plugin is being initialised after the window.load event has already been fired
1782
+ if (window.intlTelInputGlobals.documentReady()) {
1783
+ window.intlTelInputGlobals.loadUtils(this.options.utilsScript);
1784
+ } else {
1785
+ // wait until the load event so we don't block any other requests e.g. the flags image
1786
+ window.addEventListener("load", function() {
1787
+ window.intlTelInputGlobals.loadUtils(_this5.options.utilsScript);
1788
+ });
1789
+ }
1790
+ } else this.resolveUtilsScriptPromise();
1791
+ if (this.options.initialCountry === "auto") this._loadAutoCountry(); else this.resolveAutoCountryPromise();
1792
+ }
1793
+ }, {
1794
+ key: "_loadAutoCountry",
1795
+ value: function _loadAutoCountry() {
1796
+ // 3 options:
1797
+ // 1) already loaded (we're done)
1798
+ // 2) not already started loading (start)
1799
+ // 3) already started loading (do nothing - just wait for loading callback to fire)
1800
+ if (window.intlTelInputGlobals.autoCountry) {
1801
+ this.handleAutoCountry();
1802
+ } else if (!window.intlTelInputGlobals.startedLoadingAutoCountry) {
1803
+ // don't do this twice!
1804
+ window.intlTelInputGlobals.startedLoadingAutoCountry = true;
1805
+ if (typeof this.options.geoIpLookup === "function") {
1806
+ this.options.geoIpLookup(function(countryCode) {
1807
+ window.intlTelInputGlobals.autoCountry = countryCode.toLowerCase();
1808
+ // tell all instances the auto country is ready
1809
+ // TODO: this should just be the current instances
1810
+ // UPDATE: use setTimeout in case their geoIpLookup function calls this callback straight
1811
+ // away (e.g. if they have already done the geo ip lookup somewhere else). Using
1812
+ // setTimeout means that the current thread of execution will finish before executing
1813
+ // this, which allows the plugin to finish initialising.
1814
+ setTimeout(function() {
1815
+ return forEachInstance("handleAutoCountry");
1816
+ });
1817
+ }, function() {
1818
+ return forEachInstance("rejectAutoCountryPromise");
1819
+ });
1820
+ }
1821
+ }
1822
+ }
1823
+ }, {
1824
+ key: "_initKeyListeners",
1825
+ value: function _initKeyListeners() {
1826
+ var _this6 = this;
1827
+ // update flag on keyup
1828
+ this._handleKeyupEvent = function() {
1829
+ if (_this6._updateFlagFromNumber(_this6.telInput.value)) {
1830
+ _this6._triggerCountryChange();
1831
+ }
1832
+ };
1833
+ this.telInput.addEventListener("keyup", this._handleKeyupEvent);
1834
+ // update flag on cut/paste events (now supported in all major browsers)
1835
+ this._handleClipboardEvent = function() {
1836
+ // hack because "paste" event is fired before input is updated
1837
+ setTimeout(_this6._handleKeyupEvent);
1838
+ };
1839
+ this.telInput.addEventListener("cut", this._handleClipboardEvent);
1840
+ this.telInput.addEventListener("paste", this._handleClipboardEvent);
1841
+ }
1842
+ }, {
1843
+ key: "_cap",
1844
+ value: function _cap(number) {
1845
+ var max = this.telInput.getAttribute("maxlength");
1846
+ return max && number.length > max ? number.substr(0, max) : number;
1847
+ }
1848
+ }, {
1849
+ key: "_initBlurListeners",
1850
+ value: function _initBlurListeners() {
1851
+ var _this7 = this;
1852
+ // on blur or form submit: if just a dial code then remove it
1853
+ this._handleSubmitOrBlurEvent = function() {
1854
+ _this7._removeEmptyDialCode();
1855
+ };
1856
+ if (this.telInput.form) this.telInput.form.addEventListener("submit", this._handleSubmitOrBlurEvent);
1857
+ this.telInput.addEventListener("blur", this._handleSubmitOrBlurEvent);
1858
+ }
1859
+ }, {
1860
+ key: "_removeEmptyDialCode",
1861
+ value: function _removeEmptyDialCode() {
1862
+ if (this.telInput.value.charAt(0) === "+") {
1863
+ var numeric = this._getNumeric(this.telInput.value);
1864
+ // if just a plus, or if just a dial code
1865
+ if (!numeric || this.selectedCountryData.dialCode === numeric) {
1866
+ this.telInput.value = "";
1867
+ }
1868
+ }
1869
+ }
1870
+ }, {
1871
+ key: "_getNumeric",
1872
+ value: function _getNumeric(s) {
1873
+ return s.replace(/\D/g, "");
1874
+ }
1875
+ }, {
1876
+ key: "_trigger",
1877
+ value: function _trigger(name) {
1878
+ // have to use old school document.createEvent as IE11 doesn't support `new Event()` syntax
1879
+ var e = document.createEvent("Event");
1880
+ e.initEvent(name, true, true);
1881
+ // can bubble, and is cancellable
1882
+ this.telInput.dispatchEvent(e);
1883
+ }
1884
+ }, {
1885
+ key: "_showDropdown",
1886
+ value: function _showDropdown() {
1887
+ this.countryList.classList.remove("iti__hide");
1888
+ this.selectedFlag.setAttribute("aria-expanded", "true");
1889
+ this._setDropdownPosition();
1890
+ // update highlighting and scroll to active list item
1891
+ if (this.activeItem) {
1892
+ this._highlightListItem(this.activeItem, false);
1893
+ this._scrollTo(this.activeItem, true);
1894
+ }
1895
+ // bind all the dropdown-related listeners: mouseover, click, click-off, keydown
1896
+ this._bindDropdownListeners();
1897
+ // update the arrow
1898
+ this.dropdownArrow.classList.add("iti__arrow--up");
1899
+ this._trigger("open:countrydropdown");
1900
+ }
1901
+ }, {
1902
+ key: "_toggleClass",
1903
+ value: function _toggleClass(el, className, shouldHaveClass) {
1904
+ if (shouldHaveClass && !el.classList.contains(className)) el.classList.add(className); else if (!shouldHaveClass && el.classList.contains(className)) el.classList.remove(className);
1905
+ }
1906
+ }, {
1907
+ key: "_setDropdownPosition",
1908
+ value: function _setDropdownPosition() {
1909
+ var _this8 = this;
1910
+ if (this.options.dropdownContainer) {
1911
+ this.options.dropdownContainer.appendChild(this.dropdown);
1912
+ }
1913
+ if (!this.isMobile) {
1914
+ var pos = this.telInput.getBoundingClientRect();
1915
+ // windowTop from https://stackoverflow.com/a/14384091/217866
1916
+ var windowTop = window.pageYOffset || document.documentElement.scrollTop;
1917
+ var inputTop = pos.top + windowTop;
1918
+ var dropdownHeight = this.countryList.offsetHeight;
1919
+ // dropdownFitsBelow = (dropdownBottom < windowBottom)
1920
+ var dropdownFitsBelow = inputTop + this.telInput.offsetHeight + dropdownHeight < windowTop + window.innerHeight;
1921
+ var dropdownFitsAbove = inputTop - dropdownHeight > windowTop;
1922
+ // by default, the dropdown will be below the input. If we want to position it above the
1923
+ // input, we add the dropup class.
1924
+ this._toggleClass(this.countryList, "iti__country-list--dropup", !dropdownFitsBelow && dropdownFitsAbove);
1925
+ // if dropdownContainer is enabled, calculate postion
1926
+ if (this.options.dropdownContainer) {
1927
+ // by default the dropdown will be directly over the input because it's not in the flow.
1928
+ // If we want to position it below, we need to add some extra top value.
1929
+ var extraTop = !dropdownFitsBelow && dropdownFitsAbove ? 0 : this.telInput.offsetHeight;
1930
+ // calculate placement
1931
+ this.dropdown.style.top = "".concat(inputTop + extraTop, "px");
1932
+ this.dropdown.style.left = "".concat(pos.left + document.body.scrollLeft, "px");
1933
+ // close menu on window scroll
1934
+ this._handleWindowScroll = function() {
1935
+ return _this8._closeDropdown();
1936
+ };
1937
+ window.addEventListener("scroll", this._handleWindowScroll);
1938
+ }
1939
+ }
1940
+ }
1941
+ }, {
1942
+ key: "_getClosestListItem",
1943
+ value: function _getClosestListItem(target) {
1944
+ var el = target;
1945
+ while (el && el !== this.countryList && !el.classList.contains("iti__country")) {
1946
+ el = el.parentNode;
1947
+ }
1948
+ // if we reached the countryList element, then return null
1949
+ return el === this.countryList ? null : el;
1950
+ }
1951
+ }, {
1952
+ key: "_bindDropdownListeners",
1953
+ value: function _bindDropdownListeners() {
1954
+ var _this9 = this;
1955
+ // when mouse over a list item, just highlight that one
1956
+ // we add the class "highlight", so if they hit "enter" we know which one to select
1957
+ this._handleMouseoverCountryList = function(e) {
1958
+ // handle event delegation, as we're listening for this event on the countryList
1959
+ var listItem = _this9._getClosestListItem(e.target);
1960
+ if (listItem) _this9._highlightListItem(listItem, false);
1961
+ };
1962
+ this.countryList.addEventListener("mouseover", this._handleMouseoverCountryList);
1963
+ // listen for country selection
1964
+ this._handleClickCountryList = function(e) {
1965
+ var listItem = _this9._getClosestListItem(e.target);
1966
+ if (listItem) _this9._selectListItem(listItem);
1967
+ };
1968
+ this.countryList.addEventListener("click", this._handleClickCountryList);
1969
+ // click off to close
1970
+ // (except when this initial opening click is bubbling up)
1971
+ // we cannot just stopPropagation as it may be needed to close another instance
1972
+ var isOpening = true;
1973
+ this._handleClickOffToClose = function() {
1974
+ if (!isOpening) _this9._closeDropdown();
1975
+ isOpening = false;
1976
+ };
1977
+ document.documentElement.addEventListener("click", this._handleClickOffToClose);
1978
+ // listen for up/down scrolling, enter to select, or letters to jump to country name.
1979
+ // use keydown as keypress doesn't fire for non-char keys and we want to catch if they
1980
+ // just hit down and hold it to scroll down (no keyup event).
1981
+ // listen on the document because that's where key events are triggered if no input has focus
1982
+ var query = "";
1983
+ var queryTimer = null;
1984
+ this._handleKeydownOnDropdown = function(e) {
1985
+ // prevent down key from scrolling the whole page,
1986
+ // and enter key from submitting a form etc
1987
+ e.preventDefault();
1988
+ // up and down to navigate
1989
+ if (e.key === "ArrowUp" || e.key === "Up" || e.key === "ArrowDown" || e.key === "Down") _this9._handleUpDownKey(e.key); else if (e.key === "Enter") _this9._handleEnterKey(); else if (e.key === "Escape") _this9._closeDropdown(); else if (/^[a-zA-ZÀ-ÿа-яА-Я ]$/.test(e.key)) {
1990
+ // jump to countries that start with the query string
1991
+ if (queryTimer) clearTimeout(queryTimer);
1992
+ query += e.key.toLowerCase();
1993
+ _this9._searchForCountry(query);
1994
+ // if the timer hits 1 second, reset the query
1995
+ queryTimer = setTimeout(function() {
1996
+ query = "";
1997
+ }, 1e3);
1998
+ }
1999
+ };
2000
+ document.addEventListener("keydown", this._handleKeydownOnDropdown);
2001
+ }
2002
+ }, {
2003
+ key: "_handleUpDownKey",
2004
+ value: function _handleUpDownKey(key) {
2005
+ var next = key === "ArrowUp" || key === "Up" ? this.highlightedItem.previousElementSibling : this.highlightedItem.nextElementSibling;
2006
+ if (next) {
2007
+ // skip the divider
2008
+ if (next.classList.contains("iti__divider")) {
2009
+ next = key === "ArrowUp" || key === "Up" ? next.previousElementSibling : next.nextElementSibling;
2010
+ }
2011
+ this._highlightListItem(next, true);
2012
+ }
2013
+ }
2014
+ }, {
2015
+ key: "_handleEnterKey",
2016
+ value: function _handleEnterKey() {
2017
+ if (this.highlightedItem) this._selectListItem(this.highlightedItem);
2018
+ }
2019
+ }, {
2020
+ key: "_searchForCountry",
2021
+ value: function _searchForCountry(query) {
2022
+ for (var i = 0; i < this.countries.length; i++) {
2023
+ if (this._startsWith(this.countries[i].name, query)) {
2024
+ var listItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(this.countries[i].iso2));
2025
+ // update highlighting and scroll
2026
+ this._highlightListItem(listItem, false);
2027
+ this._scrollTo(listItem, true);
2028
+ break;
2029
+ }
2030
+ }
2031
+ }
2032
+ }, {
2033
+ key: "_startsWith",
2034
+ value: function _startsWith(a, b) {
2035
+ return a.substr(0, b.length).toLowerCase() === b;
2036
+ }
2037
+ }, {
2038
+ key: "_updateValFromNumber",
2039
+ value: function _updateValFromNumber(originalNumber) {
2040
+ var number = originalNumber;
2041
+ if (this.options.formatOnDisplay && window.intlTelInputUtils && this.selectedCountryData) {
2042
+ var useNational = !this.options.separateDialCode && (this.options.nationalMode || number.charAt(0) !== "+");
2043
+ var _intlTelInputUtils$nu = intlTelInputUtils.numberFormat, NATIONAL = _intlTelInputUtils$nu.NATIONAL, INTERNATIONAL = _intlTelInputUtils$nu.INTERNATIONAL;
2044
+ var format = useNational ? NATIONAL : INTERNATIONAL;
2045
+ number = intlTelInputUtils.formatNumber(number, this.selectedCountryData.iso2, format);
2046
+ }
2047
+ number = this._beforeSetNumber(number);
2048
+ this.telInput.value = number;
2049
+ }
2050
+ }, {
2051
+ key: "_updateFlagFromNumber",
2052
+ value: function _updateFlagFromNumber(originalNumber) {
2053
+ // if we're in nationalMode and we already have US/Canada selected, make sure the number starts
2054
+ // with a +1 so _getDialCode will be able to extract the area code
2055
+ // update: if we dont yet have selectedCountryData, but we're here (trying to update the flag
2056
+ // from the number), that means we're initialising the plugin with a number that already has a
2057
+ // dial code, so fine to ignore this bit
2058
+ var number = originalNumber;
2059
+ var selectedDialCode = this.selectedCountryData.dialCode;
2060
+ var isNanp = selectedDialCode === "1";
2061
+ if (number && this.options.nationalMode && isNanp && number.charAt(0) !== "+") {
2062
+ if (number.charAt(0) !== "1") number = "1".concat(number);
2063
+ number = "+".concat(number);
2064
+ }
2065
+ // update flag if user types area code for another country
2066
+ if (this.options.separateDialCode && selectedDialCode && number.charAt(0) !== "+") {
2067
+ number = "+".concat(selectedDialCode).concat(number);
2068
+ }
2069
+ // try and extract valid dial code from input
2070
+ var dialCode = this._getDialCode(number, true);
2071
+ var numeric = this._getNumeric(number);
2072
+ var countryCode = null;
2073
+ if (dialCode) {
2074
+ var countryCodes = this.countryCodes[this._getNumeric(dialCode)];
2075
+ // check if the right country is already selected. this should be false if the number is
2076
+ // longer than the matched dial code because in this case we need to make sure that if
2077
+ // there are multiple country matches, that the first one is selected (note: we could
2078
+ // just check that here, but it requires the same loop that we already have later)
2079
+ var alreadySelected = countryCodes.indexOf(this.selectedCountryData.iso2) !== -1 && numeric.length <= dialCode.length - 1;
2080
+ var isRegionlessNanpNumber = selectedDialCode === "1" && this._isRegionlessNanp(numeric);
2081
+ // only update the flag if:
2082
+ // A) NOT (we currently have a NANP flag selected, and the number is a regionlessNanp)
2083
+ // AND
2084
+ // B) the right country is not already selected
2085
+ if (!isRegionlessNanpNumber && !alreadySelected) {
2086
+ // if using onlyCountries option, countryCodes[0] may be empty, so we must find the first
2087
+ // non-empty index
2088
+ for (var j = 0; j < countryCodes.length; j++) {
2089
+ if (countryCodes[j]) {
2090
+ countryCode = countryCodes[j];
2091
+ break;
2092
+ }
2093
+ }
2094
+ }
2095
+ } else if (number.charAt(0) === "+" && numeric.length) {
2096
+ // invalid dial code, so empty
2097
+ // Note: use getNumeric here because the number has not been formatted yet, so could contain
2098
+ // bad chars
2099
+ countryCode = "";
2100
+ } else if (!number || number === "+") {
2101
+ // empty, or just a plus, so default
2102
+ countryCode = this.defaultCountry;
2103
+ }
2104
+ if (countryCode !== null) {
2105
+ return this._setFlag(countryCode);
2106
+ }
2107
+ return false;
2108
+ }
2109
+ }, {
2110
+ key: "_isRegionlessNanp",
2111
+ value: function _isRegionlessNanp(number) {
2112
+ var numeric = this._getNumeric(number);
2113
+ if (numeric.charAt(0) === "1") {
2114
+ var areaCode = numeric.substr(1, 3);
2115
+ return regionlessNanpNumbers.indexOf(areaCode) !== -1;
2116
+ }
2117
+ return false;
2118
+ }
2119
+ }, {
2120
+ key: "_highlightListItem",
2121
+ value: function _highlightListItem(listItem, shouldFocus) {
2122
+ var prevItem = this.highlightedItem;
2123
+ if (prevItem) prevItem.classList.remove("iti__highlight");
2124
+ this.highlightedItem = listItem;
2125
+ this.highlightedItem.classList.add("iti__highlight");
2126
+ if (shouldFocus) this.highlightedItem.focus();
2127
+ }
2128
+ }, {
2129
+ key: "_getCountryData",
2130
+ value: function _getCountryData(countryCode, ignoreOnlyCountriesOption, allowFail) {
2131
+ var countryList = ignoreOnlyCountriesOption ? allCountries : this.countries;
2132
+ for (var i = 0; i < countryList.length; i++) {
2133
+ if (countryList[i].iso2 === countryCode) {
2134
+ return countryList[i];
2135
+ }
2136
+ }
2137
+ if (allowFail) {
2138
+ return null;
2139
+ }
2140
+ throw new Error("No country data for '".concat(countryCode, "'"));
2141
+ }
2142
+ }, {
2143
+ key: "_setFlag",
2144
+ value: function _setFlag(countryCode) {
2145
+ var prevCountry = this.selectedCountryData.iso2 ? this.selectedCountryData : {};
2146
+ // do this first as it will throw an error and stop if countryCode is invalid
2147
+ this.selectedCountryData = countryCode ? this._getCountryData(countryCode, false, false) : {};
2148
+ // update the defaultCountry - we only need the iso2 from now on, so just store that
2149
+ if (this.selectedCountryData.iso2) {
2150
+ this.defaultCountry = this.selectedCountryData.iso2;
2151
+ }
2152
+ this.selectedFlagInner.setAttribute("class", "iti__flag iti__".concat(countryCode));
2153
+ // update the selected country's title attribute
2154
+ var title = countryCode ? "".concat(this.selectedCountryData.name, ": +").concat(this.selectedCountryData.dialCode) : "Unknown";
2155
+ this.selectedFlag.setAttribute("title", title);
2156
+ if (this.options.separateDialCode) {
2157
+ var dialCode = this.selectedCountryData.dialCode ? "+".concat(this.selectedCountryData.dialCode) : "";
2158
+ this.selectedDialCode.innerHTML = dialCode;
2159
+ // offsetWidth is zero if input is in a hidden container during initialisation
2160
+ var selectedFlagWidth = this.selectedFlag.offsetWidth || this._getHiddenSelectedFlagWidth();
2161
+ // add 6px of padding after the grey selected-dial-code box, as this is what we use in the css
2162
+ this.telInput.style.paddingLeft = "".concat(selectedFlagWidth + 6, "px");
2163
+ }
2164
+ // and the input's placeholder
2165
+ this._updatePlaceholder();
2166
+ // update the active list item
2167
+ if (this.options.allowDropdown) {
2168
+ var prevItem = this.activeItem;
2169
+ if (prevItem) {
2170
+ prevItem.classList.remove("iti__active");
2171
+ prevItem.setAttribute("aria-selected", "false");
2172
+ }
2173
+ if (countryCode) {
2174
+ // check if there is a preferred item first, else fall back to standard
2175
+ var nextItem = this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode, "-preferred")) || this.countryList.querySelector("#iti-".concat(this.id, "__item-").concat(countryCode));
2176
+ nextItem.setAttribute("aria-selected", "true");
2177
+ nextItem.classList.add("iti__active");
2178
+ this.activeItem = nextItem;
2179
+ this.selectedFlag.setAttribute("aria-activedescendant", nextItem.getAttribute("id"));
2180
+ }
2181
+ }
2182
+ // return if the flag has changed or not
2183
+ return prevCountry.iso2 !== countryCode;
2184
+ }
2185
+ }, {
2186
+ key: "_getHiddenSelectedFlagWidth",
2187
+ value: function _getHiddenSelectedFlagWidth() {
2188
+ // to get the right styling to apply, all we need is a shallow clone of the container,
2189
+ // and then to inject a deep clone of the selectedFlag element
2190
+ var containerClone = this.telInput.parentNode.cloneNode();
2191
+ containerClone.style.visibility = "hidden";
2192
+ document.body.appendChild(containerClone);
2193
+ var flagsContainerClone = this.flagsContainer.cloneNode();
2194
+ containerClone.appendChild(flagsContainerClone);
2195
+ var selectedFlagClone = this.selectedFlag.cloneNode(true);
2196
+ flagsContainerClone.appendChild(selectedFlagClone);
2197
+ var width = selectedFlagClone.offsetWidth;
2198
+ containerClone.parentNode.removeChild(containerClone);
2199
+ return width;
2200
+ }
2201
+ }, {
2202
+ key: "_updatePlaceholder",
2203
+ value: function _updatePlaceholder() {
2204
+ var shouldSetPlaceholder = this.options.autoPlaceholder === "aggressive" || !this.hadInitialPlaceholder && this.options.autoPlaceholder === "polite";
2205
+ if (window.intlTelInputUtils && shouldSetPlaceholder) {
2206
+ var numberType = intlTelInputUtils.numberType[this.options.placeholderNumberType];
2207
+ var placeholder = this.selectedCountryData.iso2 ? intlTelInputUtils.getExampleNumber(this.selectedCountryData.iso2, this.options.nationalMode, numberType) : "";
2208
+ placeholder = this._beforeSetNumber(placeholder);
2209
+ if (typeof this.options.customPlaceholder === "function") {
2210
+ placeholder = this.options.customPlaceholder(placeholder, this.selectedCountryData);
2211
+ }
2212
+ this.telInput.setAttribute("placeholder", placeholder);
2213
+ }
2214
+ }
2215
+ }, {
2216
+ key: "_selectListItem",
2217
+ value: function _selectListItem(listItem) {
2218
+ // update selected flag and active list item
2219
+ var flagChanged = this._setFlag(listItem.getAttribute("data-country-code"));
2220
+ this._closeDropdown();
2221
+ this._updateDialCode(listItem.getAttribute("data-dial-code"), true);
2222
+ // focus the input
2223
+ this.telInput.focus();
2224
+ // put cursor at end - this fix is required for FF and IE11 (with nationalMode=false i.e. auto
2225
+ // inserting dial code), who try to put the cursor at the beginning the first time
2226
+ var len = this.telInput.value.length;
2227
+ this.telInput.setSelectionRange(len, len);
2228
+ if (flagChanged) {
2229
+ this._triggerCountryChange();
2230
+ }
2231
+ }
2232
+ }, {
2233
+ key: "_closeDropdown",
2234
+ value: function _closeDropdown() {
2235
+ this.countryList.classList.add("iti__hide");
2236
+ this.selectedFlag.setAttribute("aria-expanded", "false");
2237
+ // update the arrow
2238
+ this.dropdownArrow.classList.remove("iti__arrow--up");
2239
+ // unbind key events
2240
+ document.removeEventListener("keydown", this._handleKeydownOnDropdown);
2241
+ document.documentElement.removeEventListener("click", this._handleClickOffToClose);
2242
+ this.countryList.removeEventListener("mouseover", this._handleMouseoverCountryList);
2243
+ this.countryList.removeEventListener("click", this._handleClickCountryList);
2244
+ // remove menu from container
2245
+ if (this.options.dropdownContainer) {
2246
+ if (!this.isMobile) window.removeEventListener("scroll", this._handleWindowScroll);
2247
+ if (this.dropdown.parentNode) this.dropdown.parentNode.removeChild(this.dropdown);
2248
+ }
2249
+ this._trigger("close:countrydropdown");
2250
+ }
2251
+ }, {
2252
+ key: "_scrollTo",
2253
+ value: function _scrollTo(element, middle) {
2254
+ var container = this.countryList;
2255
+ // windowTop from https://stackoverflow.com/a/14384091/217866
2256
+ var windowTop = window.pageYOffset || document.documentElement.scrollTop;
2257
+ var containerHeight = container.offsetHeight;
2258
+ var containerTop = container.getBoundingClientRect().top + windowTop;
2259
+ var containerBottom = containerTop + containerHeight;
2260
+ var elementHeight = element.offsetHeight;
2261
+ var elementTop = element.getBoundingClientRect().top + windowTop;
2262
+ var elementBottom = elementTop + elementHeight;
2263
+ var newScrollTop = elementTop - containerTop + container.scrollTop;
2264
+ var middleOffset = containerHeight / 2 - elementHeight / 2;
2265
+ if (elementTop < containerTop) {
2266
+ // scroll up
2267
+ if (middle) newScrollTop -= middleOffset;
2268
+ container.scrollTop = newScrollTop;
2269
+ } else if (elementBottom > containerBottom) {
2270
+ // scroll down
2271
+ if (middle) newScrollTop += middleOffset;
2272
+ var heightDifference = containerHeight - elementHeight;
2273
+ container.scrollTop = newScrollTop - heightDifference;
2274
+ }
2275
+ }
2276
+ }, {
2277
+ key: "_updateDialCode",
2278
+ value: function _updateDialCode(newDialCodeBare, hasSelectedListItem) {
2279
+ var inputVal = this.telInput.value;
2280
+ // save having to pass this every time
2281
+ var newDialCode = "+".concat(newDialCodeBare);
2282
+ var newNumber;
2283
+ if (inputVal.charAt(0) === "+") {
2284
+ // there's a plus so we're dealing with a replacement (doesn't matter if nationalMode or not)
2285
+ var prevDialCode = this._getDialCode(inputVal);
2286
+ if (prevDialCode) {
2287
+ // current number contains a valid dial code, so replace it
2288
+ newNumber = inputVal.replace(prevDialCode, newDialCode);
2289
+ } else {
2290
+ // current number contains an invalid dial code, so ditch it
2291
+ // (no way to determine where the invalid dial code ends and the rest of the number begins)
2292
+ newNumber = newDialCode;
2293
+ }
2294
+ } else if (this.options.nationalMode || this.options.separateDialCode) {
2295
+ // don't do anything
2296
+ return;
2297
+ } else {
2298
+ // nationalMode is disabled
2299
+ if (inputVal) {
2300
+ // there is an existing value with no dial code: prefix the new dial code
2301
+ newNumber = newDialCode + inputVal;
2302
+ } else if (hasSelectedListItem || !this.options.autoHideDialCode) {
2303
+ // no existing value and either they've just selected a list item, or autoHideDialCode is
2304
+ // disabled: insert new dial code
2305
+ newNumber = newDialCode;
2306
+ } else {
2307
+ return;
2308
+ }
2309
+ }
2310
+ this.telInput.value = newNumber;
2311
+ }
2312
+ }, {
2313
+ key: "_getDialCode",
2314
+ value: function _getDialCode(number, includeAreaCode) {
2315
+ var dialCode = "";
2316
+ // only interested in international numbers (starting with a plus)
2317
+ if (number.charAt(0) === "+") {
2318
+ var numericChars = "";
2319
+ // iterate over chars
2320
+ for (var i = 0; i < number.length; i++) {
2321
+ var c = number.charAt(i);
2322
+ // if char is number (https://stackoverflow.com/a/8935649/217866)
2323
+ if (!isNaN(parseInt(c, 10))) {
2324
+ numericChars += c;
2325
+ // if current numericChars make a valid dial code
2326
+ if (includeAreaCode) {
2327
+ if (this.countryCodes[numericChars]) {
2328
+ // store the actual raw string (useful for matching later)
2329
+ dialCode = number.substr(0, i + 1);
2330
+ }
2331
+ } else {
2332
+ if (this.dialCodes[numericChars]) {
2333
+ dialCode = number.substr(0, i + 1);
2334
+ // if we're just looking for a dial code, we can break as soon as we find one
2335
+ break;
2336
+ }
2337
+ }
2338
+ // stop searching as soon as we can - in this case when we hit max len
2339
+ if (numericChars.length === this.countryCodeMaxLen) {
2340
+ break;
2341
+ }
2342
+ }
2343
+ }
2344
+ }
2345
+ return dialCode;
2346
+ }
2347
+ }, {
2348
+ key: "_getFullNumber",
2349
+ value: function _getFullNumber() {
2350
+ var val = this.telInput.value.trim();
2351
+ var dialCode = this.selectedCountryData.dialCode;
2352
+ var prefix;
2353
+ var numericVal = this._getNumeric(val);
2354
+ if (this.options.separateDialCode && val.charAt(0) !== "+" && dialCode && numericVal) {
2355
+ // when using separateDialCode, it is visible so is effectively part of the typed number
2356
+ prefix = "+".concat(dialCode);
2357
+ } else {
2358
+ prefix = "";
2359
+ }
2360
+ return prefix + val;
2361
+ }
2362
+ }, {
2363
+ key: "_beforeSetNumber",
2364
+ value: function _beforeSetNumber(originalNumber) {
2365
+ var number = originalNumber;
2366
+ if (this.options.separateDialCode) {
2367
+ var dialCode = this._getDialCode(number);
2368
+ // if there is a valid dial code
2369
+ if (dialCode) {
2370
+ // in case _getDialCode returned an area code as well
2371
+ dialCode = "+".concat(this.selectedCountryData.dialCode);
2372
+ // a lot of numbers will have a space separating the dial code and the main number, and
2373
+ // some NANP numbers will have a hyphen e.g. +1 684-733-1234 - in both cases we want to get
2374
+ // rid of it
2375
+ // NOTE: don't just trim all non-numerics as may want to preserve an open parenthesis etc
2376
+ var start = number[dialCode.length] === " " || number[dialCode.length] === "-" ? dialCode.length + 1 : dialCode.length;
2377
+ number = number.substr(start);
2378
+ }
2379
+ }
2380
+ return this._cap(number);
2381
+ }
2382
+ }, {
2383
+ key: "_triggerCountryChange",
2384
+ value: function _triggerCountryChange() {
2385
+ this._trigger("countrychange");
2386
+ }
2387
+ }, {
2388
+ key: "handleAutoCountry",
2389
+ value: function handleAutoCountry() {
2390
+ if (this.options.initialCountry === "auto") {
2391
+ // we must set this even if there is an initial val in the input: in case the initial val is
2392
+ // invalid and they delete it - they should see their auto country
2393
+ this.defaultCountry = window.intlTelInputGlobals.autoCountry;
2394
+ // if there's no initial value in the input, then update the flag
2395
+ if (!this.telInput.value) {
2396
+ this.setCountry(this.defaultCountry);
2397
+ }
2398
+ this.resolveAutoCountryPromise();
2399
+ }
2400
+ }
2401
+ }, {
2402
+ key: "handleUtils",
2403
+ value: function handleUtils() {
2404
+ // if the request was successful
2405
+ if (window.intlTelInputUtils) {
2406
+ // if there's an initial value in the input, then format it
2407
+ if (this.telInput.value) {
2408
+ this._updateValFromNumber(this.telInput.value);
2409
+ }
2410
+ this._updatePlaceholder();
2411
+ }
2412
+ this.resolveUtilsScriptPromise();
2413
+ }
2414
+ }, {
2415
+ key: "destroy",
2416
+ value: function destroy() {
2417
+ var form = this.telInput.form;
2418
+ if (this.options.allowDropdown) {
2419
+ // make sure the dropdown is closed (and unbind listeners)
2420
+ this._closeDropdown();
2421
+ this.selectedFlag.removeEventListener("click", this._handleClickSelectedFlag);
2422
+ this.flagsContainer.removeEventListener("keydown", this._handleFlagsContainerKeydown);
2423
+ // label click hack
2424
+ var label = this._getClosestLabel();
2425
+ if (label) label.removeEventListener("click", this._handleLabelClick);
2426
+ }
2427
+ // unbind hiddenInput listeners
2428
+ if (this.hiddenInput && form) form.removeEventListener("submit", this._handleHiddenInputSubmit);
2429
+ // unbind autoHideDialCode listeners
2430
+ if (this.options.autoHideDialCode) {
2431
+ if (form) form.removeEventListener("submit", this._handleSubmitOrBlurEvent);
2432
+ this.telInput.removeEventListener("blur", this._handleSubmitOrBlurEvent);
2433
+ }
2434
+ // unbind key events, and cut/paste events
2435
+ this.telInput.removeEventListener("keyup", this._handleKeyupEvent);
2436
+ this.telInput.removeEventListener("cut", this._handleClipboardEvent);
2437
+ this.telInput.removeEventListener("paste", this._handleClipboardEvent);
2438
+ // remove attribute of id instance: data-intl-tel-input-id
2439
+ this.telInput.removeAttribute("data-intl-tel-input-id");
2440
+ // remove markup (but leave the original input)
2441
+ var wrapper = this.telInput.parentNode;
2442
+ wrapper.parentNode.insertBefore(this.telInput, wrapper);
2443
+ wrapper.parentNode.removeChild(wrapper);
2444
+ delete window.intlTelInputGlobals.instances[this.id];
2445
+ }
2446
+ }, {
2447
+ key: "getExtension",
2448
+ value: function getExtension() {
2449
+ if (window.intlTelInputUtils) {
2450
+ return intlTelInputUtils.getExtension(this._getFullNumber(), this.selectedCountryData.iso2);
2451
+ }
2452
+ return "";
2453
+ }
2454
+ }, {
2455
+ key: "getNumber",
2456
+ value: function getNumber(format) {
2457
+ if (window.intlTelInputUtils) {
2458
+ var iso2 = this.selectedCountryData.iso2;
2459
+ return intlTelInputUtils.formatNumber(this._getFullNumber(), iso2, format);
2460
+ }
2461
+ return "";
2462
+ }
2463
+ }, {
2464
+ key: "getNumberType",
2465
+ value: function getNumberType() {
2466
+ if (window.intlTelInputUtils) {
2467
+ return intlTelInputUtils.getNumberType(this._getFullNumber(), this.selectedCountryData.iso2);
2468
+ }
2469
+ return -99;
2470
+ }
2471
+ }, {
2472
+ key: "getSelectedCountryData",
2473
+ value: function getSelectedCountryData() {
2474
+ return this.selectedCountryData;
2475
+ }
2476
+ }, {
2477
+ key: "getValidationError",
2478
+ value: function getValidationError() {
2479
+ if (window.intlTelInputUtils) {
2480
+ var iso2 = this.selectedCountryData.iso2;
2481
+ return intlTelInputUtils.getValidationError(this._getFullNumber(), iso2);
2482
+ }
2483
+ return -99;
2484
+ }
2485
+ }, {
2486
+ key: "isValidNumber",
2487
+ value: function isValidNumber() {
2488
+ var val = this._getFullNumber().trim();
2489
+ var countryCode = this.options.nationalMode ? this.selectedCountryData.iso2 : "";
2490
+ return window.intlTelInputUtils ? intlTelInputUtils.isValidNumber(val, countryCode) : null;
2491
+ }
2492
+ }, {
2493
+ key: "setCountry",
2494
+ value: function setCountry(originalCountryCode) {
2495
+ var countryCode = originalCountryCode.toLowerCase();
2496
+ // check if already selected
2497
+ if (!this.selectedFlagInner.classList.contains("iti__".concat(countryCode))) {
2498
+ this._setFlag(countryCode);
2499
+ this._updateDialCode(this.selectedCountryData.dialCode, false);
2500
+ this._triggerCountryChange();
2501
+ }
2502
+ }
2503
+ }, {
2504
+ key: "setNumber",
2505
+ value: function setNumber(number) {
2506
+ // we must update the flag first, which updates this.selectedCountryData, which is used for
2507
+ // formatting the number before displaying it
2508
+ var flagChanged = this._updateFlagFromNumber(number);
2509
+ this._updateValFromNumber(number);
2510
+ if (flagChanged) {
2511
+ this._triggerCountryChange();
2512
+ }
2513
+ }
2514
+ }, {
2515
+ key: "setPlaceholderNumberType",
2516
+ value: function setPlaceholderNumberType(type) {
2517
+ this.options.placeholderNumberType = type;
2518
+ this._updatePlaceholder();
2519
+ }
2520
+ } ]);
2521
+ return Iti;
2522
+ }();
2523
+ /********************
2524
+ * STATIC METHODS
2525
+ ********************/
2526
+ // get the country data object
2527
+ intlTelInputGlobals.getCountryData = function() {
2528
+ return allCountries;
2529
+ };
2530
+ // inject a <script> element to load utils.js
2531
+ var injectScript = function injectScript(path, handleSuccess, handleFailure) {
2532
+ // inject a new script element into the page
2533
+ var script = document.createElement("script");
2534
+ script.onload = function() {
2535
+ forEachInstance("handleUtils");
2536
+ if (handleSuccess) handleSuccess();
2537
+ };
2538
+ script.onerror = function() {
2539
+ forEachInstance("rejectUtilsScriptPromise");
2540
+ if (handleFailure) handleFailure();
2541
+ };
2542
+ script.className = "iti-load-utils";
2543
+ script.async = true;
2544
+ script.src = path;
2545
+ document.body.appendChild(script);
2546
+ };
2547
+ // load the utils script
2548
+ intlTelInputGlobals.loadUtils = function(path) {
2549
+ // 2 options:
2550
+ // 1) not already started loading (start)
2551
+ // 2) already started loading (do nothing - just wait for the onload callback to fire, which will
2552
+ // trigger handleUtils on all instances, invoking their resolveUtilsScriptPromise functions)
2553
+ if (!window.intlTelInputUtils && !window.intlTelInputGlobals.startedLoadingUtilsScript) {
2554
+ // only do this once
2555
+ window.intlTelInputGlobals.startedLoadingUtilsScript = true;
2556
+ // if we have promises, then return a promise
2557
+ if (typeof Promise !== "undefined") {
2558
+ return new Promise(function(resolve, reject) {
2559
+ return injectScript(path, resolve, reject);
2560
+ });
2561
+ }
2562
+ injectScript(path);
2563
+ }
2564
+ return null;
2565
+ };
2566
+ // default options
2567
+ intlTelInputGlobals.defaults = defaults;
2568
+ // version
2569
+ intlTelInputGlobals.version = "17.0.18";
2570
+ // convenience wrapper
2571
+ return function(input, options) {
2572
+ var iti = new Iti(input, options);
2573
+ iti._init();
2574
+ input.setAttribute("data-intl-tel-input-id", iti.id);
2575
+ window.intlTelInputGlobals.instances[iti.id] = iti;
2576
+ return iti;
2577
+ };
2578
+ }();
2579
+ });
2580
+ });
2581
+
2582
+ /**
2583
+ * Exposing intl-tel-input as a component
2584
+ */
2585
+ var intlTelInput = intlTelInput$1;
2586
+
2587
+ const sallaTelInputCss = ".iti{width:100%;position:relative;display:inline-block}.iti *{box-sizing:border-box;-moz-box-sizing:border-box}.iti__hide{display:none}.iti__v-hide{visibility:hidden}.iti input,.iti input[type=text],.iti input[type=tel]{position:relative;z-index:0;direction:ltr !important;margin-top:0 !important;margin-bottom:0 !important;padding-left:95px !important;padding-right:15px !important;margin-left:0 !important}.iti__flag-container{width:100%;position:absolute;top:0;bottom:0;left:0;padding:1px}.iti__selected-flag{width:80px;z-index:1;position:relative;display:flex;align-items:center;height:100%;float:left;padding:0 15px;box-shadow:none !important;outline:none !important}.ltr .iti__selected-flag{justify-content:flex-end}.iti__selected-flag:before{content:\"\";display:block;width:1px;height:70%;background:#eee;position:absolute;top:15%;right:0}.iti__selected-flag .iti__flag{display:none}.iti__arrow{width:15px;height:15px;line-height:15px;position:absolute;left:10px;top:50%;transform:translateY(-50%)}.iti__arrow:after{content:\"\\e96d\";font-family:sallaicons;font-size:16px;color:#999;opacity:0.65}.iti__arrow--up:after{transform:rotate(180deg)}.iti__country-list{width:100%;max-height:160px;position:absolute;top:100%;left:0;z-index:2;list-style:none;margin:0;padding:0;margin:5px 0 0 0;border-radius:5px;box-shadow:0px 2px 4px 2px rgba(0, 0, 0, 0.05);border:1px solid #f5f7f9;background-color:white;white-space:nowrap;overflow:hidden;overflow-y:auto;-webkit-overflow-scrolling:touch}.iti__country-list::-webkit-scrollbar{width:4px}.dark .iti__country-list{background-color:#52525b;border-color:#52525b}.iti__country-list li{display:flex;align-items:center;justify-content:flex-start;flex-direction:row;padding:8px 10px;transition:background-color 0.3s}.iti__country-list li span{font-size:12px}.iti__country-list li:hover,.iti__country-list li.highlighted{background-color:rgba(0, 0, 0, 0.05)}.iti__country-list--dropup{bottom:100%;top:unset;margin:0 0 5px 0}@media (max-width: 500px){.iti__country-list{white-space:normal}}.iti__flag-box{display:inline-block;width:20px;margin:0 0 0 5px}.iti__divider{padding-bottom:5px;margin-bottom:5px;border-bottom:1px solid #eee}.iti__country{padding:5px 10px;outline:none}.iti__dial-code{font-family:Arial;color:#999;unicode-bidi:plaintext;letter-spacing:1px}.iti__country.iti__highlight{background-color:rgba(0, 0, 0, 0.05)}.iti__flag-box,.iti__country-name,.iti__dial-code{vertical-align:middle}.iti__country-name{flex:auto;margin:0;padding:0 10px;white-space:normal;line-height:1.3}.iti--allow-dropdown .iti__flag-container,.iti--separate-dial-code .iti__flag-container{left:0}.iti--allow-dropdown .iti__flag-container:hover{cursor:pointer}.iti--allow-dropdown input[disabled]+.iti__flag-container:hover,.iti--allow-dropdown input[readonly]+.iti__flag-container:hover{cursor:default}.iti--allow-dropdown input[disabled]+.iti__flag-container:hover .iti__selected-flag,.iti--allow-dropdown input[readonly]+.iti__flag-container:hover .iti__selected-flag{background-color:transparent}.iti--separate-dial-code .iti__selected-dial-code{unicode-bidi:plaintext;direction:ltr;letter-spacing:1px;font-family:\"Arial\", serif;font-size:13px}.iti--container{position:absolute;top:-1000px;z-index:1060;padding:1px}.iti--container:hover{cursor:pointer}.iti-mobile .iti--container{inset:0;margin:20px;width:calc(100% - 40px);position:fixed;z-index:9999}.iti-mobile .iti__country-list{max-height:100%;width:100%;inset:0}.iti-mobile .iti__country{padding:10px 10px;line-height:1.5em}.iti__flag{width:20px}.iti__flag.iti__be{width:18px}.iti__flag.iti__ch{width:15px}.iti__flag.iti__mc{width:19px}.iti__flag.iti__ne{width:18px}.iti__flag.iti__np{width:13px}.iti__flag.iti__va{width:15px}@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi){.iti__flag{background-size:5652px 15px}}.iti__flag.iti__ac{height:10px;background-position:0px 0px}.iti__flag.iti__ad{height:14px;background-position:-22px 0px}.iti__flag.iti__ae{height:10px;background-position:-44px 0px}.iti__flag.iti__af{height:14px;background-position:-66px 0px}.iti__flag.iti__ag{height:14px;background-position:-88px 0px}.iti__flag.iti__ai{height:10px;background-position:-110px 0px}.iti__flag.iti__al{height:15px;background-position:-132px 0px}.iti__flag.iti__am{height:10px;background-position:-154px 0px}.iti__flag.iti__ao{height:14px;background-position:-176px 0px}.iti__flag.iti__aq{height:14px;background-position:-198px 0px}.iti__flag.iti__ar{height:13px;background-position:-220px 0px}.iti__flag.iti__as{height:10px;background-position:-242px 0px}.iti__flag.iti__at{height:14px;background-position:-264px 0px}.iti__flag.iti__au{height:10px;background-position:-286px 0px}.iti__flag.iti__aw{height:14px;background-position:-308px 0px}.iti__flag.iti__ax{height:13px;background-position:-330px 0px}.iti__flag.iti__az{height:10px;background-position:-352px 0px}.iti__flag.iti__ba{height:10px;background-position:-374px 0px}.iti__flag.iti__bb{height:14px;background-position:-396px 0px}.iti__flag.iti__bd{height:12px;background-position:-418px 0px}.iti__flag.iti__be{height:15px;background-position:-440px 0px}.iti__flag.iti__bf{height:14px;background-position:-460px 0px}.iti__flag.iti__bg{height:12px;background-position:-482px 0px}.iti__flag.iti__bh{height:12px;background-position:-504px 0px}.iti__flag.iti__bi{height:12px;background-position:-526px 0px}.iti__flag.iti__bj{height:14px;background-position:-548px 0px}.iti__flag.iti__bl{height:14px;background-position:-570px 0px}.iti__flag.iti__bm{height:10px;background-position:-592px 0px}.iti__flag.iti__bn{height:10px;background-position:-614px 0px}.iti__flag.iti__bo{height:14px;background-position:-636px 0px}.iti__flag.iti__bq{height:14px;background-position:-658px 0px}.iti__flag.iti__br{height:14px;background-position:-680px 0px}.iti__flag.iti__bs{height:10px;background-position:-702px 0px}.iti__flag.iti__bt{height:14px;background-position:-724px 0px}.iti__flag.iti__bv{height:15px;background-position:-746px 0px}.iti__flag.iti__bw{height:14px;background-position:-768px 0px}.iti__flag.iti__by{height:10px;background-position:-790px 0px}.iti__flag.iti__bz{height:14px;background-position:-812px 0px}.iti__flag.iti__ca{height:10px;background-position:-834px 0px}.iti__flag.iti__cc{height:10px;background-position:-856px 0px}.iti__flag.iti__cd{height:15px;background-position:-878px 0px}.iti__flag.iti__cf{height:14px;background-position:-900px 0px}.iti__flag.iti__cg{height:14px;background-position:-922px 0px}.iti__flag.iti__ch{height:15px;background-position:-944px 0px}.iti__flag.iti__ci{height:14px;background-position:-961px 0px}.iti__flag.iti__ck{height:10px;background-position:-983px 0px}.iti__flag.iti__cl{height:14px;background-position:-1005px 0px}.iti__flag.iti__cm{height:14px;background-position:-1027px 0px}.iti__flag.iti__cn{height:14px;background-position:-1049px 0px}.iti__flag.iti__co{height:14px;background-position:-1071px 0px}.iti__flag.iti__cp{height:14px;background-position:-1093px 0px}.iti__flag.iti__cr{height:12px;background-position:-1115px 0px}.iti__flag.iti__cu{height:10px;background-position:-1137px 0px}.iti__flag.iti__cv{height:12px;background-position:-1159px 0px}.iti__flag.iti__cw{height:14px;background-position:-1181px 0px}.iti__flag.iti__cx{height:10px;background-position:-1203px 0px}.iti__flag.iti__cy{height:14px;background-position:-1225px 0px}.iti__flag.iti__cz{height:14px;background-position:-1247px 0px}.iti__flag.iti__de{height:12px;background-position:-1269px 0px}.iti__flag.iti__dg{height:10px;background-position:-1291px 0px}.iti__flag.iti__dj{height:14px;background-position:-1313px 0px}.iti__flag.iti__dk{height:15px;background-position:-1335px 0px}.iti__flag.iti__dm{height:10px;background-position:-1357px 0px}.iti__flag.iti__do{height:14px;background-position:-1379px 0px}.iti__flag.iti__dz{height:14px;background-position:-1401px 0px}.iti__flag.iti__ea{height:14px;background-position:-1423px 0px}.iti__flag.iti__ec{height:14px;background-position:-1445px 0px}.iti__flag.iti__ee{height:13px;background-position:-1467px 0px}.iti__flag.iti__eg{height:14px;background-position:-1489px 0px}.iti__flag.iti__eh{height:10px;background-position:-1511px 0px}.iti__flag.iti__er{height:10px;background-position:-1533px 0px}.iti__flag.iti__es{height:14px;background-position:-1555px 0px}.iti__flag.iti__et{height:10px;background-position:-1577px 0px}.iti__flag.iti__eu{height:14px;background-position:-1599px 0px}.iti__flag.iti__fi{height:12px;background-position:-1621px 0px}.iti__flag.iti__fj{height:10px;background-position:-1643px 0px}.iti__flag.iti__fk{height:10px;background-position:-1665px 0px}.iti__flag.iti__fm{height:11px;background-position:-1687px 0px}.iti__flag.iti__fo{height:15px;background-position:-1709px 0px}.iti__flag.iti__fr{height:14px;background-position:-1731px 0px}.iti__flag.iti__ga{height:15px;background-position:-1753px 0px}.iti__flag.iti__gb{height:10px;background-position:-1775px 0px}.iti__flag.iti__gd{height:12px;background-position:-1797px 0px}.iti__flag.iti__ge{height:14px;background-position:-1819px 0px}.iti__flag.iti__gf{height:14px;background-position:-1841px 0px}.iti__flag.iti__gg{height:14px;background-position:-1863px 0px}.iti__flag.iti__gh{height:14px;background-position:-1885px 0px}.iti__flag.iti__gi{height:10px;background-position:-1907px 0px}.iti__flag.iti__gl{height:14px;background-position:-1929px 0px}.iti__flag.iti__gm{height:14px;background-position:-1951px 0px}.iti__flag.iti__gn{height:14px;background-position:-1973px 0px}.iti__flag.iti__gp{height:14px;background-position:-1995px 0px}.iti__flag.iti__gq{height:14px;background-position:-2017px 0px}.iti__flag.iti__gr{height:14px;background-position:-2039px 0px}.iti__flag.iti__gs{height:10px;background-position:-2061px 0px}.iti__flag.iti__gt{height:13px;background-position:-2083px 0px}.iti__flag.iti__gu{height:11px;background-position:-2105px 0px}.iti__flag.iti__gw{height:10px;background-position:-2127px 0px}.iti__flag.iti__gy{height:12px;background-position:-2149px 0px}.iti__flag.iti__hk{height:14px;background-position:-2171px 0px}.iti__flag.iti__hm{height:10px;background-position:-2193px 0px}.iti__flag.iti__hn{height:10px;background-position:-2215px 0px}.iti__flag.iti__hr{height:10px;background-position:-2237px 0px}.iti__flag.iti__ht{height:12px;background-position:-2259px 0px}.iti__flag.iti__hu{height:10px;background-position:-2281px 0px}.iti__flag.iti__ic{height:14px;background-position:-2303px 0px}.iti__flag.iti__id{height:14px;background-position:-2325px 0px}.iti__flag.iti__ie{height:10px;background-position:-2347px 0px}.iti__flag.iti__il{height:15px;background-position:-2369px 0px}.iti__flag.iti__im{height:10px;background-position:-2391px 0px}.iti__flag.iti__in{height:14px;background-position:-2413px 0px}.iti__flag.iti__io{height:10px;background-position:-2435px 0px}.iti__flag.iti__iq{height:14px;background-position:-2457px 0px}.iti__flag.iti__ir{height:12px;background-position:-2479px 0px}.iti__flag.iti__is{height:15px;background-position:-2501px 0px}.iti__flag.iti__it{height:14px;background-position:-2523px 0px}.iti__flag.iti__je{height:12px;background-position:-2545px 0px}.iti__flag.iti__jm{height:10px;background-position:-2567px 0px}.iti__flag.iti__jo{height:10px;background-position:-2589px 0px}.iti__flag.iti__jp{height:14px;background-position:-2611px 0px}.iti__flag.iti__ke{height:14px;background-position:-2633px 0px}.iti__flag.iti__kg{height:12px;background-position:-2655px 0px}.iti__flag.iti__kh{height:13px;background-position:-2677px 0px}.iti__flag.iti__ki{height:10px;background-position:-2699px 0px}.iti__flag.iti__km{height:12px;background-position:-2721px 0px}.iti__flag.iti__kn{height:14px;background-position:-2743px 0px}.iti__flag.iti__kp{height:10px;background-position:-2765px 0px}.iti__flag.iti__kr{height:14px;background-position:-2787px 0px}.iti__flag.iti__kw{height:10px;background-position:-2809px 0px}.iti__flag.iti__ky{height:10px;background-position:-2831px 0px}.iti__flag.iti__kz{height:10px;background-position:-2853px 0px}.iti__flag.iti__la{height:14px;background-position:-2875px 0px}.iti__flag.iti__lb{height:14px;background-position:-2897px 0px}.iti__flag.iti__lc{height:10px;background-position:-2919px 0px}.iti__flag.iti__li{height:12px;background-position:-2941px 0px}.iti__flag.iti__lk{height:10px;background-position:-2963px 0px}.iti__flag.iti__lr{height:11px;background-position:-2985px 0px}.iti__flag.iti__ls{height:14px;background-position:-3007px 0px}.iti__flag.iti__lt{height:12px;background-position:-3029px 0px}.iti__flag.iti__lu{height:12px;background-position:-3051px 0px}.iti__flag.iti__lv{height:10px;background-position:-3073px 0px}.iti__flag.iti__ly{height:10px;background-position:-3095px 0px}.iti__flag.iti__ma{height:14px;background-position:-3117px 0px}.iti__flag.iti__mc{height:15px;background-position:-3139px 0px}.iti__flag.iti__md{height:10px;background-position:-3160px 0px}.iti__flag.iti__me{height:10px;background-position:-3182px 0px}.iti__flag.iti__mf{height:14px;background-position:-3204px 0px}.iti__flag.iti__mg{height:14px;background-position:-3226px 0px}.iti__flag.iti__mh{height:11px;background-position:-3248px 0px}.iti__flag.iti__mk{height:10px;background-position:-3270px 0px}.iti__flag.iti__ml{height:14px;background-position:-3292px 0px}.iti__flag.iti__mm{height:14px;background-position:-3314px 0px}.iti__flag.iti__mn{height:10px;background-position:-3336px 0px}.iti__flag.iti__mo{height:14px;background-position:-3358px 0px}.iti__flag.iti__mp{height:10px;background-position:-3380px 0px}.iti__flag.iti__mq{height:14px;background-position:-3402px 0px}.iti__flag.iti__mr{height:14px;background-position:-3424px 0px}.iti__flag.iti__ms{height:10px;background-position:-3446px 0px}.iti__flag.iti__mt{height:14px;background-position:-3468px 0px}.iti__flag.iti__mu{height:14px;background-position:-3490px 0px}.iti__flag.iti__mv{height:14px;background-position:-3512px 0px}.iti__flag.iti__mw{height:14px;background-position:-3534px 0px}.iti__flag.iti__mx{height:12px;background-position:-3556px 0px}.iti__flag.iti__my{height:10px;background-position:-3578px 0px}.iti__flag.iti__mz{height:14px;background-position:-3600px 0px}.iti__flag.iti__na{height:14px;background-position:-3622px 0px}.iti__flag.iti__nc{height:10px;background-position:-3644px 0px}.iti__flag.iti__ne{height:15px;background-position:-3666px 0px}.iti__flag.iti__nf{height:10px;background-position:-3686px 0px}.iti__flag.iti__ng{height:10px;background-position:-3708px 0px}.iti__flag.iti__ni{height:12px;background-position:-3730px 0px}.iti__flag.iti__nl{height:14px;background-position:-3752px 0px}.iti__flag.iti__no{height:15px;background-position:-3774px 0px}.iti__flag.iti__np{height:15px;background-position:-3796px 0px}.iti__flag.iti__nr{height:10px;background-position:-3811px 0px}.iti__flag.iti__nu{height:10px;background-position:-3833px 0px}.iti__flag.iti__nz{height:10px;background-position:-3855px 0px}.iti__flag.iti__om{height:10px;background-position:-3877px 0px}.iti__flag.iti__pa{height:14px;background-position:-3899px 0px}.iti__flag.iti__pe{height:14px;background-position:-3921px 0px}.iti__flag.iti__pf{height:14px;background-position:-3943px 0px}.iti__flag.iti__pg{height:15px;background-position:-3965px 0px}.iti__flag.iti__ph{height:10px;background-position:-3987px 0px}.iti__flag.iti__pk{height:14px;background-position:-4009px 0px}.iti__flag.iti__pl{height:13px;background-position:-4031px 0px}.iti__flag.iti__pm{height:14px;background-position:-4053px 0px}.iti__flag.iti__pn{height:10px;background-position:-4075px 0px}.iti__flag.iti__pr{height:14px;background-position:-4097px 0px}.iti__flag.iti__ps{height:10px;background-position:-4119px 0px}.iti__flag.iti__pt{height:14px;background-position:-4141px 0px}.iti__flag.iti__pw{height:13px;background-position:-4163px 0px}.iti__flag.iti__py{height:11px;background-position:-4185px 0px}.iti__flag.iti__qa{height:8px;background-position:-4207px 0px}.iti__flag.iti__re{height:14px;background-position:-4229px 0px}.iti__flag.iti__ro{height:14px;background-position:-4251px 0px}.iti__flag.iti__rs{height:14px;background-position:-4273px 0px}.iti__flag.iti__ru{height:14px;background-position:-4295px 0px}.iti__flag.iti__rw{height:14px;background-position:-4317px 0px}.iti__flag.iti__sa{height:14px;background-position:-4339px 0px}.iti__flag.iti__sb{height:10px;background-position:-4361px 0px}.iti__flag.iti__sc{height:10px;background-position:-4383px 0px}.iti__flag.iti__sd{height:10px;background-position:-4405px 0px}.iti__flag.iti__se{height:13px;background-position:-4427px 0px}.iti__flag.iti__sg{height:14px;background-position:-4449px 0px}.iti__flag.iti__sh{height:10px;background-position:-4471px 0px}.iti__flag.iti__si{height:10px;background-position:-4493px 0px}.iti__flag.iti__sj{height:15px;background-position:-4515px 0px}.iti__flag.iti__sk{height:14px;background-position:-4537px 0px}.iti__flag.iti__sl{height:14px;background-position:-4559px 0px}.iti__flag.iti__sm{height:15px;background-position:-4581px 0px}.iti__flag.iti__sn{height:14px;background-position:-4603px 0px}.iti__flag.iti__so{height:14px;background-position:-4625px 0px}.iti__flag.iti__sr{height:14px;background-position:-4647px 0px}.iti__flag.iti__ss{height:10px;background-position:-4669px 0px}.iti__flag.iti__st{height:10px;background-position:-4691px 0px}.iti__flag.iti__sv{height:12px;background-position:-4713px 0px}.iti__flag.iti__sx{height:14px;background-position:-4735px 0px}.iti__flag.iti__sy{height:14px;background-position:-4757px 0px}.iti__flag.iti__sz{height:14px;background-position:-4779px 0px}.iti__flag.iti__ta{height:10px;background-position:-4801px 0px}.iti__flag.iti__tc{height:10px;background-position:-4823px 0px}.iti__flag.iti__td{height:14px;background-position:-4845px 0px}.iti__flag.iti__tf{height:14px;background-position:-4867px 0px}.iti__flag.iti__tg{height:13px;background-position:-4889px 0px}.iti__flag.iti__th{height:14px;background-position:-4911px 0px}.iti__flag.iti__tj{height:10px;background-position:-4933px 0px}.iti__flag.iti__tk{height:10px;background-position:-4955px 0px}.iti__flag.iti__tl{height:10px;background-position:-4977px 0px}.iti__flag.iti__tm{height:14px;background-position:-4999px 0px}.iti__flag.iti__tn{height:14px;background-position:-5021px 0px}.iti__flag.iti__to{height:10px;background-position:-5043px 0px}.iti__flag.iti__tr{height:14px;background-position:-5065px 0px}.iti__flag.iti__tt{height:12px;background-position:-5087px 0px}.iti__flag.iti__tv{height:10px;background-position:-5109px 0px}.iti__flag.iti__tw{height:14px;background-position:-5131px 0px}.iti__flag.iti__tz{height:14px;background-position:-5153px 0px}.iti__flag.iti__ua{height:14px;background-position:-5175px 0px}.iti__flag.iti__ug{height:14px;background-position:-5197px 0px}.iti__flag.iti__um{height:11px;background-position:-5219px 0px}.iti__flag.iti__un{height:14px;background-position:-5241px 0px}.iti__flag.iti__us{height:11px;background-position:-5263px 0px}.iti__flag.iti__uy{height:14px;background-position:-5285px 0px}.iti__flag.iti__uz{height:10px;background-position:-5307px 0px}.iti__flag.iti__va{height:15px;background-position:-5329px 0px}.iti__flag.iti__vc{height:14px;background-position:-5346px 0px}.iti__flag.iti__ve{height:14px;background-position:-5368px 0px}.iti__flag.iti__vg{height:10px;background-position:-5390px 0px}.iti__flag.iti__vi{height:14px;background-position:-5412px 0px}.iti__flag.iti__vn{height:14px;background-position:-5434px 0px}.iti__flag.iti__vu{height:12px;background-position:-5456px 0px}.iti__flag.iti__wf{height:14px;background-position:-5478px 0px}.iti__flag.iti__ws{height:10px;background-position:-5500px 0px}.iti__flag.iti__xk{height:15px;background-position:-5522px 0px}.iti__flag.iti__ye{height:14px;background-position:-5544px 0px}.iti__flag.iti__yt{height:14px;background-position:-5566px 0px}.iti__flag.iti__za{height:14px;background-position:-5588px 0px}.iti__flag.iti__zm{height:14px;background-position:-5610px 0px}.iti__flag.iti__zw{height:10px;background-position:-5632px 0px}.iti__flag{height:15px;box-shadow:0px 0px 1px 0px #888;background-image:url(\"https://cdn.salla.network/images/flags.png\");background-repeat:no-repeat;background-color:#f5f7f9;background-position:20px 0}@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi){.iti__flag{background-image:url(\"https://cdn.salla.network/images/flags@2x.png\")}}.iti__flag.iti__np{background-color:transparent}";
2588
+
2589
+ const SallaTelInput = class {
2590
+ constructor(hostRef) {
2591
+ registerInstance(this, hostRef);
2592
+ this.enterClicked = createEvent(this, "enterClicked", 7);
2593
+ /**
2594
+ * input name
2595
+ */
2596
+ this.name = 'phone';
2597
+ /**
2598
+ * Current country_code
2599
+ */
2600
+ this.countryCode = salla.config.get('user.country_code', 'SA');
2601
+ this.countryCodeLabel = salla.lang.get('common.country_code');
2602
+ this.mobileLabel = salla.lang.get('common.elements.mobile');
2603
+ this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
2604
+ this.tooLong = salla.lang.get('common.errors.too_long', { attribute: this.mobileLabel });
2605
+ this.invalidCountryCode = salla.lang.get('common.errors.invalid_value', { attribute: this.countryCodeLabel });
2606
+ this.invalidNumber = salla.lang.get('common.errors.invalid_value', { attribute: this.mobileLabel });
2607
+ this.errorMap = [this.invalidNumber, this.invalidCountryCode, this.tooShort, this.tooLong, this.invalidNumber];
2608
+ Helper.setHost(this.host);
2609
+ salla.lang.onLoaded(() => {
2610
+ this.mobileLabel = salla.lang.get('common.elements.mobile');
2611
+ this.countryCodeLabel = salla.lang.get('common.elements.country_code');
2612
+ this.invalidNumber = salla.lang.get('common.errors.invalid_value', { attribute: this.mobileLabel });
2613
+ this.invalidCountryCode = salla.lang.get('common.errors.invalid_value', { attribute: this.countryCodeLabel });
2614
+ this.tooShort = salla.lang.get('common.errors.too_short', { attribute: this.mobileLabel });
2615
+ this.tooLong = salla.lang.get('common.errors.too_long', { attribute: this.mobileLabel });
2616
+ this.mobileRequired = salla.lang.get('common.errors.field_required', { attribute: this.mobileLabel });
2617
+ this.errorMap = [this.invalidNumber, this.invalidCountryCode, this.tooShort, this.tooLong, this.invalidNumber];
2618
+ });
2619
+ }
2620
+ /**
2621
+ * Get current values
2622
+ * @return {{mobile:number,countryCode:'SA'|string}}
2623
+ */
2624
+ async getValues() {
2625
+ return {
2626
+ [this.name]: this.phone = this.phoneInput.value,
2627
+ countryCode: this.countryCode = this.countryCodeInput.value
2628
+ };
2629
+ }
2630
+ /**
2631
+ * Is current data valid or not
2632
+ * @return {boolean}
2633
+ */
2634
+ async isValid() {
2635
+ this.reset();
2636
+ if (this.iti.isValidNumber())
2637
+ return true;
2638
+ if (!this.phoneInput.value.trim()) {
2639
+ this.phoneInput.classList.add("s-has-error");
2640
+ this.errorMsg.innerText = this.mobileRequired || 'The mobile is required';
2641
+ return;
2642
+ }
2643
+ this.phoneInput.classList.add("s-has-error");
2644
+ let errorCode = this.iti.getValidationError();
2645
+ this.errorMsg.innerText = this.errorMap[errorCode] || '';
2646
+ salla.logger.info('Phone number (' + this.countryCode + ' - ' + this.phone + ') is not valid, error code ' + errorCode);
2647
+ return false;
2648
+ }
2649
+ initTelInput() {
2650
+ salla.helpers.inputDigitsOnly(this.phoneInput);
2651
+ this.iti = intlTelInput(this.phoneInput, {
2652
+ initialCountry: this.countryCode || 'sa',
2653
+ preferredCountries: ['sa', 'ae', 'kw', 'bh', 'qa', 'iq', 'om', 'ye', 'eg', 'jo', 'sy', 'ps', 'sd', 'lb', 'dz', 'tn', 'ma', 'ly'],
2654
+ formatOnDisplay: false,
2655
+ separateDialCode: true,
2656
+ autoPlaceholder: 'aggressive',
2657
+ utilsScript: 'https://cdnjs.cloudflare.com/ajax/libs/intl-tel-input/17.0.12/js/utils.min.js',
2658
+ });
2659
+ this.phoneInput.addEventListener("countrychange", () => {
2660
+ let data = this.iti.getSelectedCountryData();
2661
+ this.countryCodeInput.value = data.iso2.toUpperCase();
2662
+ });
2663
+ // on blur: validate
2664
+ // this.phoneInput.addEventListener('blur', () => this.isValid());
2665
+ // on keyup / change flag: reset
2666
+ this.phoneInput.addEventListener('input', e => {
2667
+ salla.helpers.inputDigitsOnly(e.target);
2668
+ this.reset();
2669
+ });
2670
+ }
2671
+ reset() {
2672
+ this.phoneInput.classList.remove("s-has-error");
2673
+ this.errorMsg.innerHTML = "";
2674
+ }
2675
+ ;
2676
+ render() {
2677
+ return (h(Host, { class: "s-tel-input" }, h("input", { type: "tel", name: this.name, value: this.phone, ref: el => this.phoneInput = el, class: "s-tel-input-control tel-input s-ltr" }), h("span", { class: "s-tel-input-error-msg", ref: el => this.errorMsg = el }), h("input", { type: "hidden", name: "country_code", value: this.countryCode, ref: el => this.countryCodeInput = el, class: "country_code" })));
2678
+ }
2679
+ componentDidLoad() {
2680
+ this.initTelInput();
2681
+ }
2682
+ get host() { return getElement(this); }
2683
+ };
2684
+ SallaTelInput.style = sallaTelInputCss;
2685
+
2686
+ const AndroidPhoneIcon = `<!-- Generated by IcoMoon.io -->
2687
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
2688
+ <title>android-phone</title>
2689
+ <path d="M22.667 0h-13.333c-2.941 0-5.333 2.392-5.333 5.333v21.333c0 2.941 2.392 5.333 5.333 5.333h13.333c2.941 0 5.333-2.392 5.333-5.333v-21.333c0-2.941-2.392-5.333-5.333-5.333zM25.333 26.667c0 1.471-1.196 2.667-2.667 2.667h-13.333c-1.471 0-2.667-1.196-2.667-2.667v-2.667h18.667zM25.333 21.333h-18.667v-16c0-1.471 1.196-2.667 2.667-2.667h13.333c1.471 0 2.667 1.196 2.667 2.667zM13.333 28h5.333c0.736 0 1.333-0.597 1.333-1.333s-0.597-1.333-1.333-1.333h-5.333c-0.736 0-1.333 0.597-1.333 1.333s0.597 1.333 1.333 1.333z"></path>
2690
+ </svg>
2691
+ `;
2692
+
2693
+ const sallaVerifyCss = "salla-verify{display:block}";
2694
+
2695
+ const SallaVerify = class {
2696
+ constructor(hostRef) {
2697
+ registerInstance(this, hostRef);
2698
+ this.verified = createEvent(this, "verified", 7);
2699
+ this.initiated = false;
2700
+ this.translationLoaded = false;
2701
+ /**
2702
+ * Should render component without modal
2703
+ */
2704
+ this.display = 'modal';
2705
+ /**
2706
+ * Verifying method
2707
+ */
2708
+ this.type = 'mobile';
2709
+ /**
2710
+ * should auto reloading the page after success verification
2711
+ */
2712
+ this.autoReload = true;
2713
+ this.resendAfter = 30;
2714
+ /**
2715
+ * to use: `salla.api.auth.verify` or `salla.profile.verify`
2716
+ */
2717
+ this.isProfileVerify = false;
2718
+ // Helper.setHost(this.host);
2719
+ salla.lang.onLoaded(() => {
2720
+ var _a;
2721
+ this.translationLoaded = true;
2722
+ this.title = salla.lang.get('pages.profile.verify_title') + salla.lang.get('common.elements.' + this.type);
2723
+ (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
2724
+ });
2725
+ if (this.display == 'inline') {
2726
+ this.modal = { open: () => '', close: () => '', setTitle: () => '' };
2727
+ return;
2728
+ }
2729
+ salla.event.on('profile::verification', data => {
2730
+ var _a;
2731
+ this.isProfileVerify = true;
2732
+ this.open(data);
2733
+ this.title = salla.lang.get('pages.profile.verify_title') + salla.lang.get('common.elements.' + data.type);
2734
+ (_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title);
2735
+ });
2736
+ salla.event.on('modalClosed', () => {
2737
+ this.resendAfter = 0;
2738
+ this.timer.innerHTML = '30 : 00';
2739
+ });
2740
+ }
2741
+ /**
2742
+ * Get current code
2743
+ * @return {string}
2744
+ */
2745
+ async getCode() {
2746
+ return this.code.value;
2747
+ }
2748
+ /**
2749
+ * Open verifying modal
2750
+ * @param data
2751
+ */
2752
+ async open(data) {
2753
+ var _a;
2754
+ this.data = data;
2755
+ this.data.type = this.data.type || this.type;
2756
+ this.type = this.data.type;
2757
+ this.resendTimer();
2758
+ this.otpInputs = this.body.querySelectorAll('.s-verify-input');
2759
+ if (!this.initiated) {
2760
+ Helper.on('input', '.s-verify-input', e => salla.helpers.inputDigitsOnly(e.target));
2761
+ Helper.onKeyUp('.s-verify-input', event => {
2762
+ var _a, _b, _c, _d;
2763
+ let key = event.keyCode || event.charCode;
2764
+ if (event.target.value) {
2765
+ (_a = event.target.nextElementSibling) === null || _a === void 0 ? void 0 : _a.focus();
2766
+ (_b = event.target.nextElementSibling) === null || _b === void 0 ? void 0 : _b.select();
2767
+ }
2768
+ else if ([8, 46].includes(key)) {
2769
+ (_c = event.target.previousElementSibling) === null || _c === void 0 ? void 0 : _c.focus();
2770
+ (_d = event.target.previousElementSibling) === null || _d === void 0 ? void 0 : _d.select();
2771
+ }
2772
+ this.toggleOTPSubmit();
2773
+ });
2774
+ Helper.on('paste', '.s-verify-input', event => {
2775
+ let text = salla.helpers.number(event.clipboardData.getData('text')).replace(/[^0-9.]/g, '').replace('..', '.');
2776
+ this.otpInputs.forEach((input, i) => input.value = text[i] || '');
2777
+ this.toggleOTPSubmit();
2778
+ setTimeout(() => this.otpInputs[3].focus(), 100);
2779
+ });
2780
+ // return this.modal.open();
2781
+ this.initiated = true;
2782
+ }
2783
+ this.reset();
2784
+ this.display == 'modal' && ((_a = this.modal) === null || _a === void 0 ? void 0 : _a.setTitle(this.title));
2785
+ this.modal.open();
2786
+ // focus the first input after opening the modal
2787
+ setTimeout(() => this.otpInputs[0].focus(), 100);
2788
+ }
2789
+ toggleOTPSubmit() {
2790
+ let otp = [];
2791
+ this.otpInputs.forEach(input => input.value && otp.push(input.value));
2792
+ this.code.value = otp.join('');
2793
+ if (otp.length === 4) {
2794
+ this.btn.disable();
2795
+ this.btn.click();
2796
+ return;
2797
+ }
2798
+ this.btn.enable();
2799
+ }
2800
+ reset() {
2801
+ this.otpInputs.forEach((input) => input.value = '');
2802
+ this.code.value = '';
2803
+ this.otpInputs[0].focus();
2804
+ }
2805
+ resendTimer() {
2806
+ Helper.showElement(this.resendMessage).hideElement(this.resend);
2807
+ this.resendAfter = 30;
2808
+ let timerId = setInterval(() => {
2809
+ if (this.resendAfter <= 0) {
2810
+ clearInterval(timerId);
2811
+ Helper.hideElement(this.resendMessage).showElement(this.resend);
2812
+ }
2813
+ else {
2814
+ this.timer.innerHTML = `${this.resendAfter >= 10 ? this.resendAfter : '0' + this.resendAfter} : 00`;
2815
+ this.resendAfter--;
2816
+ }
2817
+ }, 1000);
2818
+ }
2819
+ resendCode() {
2820
+ return this.btn.stop()
2821
+ .then(() => this.btn.disable())
2822
+ .then(() => {
2823
+ this.otpInputs.forEach(input => input.value = '');
2824
+ this.otpInputs[0].focus();
2825
+ })
2826
+ .then(() => salla.api.auth.resend(this.data))
2827
+ .finally(() => this.resendTimer());
2828
+ }
2829
+ submit() {
2830
+ let data = Object.assign({ code: this.code.value }, this.data);
2831
+ return this.btn.load()
2832
+ .then(() => this.btn.disable())
2833
+ .then(() => this.isProfileVerify ? salla.profile.verify(data) : salla.auth.verify(data, true))
2834
+ .then(response => this.verified.emit(response))
2835
+ .then(() => this.btn.stop() && this.btn.disable())
2836
+ .then(() => this.modal.close())
2837
+ .then(() => this.autoReload && window.location.reload())
2838
+ .catch((error) => {
2839
+ salla.logger.error(error);
2840
+ this.btn.stop() && this.btn.enable() && this.reset();
2841
+ });
2842
+ }
2843
+ render() {
2844
+ return this.display == 'inline' ? h(Host, null, this.myBody()) :
2845
+ h("salla-modal", { width: "xs", class: "s-verify", ref: modal => this.modal = modal, "modal-title": this.title }, h("span", { slot: 'icon', innerHTML: AndroidPhoneIcon }), this.myBody());
2846
+ }
2847
+ myBody() {
2848
+ return (h("div", { class: "s-verify-body", ref: body => this.body = body }, h("div", { class: "s-verify-message", innerHTML: salla.lang.get('pages.profile.verify_message') }), h("input", { type: "hidden", name: "code", maxlength: "4", required: true, ref: code => this.code = code }), h("div", { class: "s-verify-codes", dir: "ltr" }, [1, 2, 3, 4].map(() => h("input", { type: "text", maxlength: "1", class: "s-verify-input", required: true }))), h("div", { slot: "footer", class: "s-verify-footer" }, h("salla-button", { class: "s-verify-submit", "loader-position": 'center', disabled: true, onClick: () => this.submit(), ref: b => this.btn = b }, salla.lang.get('pages.profile.verify')), h("p", { class: "s-verify-resend-message", ref: el => this.resendMessage = el }, salla.lang.get('blocks.header.resend_after'), h("b", { class: "s-verify-timer", ref: el => this.timer = el }), " "), h("a", { href: "#", class: "s-verify-resend", onClick: () => this.resendCode(), ref: el => this.resend = el }, salla.lang.get('blocks.comments.submit'))), h("slot", { name: "after-footer" })));
2849
+ }
2850
+ get host() { return getElement(this); }
2851
+ };
2852
+ SallaVerify.style = sallaVerifyCss;
2853
+
2854
+ export { SallaAddProductButton as salla_add_product_button, SallaButton as salla_button, SallaLoading as salla_loading, SallaLocalizationModal as salla_localization_modal, SallaLoginModal as salla_login_modal, SallaModal as salla_modal, SallaOfferModal as salla_offer_modal, SallaProductAvailability as salla_product_availability, SallaRatingStars as salla_rating_stars, SallaSearch as salla_search, SallaSkeleton as salla_skeleton, SallaTelInput as salla_tel_input, SallaVerify as salla_verify };