jQuery(document).ready(function ($) {
  $(window).scroll(function () {
    if ($(this).scrollTop() > 100) {
      $(".back-to-top a").fadeIn();
    } else {
      $(".back-to-top a").fadeOut();
    }
  });

  $(".back-to-top a").click(function () {
    $("html, body").animate({ scrollTop: 0 }, 800);
    return false;
  });

});

// post Swiper 

jQuery(document).ready(function ($) {
  // Target your query loop wrapper
  const $wrapper = $(".readable-blog-section .wp-block-post-template");

  // Add Swiper wrapper class
  $wrapper.addClass("swiper-wrapper");

  // Add Swiper slide class to each li
  $wrapper.find("li").addClass("swiper-slide");

  // Initialize Swiper
  var swiper = new Swiper(".mySwiper", {
    slidesPerView: 2,
    spaceBetween: 30,
    loop: false,
    speed: 800,
    autoplay: {
      delay: 3000,
      disableOnInteraction: false,
    },
    navigation: {
      nextEl: ".readable-post-swiper-button-next",
      prevEl: ".readable-post-swiper-button-prev",
    },
    breakpoints: {
      0: {
        slidesPerView: 1,   // 1 slide on mobile (0 - 767px)
      },
      991: {
        slidesPerView: 2,   // 2 slides from 768px and up
      }
    }
  });
});

// tabs.js

// Initialize tabs and tab contents
const fse_personal_blog_tabTiles = [...document.querySelectorAll("div.main-tab div")];
const fse_personal_blog_tabContents = [...document.querySelectorAll(".tab-content")];

// Set first tab active
fse_personal_blog_tabTiles.forEach((tabTile, index) => {
  tabTile.classList.toggle('active', index === 0);
  tabTile.querySelector('a').setAttribute('tabindex', '0'); // all tabs focusable for Tab key
});

fse_personal_blog_tabContents.forEach((tabContent, index) => {
  tabContent.classList.toggle('active', index === 0);
});

// Function to activate a tab
function fse_personal_blog_activateTab(fse_personal_blog_tabDiv) {
  const fse_personal_blog_activeIndex = fse_personal_blog_tabTiles.findIndex(tab => tab === fse_personal_blog_tabDiv);

  fse_personal_blog_tabTiles.forEach((tabTile, index) => {
    tabTile.classList.toggle('active', index === fse_personal_blog_activeIndex);
  });

  fse_personal_blog_tabContents.forEach((tabContent, index) => {
    tabContent.classList.toggle('active', index === fse_personal_blog_activeIndex);
  });

  fse_personal_blog_tabDiv.querySelector('a').focus();
}

// Click on tab
document.addEventListener("click", e => {
  const fse_personal_blog_tabDiv = e.target.closest(".tab-title");
  if (fse_personal_blog_tabDiv) {
    fse_personal_blog_activateTab(fse_personal_blog_tabDiv);
  }
});

// Optional: Enter/Space for keyboard activation
fse_personal_blog_tabTiles.forEach(tabTile => {
  const fse_personal_blog_tabLink = tabTile.querySelector('a');
  fse_personal_blog_tabLink.addEventListener('keydown', e => {
    if (e.key === 'Enter' || e.key === ' ') {
      e.preventDefault();
      fse_personal_blog_activateTab(tabTile);
    }
  });
});