(function (){
'use strict';
function getPerView(root){
var width=window.innerWidth||document.documentElement.clientWidth;
if(width <=767) return 1;
if(width <=1024) return 2;
return parseInt(root.getAttribute('data-per-view')||'3', 10);
}
function setupCarousel(root){
if(root.getAttribute('data-tpcr-carousel-ready')==='1') return;
root.setAttribute('data-tpcr-carousel-ready', '1');
var track=root.querySelector('.tpcr__track');
var cards=root.querySelectorAll('.tpcr__card');
var prev=root.querySelector('.tpcr__nav--prev');
var next=root.querySelector('.tpcr__nav--next');
if(!track||!cards.length||!prev||!next) return;
var index=0;
function maxIndex(){
return Math.max(0, cards.length - getPerView(root));
}
function update(){
var gap=20;
var first=cards[0];
var step=first.getBoundingClientRect().width + gap;
track.style.transform='translateX(' + ((step * index) * -1) + 'px)';
prev.disabled=index <=0;
next.disabled=index >=maxIndex();
}
prev.addEventListener('click', function (){
if(index > 0){
index -=1;
update();
}});
next.addEventListener('click', function (){
if(index < maxIndex()){
index +=1;
update();
}});
window.addEventListener('resize', function (){
index=Math.min(index, maxIndex());
update();
});
update();
}
function setupReadMore(root){
var entries=root.querySelectorAll('.tpcr__text-wrap');
if(!entries.length) return;
function refreshEntry(entry){
var text=entry.querySelector('.tpcr__text');
var button=entry.querySelector('.tpcr__read-more');
if(!text||!button) return;
var wrap=entry.querySelector('.tpcr__read-more-wrap');
if(text.classList.contains('is-expanded')){
button.hidden=false;
if(wrap) wrap.hidden=false;
return;
}
var isShort=text.scrollHeight <=(text.clientHeight + 2);
button.hidden=isShort;
if(wrap) wrap.hidden=isShort;
}
entries.forEach(function (entry){
var text=entry.querySelector('.tpcr__text');
var button=entry.querySelector('.tpcr__read-more');
if(!text||!button) return;
button.addEventListener('click', function (){
var expanded=text.classList.toggle('is-expanded');
button.setAttribute('aria-expanded', expanded ? 'true':'false');
button.textContent=expanded ? (button.getAttribute('data-less-label')||'Read less'):(button.getAttribute('data-more-label')||'Read more');
refreshEntry(entry);
});
refreshEntry(entry);
});
window.addEventListener('resize', function (){
entries.forEach(refreshEntry);
});
}
document.addEventListener('DOMContentLoaded', function (){
var carousels=document.querySelectorAll('.tpcr.tpcr--isolated[data-tpcr-instance="1"]');
carousels.forEach(function (carousel){
setupCarousel(carousel);
setupReadMore(carousel);
});
});
})();