function getOrdersHtmlByCurrentPage({currentPage}) {
  const matchingData = Wick.FEMock.orders.find(item => item.page === currentPage);
  return matchingData.html;
}

function initMyOrdersEvent() {
  if (!Wick?.MyOrders?.events) {
    return;
  }

  $(window).on(Wick.MyOrders.events.MONTHLY_VIEW_EVENT, function ({ detail: { resolve, reject, payload } }) {
    setTimeout(() => {
      return resolve({});
    }, 500);
  });

  $(window).on(Wick.MyOrders.events.SORT_BY_EVENT, function ({ detail: { resolve, reject, payload } }) {
    setTimeout(() => {
      return resolve({url: '/sitemap.html'});
    }, 500);
  });

  $(window).on(Wick.MyOrders.events.CATEGORY_EVENT, function ({ detail: { resolve, reject, payload } }) {
    setTimeout(() => {
      return resolve({url: '/sitemap.html'});
    }, 500);
  });

  $(window).on(Wick.MyOrders.events.LOAD_MORE_EVENT, function ({ detail: { resolve, reject, payload } }) {
    setTimeout(() => {
      resolve({
        innerHTML: getOrdersHtmlByCurrentPage(payload),
        callback: () => {}
      });
    }, 1500);
  });
}

$(document).ready(function () {
  initMyOrdersEvent();
});
