@salla.sa/twilight-components 1.0.14 → 1.0.15

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 (88) hide show
  1. package/dist/cjs/Helper-8852feaa.js +23 -0
  2. package/dist/cjs/index-0b5b5867.js +1656 -0
  3. package/dist/cjs/index.cjs.js +13 -0
  4. package/dist/cjs/loader.cjs.js +21 -0
  5. package/dist/cjs/salla-branches.cjs.entry.js +92 -0
  6. package/dist/cjs/salla-button.cjs.entry.js +77 -0
  7. package/dist/cjs/salla-localization.cjs.entry.js +77 -0
  8. package/dist/cjs/salla-login-6a54572d.js +14 -0
  9. package/dist/cjs/salla-login_2.cjs.entry.js +97 -0
  10. package/dist/cjs/salla-product-availability.cjs.entry.js +75 -0
  11. package/dist/cjs/salla-rating.cjs.entry.js +303 -0
  12. package/dist/cjs/salla-search-311c7053.js +81 -0
  13. package/dist/cjs/salla-search.cjs.entry.js +11 -0
  14. package/dist/cjs/salla-verify.cjs.entry.js +96 -0
  15. package/dist/cjs/twilight-components.cjs.js +19 -0
  16. package/dist/collection/Helpers/Helper.js +19 -0
  17. package/dist/collection/collection-manifest.json +20 -0
  18. package/dist/collection/components/generate-summary.js +35 -0
  19. package/dist/collection/components/salla-branches/salla-branches.css +12 -0
  20. package/dist/collection/components/salla-branches/salla-branches.js +235 -0
  21. package/dist/collection/components/salla-button/salla-button.css +3 -0
  22. package/dist/collection/components/salla-button/salla-button.js +243 -0
  23. package/dist/collection/components/salla-localization/salla-localization.js +200 -0
  24. package/dist/collection/components/salla-login/salla-login.js +31 -0
  25. package/dist/collection/components/salla-modal/salla-modal.js +360 -0
  26. package/dist/collection/components/salla-product-availability/salla-product-availability.js +331 -0
  27. package/dist/collection/components/salla-rating/salla-rating.css +3 -0
  28. package/dist/collection/components/salla-rating/salla-rating.js +488 -0
  29. package/dist/collection/components/salla-search/salla-search.js +132 -0
  30. package/dist/collection/components/salla-verify/salla-verify.js +99 -0
  31. package/dist/collection/index.js +2 -0
  32. package/dist/collection/interfaces/colors.js +1 -0
  33. package/dist/collection/interfaces/index.js +2 -0
  34. package/dist/collection/interfaces/ratio.js +1 -0
  35. package/dist/collection/plugins/tailwind-theme/generator.js +53 -0
  36. package/dist/collection/plugins/tailwind-theme/index.js +26 -0
  37. package/dist/{twilight-components → esm}/Helper-81ac9a8c.js +0 -0
  38. package/dist/esm/index-8b97d225.js +1628 -0
  39. package/dist/esm/index.js +4 -0
  40. package/dist/esm/loader.js +17 -0
  41. package/dist/esm/polyfills/core-js.js +11 -0
  42. package/dist/esm/polyfills/css-shim.js +1 -0
  43. package/dist/esm/polyfills/dom.js +79 -0
  44. package/dist/esm/polyfills/es5-html-element.js +1 -0
  45. package/dist/esm/polyfills/index.js +34 -0
  46. package/dist/esm/polyfills/system.js +6 -0
  47. package/dist/{twilight-components/multi-warehouse.entry.js → esm/salla-branches.entry.js} +16 -17
  48. package/dist/{twilight-components → esm}/salla-button.entry.js +1 -1
  49. package/dist/{twilight-components → esm}/salla-localization.entry.js +1 -1
  50. package/dist/{twilight-components/salla-login-97e0a9ab.js → esm/salla-login-c9c9fa57.js} +1 -1
  51. package/dist/{twilight-components/salla-modal.entry.js → esm/salla-login_2.entry.js} +16 -9
  52. package/dist/{twilight-components → esm}/salla-product-availability.entry.js +1 -1
  53. package/dist/{twilight-components → esm}/salla-rating.entry.js +9 -5
  54. package/dist/esm/salla-search-add7bdb6.js +79 -0
  55. package/dist/esm/salla-search.entry.js +3 -0
  56. package/dist/{twilight-components → esm}/salla-verify.entry.js +1 -1
  57. package/dist/esm/twilight-components.js +17 -0
  58. package/dist/index.cjs.js +1 -0
  59. package/dist/index.js +1 -0
  60. package/dist/twilight-components/index.esm.js +1 -3
  61. package/dist/twilight-components/p-010b8dfd.entry.js +1 -0
  62. package/dist/twilight-components/p-0ceecf63.js +1 -0
  63. package/dist/twilight-components/p-32d29245.entry.js +1 -0
  64. package/dist/twilight-components/p-50e70ad4.entry.js +1 -0
  65. package/dist/twilight-components/p-68c9f122.entry.js +1 -0
  66. package/dist/twilight-components/p-8126278e.entry.js +1 -0
  67. package/dist/twilight-components/p-9bc28e0c.js +1 -0
  68. package/dist/twilight-components/p-9d327a79.entry.js +1 -0
  69. package/dist/twilight-components/p-b05450bc.entry.js +1 -0
  70. package/dist/twilight-components/p-bd5da080.js +1 -0
  71. package/dist/twilight-components/p-cb1c59a2.js +1 -0
  72. package/dist/twilight-components/p-d584d0c7.entry.js +1 -0
  73. package/dist/twilight-components/twilight-components.css +1 -3
  74. package/dist/twilight-components/twilight-components.esm.js +1 -125
  75. package/dist/types/components/{multi-warehouse/multi-warehouse.d.ts → salla-branches/salla-branches.d.ts} +1 -1
  76. package/dist/types/components/salla-modal/salla-modal.d.ts +3 -0
  77. package/dist/types/components/salla-rating/salla-rating.d.ts +2 -2
  78. package/dist/types/components/salla-search/salla-search.d.ts +20 -17
  79. package/dist/types/components.d.ts +19 -15
  80. package/package.json +1 -1
  81. package/dist/twilight-components/app-globals-0f993ce5.js +0 -3
  82. package/dist/twilight-components/css-shim-a64b8820.js +0 -4
  83. package/dist/twilight-components/dom-d08ba8aa.js +0 -73
  84. package/dist/twilight-components/index-8cf58712.js +0 -3010
  85. package/dist/twilight-components/salla-login.entry.js +0 -2
  86. package/dist/twilight-components/salla-search-df1c9b54.js +0 -95
  87. package/dist/twilight-components/salla-search.entry.js +0 -2
  88. package/dist/twilight-components/shadow-css-bc14d9fd.js +0 -389
@@ -0,0 +1,488 @@
1
+ import { Component, h, Prop, Method, Element, Host } from '@stencil/core';
2
+ import Helper from "../../Helpers/Helper";
3
+ export class SallaRating {
4
+ constructor() {
5
+ this.stars = [1, 2, 3, 4, 5];
6
+ this.order = {
7
+ shipping: { id: 5622 },
8
+ products: [
9
+ {
10
+ "title": "ميكروفون عالى الجودة",
11
+ "image": "https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/pMdEEyMVpZFj4L1Hrdm2g48AuiSx0TrKULBiOnPo.jpg",
12
+ "price": "‏10,978.00 ر.س",
13
+ "qty": "‏2",
14
+ "totalBefore": "‏1120 ر.س",
15
+ "discount": "-5%",
16
+ "total": "‏1064 ر.س",
17
+ "id": "2314513454",
18
+ "getOptimusRouteKey": "7351233357"
19
+ },
20
+ // {
21
+ // "title": "وحدة تحكم لمشغل العاب",
22
+ // "image": "https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/NOa4kHvOkd1hBWHk3JIgAo1602oVACfuWGFz3vXv.jpg",
23
+ // "price": "‏10,978.00 ر.س",
24
+ // "qty": "‏2",
25
+ // "totalBefore": "‏1120 ر.س",
26
+ // "discount": "-5%",
27
+ // "total": "‏1064 ر.س",
28
+ // "id": "9842833",
29
+ // "getOptimusRouteKey": "735152357"
30
+ // },
31
+ {
32
+ "title": "ساعة ذكية بنظام اندرويد",
33
+ "image": "https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/T4kTqYNuPAZmPMLw1bx92RnjVMZyFszVXOUZQsFJ.jpg",
34
+ "price": "‏10,978.00 ر.س",
35
+ "qty": "‏2",
36
+ "totalBefore": "‏1120 ر.س",
37
+ "discount": "-5%",
38
+ "total": "‏1064 ر.س",
39
+ "id": "679822376",
40
+ "getOptimusRouteKey": "73233357"
41
+ }
42
+ ],
43
+ };
44
+ this.isProductsRating = false;
45
+ this.ratingChain = Promise.resolve();
46
+ this.stepsCount = 0;
47
+ Helper.setHost(this.host);
48
+ }
49
+ async show() {
50
+ return this.modal.show();
51
+ }
52
+ async hide() {
53
+ return this.modal.hide();
54
+ }
55
+ componentWillLoad() {
56
+ this.stepsCount = [this.isStoreRating, this.isProductsRating, this.isShippingRating].filter(item => item).length;
57
+ this.getData();
58
+ }
59
+ componentDidRender() {
60
+ this.show();
61
+ this.initiateRating();
62
+ }
63
+ initiateRating() {
64
+ this.highlightSelectedStars();
65
+ this.starsRating();
66
+ this.handleWizard();
67
+ const step = this.host.querySelector('.step:first-child');
68
+ this.setModalHeight(step);
69
+ salla.event.on('submit::order-rating', () => this.sendRating().then(() => {
70
+ let seconds = 10;
71
+ let timeToClose = setInterval(() => {
72
+ seconds--;
73
+ this.host.querySelector('.close-time').innerHTML = `00:0${seconds}`;
74
+ if (seconds == 0) {
75
+ this.hide();
76
+ clearInterval(timeToClose);
77
+ }
78
+ }, 1000);
79
+ this.host.querySelector('.wizard-footer').classList.add('opacity-0', 'pointer-events-0');
80
+ Helper.toggle('.step', 'hidden', 'block', () => true);
81
+ Helper.toggle('.thankyou-view', 'is-opened', 'hidden', () => true);
82
+ const thankYouView = this.host.querySelector('.thankyou-view');
83
+ this.setModalHeight(thankYouView);
84
+ setTimeout(() => {
85
+ Helper.toggleElement(thankYouView, ['opacity-1', 'translate-x-0'], ['opacity-0', 'translate-x-3'], () => true);
86
+ }, 200);
87
+ }));
88
+ }
89
+ // handle wizard
90
+ handleWizard() {
91
+ var _a;
92
+ let index = 0, steps = this.host.querySelectorAll(".step"), dots = this.host.querySelectorAll(".step-dot"), nextBtnText = this.host.querySelector('#next-btn .btn-text');
93
+ // show first step
94
+ this.showActiveStep(steps, dots, index);
95
+ // handle btn text
96
+ nextBtnText.innerHTML = ((_a = steps[index + 1]) === null || _a === void 0 ? void 0 : _a.dataset.stepName) || 'إرسال التقييم';
97
+ Helper.onClick("#prev-btn", () => {
98
+ var _a;
99
+ index > 0 && index--;
100
+ this.showActiveStep(steps, dots, index);
101
+ nextBtnText.innerHTML = ((_a = steps[index + 1]) === null || _a === void 0 ? void 0 : _a.dataset.stepName) || 'إرسال التقييم';
102
+ index == 0 && Helper.toggle('#prev-btn', ['pointer-events-none', 'opacity-0'], 'block', () => true);
103
+ });
104
+ Helper.onClick("#next-btn", () => {
105
+ var _a;
106
+ this.ratingValidation();
107
+ if (index == this.stepsCount - 1) {
108
+ salla.event.dispatch("submit::order-rating");
109
+ }
110
+ else {
111
+ index < this.stepsCount - 1 && index++;
112
+ this.showActiveStep(steps, dots, index);
113
+ nextBtnText.innerHTML = ((_a = steps[index + 1]) === null || _a === void 0 ? void 0 : _a.dataset.stepName) || 'إرسال التقييم';
114
+ Helper.toggle('#prev-btn', 'block', ['pointer-events-none', 'opacity-0'], () => true);
115
+ }
116
+ });
117
+ }
118
+ showActiveStep(steps, dots, currentIndex) {
119
+ Helper.toggle('.step-dot', 'bg-gray-200', 'bg-primay', () => true);
120
+ this.stepsCount > 1 && Helper.toggleElement(dots[currentIndex], 'bg-primary', 'bg-gray-200', () => true);
121
+ // hide all steps
122
+ Helper.toggle('.step', ['hidden', 'opacity-0', 'translate-x-3'], ['active', 'opacity-1', 'translate-x-0'], () => true);
123
+ Helper.toggleElement(steps[currentIndex], 'active', 'hidden', () => true);
124
+ this.setModalHeight(steps[currentIndex]);
125
+ setTimeout(() => {
126
+ Helper.toggleElement(steps[currentIndex], ['opacity-1', 'translate-x-0'], ['opacity-0', 'translate-x-3',], () => true);
127
+ }, 200);
128
+ }
129
+ setModalHeight(current) {
130
+ const wrapper = this.host.querySelector('.s-order-rating-steps-wrapper');
131
+ setTimeout(() => {
132
+ wrapper === null || wrapper === void 0 ? void 0 : wrapper.setAttribute('style', 'height:' + (current === null || current === void 0 ? void 0 : current.scrollHeight) + 'px');
133
+ });
134
+ }
135
+ // send feedback rating and validation
136
+ sendRating() {
137
+ Helper.all('.rating-section', ratingSection => {
138
+ let type = ratingSection.dataset.type;
139
+ let formsData = [];
140
+ ratingSection.querySelectorAll('.rating-outer-form')
141
+ .forEach((form) => {
142
+ let formData = {};
143
+ form.querySelectorAll('[name]')
144
+ .forEach(function (input) {
145
+ let inputData = salla.helpers.inputData(input.name, input.value, formData);
146
+ formData[inputData.name] = inputData.value;
147
+ });
148
+ formsData = [];
149
+ formsData.push(formData);
150
+ this.sendFeedback(type, formsData);
151
+ });
152
+ });
153
+ return this.ratingChain;
154
+ }
155
+ sendFeedback(type, formsData) {
156
+ if (!formsData || formsData.length == 0) {
157
+ return;
158
+ }
159
+ this.nextBtn.load();
160
+ salla.config.canLeave = false;
161
+ this.ratingChain = salla.feedback.api[type](formsData[0])
162
+ .then(function () {
163
+ salla.config.canLeave = true;
164
+ }).catch(() => salla.config.canLeave = true);
165
+ }
166
+ ratingValidation() {
167
+ let errorMsg = '';
168
+ document.querySelectorAll('.rating-section.active')
169
+ .forEach((ratingSection) => {
170
+ ratingSection.querySelectorAll('.rating-outer-form')
171
+ .forEach((rating) => {
172
+ let ratingInput = rating.querySelector('.rating_hidden_input');
173
+ let commentInput = rating.querySelector('.comment');
174
+ // let sectionTitle = rating.querySelector('.section-title');
175
+ let validationMessage = rating.querySelector('.validation-message');
176
+ if (ratingInput.value && commentInput.value && commentInput.value.length > 3) {
177
+ commentInput.classList.remove('has-error');
178
+ // sectionTitle?.classList.remove('has-error', 'text-red-400');
179
+ validationMessage.innerHTML = '';
180
+ return;
181
+ }
182
+ else if (commentInput.value && commentInput.value.length > 3) {
183
+ commentInput.classList.remove('has-error');
184
+ }
185
+ else {
186
+ commentInput.classList.add('has-error');
187
+ }
188
+ // sectionTitle?.classList.add('has-error', 'text-red-400');
189
+ errorMsg = ratingInput.value
190
+ ? (salla.lang.get('common.errors.not_less_than_chars', { chars: 4 }) + ' ' + commentInput.getAttribute('placeholder'))
191
+ : (rating.dataset.starsError || salla.lang.get('pages.rating.rate_store_stars'));
192
+ validationMessage.innerHTML = errorMsg;
193
+ });
194
+ });
195
+ //Fire error to prevent sending rating
196
+ if (errorMsg) {
197
+ // scroll to first error
198
+ let ratingErrors = document.querySelectorAll('.has-error');
199
+ if (ratingErrors.length) {
200
+ let firstError = ratingErrors[0].offsetTop;
201
+ window.scrollTo({ top: firstError - 80 }); // 80 = fixed nav height
202
+ }
203
+ throw new Error(errorMsg);
204
+ }
205
+ }
206
+ // getdata
207
+ getData() {
208
+ salla.api.order.endpointsMethods.details = 'get';
209
+ salla.order.api.details(salla.config.page.id).then(data => console.log(data));
210
+ }
211
+ // handle star rating
212
+ starsRating() {
213
+ let selectedClasses = ['selected', 'text-theme-yellow'];
214
+ // Listen for form submissions
215
+ salla.document.event.onSubmit('.rate-element', function (event) {
216
+ // Prevent form from submitting
217
+ event.preventDefault();
218
+ // Get the selected star - activeElement is not supported in safari
219
+ var activeStars = event.target.querySelectorAll('.btn--star.hovered');
220
+ var selected = activeStars[activeStars.length - 1];
221
+ if (!selected)
222
+ return;
223
+ var selectedIndex = parseInt(selected.dataset.star, 10);
224
+ event.target.querySelector('.rating_hidden_input').value = selectedIndex;
225
+ // Get all stars in this form (only search in the form, not the whole document)
226
+ // Loop through each star, and add or remove the `.selected` class to toggle highlighting
227
+ event.target
228
+ .querySelectorAll('.btn--star')
229
+ .forEach(function (star, index) {
230
+ if (index < selectedIndex) {
231
+ // Selected star or before it, Add highlighting
232
+ star.classList.add(...selectedClasses);
233
+ return;
234
+ }
235
+ // After selected star, Remove highlight
236
+ star.classList.remove(...selectedClasses);
237
+ });
238
+ // Remove aria-pressed from any previously selected star
239
+ var previousRating = event.target.querySelector('.star[aria-pressed="true"]');
240
+ if (previousRating) {
241
+ previousRating.removeAttribute('aria-pressed');
242
+ }
243
+ // Add aria-pressed role to the selected button
244
+ selected.setAttribute('aria-pressed', true);
245
+ });
246
+ }
247
+ highlightSelectedStars() {
248
+ let hover = ['hovered', 'text-theme-yellow'];
249
+ Helper.all('.rate-element', el => {
250
+ let starElements = el.querySelectorAll('.btn--star');
251
+ // remove hovered state from stars ---
252
+ el.addEventListener('mouseout', () => el.querySelectorAll('.btn--star').forEach(star => star.classList.remove(...hover)));
253
+ starElements.forEach((starElement, index) => {
254
+ starElement.addEventListener('mouseover', () => {
255
+ starElement.classList.add(...hover);
256
+ if (index <= 1) {
257
+ starElement.previousElementSibling.tagName === 'BUTTON' ? starElement.previousElementSibling.classList.add(...hover) : null;
258
+ }
259
+ else {
260
+ for (let i = 0; i < index; i++) {
261
+ starElements[i].classList.add(...hover);
262
+ }
263
+ }
264
+ });
265
+ starElement.addEventListener('mouseout', () => {
266
+ starElement.classList.contains(...hover) ? starElement.classList.remove(...hover) : null;
267
+ });
268
+ });
269
+ });
270
+ }
271
+ // render
272
+ render() {
273
+ return (h(Host, null,
274
+ h("salla-modal", { class: "hidden", "modal-width": "w-[800px]", ref: modal => this.modal = modal, title: salla.lang.get('pages.rating.rate_order') + ' <span class="unicode">(#' + this.orderId + ')</span>' },
275
+ h("div", { class: "s-order-rating-steps-wrapper mt-12 mb-10 transition-all duration-300 ease-elastic" },
276
+ this.isStoreRating && this.renderStoreRating(),
277
+ this.isProductsRating && this.renderProductsRating(),
278
+ this.isShippingRating && this.renderShippingRating(),
279
+ this.renderThanksView()),
280
+ h("div", { class: "wizard-footer relative flex justify-between items-center" },
281
+ h("button", { id: "prev-btn", class: "font-bold text-sm w-28 h-10 px-4 text-primary hover:text-primary-d opacity-0 pointer-events-none duration-300 transition-all" }, "\u0627\u0644\u0633\u0627\u0628\u0642"),
282
+ this.stepsCount > 1 ?
283
+ h("ul", { class: "flex justify-center text-center space-s-1.5 flex-1" }, [0, 1, 2].slice(0, this.stepsCount).map(index => h("li", { class: `${index == 0 ? 'bg-primary' : 'bg-gray-200'} step-dot w-2.5 h-2.5 rounded-full transition-colors duration-300` }))) : '',
284
+ h("salla-button", { id: "next-btn", class: "w-28", ref: nextBtn => this.nextBtn = nextBtn }, "\u0627\u0644\u062A\u0627\u0644\u064A")))));
285
+ }
286
+ renderStoreRating() {
287
+ return (h("section", { class: "step rating-section active transition-all duration-500 opacity-0 translate-x-3 hidden", "data-type": "store", "data-step-name": "\u062A\u0642\u064A\u064A\u0645 \u0627\u0644\u0645\u062A\u062C\u0631" },
288
+ h("div", { class: "rating-outer-form", "data-stars-error": salla.lang.get('pages.rating.rate_store_stars') },
289
+ h("input", { type: "hidden", name: "order_id", value: this.orderId }),
290
+ h("input", { type: "hidden", name: "type", value: "store" }),
291
+ h("div", { class: "flex flex-col items-center " },
292
+ h("div", { class: "w-28 h-28 border border-gray-200 rounded-full flex items-center justify-center mb-4" },
293
+ h("img", { src: "https://salla-dev.s3.eu-central-1.amazonaws.com/Mvyk/X3NKcY7nhaFQlR7kBBHvfDpMY48cerunKrmDA1gi.png", alt: "store name", class: "w-12 object-contain" })),
294
+ h("h2", { class: "section-title text-lg font-bold mb-4" }, salla.lang.get('pages.rating.rate_the_store'))),
295
+ h("div", { class: "rating-wrap flex items-center flex justify-center mb-4" },
296
+ h("form", { class: "rate-element rate-element--has-label" }, this.getStarsRating())),
297
+ h("textarea", { id: "storeReview", name: "comment", class: "form-input comment h-20", placeholder: salla.lang.get('pages.rating.write_store_rate') }),
298
+ h("small", { class: "text-red-400 validation-message" }))));
299
+ }
300
+ renderProductsRating() {
301
+ return (h("section", { class: "step rating-section products-section transition-all duration-500 opacity-0 translate-x-3 hidden", "data-type": "product", "data-step-name": "\u062A\u0642\u064A\u064A\u0645 \u0627\u0644\u0645\u0646\u062A\u062C\u0627\u062A" },
302
+ h("div", { class: "overflow-hidden" }, this.order.products.map((item, index) => h("div", { class: "rating-outer-form mb-8 last:mb-0", "data-stars-error": salla.lang.get('pages.rating.rate_product_stars', { "item": item.title }) },
303
+ h("div", { class: "product-item" },
304
+ h("div", { class: "flex space-s-5" },
305
+ h("img", { src: item.image, alt: item.title, class: "w-18 h-14 object-cover rounded-md" }),
306
+ h("div", { class: "flex-1" },
307
+ h("h3", { class: "section-title leading-5 mb-1.5 font-bold md:text-sm" },
308
+ " ",
309
+ item.title),
310
+ h("div", { class: "rw-product-entry__rate" },
311
+ h("div", { class: "rating-wrap flex items-center space-s-4" },
312
+ h("form", { class: "rate-element rate-element--has-label" }, this.getStarsRating())),
313
+ h("input", { type: "hidden", name: "order_id", value: this.orderId }),
314
+ h("input", { type: "hidden", name: `products[${index}][product_id]`, value: item.getOptimusRouteKey }),
315
+ h("input", { type: "hidden", name: "type", value: "products" }),
316
+ h("textarea", { "data-product-id": item.id, name: `products[${index}][comment]`, id: `productReview_${item.id}`, class: "comment form-input h-20 product-review", placeholder: salla.lang.get('pages.rating.write_product_rate') }),
317
+ h("small", { class: "text-red-400 validation-message" }))))))))));
318
+ }
319
+ renderShippingRating() {
320
+ return (h("section", { class: "step rating-section py-5 rounded-md transition-all duration-500 opacity-0 translate-x-3 hidden", "data-type": "shipping", "data-step-name": "\u062A\u0642\u064A\u064A\u0645 \u0634\u0631\u0643\u0629 \u0627\u0644\u0634\u062D\u0646" },
321
+ h("div", { class: "rating-outer-form", "data-stars-error": salla.lang.get('pages.rating.rate_shipping_stars') },
322
+ h("input", { type: "hidden", name: "order_id", value: this.orderId }),
323
+ h("input", { type: "hidden", name: "shipping_company_id", value: this.order.shipping.id }),
324
+ h("input", { type: "hidden", name: "type", value: "shipping" }),
325
+ h("div", { class: "flex flex-col items-center " },
326
+ h("div", { class: "w-28 h-28 overflow-hidden border border-gray-200 rounded-full flex items-center justify-center mb-4" },
327
+ h("img", { src: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcScPt4R6KaKDldrXb-9pUljFwL3m6A72BhN6p1qZJKprwC6VbCWC_8ASZgiJAoL_l7DepM&usqp=CAU", alt: "company name", class: "w-full h-full object-contain" })),
328
+ h("h2", { class: "section-title text-lg font-bold mb-4" },
329
+ " ",
330
+ salla.lang.get('pages.rating.rate_shipping'),
331
+ " \u0627\u0631\u0627\u0645\u0643\u0633")),
332
+ h("div", { class: "rating-wrap flex flex justify-center mb-4" },
333
+ h("form", { class: "rate-element ratFeedbackPresentere-element--has-label" }, this.getStarsRating())),
334
+ h("textarea", { id: "shippingReview", name: "comment", class: "form-input comment h-20 mb-2", placeholder: salla.lang.get('pages.rating.write_shipping_rate') }),
335
+ h("small", { class: "text-red-400 validation-message" }))));
336
+ }
337
+ renderThanksView() {
338
+ return (h("div", { class: "thankyou-view px-8 text-center transition-all duration-500 opacity-0 translate-x-3 hidden" },
339
+ h("span", { class: "w-20 h-20 text-4xl inline-flex justify-center items-center bg-gray-50 rounded-full text-primary sicon-check-circle2" }),
340
+ h("div", { class: "mt-4 mb-6" },
341
+ h("h3", { class: "font-bold" }, salla.lang.get('pages.rating.thanks')),
342
+ h("div", { class: "text-gray-400 text-sm", innerHTML: this.thanksMsg })),
343
+ h("a", { href: "#!", onClick: () => this.hide(), class: "btn btn-primary h-10 flex-none px-8" }, "\u0639\u0648\u062F\u0629 \u0625\u0644\u064A \u062A\u0641\u0627\u0635\u064A\u0644 \u0627\u0644\u0637\u0644\u0628"),
344
+ h("time", { class: "close-time text-gray-400 block h-6 mt-3 text-sm" })));
345
+ }
346
+ getStarsRating() {
347
+ return (h("div", { class: "mb-1" },
348
+ h("input", { type: "hidden", class: "rating_hidden_input", name: "rating", value: "" }),
349
+ this.stars.map((star) => h("button", { type: "submit", class: "btn btn--transparent px-1 text-2xl text-gray-400 btn--star", "data-star": star },
350
+ h("i", { class: "sicon-star2" })))));
351
+ }
352
+ static get is() { return "salla-rating"; }
353
+ static get originalStyleUrls() { return {
354
+ "$": ["salla-rating.css"]
355
+ }; }
356
+ static get styleUrls() { return {
357
+ "$": ["salla-rating.css"]
358
+ }; }
359
+ static get properties() { return {
360
+ "orderId": {
361
+ "type": "number",
362
+ "mutable": false,
363
+ "complexType": {
364
+ "original": "number",
365
+ "resolved": "number",
366
+ "references": {}
367
+ },
368
+ "required": false,
369
+ "optional": false,
370
+ "docs": {
371
+ "tags": [],
372
+ "text": ""
373
+ },
374
+ "attribute": "order-id",
375
+ "reflect": false
376
+ },
377
+ "thanksMsg": {
378
+ "type": "string",
379
+ "mutable": false,
380
+ "complexType": {
381
+ "original": "string",
382
+ "resolved": "string",
383
+ "references": {}
384
+ },
385
+ "required": false,
386
+ "optional": false,
387
+ "docs": {
388
+ "tags": [],
389
+ "text": ""
390
+ },
391
+ "attribute": "thanks-msg",
392
+ "reflect": false
393
+ },
394
+ "isStoreRating": {
395
+ "type": "boolean",
396
+ "mutable": false,
397
+ "complexType": {
398
+ "original": "boolean",
399
+ "resolved": "boolean",
400
+ "references": {}
401
+ },
402
+ "required": false,
403
+ "optional": false,
404
+ "docs": {
405
+ "tags": [],
406
+ "text": ""
407
+ },
408
+ "attribute": "is-store-rating",
409
+ "reflect": false
410
+ },
411
+ "isProductsRating": {
412
+ "type": "boolean",
413
+ "mutable": false,
414
+ "complexType": {
415
+ "original": "boolean",
416
+ "resolved": "boolean",
417
+ "references": {}
418
+ },
419
+ "required": false,
420
+ "optional": false,
421
+ "docs": {
422
+ "tags": [],
423
+ "text": ""
424
+ },
425
+ "attribute": "is-products-rating",
426
+ "reflect": false,
427
+ "defaultValue": "false"
428
+ },
429
+ "isShippingRating": {
430
+ "type": "boolean",
431
+ "mutable": false,
432
+ "complexType": {
433
+ "original": "boolean",
434
+ "resolved": "boolean",
435
+ "references": {}
436
+ },
437
+ "required": false,
438
+ "optional": false,
439
+ "docs": {
440
+ "tags": [],
441
+ "text": ""
442
+ },
443
+ "attribute": "is-shipping-rating",
444
+ "reflect": false
445
+ }
446
+ }; }
447
+ static get methods() { return {
448
+ "show": {
449
+ "complexType": {
450
+ "signature": "() => Promise<HTMLElement>",
451
+ "parameters": [],
452
+ "references": {
453
+ "Promise": {
454
+ "location": "global"
455
+ },
456
+ "HTMLElement": {
457
+ "location": "global"
458
+ }
459
+ },
460
+ "return": "Promise<HTMLElement>"
461
+ },
462
+ "docs": {
463
+ "text": "",
464
+ "tags": []
465
+ }
466
+ },
467
+ "hide": {
468
+ "complexType": {
469
+ "signature": "() => Promise<HTMLElement>",
470
+ "parameters": [],
471
+ "references": {
472
+ "Promise": {
473
+ "location": "global"
474
+ },
475
+ "HTMLElement": {
476
+ "location": "global"
477
+ }
478
+ },
479
+ "return": "Promise<HTMLElement>"
480
+ },
481
+ "docs": {
482
+ "text": "",
483
+ "tags": []
484
+ }
485
+ }
486
+ }; }
487
+ static get elementRef() { return "host"; }
488
+ }
@@ -0,0 +1,132 @@
1
+ import { Component, h, Host, Prop, State, Element, Listen } from '@stencil/core';
2
+ import Helper from "../../Helpers/Helper";
3
+ export class SallaSearch {
4
+ constructor() {
5
+ var _a, _b;
6
+ this.results = [];
7
+ /**
8
+ * Override search placeholder.
9
+ */
10
+ this.placeholder = salla.lang.get('blocks.header.search_placeholder');
11
+ /**
12
+ * Override no results error message.
13
+ */
14
+ this.noResultsText = salla.lang.get('common.elements.no_options');
15
+ Helper.setHost(this.host);
16
+ this.buttonSlot = ((_a = Helper.getElement('[slot="button"]')) === null || _a === void 0 ? void 0 : _a.innerHTML) || '<i class="sicon-search font-bold"></i>';
17
+ this.productSlot = ((_b = Helper.getElement('[slot="product"]')) === null || _b === void 0 ? void 0 : _b.innerHTML) || this.getDefaultProductSlot();
18
+ }
19
+ onModalClose() {
20
+ Helper.getElement('.s-search-input').value = '';
21
+ this.results = [];
22
+ this.afterSearching();
23
+ }
24
+ getDefaultProductSlot() {
25
+ return '<a target="_blank" href={url} class="s-search-product-image-container">' +
26
+ ' <img class="s-search-product-image" src="{image}" alt="{name}"/>' +
27
+ '</a>' +
28
+ '<div class="s-search-product-details">' +
29
+ ' <div class="s-search-product-name">{name}</div> <div class="s-search-product-price">{price}</div>' +
30
+ '</div>';
31
+ }
32
+ //todo:: reset data when closing
33
+ search(e) {
34
+ Helper.hideElement(this.noResults);
35
+ if (e.target.value.length === 0) {
36
+ this.results = [];
37
+ this.afterSearching();
38
+ return;
39
+ }
40
+ if (e.target.value.length <= 2) {
41
+ return;
42
+ }
43
+ //run loading spinner or stop it
44
+ Helper.toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => true);
45
+ salla.search.api.search(e.target.value)
46
+ .then(response => this.results = response.results)
47
+ .catch(err => err !== 'Query Same As Previous!' ? this.results = [] : null)
48
+ .finally(() => this.afterSearching(/*isEmpty*/ false));
49
+ }
50
+ afterSearching(isEmpty = true) {
51
+ this.noResults.style.display = isEmpty || this.results.length > 0 ? 'none' : 'block';
52
+ Helper.toggleElement(this.container, 's-search-container-open', 'no-results', () => this.results.length)
53
+ .toggleElement(this.searchIcon, 's-search-spinner-loader', 'sicon-search', () => false); //stop searching anime
54
+ salla.search.api.previousQuery = ''; //avoid having error 'Query Same As Previous' after reopen modal;
55
+ }
56
+ render() {
57
+ var _a;
58
+ return (h(Host, { class: "s-search" },
59
+ h("button", { onClick: () => this.modal.show(), class: "s-search-button-icon", innerHTML: this.buttonSlot }),
60
+ h("salla-modal", { ref: modal => this.modal = modal },
61
+ h("div", { class: "s-search-container", slot: "body", ref: container => this.container = container },
62
+ h("input", { class: "s-search-input", type: "text", placeholder: this.placeholder, onInput: e => this.search(e) }),
63
+ h("span", { class: "s-search-icon" },
64
+ h("i", { class: "sicon-search", ref: el => this.searchIcon = el })),
65
+ h("div", { class: "s-search-results" }, (_a = this.results) === null || _a === void 0 ? void 0 :
66
+ _a.map(item => {
67
+ var _a;
68
+ return h("div", { class: "s-search-product", innerHTML: this.productSlot
69
+ .replace(/\{name\}/g, item.title)
70
+ .replace(/\{price\}/g, (_a = item.price) === null || _a === void 0 ? void 0 : _a.after) //todo:: get discounted price too
71
+ .replace(/\{url\}/g, item.url)
72
+ .replace(/\{image\}/g, item.thumb) });
73
+ }),
74
+ h("p", { ref: el => this.noResults = el, class: "s-search-no-results" }, this.noResultsText))))));
75
+ }
76
+ /**
77
+ * Run it one time after load
78
+ */
79
+ componentDidLoad() {
80
+ this.afterSearching();
81
+ }
82
+ static get is() { return "salla-search"; }
83
+ static get properties() { return {
84
+ "placeholder": {
85
+ "type": "string",
86
+ "mutable": false,
87
+ "complexType": {
88
+ "original": "string",
89
+ "resolved": "string",
90
+ "references": {}
91
+ },
92
+ "required": false,
93
+ "optional": false,
94
+ "docs": {
95
+ "tags": [],
96
+ "text": "Override search placeholder."
97
+ },
98
+ "attribute": "placeholder",
99
+ "reflect": false,
100
+ "defaultValue": "salla.lang.get('blocks.header.search_placeholder')"
101
+ },
102
+ "noResultsText": {
103
+ "type": "string",
104
+ "mutable": false,
105
+ "complexType": {
106
+ "original": "string",
107
+ "resolved": "string",
108
+ "references": {}
109
+ },
110
+ "required": false,
111
+ "optional": false,
112
+ "docs": {
113
+ "tags": [],
114
+ "text": "Override no results error message."
115
+ },
116
+ "attribute": "no-results-text",
117
+ "reflect": false,
118
+ "defaultValue": "salla.lang.get('common.elements.no_options')"
119
+ }
120
+ }; }
121
+ static get states() { return {
122
+ "results": {}
123
+ }; }
124
+ static get elementRef() { return "host"; }
125
+ static get listeners() { return [{
126
+ "name": "close",
127
+ "method": "onModalClose",
128
+ "target": undefined,
129
+ "capture": false,
130
+ "passive": false
131
+ }]; }
132
+ }