const validProjectListId = ['45d94c37-06b1-4961-9fae-89d9082bc97b', 'AAA123456', 'AA123456'];
function initAddProjectListId () {
  if (!Wick?.AddProjectListId?.ADD_PROJECT_LIST_EVENT) {
    return;
  }

  $(window).on(Wick.AddProjectListId.ADD_PROJECT_LIST_EVENT, function ({ detail: { resolve, reject, payload }}) {
    setTimeout(() => {
      if (validProjectListId.includes(payload.projectEntryId)) {
        resolve({redirectUrl: parseUrl('page_checkout_merge-basket-with-energy.html')});
      } else {
        reject({errorMessage: 'Project list not found'})
      }
    }, 500);
  });
};

function parseUrl (url) {
  const currentPath = window.location.pathname;
  return currentPath.substring(0, currentPath.lastIndexOf("/")) + `/${url}`;
}

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