$("#searchBtn").click(function(e){

  $(".search-area").show();
  
  $(".search-area").addClass("active");
  
  $(".sub-menu").addClass("hide");
  
  $(".language-sub-menu").addClass("hide");
  
});
  
  $("#close-btn").click(function(e){
  
  $(".search-area").hide();
  
  $(".search-area").removeClass("active");
  
  $(".sub-menu").removeClass("hide");

  $(".language-sub-menu").removeClass("hide");
  
  
});
/// Page Loader
$(window).on('load', function () {
});
setTimeout(function () {
  $("#loader-wrapper").fadeOut();
  $("#loader-wrapper").delay(400).fadeOut("slow");
}, 400);
/*
////sticky-menu
$(window).scroll(function() {
  if ($(this).scrollTop() > 50){  
    $('.site-navigation').addClass("sticky");
  }
  else{
      $('.site-navigation').removeClass("sticky");
  }
});
////mobil-sticky-menu
$(window).scroll(function() {
  if ($(this).scrollTop() > 50){  
    $('.mobil-site-navigation ').addClass("mobile-sticky");
  }
  else{
    $('.mobil-site-navigation ').removeClass("mobile-sticky");
  }
});
*/
/// go-up button
$(window).scroll(function () {
  if ($(this).scrollTop() > 100) {
  $('.scrollup').fadeIn();
  } else {
  $('.scrollup').fadeOut();
  }
});
$('.scrollup').click(function () {
    $("html, body").animate({
    scrollTop: 0}, 50);
    return false;   
});
////// wow.js
new WOW().init();
//// acordion-menu-js
var Accordion = function(el, multiple) {
  this.el = el || {};
  this.multiple = multiple || false;
  var links = this.el.find('.link');
  links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown)
}
Accordion.prototype.dropdown = function(e) {
    var $el = e.data.el;
    $this = $(this),
    $next = $this.next();
    $next.slideToggle();
    $this.parent().toggleClass('open');
    if (!e.data.multiple) {
    $el.find('.accordion-submenu').not($next).slideUp().parent().removeClass('open');
    };
}	
var accordion = new Accordion($('#accordion'), false);
/// cokie bar
$(".cerez-btn-close").on('click', function() {
    localStorage.setItem("cookie", 1);
    $(".cerez-bar").hide();  
});
  let cookieControl = localStorage.getItem("cookie");
  if(cookieControl == 1){
  $(".cerez-bar").hide();
}
/////////////////////////////////////////////////////////
$('#owl-urun').owlCarousel({
  loop: true,
  margin: 20,
  nav: true,
  navText: [
    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
  ],
  responsive: {
    0: {
      items: 1
    },
    600: {
      items: 1
    },
    1000: {
      items: 1
    }
  }
});
///////////////////
$('.owl-carousel').owlCarousel({
  loop: true,
  margin: 0,
  nav: true,
  navText: [
    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
  ],
  autoplay: true,
  autoplayTimeout: 3000, // 5 saniye
  autoplayHoverPause: true, // Üzerine gelince durdurur
  responsive: {
    0: {
      items: 1
    },
    600: {
      items: 1
    },
    1000: {
      items: 1
    }
  }
});
///////////////////////
$('#owl-mobil-slider').owlCarousel({
  loop: true,
  margin: 0,
  nav: true,
  navText: [
    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
  ],
  autoplay: true,
  autoplayTimeout: 5000, // 5 saniye
  autoplayHoverPause: true, // Üzerine gelince durdurur
  responsive: {
    0: {
      items: 1
    },
    600: {
      items: 1
    },
    1000: {
      items: 1
    }
  }
});
//////////////////////////////////////
$('#owl-haber').owlCarousel({
  loop: true,
  margin: 0,
  nav: true,
  navText: [
    '<i class="fa fa-angle-left" aria-hidden="true"></i>',
    '<i class="fa fa-angle-right" aria-hidden="true"></i>'
  ],
  responsive: {
    0: {
      items: 1
    },
    600: {
      items: 1
    },
    1000: {
      items: 1
    }
  }
});
/////////////////////////////////////////////////////
/* product left start */
if ($(".product-left").length) {
  // Thumbnail (alt görseller) Swiper
  var productThumbs = new Swiper(".product-thumbs", {
    spaceBetween: 10,
    slidesPerView: 3,
    freeMode: true,
    watchSlidesProgress: true,
    watchSlidesVisibility: true,
    slideToClickedSlide: true, // Tıklanınca büyük slider da değişsin
  });

  // Ana (büyük görsel) Swiper
  var productSlider = new Swiper(".product-slider", {
    spaceBetween: 0,
    loop: true,
    navigation: {
      nextEl: ".product-left .swiper-button-next",
      prevEl: ".product-left .swiper-button-prev",
    },
    thumbs: {
      swiper: productThumbs,
    },
  });
}



// Sayfa yüklendikten sonra zoom seviyesini kontrol et
document.addEventListener("DOMContentLoaded", function () {
  const zoomLevel = Math.round(window.devicePixelRatio * 100);

  // Eğer zoom seviyesi 125 ise, 'zoom-125' class'ını body'ye ekle
  if (zoomLevel === 125) {
    document.body.classList.add("zoom-125");
  }

  // Eğer zoom seviyesi 120 ile 130 arasında ise, belirli elementlere class ekle
  if (zoomLevel >= 120 && zoomLevel <= 130) {
    document.querySelector("footer")?.classList.add("footer-zoom-fix");
    document.querySelector("#owl-haber")?.classList.add("owl-zoom-fix");
    document.querySelector(".svg-turkiye-haritasi")?.classList.add("harita-zoom-fix");
  }
});

document.addEventListener("DOMContentLoaded", function () {
  const zoomLevel = Math.round(window.devicePixelRatio * 100);  // Ekran zoom seviyesini hesapla

  // Eğer zoom seviyesi 125 ise, ilgili class'ı ekle
  if (zoomLevel === 125) {
    document.querySelector(".socail-media > ul")?.classList.add("socail-media-ul-fix");
  }
  else if (zoomLevel === 100) {
    document.querySelector(".socail-media > ul")?.classList.add("socail-media-ul-remove");
    document.querySelector(".socail-media > ul")?.classList.remove("socail-media-ul-fix");
  }
});


document.addEventListener("DOMContentLoaded", function () {
  const zoomLevel = Math.round(window.devicePixelRatio * 100);  // Zoom seviyesini hesapla

  function adjustUrunlerMargin() {
    const urunler = document.querySelector(".urunler");

    if (zoomLevel === 125) {
      // %125 zoom seviyesi için
      urunler.style.marginBottom = "16rem";
    } else if (zoomLevel === 100) {
      // %100 zoom seviyesi için
      urunler.style.marginBottom = "18rem";
    }
  }

  // Fonksiyonu çalıştır
  adjustUrunlerMargin();
});

function fixMapZoomIfNeeded() {
  const map = document.querySelector('.svg-turkiye-haritasi');


  const zoomRatio = Math.round(window.devicePixelRatio * 100); // 100, 125, 150 vb.


  if (zoomRatio === 125) {
    map.classList.add('harita-zoom-fix');
  } else {
    map.classList.remove('harita-zoom-fix');
  }
}

window.addEventListener('load', fixMapZoomIfNeeded);
window.addEventListener('resize', fixMapZoomIfNeeded); 

