
(function(){
  function init(root){
    if(!root) return;
    var el = root.querySelector('.swiper');
    if(!el || el.__nikanInited) return;
    if(typeof Swiper==='undefined') return;

    var cfg={};
    try{ cfg=JSON.parse(root.getAttribute('data-nikan-sepid-s3')||'{}'); }catch(e){ cfg={}; }

    el.__nikanInited = true;

    new Swiper(el, {
      slidesPerView: 1,
      spaceBetween: 0,
      loop: false,
      rewind: true,
      watchOverflow: true,
      pagination: { el: root.querySelector('.swiper-pagination'), clickable: true },
      autoplay: cfg.autoplay ? cfg.autoplay : false,
    });
  }

  function scan(){
    document.querySelectorAll('.nikan-sepid-slider-model-3').forEach(init);
  }

  document.addEventListener('DOMContentLoaded', scan);
  window.addEventListener('load', scan);

  if(window.elementorFrontend && window.elementorFrontend.hooks){
    window.elementorFrontend.hooks.addAction('frontend/element_ready/nikan_sepid_slider_model_3.default', function($scope){
      var r=$scope[0] || ($scope.get && $scope.get(0));
      if(r) init(r);
    });
  } else {
    var tries=0, t=setInterval(function(){tries++; scan(); if(tries>40) clearInterval(t);}, 250);
  }
})();
