webpackJsonp_name_([3],{"../../component-library/dist/esm/cla-likes-modal.entry.js":function(a,b,c){"use strict";function d(a,...b){return window&&window.lmsg&&"function"==typeof window.lmsg?window.lmsg(a,...b):a}var e=Math.floor;Object.defineProperty(b,"__esModule",{value:!0}),c.d(b,"cla_likes_modal",function(){return g});var f=c("../../component-library/dist/esm/index-b3c803fc.js");const g=class{constructor(a){c.i(f.c)(this,a),this.ITEMS_PER_PAGE=30,this.ITEMS_PER_COLUMN=10,this.MAX_PAGES_TO_SHOW=5,this.currentPage=1,this.totalPages=0,this.totalLikes=0,this.likers=[],this.isOpen=!1,this.objectType=void 0,this.objectId=void 0,this.total=0}componentWillLoad(){this.totalLikes=this.total}componentDidRender(){if(this.isOpen){const a=this.element.querySelector(".modal");a&&document.body.contains(a)&&document.body.appendChild(a)}}onTotalChange(a){this.totalLikes=a}async fetchData(a=0){try{let b;{const c=await fetch(`/api/like/${this.objectType}/${this.objectId}?limit=${this.ITEMS_PER_PAGE}&offset=${a}`);b=await c.json()}this.likers=b.data,this.totalLikes=b.paging.total,this.totalPages=Math.ceil(b.paging.total/this.ITEMS_PER_PAGE),this.currentPage=e(b.paging.offset/b.paging.limit)+1,this.isOpen=!0}catch(a){console.error("Error fetching likers:",a)}}handlePageClick(a,b){a.preventDefault(),1<=b&&(this.currentPage=b,this.fetchData((b-1)*this.ITEMS_PER_PAGE))}closeModal(){this.isOpen=!1,this.likers=[]}getLikersByColumn(a){return this.likers.slice(a*this.ITEMS_PER_COLUMN,(a+1)*this.ITEMS_PER_COLUMN)}render(){return c.i(f.d)("div",null,c.i(f.d)("a",{href:"#",onClick:(a)=>this.handlePageClick(a,1)},this.totalLikes," ",1>=this.totalLikes?d("common.notifications.post_like"):d("common.notifications.post_likes")),this.isOpen&&c.i(f.d)("div",{class:"modal fade show d-block overflow-auto"},c.i(f.d)("div",{class:"modal-dialog modal-lg"},c.i(f.d)("div",{class:"modal-content"},c.i(f.d)("div",{class:"modal-header"},c.i(f.d)("h5",{class:"modal-title"},c.i(f.d)("span",{class:"mr-3"},d("common.cla_comments.people_who_liked_this")),c.i(f.d)("cla-badge",{slot:"status",styleclass:"badge badge-pill badge-secondary"},this.totalLikes)),c.i(f.d)("cla-button",{class:"close",onClick:()=>this.closeModal()},c.i(f.d)("span",{"aria-hidden":"true"},c.i(f.d)("ion-icon",{name:"close-outline"})))),c.i(f.d)("div",{class:"modal-body"},c.i(f.d)("div",{class:"row row-col-3"},[[],[],[]].map((a,b)=>0<this.getLikersByColumn(b).length&&c.i(f.d)("div",{class:"col"},c.i(f.d)("ul",{class:"list-group list-group-flush"},this.likers.slice(b*this.ITEMS_PER_COLUMN,(b+1)*this.ITEMS_PER_COLUMN).map((a)=>c.i(f.d)("li",{class:"list-group-item"},c.i(f.d)("div",{class:"media align-items-center"},c.i(f.d)("a",{href:a.profile_link,target:"_blank"},c.i(f.d)("img",{src:a.profile_photo,alt:"",width:"32",class:"media-object profile-img"})),c.i(f.d)("div",{class:"media-body ml-2 text-truncate"},c.i(f.d)("a",{href:a.profile_link,target:"_blank"},a.user_name))))))))),1<this.totalPages&&c.i(f.d)("nav",{class:"d-flex justify-content-center","aria-label":"Likes Modal Pagination"},c.i(f.d)("ul",{class:"pagination"},c.i(f.d)("li",{class:`page-item ${1===this.currentPage?"disabled":""}`},c.i(f.d)("a",{class:"page-link",href:"#",onClick:(a)=>this.handlePageClick(a,1),"aria-label":"First"},"\xAB")),c.i(f.d)("li",{class:`page-item ${1===this.currentPage?"disabled":""}`},c.i(f.d)("a",{class:"page-link",href:"#",onClick:(a)=>this.handlePageClick(a,this.currentPage-1),"aria-label":"Previous"},"\u2039")),(()=>{var a=Math.max;let b=a(1,this.currentPage-e(this.MAX_PAGES_TO_SHOW/2)),d=Math.min(this.totalPages,b+this.MAX_PAGES_TO_SHOW-1);return d-b<this.MAX_PAGES_TO_SHOW-1&&(b=a(1,d-this.MAX_PAGES_TO_SHOW+1)),[...Array(d-b+1)].map((a,d)=>{const e=b+d;return c.i(f.d)("li",{class:`page-item ${e===this.currentPage?"active":""}`},c.i(f.d)("a",{class:"page-link",href:"#",onClick:(a)=>this.handlePageClick(a,e)},e))})})(),c.i(f.d)("li",{class:`page-item ${this.currentPage===this.totalPages?"disabled":""}`},c.i(f.d)("a",{class:"page-link",href:"#",onClick:(a)=>this.handlePageClick(a,this.currentPage+1),"aria-label":"Next"},"\u203A")),c.i(f.d)("li",{class:`page-item ${this.currentPage===this.totalPages?"disabled":""}`},c.i(f.d)("a",{class:"page-link",href:"#",onClick:(a)=>this.handlePageClick(a,this.totalPages),"aria-label":"Last"},"\xBB"))))),c.i(f.d)("div",{class:"modal-footer d-flex justify-content-center"},c.i(f.d)("button",{type:"button",class:"btn btn-block btn-secondary d-md-inline-block w-md-25 w-100",onClick:()=>this.closeModal()},d("common.close")))))))}get element(){return c.i(f.e)(this)}static get watchers(){return{total:["onTotalChange"]}}}}});
//# sourceMappingURL=3.js.map