@salla.sa/twilight-components 2.13.41 → 2.13.43

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 (68) hide show
  1. package/dist/cjs/{app-globals-81a53f2c.js → app-globals-45feca8f.js} +5 -5
  2. package/dist/cjs/app-globals-45feca8f.js.map +1 -0
  3. package/dist/cjs/loader.cjs.js +2 -2
  4. package/dist/cjs/salla-add-product-button_47.cjs.entry.js +4 -2
  5. package/dist/cjs/salla-add-product-button_47.cjs.entry.js.map +1 -1
  6. package/dist/cjs/salla-reviews.cjs.entry.js +2 -1
  7. package/dist/cjs/salla-reviews.cjs.entry.js.map +1 -1
  8. package/dist/cjs/twilight.cjs.js +2 -2
  9. package/dist/collection/components/salla-comments/salla-comments.js +38 -2
  10. package/dist/collection/components/salla-comments/salla-comments.js.map +1 -1
  11. package/dist/collection/components/salla-reviews/salla-reviews.js +2 -1
  12. package/dist/collection/components/salla-reviews/salla-reviews.js.map +1 -1
  13. package/dist/components/index.js +4 -4
  14. package/dist/components/index.js.map +1 -1
  15. package/dist/components/salla-comments.js +6 -2
  16. package/dist/components/salla-comments.js.map +1 -1
  17. package/dist/components/salla-quick-buy2.js.map +1 -1
  18. package/dist/components/salla-reviews.js +2 -1
  19. package/dist/components/salla-reviews.js.map +1 -1
  20. package/dist/esm/{app-globals-a29bbe83.js → app-globals-486fea68.js} +5 -5
  21. package/dist/esm/app-globals-486fea68.js.map +1 -0
  22. package/dist/esm/loader.js +2 -2
  23. package/dist/esm/salla-add-product-button_47.entry.js +4 -2
  24. package/dist/esm/salla-add-product-button_47.entry.js.map +1 -1
  25. package/dist/esm/salla-reviews.entry.js +2 -1
  26. package/dist/esm/salla-reviews.entry.js.map +1 -1
  27. package/dist/esm/twilight.js +2 -2
  28. package/dist/esm-es5/{app-globals-a29bbe83.js → app-globals-486fea68.js} +3 -3
  29. package/dist/esm-es5/app-globals-486fea68.js.map +1 -0
  30. package/dist/esm-es5/loader.js +1 -1
  31. package/dist/esm-es5/loader.js.map +1 -1
  32. package/dist/esm-es5/salla-add-product-button_47.entry.js +1 -1
  33. package/dist/esm-es5/salla-add-product-button_47.entry.js.map +1 -1
  34. package/dist/esm-es5/salla-reviews.entry.js +1 -1
  35. package/dist/esm-es5/salla-reviews.entry.js.map +1 -1
  36. package/dist/esm-es5/twilight.js +1 -1
  37. package/dist/esm-es5/twilight.js.map +1 -1
  38. package/dist/twilight/p-6005717c.system.js +25 -0
  39. package/dist/twilight/p-6005717c.system.js.map +1 -0
  40. package/dist/twilight/{p-f82c4cd5.system.entry.js → p-6b99863e.system.entry.js} +2 -2
  41. package/dist/twilight/p-6b99863e.system.entry.js.map +1 -0
  42. package/dist/twilight/{p-410e7750.entry.js → p-6c7b9377.entry.js} +2 -2
  43. package/dist/twilight/p-6c7b9377.entry.js.map +1 -0
  44. package/dist/twilight/{p-2364cab4.system.entry.js → p-9ca75cfb.system.entry.js} +2 -2
  45. package/dist/twilight/p-9ca75cfb.system.entry.js.map +1 -0
  46. package/dist/twilight/p-bf392e76.system.js +5 -0
  47. package/dist/twilight/{p-9cff5cc3.system.js.map → p-bf392e76.system.js.map} +1 -1
  48. package/dist/twilight/{p-66cd8840.js → p-c1d20d62.js} +4 -4
  49. package/dist/twilight/p-c1d20d62.js.map +1 -0
  50. package/dist/twilight/{p-d38e7783.entry.js → p-f209fb12.entry.js} +2 -2
  51. package/dist/twilight/p-f209fb12.entry.js.map +1 -0
  52. package/dist/twilight/twilight.esm.js +1 -1
  53. package/dist/twilight/twilight.esm.js.map +1 -1
  54. package/dist/twilight/twilight.js +1 -1
  55. package/dist/types/components/salla-comments/salla-comments.d.ts +8 -0
  56. package/dist/types/components.d.ts +16 -0
  57. package/package.json +5 -5
  58. package/dist/cjs/app-globals-81a53f2c.js.map +0 -1
  59. package/dist/esm/app-globals-a29bbe83.js.map +0 -1
  60. package/dist/esm-es5/app-globals-a29bbe83.js.map +0 -1
  61. package/dist/twilight/p-2364cab4.system.entry.js.map +0 -1
  62. package/dist/twilight/p-410e7750.entry.js.map +0 -1
  63. package/dist/twilight/p-66cd8840.js.map +0 -1
  64. package/dist/twilight/p-9cff5cc3.system.js +0 -5
  65. package/dist/twilight/p-d38e7783.entry.js.map +0 -1
  66. package/dist/twilight/p-dded16f6.system.js +0 -25
  67. package/dist/twilight/p-dded16f6.system.js.map +0 -1
  68. package/dist/twilight/p-f82c4cd5.system.entry.js.map +0 -1
@@ -24,6 +24,8 @@ const SallaComments$1 = /*@__PURE__*/ proxyCustomElement(class SallaComments ext
24
24
  this.itemId = undefined;
25
25
  this.loadMoreText = undefined;
26
26
  this.hideForm = undefined;
27
+ this.blockTitle = undefined;
28
+ this.hideTitle = undefined;
27
29
  this.type = CommentType.PAGE;
28
30
  this.comments = undefined;
29
31
  this.pagination = undefined;
@@ -160,9 +162,9 @@ const SallaComments$1 = /*@__PURE__*/ proxyCustomElement(class SallaComments ext
160
162
  render() {
161
163
  // We should show a different placeholder for pages and products (WIP)
162
164
  if (this.showPlaceholder) {
163
- return (h("div", null, h("h2", { class: "s-comments-title" }, this.comment_title), !this.hideForm && h("salla-comment-form", { type: this.type, "item-id": this.itemId }), h("div", { class: "no-content-placeholder--comments" }, h("i", { class: "sicon-chat-bubbles text-5xl block mb-5 text-gray-400" }), h("p", { class: "text-sm" }, this.noComments))));
165
+ return (h("div", null, !!this.total && !this.hideTitle ? h("h2", { class: "s-comments-title" }, this.blockTitle ? this.blockTitle : this.comment_title) : '', !this.hideForm && h("salla-comment-form", { type: this.type, "item-id": this.itemId }), h("div", { class: "no-content-placeholder--comments" }, h("i", { class: "sicon-chat-bubbles text-5xl block mb-5 text-gray-400" }), h("p", { class: "text-sm" }, this.noComments))));
164
166
  }
165
- return (h("div", { class: `s-comments s-comments-${this.type}` }, h("div", { class: `${this.type == CommentType.PAGE ? "s-comments-page-container" : "s-comments-container"}` }, h("h2", { class: "s-comments-title" }, this.comment_title), !this.hideForm && h("salla-comment-form", { type: this.type, "item-id": this.itemId }), !!this.total && h("h2", { class: "s-comments-count-label", innerHTML: this.pluralize(this.comment_name, this.total) }), h("div", { ref: wrapper => this.wrapper = wrapper }), this.nextPage && (h("div", { class: "s-infinite-scroll-wrapper", ref: status => this.status = status }, h("button", { onClick: () => this.loadMore(), class: "s-infinite-scroll-btn s-button-btn s-button-primary" }, h("span", { class: "s-button-text s-infinite-scroll-btn-text" }, this.loadMoreText ? this.loadMoreText : salla.lang.get('common.elements.load_more')), h("span", { class: "s-button-loader s-button-loader-center s-infinite-scroll-btn-loader", ref: btnLoader => this.btnLoader = btnLoader, style: { "display": "none" } })))))));
167
+ return (h("div", { class: `s-comments s-comments-${this.type}` }, h("div", { class: `${this.type == CommentType.PAGE ? "s-comments-page-container" : "s-comments-container"}` }, !!this.total && !this.hideTitle ? h("h2", { class: "s-comments-title" }, this.blockTitle ? this.blockTitle : this.comment_title) : '', !this.hideForm && h("salla-comment-form", { type: this.type, "item-id": this.itemId }), !!this.total && h("h2", { class: "s-comments-count-label", innerHTML: this.pluralize(this.comment_name, this.total) }), h("div", { ref: wrapper => this.wrapper = wrapper }), this.nextPage && (h("div", { class: "s-infinite-scroll-wrapper", ref: status => this.status = status }, h("button", { onClick: () => this.loadMore(), class: "s-infinite-scroll-btn s-button-btn s-button-primary" }, h("span", { class: "s-button-text s-infinite-scroll-btn-text" }, this.loadMoreText ? this.loadMoreText : salla.lang.get('common.elements.load_more')), h("span", { class: "s-button-loader s-button-loader-center s-infinite-scroll-btn-loader", ref: btnLoader => this.btnLoader = btnLoader, style: { "display": "none" } })))))));
166
168
  }
167
169
  async componentWillLoad() {
168
170
  await this.loadInitialData(); // Load initial data before rendering the component
@@ -173,6 +175,8 @@ const SallaComments$1 = /*@__PURE__*/ proxyCustomElement(class SallaComments ext
173
175
  "itemId": [2, "item-id"],
174
176
  "loadMoreText": [1, "load-more-text"],
175
177
  "hideForm": [4, "hide-form"],
178
+ "blockTitle": [1, "block-title"],
179
+ "hideTitle": [4, "hide-title"],
176
180
  "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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaComments"],"sources":["src/components/salla-comments/interfaces.ts","src/components/salla-comments/salla-comments.scss?tag=salla-comments","src/components/salla-comments/salla-comments.tsx"],"sourcesContent":["export enum CommentType {\n PAGE= \"page\",\n PRODUCT = \"product\"\n}\n\nexport interface Comment {\n id?: number;\n avatar?: string;\n name?: string;\n has_order?: boolean;\n date?: string;\n rating?: number;\n content?: string;\n is_pending?: boolean;\n replies?: Comment[];\n customer?: Customer;\n type?: string;\n created_at?: CreatedAt;\n}\nexport interface CreatedAt {\n date?: Date;\n timezone_type?: number;\n timezone?: string;\n}\nexport interface UserComments {\n id?: number;\n type?: string;\n next_page?: string;\n comments?: Comment[];\n}\n\n// Pagination\nexport interface Pagination {\n count?: number;\n total?: number;\n perPage?: number;\n currentPage?: number;\n totalPages?: number;\n links?: Links;\n}\nexport interface Customer {\n id?: number;\n name?: string;\n mobile?: string;\n email?: string;\n avatar?: string;\n country?: string;\n city?: string;\n}\nexport interface Links {\n next?: string;\n}\n",":host {\n display: block;\n}\n","import { Component, Prop, State, Element, h } from '@stencil/core';\nimport { CommentType, UserComments, Pagination } from './interfaces';\nimport anime from 'animejs';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-comments',\n styleUrl: 'salla-comments.scss',\n})\nexport class SallaComments {\n\n constructor() {\n salla.lang.onLoaded(() => {\n this.comment_title = salla.lang.get('blocks.comments.title')\n this.comment_name = salla.lang.get('blocks.comments.comment')\n this.noComments = salla.lang.get('pages.rating.no_ratings')\n })\n }\n\n /**\n * Page or product ID\n */\n @Prop() itemId!: number;\n\n /**\n * Load more text\n */\n @Prop() loadMoreText: string;\n\n /**\n * Load more text\n */\n @Prop() hideForm: boolean;\n\n /**\n * Comment Type\n */\n @Prop() type: CommentType.PAGE | CommentType.PRODUCT = CommentType.PAGE;\n\n @State() comments: UserComments[];\n @State() pagination: Pagination;\n @State() total: number;\n @State() showPlaceholder: boolean;\n @State() nextPage: string;\n\n private status: any;\n private btnLoader: any;\n private infiniteScroll: any;\n private wrapper: any;\n\n @Element() host: HTMLElement;\n\n // Translations\n @State() noComments: string = salla.lang.get('blocks.comments.no_comments');\n @State() comment_title = salla.lang.get('blocks.comments.title')\n @State() comment_name = salla.lang.get('blocks.comments.comment')\n @State() placeholder_text: string;\n\n // TOOD: it's a good idea to move this into lang.js\n // Pluralize a string based on the count\n private pluralize(phrases: string, count: number): string {\n const options = phrases.split('|');\n\n const conditions = [\n { condition: count === 0, index: 0 },\n { condition: count === 1, index: 1 },\n { condition: count === 2, index: 2 },\n { condition: count > 2 && count <= 10, index: 3 },\n { condition: count >= 11, index: 4 }\n ];\n\n const { index } = conditions.find(({ condition }) => condition) || { index: options.length - 1 };\n\n const selectedOption = options[index];\n return selectedOption.replace(':count', salla.helpers.number(count.toString()))\n .replace(/\\{[0-9]+\\}/g, '')\n .replace(/\\[\\d+,\\d+\\]|\\[11,\\*\\]/g, '');\n }\n\n\n\n // Initiate infinite scroll\n private initiateInfiniteScroll() {\n if (!this.wrapper) {\n console.error('Wrapper is undefined. Cannot initiate infinite scroll.');\n return;\n }\n\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: true,\n nextPage: this.nextPage,\n scrollThreshold: false,\n }, true);\n\n this.infiniteScroll?.on('request', _response => {\n this.loading();\n });\n this.infiniteScroll?.on('load', response => {\n this.pagination = response.pagination;\n this.nextPage = typeof response.pagination.links == 'object' && !!response.pagination.links.next ? response.pagination.links.next : null;\n this.handleResponse(response).forEach(card => this.wrapper.append(card));\n\n let items = this.host.querySelectorAll('salla-comment-item:not(.animated):not(.s-comments-item-admin)');\n this.animateItems(items);\n this.loading(false);\n });\n this.infiniteScroll?.on('error', (e) => {\n salla.console.error('Error loading more comments:', e);\n });\n }\n\n // Show/hide loading\n private loading(isLoading = true) {\n let btnText = this.status?.querySelector('.s-button-text');\n if (btnText) {\n Helper.toggleElementClassIf(btnText, 's-button-hide', 's-button-show', () => isLoading);\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n }\n\n // Animate newly added items\n private animateItems(items) {\n anime({\n targets: items,\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n easing: 'easeOutExpo',\n complete: function (_anim) {\n items.forEach(item => {\n item.classList.add('animated');\n })\n }\n\n })\n }\n\n // Get comment item HTML\n private getCommentHTML(comment) {\n const commentItem = document.createElement('salla-comment-item') as HTMLSallaCommentItemElement;\n commentItem.comment = comment;\n\n return commentItem;\n }\n\n\n\n // Parse response and return an array of comment items to be appended to the wrapper\n private handleResponse(response): Array<HTMLElement> {\n return response.data?.map(comment => this.getCommentHTML(comment)) || [];\n }\n\n\n\n // Load initial data\n private async loadInitialData() {\n this.loading();\n try {\n const resp = await (this.type == CommentType.PAGE\n ? salla.api.comment.getPageComments(this.itemId)\n : salla.api.comment.getProductComments(this.itemId));\n if (!resp.data || !resp.data.length) {\n this.showPlaceholder = false;\n this.loading(false);\n return;\n }\n this.comments = resp.data;\n this.pagination = resp.pagination;\n this.total = resp.pagination.total;\n this.nextPage = typeof resp.pagination.links == 'object' && !!resp.pagination.links.next ? resp.pagination.links.next : null;\n\n\n setTimeout(() => {\n this.handleResponse(resp).forEach(card => this.wrapper.append(card));\n this.initiateInfiniteScroll(); // Initiate infinite scroll after the initial data is loaded\n let items = this.wrapper.querySelectorAll('salla-comment-item:not(.animated)');\n this.animateItems(items);\n }, 100);\n } catch (error) {\n console.error('Error loading initial data:', error);\n this.showPlaceholder = true;\n this.loading(false);\n }\n }\n\n // Get next page\n async loadMore() {\n this.infiniteScroll?.loadNextPage();\n }\n\n render() {\n // We should show a different placeholder for pages and products (WIP)\n if (this.showPlaceholder) {\n return (\n <div>\n <h2 class=\"s-comments-title\">{this.comment_title}</h2>\n {!this.hideForm && <salla-comment-form type={this.type} item-id={this.itemId}></salla-comment-form>}\n <div class=\"no-content-placeholder--comments\">\n <i class=\"sicon-chat-bubbles text-5xl block mb-5 text-gray-400\"></i>\n <p class=\"text-sm\">{this.noComments}</p>\n </div>\n </div>\n )\n }\n return (\n <div class={`s-comments s-comments-${this.type}`}>\n <div class={`${this.type == CommentType.PAGE ? \"s-comments-page-container\" : \"s-comments-container\"}`} >\n <h2 class=\"s-comments-title\">{this.comment_title}</h2>\n {!this.hideForm && <salla-comment-form type={this.type} item-id={this.itemId}></salla-comment-form>}\n\n {!!this.total && <h2 class=\"s-comments-count-label\" innerHTML={this.pluralize(this.comment_name, this.total)}></h2>}\n <div ref={wrapper => this.wrapper = wrapper}></div>\n\n\n {this.nextPage && (\n <div class=\"s-infinite-scroll-wrapper\" ref={status => this.status = status}>\n <button onClick={() => this.loadMore()} class=\"s-infinite-scroll-btn s-button-btn s-button-primary\">\n <span class=\"s-button-text s-infinite-scroll-btn-text\">{this.loadMoreText ? this.loadMoreText : salla.lang.get('common.elements.load_more')}</span>\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" ref={btnLoader => this.btnLoader = btnLoader} style={{ \"display\": \"none\" }}></span>\n </button>\n </div>\n )}\n </div>\n </div>\n\n );\n }\n\n\n\n async componentWillLoad() {\n await this.loadInitialData(); // Load initial data before rendering the component\n }\n\n}\n"],"version":3}
1
+ {"file":"salla-comments.js","mappings":";;;;;;;;;;;AAAA,IAAY,WAGX;AAHD,WAAY,WAAW;EACnB,4BAAY,CAAA;EACZ,kCAAmB,CAAA;AACvB,CAAC,EAHW,WAAW,KAAX,WAAW;;ACAvB,MAAM,gBAAgB,GAAG,sBAAsB;;MCQlCA,eAAa;EAExB;;;;;;;;gBAoCuD,WAAW,CAAC,IAAI;;;;;;sBAgBzC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,6BAA6B,CAAC;yBAClD,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC;wBACxC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,yBAAyB,CAAC;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U,GAAG,IAAI,CAAC,aAAa,CAAM,GAAG,EAAE,EACjI,CAAC,IAAI,CAAC,QAAQ,IAAI,0BAAoB,IAAI,EAAE,IAAI,CAAC,IAAI,aAAW,IAAI,CAAC,MAAM,GAAuB,EAElG,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,UAAI,KAAK,EAAC,wBAAwB,EAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,GAAO,EACnH,WAAK,GAAG,EAAE,OAAO,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,GAAQ,EAGlD,IAAI,CAAC,QAAQ,KACZ,WAAK,KAAK,EAAC,2BAA2B,EAAC,GAAG,EAAE,MAAM,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,IACxE,cAAQ,OAAO,EAAE,MAAM,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAC,qDAAqD,IACjG,YAAM,KAAK,EAAC,0CAA0C,IAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAQ,EACnJ,YAAM,KAAK,EAAC,qEAAqE,EAAC,GAAG,EAAE,SAAS,IAAI,IAAI,CAAC,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,GAAS,CAC9J,CACL,CACP,CACG,CACF,EAEN;GACH;EAID,MAAM,iBAAiB;IACrB,MAAM,IAAI,CAAC,eAAe,EAAE,CAAC;GAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":["SallaComments"],"sources":["src/components/salla-comments/interfaces.ts","src/components/salla-comments/salla-comments.scss?tag=salla-comments","src/components/salla-comments/salla-comments.tsx"],"sourcesContent":["export enum CommentType {\n PAGE= \"page\",\n PRODUCT = \"product\"\n}\n\nexport interface Comment {\n id?: number;\n avatar?: string;\n name?: string;\n has_order?: boolean;\n date?: string;\n rating?: number;\n content?: string;\n is_pending?: boolean;\n replies?: Comment[];\n customer?: Customer;\n type?: string;\n created_at?: CreatedAt;\n}\nexport interface CreatedAt {\n date?: Date;\n timezone_type?: number;\n timezone?: string;\n}\nexport interface UserComments {\n id?: number;\n type?: string;\n next_page?: string;\n comments?: Comment[];\n}\n\n// Pagination\nexport interface Pagination {\n count?: number;\n total?: number;\n perPage?: number;\n currentPage?: number;\n totalPages?: number;\n links?: Links;\n}\nexport interface Customer {\n id?: number;\n name?: string;\n mobile?: string;\n email?: string;\n avatar?: string;\n country?: string;\n city?: string;\n}\nexport interface Links {\n next?: string;\n}\n",":host {\n display: block;\n}\n","import { Component, Prop, State, Element, h } from '@stencil/core';\nimport { CommentType, UserComments, Pagination } from './interfaces';\nimport anime from 'animejs';\nimport Helper from '../../Helpers/Helper';\n@Component({\n tag: 'salla-comments',\n styleUrl: 'salla-comments.scss',\n})\nexport class SallaComments {\n\n constructor() {\n salla.lang.onLoaded(() => {\n this.comment_title = salla.lang.get('blocks.comments.title')\n this.comment_name = salla.lang.get('blocks.comments.comment')\n this.noComments = salla.lang.get('pages.rating.no_ratings')\n })\n }\n\n /**\n * Page or product ID\n */\n @Prop() itemId!: number;\n\n /**\n * Load more text\n */\n @Prop() loadMoreText: string;\n\n /**\n * Load more text\n */\n @Prop() hideForm: boolean;\n\n /**\n * Block Title\n */\n @Prop() blockTitle: string;\n \n /**\n * Hide Title\n */\n @Prop() hideTitle: boolean;\n\n /**\n * Comment Type\n */\n @Prop() type: CommentType.PAGE | CommentType.PRODUCT = CommentType.PAGE;\n\n @State() comments: UserComments[];\n @State() pagination: Pagination;\n @State() total: number;\n @State() showPlaceholder: boolean;\n @State() nextPage: string;\n\n private status: any;\n private btnLoader: any;\n private infiniteScroll: any;\n private wrapper: any;\n\n @Element() host: HTMLElement;\n\n // Translations\n @State() noComments: string = salla.lang.get('blocks.comments.no_comments');\n @State() comment_title = salla.lang.get('blocks.comments.title')\n @State() comment_name = salla.lang.get('blocks.comments.comment')\n @State() placeholder_text: string;\n\n // TOOD: it's a good idea to move this into lang.js\n // Pluralize a string based on the count\n private pluralize(phrases: string, count: number): string {\n const options = phrases.split('|');\n\n const conditions = [\n { condition: count === 0, index: 0 },\n { condition: count === 1, index: 1 },\n { condition: count === 2, index: 2 },\n { condition: count > 2 && count <= 10, index: 3 },\n { condition: count >= 11, index: 4 }\n ];\n\n const { index } = conditions.find(({ condition }) => condition) || { index: options.length - 1 };\n\n const selectedOption = options[index];\n return selectedOption.replace(':count', salla.helpers.number(count.toString()))\n .replace(/\\{[0-9]+\\}/g, '')\n .replace(/\\[\\d+,\\d+\\]|\\[11,\\*\\]/g, '');\n }\n\n\n\n // Initiate infinite scroll\n private initiateInfiniteScroll() {\n if (!this.wrapper) {\n console.error('Wrapper is undefined. Cannot initiate infinite scroll.');\n return;\n }\n\n this.infiniteScroll = salla.infiniteScroll.initiate(this.wrapper, this.wrapper, {\n path: () => this.nextPage,\n history: true,\n nextPage: this.nextPage,\n scrollThreshold: false,\n }, true);\n\n this.infiniteScroll?.on('request', _response => {\n this.loading();\n });\n this.infiniteScroll?.on('load', response => {\n this.pagination = response.pagination;\n this.nextPage = typeof response.pagination.links == 'object' && !!response.pagination.links.next ? response.pagination.links.next : null;\n this.handleResponse(response).forEach(card => this.wrapper.append(card));\n\n let items = this.host.querySelectorAll('salla-comment-item:not(.animated):not(.s-comments-item-admin)');\n this.animateItems(items);\n this.loading(false);\n });\n this.infiniteScroll?.on('error', (e) => {\n salla.console.error('Error loading more comments:', e);\n });\n }\n\n // Show/hide loading\n private loading(isLoading = true) {\n let btnText = this.status?.querySelector('.s-button-text');\n if (btnText) {\n Helper.toggleElementClassIf(btnText, 's-button-hide', 's-button-show', () => isLoading);\n this.btnLoader.style.display = isLoading ? 'inherit' : 'none';\n }\n }\n\n // Animate newly added items\n private animateItems(items) {\n anime({\n targets: items,\n opacity: [0, 1],\n duration: 1200,\n translateY: [20, 0],\n delay: function (_el, i) {\n return i * 100;\n },\n easing: 'easeOutExpo',\n complete: function (_anim) {\n items.forEach(item => {\n item.classList.add('animated');\n })\n }\n\n })\n }\n\n // Get comment item HTML\n private getCommentHTML(comment) {\n const commentItem = document.createElement('salla-comment-item') as HTMLSallaCommentItemElement;\n commentItem.comment = comment;\n\n return commentItem;\n }\n\n\n\n // Parse response and return an array of comment items to be appended to the wrapper\n private handleResponse(response): Array<HTMLElement> {\n return response.data?.map(comment => this.getCommentHTML(comment)) || [];\n }\n\n\n\n // Load initial data\n private async loadInitialData() {\n this.loading();\n try {\n const resp = await (this.type == CommentType.PAGE\n ? salla.api.comment.getPageComments(this.itemId)\n : salla.api.comment.getProductComments(this.itemId));\n if (!resp.data || !resp.data.length) {\n this.showPlaceholder = false;\n this.loading(false);\n return;\n }\n this.comments = resp.data;\n this.pagination = resp.pagination;\n this.total = resp.pagination.total;\n this.nextPage = typeof resp.pagination.links == 'object' && !!resp.pagination.links.next ? resp.pagination.links.next : null;\n\n\n setTimeout(() => {\n this.handleResponse(resp).forEach(card => this.wrapper.append(card));\n this.initiateInfiniteScroll(); // Initiate infinite scroll after the initial data is loaded\n let items = this.wrapper.querySelectorAll('salla-comment-item:not(.animated)');\n this.animateItems(items);\n }, 100);\n } catch (error) {\n console.error('Error loading initial data:', error);\n this.showPlaceholder = true;\n this.loading(false);\n }\n }\n\n // Get next page\n async loadMore() {\n this.infiniteScroll?.loadNextPage();\n }\n\n render() {\n // We should show a different placeholder for pages and products (WIP)\n if (this.showPlaceholder) {\n return (\n <div>\n {!!this.total && !this.hideTitle ? <h2 class=\"s-comments-title\">{this.blockTitle ? this.blockTitle : this.comment_title}</h2> : ''}\n {!this.hideForm && <salla-comment-form type={this.type} item-id={this.itemId}></salla-comment-form>}\n <div class=\"no-content-placeholder--comments\">\n <i class=\"sicon-chat-bubbles text-5xl block mb-5 text-gray-400\"></i>\n <p class=\"text-sm\">{this.noComments}</p>\n </div>\n </div>\n )\n }\n return (\n <div class={`s-comments s-comments-${this.type}`}>\n <div class={`${this.type == CommentType.PAGE ? \"s-comments-page-container\" : \"s-comments-container\"}`} >\n {!!this.total && !this.hideTitle ? <h2 class=\"s-comments-title\">{this.blockTitle ? this.blockTitle : this.comment_title}</h2> : ''}\n {!this.hideForm && <salla-comment-form type={this.type} item-id={this.itemId}></salla-comment-form>}\n\n {!!this.total && <h2 class=\"s-comments-count-label\" innerHTML={this.pluralize(this.comment_name, this.total)}></h2>}\n <div ref={wrapper => this.wrapper = wrapper}></div>\n\n\n {this.nextPage && (\n <div class=\"s-infinite-scroll-wrapper\" ref={status => this.status = status}>\n <button onClick={() => this.loadMore()} class=\"s-infinite-scroll-btn s-button-btn s-button-primary\">\n <span class=\"s-button-text s-infinite-scroll-btn-text\">{this.loadMoreText ? this.loadMoreText : salla.lang.get('common.elements.load_more')}</span>\n <span class=\"s-button-loader s-button-loader-center s-infinite-scroll-btn-loader\" ref={btnLoader => this.btnLoader = btnLoader} style={{ \"display\": \"none\" }}></span>\n </button>\n </div>\n )}\n </div>\n </div>\n\n );\n }\n\n\n\n async componentWillLoad() {\n await this.loadInitialData(); // Load initial data before rendering the component\n }\n\n}\n"],"version":3}