import{$ as e}from"./iframe-DSGyX7_4.js";class c{constructor(t,i,h,s="primary"){this.section=t.addClass("initiated"),this.sizes=h,this.items=[],this.visibleItems=[],this.batchSize=0,this.btn=e('<button class="btn btn-regular icon-right icon-laden '+s+'" />').text(i),t.children().each((a,o)=>{this.items.push(e(o).remove())}),t.after(e('<div class="button-wrapper" />').append(this.btn)),this.btn.on("click",a=>{a.preventDefault(),this.addBatch()}),this.buildCols(),this.addBatch(),this.handleResize()}addBatch(){const t=[];for(let i=0;i<this.batchSize;i++)this.items.length>0&&(this.items[0].attr("data-thumb")&&this.loadImage(this.items[0]),this.items[0].find("img[data-src]").each((h,s)=>{e(s).one("load",a=>{e(a.currentTarget).addClass("loaded")}).attr("src",e(s).attr("data-src"))}),this.visibleItems.push(this.items[0]),t.push(this.items[0].css({opacity:0,transform:"scale(0.8)",transition:"0.4s ease "+.07*i+"s"})),this.items.splice(0,1));this.items.length===0&&this.btn.parent().hide(),this.addToCols(t)}loadImage(t){const i=e('<img src="'+this.items[0].attr("data-thumb")+'" alt="'+this.items[0].attr("data-alt")+'" />').one("load",()=>{setTimeout(()=>{t.addClass("loaded")},200)});t.find("a").append(i)}handleResize(){this.width=this.section.outerWidth(),this.timer=null,e(window).on("resize",()=>{this.timer&&clearTimeout(this.timer),setTimeout(()=>{this.buildCols()},200)})}buildCols(){const t=this.section.width();let i=1;if(e.each(this.sizes,(h,s)=>{if(t>s.minWidth)i=h+1,this.batchSize=s.batchSize;else return!1}),!(this.cols&&i===this.cols.length)){e.each(this.cols,(h,s)=>{s.col.remove()}),this.cols=[],this.section.attr("data-cols",i);for(let h=0;h<i;h++){const s=e('<div class="column" />').appendTo(this.section);this.cols.push({col:s,index:h,height:0})}this.addToCols(this.visibleItems)}}addToCols(t){e.each(t,(i,h)=>{const s=e(h);this.cols[0].col.append(s),this.cols[0].height=Math.round(s.position().top+s.outerHeight()),this.cols.sort(this.compareCols),window.requestAnimationFrame(()=>{s.css({opacity:"1",transform:"scale(1)"})})})}compareCols(t,i){return t.height<i.height?-1:t.height>i.height?1:t.index<i.index?-1:t.index>i.index?1:0}}e("body").on("ihk-init dynamic-component-loaded gfi-dynamic-init",function(){e('.teasers[data-type="masonry"] .row:not(.initiated)').each((n,t)=>{const i=window.ihk.translations.loadMoreArticles,h=e(t);h.find("dynamic-content").length||new c(h,i,[{minWidth:0,batchSize:2},{minWidth:567,batchSize:3},{minWidth:1e3,batchSize:6}])})});export{c as M};
