feather.replace();

jQuery(document).ready(function ($) {
  $(document).ready(function () {
    $("#orderList").DataTable({
      language: {
        lengthMenu: "نمایش _MENU_ در هر صفحه",
        thousands: "٬",
        paginate: {
          first: "اولین",
          last: "آخرین",
          next: "بعدی",
          previous: "قبلی",
        },
        zeroRecords: "موردی یافت نشد",
        info: "مشاهده صفحه _PAGE_ از _PAGES_",
        infoEmpty: "رکوردی موجود نیست",
        infoFiltered: "(فیلتر شده از مجموع _MAX_ مورد)",
      },
      ordering: false,
      responsive: false,
      dom: '<"top">rt<"bottom"lp><"clear">',
    });
  });
});

const aside = document.querySelector('[data-sticky="true"]'),
  startScroll = 32;
var endScroll = window.innerHeight - aside.offsetHeight - 500,
  currPos = window.scrollY,
  screenHeight = window.innerHeight,
  asideHeight = aside.offsetHeight;
aside.style.top = startScroll + "px";
window.addEventListener("resize", () => {
  screenHeight = window.innerHeight;
  asideHeight = aside.offsetHeight;
});
document.addEventListener(
  "scroll",
  () => {
    endScroll = window.innerHeight - aside.offsetHeight;
    let asideTop = parseInt(aside.style.top.replace("px;", ""));
    if (asideHeight > screenHeight) {
      if (window.scrollY < currPos) {
        if (asideTop < startScroll) {
          aside.style.top = asideTop + currPos - window.scrollY + "px";
        } else if (asideTop >= startScroll && asideTop != startScroll) {
          aside.style.top = startScroll + "px";
        }
      } else {
        if (asideTop > endScroll) {
          aside.style.top = asideTop + currPos - window.scrollY + "px";
        } else if (asideTop < endScroll && asideTop != endScroll) {
          aside.style.top = endScroll + "px";
        }
      }
    } else {
      aside.style.top = startScroll + "px";
    }
    currPos = window.scrollY;
  },
  {
    capture: true,
    passive: true,
  }
);

jQuery(document).ready(function ($) {
  $("[data-modal]").click(function (event) {
    $(this).modal({
      fadeDuration: 250,
      showClose: false,
      closeText: " ",
    });
    return false;
  });
});

function openNav() {
  document.getElementById("mainNav").style.width = "276px";
  document.getElementById("mainNav").style.padding = "var(--card-padding)";
  document.getElementById("closeNav").style.width = "100%";
}

function closeNav() {
  document.getElementById("mainNav").style.width = "0";
  document.getElementById("mainNav").style.padding = "0";
  document.getElementById("closeNav").style.width = "0";
}

function enableLoadingBtn(btn){
    btn.classList.add('loading')
    btn.disabled = true
}
function disableLoadingBtn(btn){
    btn.classList.remove('loading')
    btn.disabled = false
}
function submitForm(form){
    return $.ajax({
        url: form.action,
        type: form.method,
        data: new FormData(form),
        processData: false,
        contentType: false,
    });
}
