function loadmore(elem) {
    window.pagination += 5;
    window.paginationElem = elem;
    elem.innerText = 'Yükleniyor...';
    $("#queryDomain").submit();
}

var api = "https://serversistemleri.com/api/?action=";

(function ($) {
    "use strict";

    // Kampanya barını kaldırma
    $(".sscampaignbar a").click(function () {
        $(".sscampaignbar").remove();
    });
    var U = new URL(location.href);
    $("#BtnPrice2").change(function () {
    var scl = (this.checked) ? "USD" : "TRY";
    document.querySelector("html").className = scl;
    //console.log("Değişti");
    location.reload();
    if (document.querySelector(".basket-details")) {
        $('#ss-loader').addClass('show transparent');
        $("#cartCurChange option").removeAttr("selected");
        $("#cartCurChange option[value=" + scl + "]").attr('selected', 'selected')
        $("#cartCurChange").next(".select-check-styled").text((scl === "TRY") ? "TL" : "USD");
        document.getElementById("pp").src = "//sspanel.serversistemleri.com/feeds/req.php?currency=" + cookie[cookie.doviz.value].value;

    }
})
    window.pagination = 0;
    $("#queryDomain").submit(function (event) {
      if (!event.isTrigger) {
          window.pagination = 0;
      }

        if (this.domain.value) {
          this[1].value = 'Bekleyiniz...';
         var domainName = this.domain.value.split(".")[0],
             ext = this.domain.value.split(".").splice(1).join(".");
         var results = $("#results"),
             html = '';
         if (window.pagination === 0) {
             $(".domain-whois").addClass("disnone");
             results.html('');
         }
            let extsorgu = '';
            if (ext) {
              extsorgu = '&ext=' + ext;
            }
            $.get(api + 'queryDomain&domain=' + domainName + extsorgu + '&skip=' + window.pagination, (data) => {
                if (data) {
                    $(".domain-whois").removeClass("disnone"); // Veri geldiyse whois bölümü gösteriliyor
                    if (window.pagination === 0) {
                        $(document).scrollTop($("#results").offset().top - ($("#ss-navbar").height() + 420)); // İlk sorguda otomatik kaydırma yapılıyor
                    }

                    if (data.Code) {
                        html += `<div class="alert alert-danger">
                                    <span>Hata!</span>
                                    <p>${errors[data.Message] ? errors[data.Message] : errors["none"]}</p>
                                </div>`;
                    } else {
                        data.sort((e) => (e.TLD === ext ? -1 : 1)).forEach(e => {
                            var action, text;

                            if (window.Cart && window.Cart.domains && window.Cart.domains.find(f => f.domain === `${e.DomainName}.${e.TLD}`)) {
                                action = `href="sepet"`;
                                text = `<a ${action} class="domain-to-cart register"><span class="icon-basket"></span> Ödeme Yap</a>`;
                            } else {
                                action = e.Status === "notavailable"
                                    ? `href="./domain-transferi?domain=${e.DomainName}.${e.TLD}"`
                                    : e.Status === "unsupportedtld"
                                        ? ""
                                        : e.Status === "premium"
                                            ? `href='javascript:void(0)' onclick="Tawk_API.maximize()"`
                                            : `onclick="javascript:domainAddCart('${e.DomainName}.${e.TLD}', this, ${e.Premium},${e.Price});"`;

                                text = `<a ${action} data-domain="${e.DomainName}.${e.TLD}" class="domain-to-cart ${(e.Status === "notavailable") ? "transfer" : (e.Status === "premium") ? 'transfer' :'register'}">
                                            <span class="icon-${(e.Status === "notavailable") ? "rocket" : (e.Status === "premium") ? 'message' :'fs-plus'}"></span>
                                            ${(e.Status === "notavailable") ? '<i class="fa-solid fa-arrow-right-arrow-left"></i> Transfer' : (e.Status === "premium") ? 'İletişim' : '<i class="fa-solid fa-basket-shopping"></i> Sepete Ekle'}
                                        </a>`;
                            }
                            let alan;
                            if (e.Status === "notavailable") {
                                alan = `<a class="kime-ait" target="_blank" style="background-color: rgba(0, 0, 0, 0) !important;border: 1px solid #455cc7;" href="whois-sorgulama?domain=${e.DomainName}.${e.TLD}">Kime Ait?</a>`;
                            } else if (e.Status === "unsupportedtld") {
                                alan = "error";
                            } else if (e.Status === "premium") {
                                alan = `premium`;
                            } else {
                                alan = `<div class="fiyat"><span class="price usd"><usd>$${e.Price} / Yıl</usd><try>₺${new Number(e.Price.replace(",","")*document.getElementById("usdpr").innerText).toFixed(2)} / Yıl</try></span></div>`;
                            }
                            html += `<div class="item">
                                <div class="result ${(e.Status === "notavailable") ? "transfer" : (e.Status === "unsupportedtld") ? 'error' : (e.Status === "premium") ? 'transfer' :'register'}">
                                <div class="row">
                                  <div class="col">
                                    <div class="domain-icon"></div>
                                    <div class="domain-name" style="font-size:19px;"> ${(e.Status === "notavailable") ? " <transfer>Alınmış</transfer>" : (e.Status === "unsupportedtld") ? 'error' : (e.Status === "premium") ? '<transfer>Alınmış</transfer>' :'<register>Müsait</register>'} <dikcizgi></dikcizgi> ${e.DomainName}.${e.TLD}${(e.Status === "premium") ? ' - Premium domainler için lütfen <a href="javascript:void()" onclick="Tawk_API.maximize()">iletişime geçin</a>' : ''}${(e.Status === "unsupportedtld") ? ' - Bu uzantı hatalıdır.' : ''}</div>
                                    <div class="domain-button whois-button">
                                      <a target="_blank" href="whois-sorgulama?domain=${e.DomainName}.${e.TLD}" ${(e.Status === "notavailable") ? "class='whois'" : ''}> Kime Ait?</a>
                                    </div>
                                    <div class="domain-badges">
                                      <div class="domain-status"></div>
                                      <div class="free-transfer"></div>
                                    </div>
                                  </div>
                                  <div class="col-sm-1 mobile-prices col-md-3 col-lg-3 justify-content-end mobile-center">
                                  ${(!e.Aciklama && e.oldPrice) ? `<div class="domain-discount">%${Math.round(100 - (e.Price / e.oldPrice) * 100)} İndirim</div>

                                    <div class="domain-price-old">
                                      <span class="prices">
                                        <span class="price usd"><usd>$${e.oldPrice} / Yıl</usd><try>₺${new Number(e.oldPrice*document.getElementById("usdpr").innerText).toFixed(2)} / Yıl</try></span>
                                      </span>
                                    </div>`:''}
                                    ${(e.Aciklama)?`<div class="domain-discount" style="background-color:#3781d8;min-width: 40%; color: white;">${e.Aciklama}</div>`:''}

                                    <div class="domain-price">
                                      <span class="prices">
                                        <span class="price usd"><usd>$${e.Price} / Yıl</usd><try>₺${new Number(e.Price.replace(",","")*document.getElementById("usdpr").innerText).toFixed(2)} / Yıl</try></span>
                                      </span>
                                    </div>
                                  </div>
                                  <div class="col-sm-2 col-md-6 col-lg-2">
                                    <div class="domain-button">
                                       ${alan}
                                    </div>
                                    <div class="domain-button">
                                      ${text}
                                    </div>
                                  </div>
                                </div>
                              </div>
                              </div>`;

                        });
                    }

                    if (window.pagination === 0) {
                        results.html(html); // İlk sorguda sonuçlar yenileniyor
                    } else {
                        results.append(html); // Daha fazla sonuç yüklendiğinde eski sonuçlar korunuyor
                    }
                }
            }).always(() => {
                this[1].value = "Sorgula";
                if (window.paginationElem) {
                    paginationElem.parentElement.parentElement.parentElement.parentElement.parentElement.remove();
                }
                results.append(`<div class="item">
        <div class="result register">
        <div class="row">
          <div class="col">
          <div class="domain-button" style="margin: 0 auto;">
          <a onclick="javascript:loadmore(this)" class="domain-to-cart register">Daha Fazla</a>
        </div>
          </div>
        </div>
      </div>
      </div>`);
            });
        }
        event.preventDefault();
        event.stopPropagation();
    });
window.startWaitedOpt = true;
    if (U.searchParams.get("domain") && $("#domain").length) {
        $("#domain").val(U.searchParams.get("domain"))
        var dsfdf = setInterval(() => {
            if (window.startWaitedOpt) {
                $("#queryDomain").submit();
                clearInterval(dsfdf);
            }
        }, 200);
    }
})(jQuery);

let slider = document.getElementById('slider');
if (slider) {
    let slides = document.querySelectorAll('.slide_slider');
    let currentIndex = 0;
    let totalSlides = slides.length;
    let slideInterval = setInterval(nextSlide, 3000);

    document.getElementById('next').addEventListener('click', nextSlide);
    document.getElementById('prev').addEventListener('click', prevSlide);
    slider.addEventListener('mouseenter', stopSlider);
    slider.addEventListener('mouseleave', startSlider);

    function nextSlide() {
        currentIndex = (currentIndex + 1) % totalSlides;
        updateSliderPosition();
    }

    function prevSlide() {
        currentIndex = (currentIndex - 1 + totalSlides) % totalSlides;
        updateSliderPosition();
    }

    function updateSliderPosition() {
        slider.style.transform = `translateX(-${currentIndex * 100}%)`;
    }

    function stopSlider() {
        clearInterval(slideInterval);
    }

    function startSlider() {
        slideInterval = setInterval(nextSlide, 3000);
    }
}
