import { SnkMessageBuilder } from "../../../../../message/SnkMessageBuilder";
export async function showAskCancelPaginationPopup() {
  return new Promise((resolve) => {
    const messagesBuilder = new SnkMessageBuilder();
    const { checkboxContainer, checkbox } = buildCheckboxContainer(messagesBuilder);
    const popup = builPopup(resolve, checkbox, messagesBuilder);
    const contentContainer = buildContentContainer();
    const actionsContainer = buildActionsContainer();
    contentContainer.appendChild(checkboxContainer);
    contentContainer.appendChild(buildMessage(messagesBuilder));
    actionsContainer.appendChild(buildContinuePaginationBtn(popup, checkbox, resolve, messagesBuilder));
    actionsContainer.appendChild(buildCancelPaginationBtn(popup, resolve, messagesBuilder));
    contentContainer.appendChild(actionsContainer);
    popup.appendChild(contentContainer);
    document.body.appendChild(popup);
  });
}
function buildCheckboxContainer(messagesBuilder) {
  const checkboxContainer = document.createElement('div');
  checkboxContainer.style.marginBottom = '14px';
  checkboxContainer.style.display = 'flex';
  checkboxContainer.style.alignItems = 'center';
  const { checkbox, checkboxLabel } = buildCheckbox(messagesBuilder);
  checkboxContainer.appendChild(checkbox);
  checkboxContainer.appendChild(checkboxLabel);
  return { checkboxContainer, checkbox };
}
function buildCheckbox(messagesBuilder) {
  const checkbox = document.createElement('input');
  checkbox.type = 'checkbox';
  checkbox.id = 'loadAll';
  const checkboxLabel = document.createElement('label');
  checkboxLabel.htmlFor = 'loadAll';
  checkboxLabel.textContent = messagesBuilder === null || messagesBuilder === void 0 ? void 0 : messagesBuilder.getMessage("dataUnitDataLoaderHelper.checkbox.loadAll");
  checkboxLabel.style.marginLeft = '5px';
  return { checkbox, checkboxLabel };
}
function buildActionsContainer() {
  const actionsContainer = document.createElement('div');
  actionsContainer.style.display = 'flex';
  actionsContainer.style.flexDirection = 'row';
  actionsContainer.style.justifyContent = 'end';
  actionsContainer.style.gap = '5px';
  return actionsContainer;
}
function buildContentContainer() {
  const contentContainer = document.createElement('div');
  contentContainer.style.display = 'flex';
  contentContainer.style.flexDirection = 'column';
  contentContainer.style.fontFamily = 'var(--font-pattern, Roboto)';
  contentContainer.style.fontSize = 'var(--text--medium)';
  return contentContainer;
}
function buildMessage(messagesBuilder) {
  const message = document.createElement('div');
  const line1 = document.createElement('p');
  const line2 = document.createElement('p');
  const line3 = document.createElement('p');
  line3.style.fontWeight = 'var(--text-weight--large, 600)';
  line1.textContent = messagesBuilder === null || messagesBuilder === void 0 ? void 0 : messagesBuilder.getMessage("dataUnitDataLoaderHelper.pagination.line1");
  line2.textContent = messagesBuilder === null || messagesBuilder === void 0 ? void 0 : messagesBuilder.getMessage("dataUnitDataLoaderHelper.pagination.line2");
  line3.textContent = messagesBuilder === null || messagesBuilder === void 0 ? void 0 : messagesBuilder.getMessage("dataUnitDataLoaderHelper.pagination.line3");
  message.appendChild(line1);
  message.appendChild(line2);
  message.appendChild(line3);
  return message;
}
function buildCancelPaginationBtn(popup, resolve, messagesBuilder) {
  const cancelPaginationBtn = document.createElement('ez-button');
  cancelPaginationBtn.label = messagesBuilder === null || messagesBuilder === void 0 ? void 0 : messagesBuilder.getMessage("dataUnitDataLoaderHelper.buttons.cancel");
  cancelPaginationBtn.size = 'medium';
  cancelPaginationBtn.classList.add('ez-button--primary');
  cancelPaginationBtn.onclick = () => {
    document.body.removeChild(popup);
    resolve(CancelPaginationResponse.CANCEL);
  };
  return cancelPaginationBtn;
}
function buildContinuePaginationBtn(popup, checkBox, resolve, messagesBuilder) {
  const continuePaginationBtn = document.createElement('ez-button');
  continuePaginationBtn.label = messagesBuilder === null || messagesBuilder === void 0 ? void 0 : messagesBuilder.getMessage("dataUnitDataLoaderHelper.buttons.continue");
  continuePaginationBtn.size = 'medium';
  continuePaginationBtn.onclick = () => {
    document.body.removeChild(popup);
    resolve(checkBox.checked ? CancelPaginationResponse.LOAD_ALL : CancelPaginationResponse.CONTINUE);
  };
  return continuePaginationBtn;
}
function builPopup(resolve, checkBox, messagesBuilder) {
  const popup = document.createElement('ez-popup');
  popup.opened = true;
  popup.size = 'x-small';
  popup.ezTitle = messagesBuilder === null || messagesBuilder === void 0 ? void 0 : messagesBuilder.getMessage("dataUnitDataLoaderHelper.pagination.title");
  popup.heightMode = "auto";
  popup.addEventListener('ezClosePopup', () => {
    document.body.removeChild(popup);
    resolve(checkBox.checked ? CancelPaginationResponse.LOAD_ALL : CancelPaginationResponse.CONTINUE);
  }, { once: true });
  popup.addEventListener('ezPopupAction', () => {
    document.body.removeChild(popup);
    resolve(CancelPaginationResponse.CANCEL);
  }, { once: true });
  return popup;
}
export var CancelPaginationResponse;
(function (CancelPaginationResponse) {
  CancelPaginationResponse["CANCEL"] = "CANCEL";
  CancelPaginationResponse["CONTINUE"] = "CONTINUE";
  CancelPaginationResponse["LOAD_ALL"] = "LOAD_ALL";
})(CancelPaginationResponse || (CancelPaginationResponse = {}));
