var Wick = Wick || {};
Wick.GenerateProjectIdLocal = {
  GENERATE_PROJECT_ID_EVENT: 'generateProjectId',
  isErrorTriggered: false,
  projectId: 'DEF123102',
  errorMessage: 'Test error message, please click again',
  el: {
    generateBtn: '.generate-project-id__btn',
  },
  init() {
    $(window).on(Wick.GenerateProjectIdLocal.GENERATE_PROJECT_ID_EVENT, function ({ detail: { resolve, reject }}) {
      setTimeout(() => {
        if (!Wick.GenerateProjectIdLocal.isErrorTriggered) {
          Wick.GenerateProjectIdLocal.isErrorTriggered = true;
          reject({errorMessage: Wick.GenerateProjectIdLocal.errorMessage});
          return;
        }

        resolve({ projectId: Wick.GenerateProjectIdLocal.projectId });
      }, 1500);
    });
  },
};

$(document).ready(function () {
  if (!Wick.GenerateProjectIdLocal.el.generateBtn.length) {
    return;
  }

  Wick.GenerateProjectIdLocal.init();
});
