"use strict";

require("core-js/modules/es.promise.js");

require("core-js/modules/es.json.stringify.js");

function test(mainColor, url, path, local, background, reg, demo) {
  // created elements
  const wrapp = document.querySelector(".wrapp");
  const topBlock = document.createElement("div");
  const middleBlock = document.createElement("div");
  const bottomBlock = document.createElement("div");
  const registrationWrap = document.createElement("div");
  const registration = document.createElement("p");
  const enterWrap = document.createElement("div");
  const enter = document.createElement("p");
  const dotted = document.createElement("p");
  const or = document.createElement("p");
  const loginInput = document.createElement("input");
  loginInput.setAttribute("autocomplete", "off");
  const inputWrap = document.createElement("div");
  const inputWrapSecond = document.createElement("div");
  const passwordInput = document.createElement("input");
  passwordInput.setAttribute("type", "password");
  passwordInput.setAttribute("autocomplete", "off");
  const loginLabel = document.createElement("div");
  const passwordLabel = document.createElement("div");
  const loginBtnWrap = document.createElement("div");
  const loginBtn = document.createElement("button");
  const loginBtnText = document.createElement("span");
  const registationBtn = document.createElement("button");
  const forgotPasswordBtn = document.createElement("div");
  const forgotPasswordBtnText = document.createElement("p");
  const popup = document.createElement('span');
  const stylesWrapp = {
    width: "336px",
    height: "300px",
    display: "flex",
    flexDirection: "column",
    margin: "120px auto",
    alignItems: "center",
    boxSizing: "border-box",
    fontFamily: "'CircleRegular',Fallback, sans-serif"
  };
  const stylesTopBlock = {
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    width: "336px",
    textAlign: "center"
  };
  const stylesMiddleBlock = {
    display: "flex",
    flexDirection: "column",
    alignItems: "center",
    width: "336px"
  };
  const stylesInputWrap = {
    width: "315px",
    border: "solid 1px #b5b5b5",
    boxSizing: "border-box",
    borderRadius: "3px",
    position: "relative",
    height: "40px",
    marginBottom: "50px",
    background: 'white'
  };
  const stylesloginInput = {
    border: "none",
    width: "90%",
    height: "90%",
    fontSize: "18px",
    fontFamily: "Circe-Regular,sans-serif",
    fontStyle: "normal",
    fontWeight: "350",
    lineHeight: "27px",
    paddingLeft: "30px",
    paddingRight: "0px",
    boxShadow: '0 0 0 30px white inset' // padding: '0 13px 0 27px',

  };
  const stylesLoginBtn = {
    // fontSize: "15px",
    lineHeight: "12px",
    color: "#fff",
    border: "none",
    border: "none",
    background: "linear-gradient(\n160.87deg,".concat(mainColor, " 15.1%,#776aec 139.67%),").concat(mainColor),
    borderRadius: "3px",
    width: "96%",
    height: "44px",
    margin: "3px"
  };
  const stylesBottomBlock = {
    // marginTop: '44px',
    height: "50px",
    width: "336px",
    display: "flex",
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "space-between"
  };
  const stylesLoginBtnWrap = {
    fontize: "16px",
    lineHeight: "23.2px",
    color: "black",
    width: "144px",
    border: "1px solid #3668a8",
    borderRadius: "3px"
  };
  const stylesRegistration = {
    fontSize: " 1.25rem",
    lineHeight: "23.2px",
    color: "".concat(mainColor),
    marginBottom: '30px'
  };
  const stylesEnter = {
    fontSize: " 1.687rem",
    lineHeight: "23.2px",
    color: "black"
  };
  const stylesForgotPasswordBtn = {
    fontSize: " 0.887rem",
    lineHeight: "23.2px",
    color: "".concat(mainColor),
    width: "144px",
    lineHeight: "1"
  };
  const stylesDotted = {
    marginTop: '-25px'
  };
  const stylesInputLabel = {
    fontSize: "18px",
    fontFamily: "Circe-Regular,sans-serif",
    fontStyle: "normal",
    fontWeight: 400,
    lineHeight: "27px",
    color: "#313131",
    height: "20px",
    marginLeft: "16px",
    marginTop: '10px',
    padding: "0px 11px",
    background: background || 'white',
    textAlign: "left",
    position: "absolute",
    top: "-30px",
    width: ["-webkit-fit-content", "-moz-fit-content", "fit-content"]
  };
  const stylesOr = {
    fontSize: "18px",
    fontFamily: "Circe-Regular,sans-serif",
    fontWeight: "400",
    lineHeight: "27px",
    color: "#818181"
  };
  const stylesPopup = {
    width: '100px',
    color: 'red'
  }; // function for adding classes

  const stylesSetter = (stylesObj, el) => {
    Object.keys(stylesObj).forEach(key => {
      el.style[key] = stylesObj[key];
    });
  };

  stylesSetter(stylesWrapp, wrapp);
  stylesSetter(stylesTopBlock, topBlock);
  stylesSetter(stylesMiddleBlock, middleBlock);
  stylesSetter(stylesLoginBtn, loginBtn);
  stylesSetter(stylesBottomBlock, bottomBlock);
  stylesSetter(stylesLoginBtnWrap, loginBtnWrap);
  stylesSetter(stylesloginInput, loginInput);
  stylesSetter(stylesloginInput, passwordInput);
  stylesSetter(stylesInputWrap, inputWrap);
  stylesSetter(stylesInputWrap, inputWrapSecond);
  stylesSetter(stylesRegistration, registration);
  stylesSetter(stylesEnter, enterWrap);
  stylesSetter(stylesDotted, dotted);
  stylesSetter(stylesForgotPasswordBtn, forgotPasswordBtn);
  stylesSetter(stylesInputLabel, loginLabel);
  stylesSetter(stylesInputLabel, passwordLabel);
  stylesSetter(stylesOr, or);
  stylesSetter(stylesPopup, popup);

  if (!demo) {
    // !reg ? wrapp.appendChild(topBlock) : null;
    wrapp.appendChild(topBlock);
    wrapp.appendChild(middleBlock);
    wrapp.appendChild(bottomBlock);
    topBlock.appendChild(enterWrap);
    topBlock.appendChild(registrationWrap);
    enterWrap.appendChild(enter);
    registrationWrap.appendChild(or);
    registrationWrap.appendChild(registration);
    registrationWrap.appendChild(dotted);
    registration.innerHTML = local === "ru" ? "<span onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">\u0420\u0415\u0413\u0418\u0421\u0422\u0420\u0410\u0426\u0418\u042F</span>" : "<span onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">REGISTER</span>";
    enter.innerHTML = local === "ru" ? "<span>ВХОД</span>" : "<span>SIGN IN</span>";
    or.innerHTML = local === "ru" ? "<p>или</p>" : "<p>or</p>";
    dotted.innerHTML = "&#729;";
    middleBlock.appendChild(inputWrap);
    middleBlock.appendChild(inputWrapSecond);
    inputWrap.appendChild(loginInput);
    inputWrapSecond.appendChild(passwordInput);
    inputWrap.appendChild(loginLabel);
    loginLabel.innerHTML = "<span>Email</span>";
    inputWrapSecond.appendChild(passwordLabel);
    passwordLabel.innerHTML = "<span>Password</span>";
    bottomBlock.appendChild(loginBtnWrap);
    loginBtnWrap.appendChild(loginBtn);
    loginBtn.appendChild(loginBtnText);
    loginBtn.textContent = local !== "ru" ? "SIGN IN" : "ВХОД"; // loginBtnText.textContent = "SIGN IN";

    bottomBlock.appendChild(forgotPasswordBtn);
    forgotPasswordBtn.appendChild(forgotPasswordBtnText);
    forgotPasswordBtnText.innerHTML = local === "ru" ? "<p onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">\u0417\u0430\u0431\u044B\u043B\u0438 \u043F\u0430\u0440\u043E\u043B\u044C?</p>" : "<p onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">Forgot password?</p>"; // bottomBlock.appendChild(registationBtn);

    const paragraphs = wrapp.querySelectorAll('p');
    const buttons = wrapp.querySelectorAll('button');
    paragraphs.forEach((el, i) => {
      el.style.fontSize = '20px'; // el.style.padding = '0px'
      // el.style.margin = '0px'
    }); // Events

    registrationWrap.addEventListener("click", event => {
      loginInput.value = '';
      passwordInput.value = '';
      popup.textContent = "";
      inputWrap.style.borderColor = 'black';
      inputWrapSecond.style.borderColor = 'black';
      inputWrap.appendChild(popup);

      if (local === "ru") {
        if (registration.textContent === "РЕГИСТРАЦИЯ") {
          registration.innerHTML = "<p style=\"font-size: 20px\" onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">\u0412\u0425\u041E\u0414</p>";
          enter.textContent = "РЕГИСТРАЦИЯ";
          loginBtn.textContent = "РЕГИСТРАЦИЯ";
          inputWrapSecond.style.display = "block";
          forgotPasswordBtn.style.display = "block";
        } else {
          registration.innerHTML = "<p style=\"font-size: 20px\" onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">\u0420\u0415\u0413\u0418\u0421\u0422\u0420\u0410\u0426\u0418\u042F</p>";
          enter.textContent = "ВХОД";
          loginBtn.textContent = "ВХОД";
        }

        if (forgotPasswordBtnText.textContent === "Забыли пароль?") {
          forgotPasswordBtnText.innerHTML = "<span style=\"font-size: 15px;\" \"onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">'\u042F \u0441\u043E\u0433\u043B\u0430\u0448\u0430\u044E\u0441\u044C \u0441 \u0443\u0441\u043B\u043E\u0432\u0438\u044F\u043C\u0438 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u044F \u043F\u043B\u0430\u0442\u0444\u043E\u0440\u043C\u044B'</span>";
        } else {
          forgotPasswordBtnText.innerHTML = "<p style=\"font-size: 15px\" onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">\u0417\u0430\u0431\u044B\u043B\u0438 \u043F\u0430\u0440\u043E\u043B\u044C?</p>";
        }
      } else {
        if (registration.textContent === "REGISTER") {
          registration.innerHTML = "<p style=\"font-size: 20px;\" onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">SIGN IN</p>";
          enter.textContent = "REGISTER";
          loginBtn.textContent = "SIGN UP";
          inputWrapSecond.style.display = "block";
          forgotPasswordBtn.style.display = "block";
        } else {
          registration.innerHTML = "<p style=\"font-size: 20px\" onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">REGISTER</p>";
          enter.textContent = "SIGN IN";
          loginBtn.textContent = "SIGN IN";
        }

        if (forgotPasswordBtnText.textContent === "Forgot password?") {
          forgotPasswordBtnText.innerHTML = "<p style=\"font-size: 15px\" onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">I agree to Navigine Privacy Policy and Terms & Conditions</p>";
        } else {
          forgotPasswordBtnText.innerHTML = "<p style=\"font-size: 20px\" onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">Forgot password?</p>";
        }
      }
    });
    forgotPasswordBtn.addEventListener("click", event => {
      "";

      if (loginBtn.textContent === "SIGN IN") {
        local === 'ru' ? loginBtn.textContent = "СБРОСИТЬ" : loginBtn.textContent = "RESTORE";
        inputWrapSecond.style.display = "none";
        forgotPasswordBtn.style.display = "none";
      } else if (loginBtn.textContent === "ВХОД") {
        local === 'ru' ? loginBtn.textContent = "СБРОСИТЬ" : loginBtn.textContent = "RESTORE";
        inputWrapSecond.style.display = "none";
        forgotPasswordBtn.style.display = "none";
      } else {
        // registration.textContent = 'Регистрация';
        // login.textContent = 'Вход';
        window.open('https://navigine.com/privacy/');
      }
    });
    loginBtn.addEventListener("click", async event => {
      event.preventDefault();

      if (loginBtn.textContent === "ВХОД") {
        let user = {
          email: loginInput.value,
          password: passwordInput.value
        };
        let response = await fetch("".concat(path, "/login"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(user)
        });
        let result = await response.json();
        const cookieValue = result.token;
        let date = new Date(Date.now() + 86400e3);
        date = date.toUTCString();
        const cookieName = "navtok";
        document.cookie = cookieName + "=" + cookieValue + "; domain=.navigine.com; max-age=3600; path=/";

        if (response.status === 200) {
          window.open(url);
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          inputWrap.removeChild(popup);
        } else {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }
      } else if (loginBtn.textContent === "RESTORE") {
        let user = {
          email: loginInput.value
        };
        let response = await fetch("".concat(path, "/restorePassword"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(user)
        });
        let result = await response.json();
        loginInput.value = '';

        if (response.status === 200) {
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          popup.textContent = result.data;
          inputWrap.appendChild(popup);
          location.reload();
        } else {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }
      } else if (loginBtn.textContent === "СБРОСИТЬ") {
        let user = {
          email: loginInput.value
        };
        let response = await fetch("".concat(path, "/restorePassword"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(user)
        });
        let result = await response.json();
        loginInput.value = '';

        if (response.status === 200) {
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          popup.textContent = result.data;
          inputWrap.appendChild(popup);
          location.reload();
        } else {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }
      } else if (loginBtn.textContent === "SIGN IN") {
        let user = {
          email: loginInput.value,
          password: passwordInput.value
        };
        let response = await fetch("".concat(path, "/login"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(user)
        });
        let result = await response.json();
        const cookieValue = result.token;
        let date = new Date(Date.now() + 86400e3);
        date = date.toUTCString();
        const cookieName = "navtok";
        document.cookie = cookieName + "=" + cookieValue + "; domain=.navigine.com; max-age=3600; path=/";

        if (response.status === 200) {
          window.open(url);
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          inputWrap.removeChild(popup);
        } else {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }
      } else if (loginBtn.textContent === "РЕГИСТРАЦИЯ") {
        let newUser = {
          company: "",
          email: loginInput.value,
          password: passwordInput.value,
          confirmed_password: passwordInput.value,
          language: "ru",
          name: ""
        };
        let response = await fetch("".concat(path, "/registration"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(newUser)
        });
        let result = await response.json();

        if (response.status === 400) {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }

        if (response.status === 200) {
          loginInput.value = "";
          passwordInput.value = "";
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          popup.textContent = "";
          inputWrap.removeChild(popup);
        }
      } else {
        let newUser = {
          company: "",
          email: loginInput.value,
          password: passwordInput.value,
          confirmed_password: passwordInput.value,
          language: "ru",
          name: ""
        };
        let response = await fetch("".concat(path, "/registration"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(newUser)
        });
        let result = await response.json();

        if (response.status === 400) {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }

        if (response.status === 200) {
          loginInput.value = "";
          passwordInput.value = "";
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          popup.textContent = "";
          inputWrap.removeChild(popup);
        }
      }
    });
  } else {
    wrapp.appendChild(topBlock);
    wrapp.appendChild(middleBlock);
    wrapp.appendChild(bottomBlock);
    topBlock.appendChild(enterWrap);
    topBlock.appendChild(registrationWrap);
    enterWrap.appendChild(enter);
    registrationWrap.appendChild(or);
    registrationWrap.appendChild(registration);
    registrationWrap.appendChild(dotted);
    registration.innerHTML = local === "ru" ? "<a data-toggle='modal' data-target='#partnersModal' onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">\u0417\u0410\u041F\u0420\u041E\u0421\u0418\u0422\u042C \u0414\u0415\u041C\u041E</a>" : "<a data-toggle='modal' data-target='#partnersModal' onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">Start 14 Day Trial</a>";
    enter.innerHTML = local === "ru" ? "<span>ВХОД</span>" : "<span>SIGN IN</span>";
    or.innerHTML = local === "ru" ? "<p>или</p>" : "<p>or</p>";
    dotted.innerHTML = ". . . . . . .";
    middleBlock.appendChild(inputWrap);
    middleBlock.appendChild(inputWrapSecond);
    inputWrap.appendChild(loginInput);
    inputWrapSecond.appendChild(passwordInput);
    inputWrap.appendChild(loginLabel);
    loginLabel.innerHTML = "<span>Email</span>";
    inputWrapSecond.appendChild(passwordLabel);
    passwordLabel.innerHTML = "<span>Password</span>";
    bottomBlock.appendChild(loginBtnWrap);
    loginBtnWrap.appendChild(loginBtn);
    loginBtn.appendChild(loginBtnText);
    loginBtn.textContent = local !== "ru" ? "SIGN IN" : "ВХОД"; // loginBtnText.textContent = "SIGN IN";

    bottomBlock.appendChild(forgotPasswordBtn);
    forgotPasswordBtn.appendChild(forgotPasswordBtnText);
    forgotPasswordBtnText.innerHTML = local === "ru" ? "<p onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">\u0417\u0430\u0431\u044B\u043B\u0438 \u043F\u0430\u0440\u043E\u043B\u044C?</p>" : "<p onMouseOver=\"this.style.cursor='pointer'\" onMouseOut=\"this.style.cursor=''\">Forgot password?</p>"; // bottomBlock.appendChild(registationBtn);

    const paragraphs = wrapp.querySelectorAll('p');
    const buttons = wrapp.querySelectorAll('button');
    paragraphs.forEach((el, i) => {
      el.style.fontSize = '20px'; // el.style.padding = '0px'
      // el.style.margin = '0px'
    }); // Events

    registrationWrap.addEventListener("click", event => {});
    forgotPasswordBtn.addEventListener("click", event => {
      "";

      if (loginBtn.textContent === "SIGN IN") {
        local === 'ru' ? loginBtn.textContent = "СБРОСИТЬ" : loginBtn.textContent = "RESTORE";
        inputWrapSecond.style.display = "none";
        forgotPasswordBtn.style.display = "none";
      } else if (loginBtn.textContent === "ВХОД") {
        local === 'ru' ? loginBtn.textContent = "СБРОСИТЬ" : loginBtn.textContent = "RESTORE";
        inputWrapSecond.style.display = "none";
        forgotPasswordBtn.style.display = "none";
      } else {
        // registration.textContent = 'Регистрация';
        // login.textContent = 'Вход';
        window.open('https://navigine.com/privacy/');
      }
    });
    loginBtn.addEventListener("click", async event => {
      event.preventDefault();

      if (loginBtn.textContent === "ВХОД") {
        let user = {
          email: loginInput.value,
          password: passwordInput.value
        };
        let response = await fetch("".concat(path, "/login"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(user)
        });
        let result = await response.json();
        const cookieValue = result.token;
        let date = new Date(Date.now() + 86400e3);
        date = date.toUTCString();
        const cookieName = "navtok";
        document.cookie = cookieName + "=" + cookieValue + "; domain=.navigine.com; max-age=3600; path=/";

        if (response.status === 200) {
          window.open(url);
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          inputWrap.removeChild(popup);
        } else {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }
      } else if (loginBtn.textContent === "RESTORE") {
        let user = {
          email: loginInput.value
        };
        let response = await fetch("".concat(path, "/restorePassword"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(user)
        });
        let result = await response.json();
        loginInput.value = '';

        if (response.status === 200) {
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          popup.textContent = result.data;
          inputWrap.appendChild(popup);
          location.reload();
        } else {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }
      } else if (loginBtn.textContent === "СБРОСИТЬ") {
        let user = {
          email: loginInput.value
        };
        let response = await fetch("".concat(path, "/restorePassword"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(user)
        });
        let result = await response.json();
        loginInput.value = '';

        if (response.status === 200) {
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          popup.textContent = result.data;
          inputWrap.appendChild(popup);
          location.reload();
        } else {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }
      } else if (loginBtn.textContent === "SIGN IN") {
        let user = {
          email: loginInput.value,
          password: passwordInput.value
        };
        console.log(path);
        console.log(url);
        let response = await fetch("".concat(path, "/login"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(user)
        });
        let result = await response.json();
        const cookieValue = result.token;
        let date = new Date(Date.now() + 86400e3);
        date = date.toUTCString();
        const cookieName = "navtok";
        document.cookie = cookieName + "=" + cookieValue + "; domain=.navigine.com; max-age=3600; path=/";

        if (response.status === 200) {
          console.log(response);
          localStorage.setItem('navtok', cookieValue);
          console.log(localStorage.getItem('navtok')); // window.location.replace(url);
          // window.open(url) 

          window.location.href = url;
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          inputWrap.removeChild(popup);
        } else {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }
      } else if (loginBtn.textContent === "РЕГИСТРАЦИЯ") {
        let newUser = {
          company: "",
          email: loginInput.value,
          password: passwordInput.value,
          confirmed_password: passwordInput.value,
          language: "ru",
          name: ""
        };
        let response = await fetch("".concat(path, "/registration"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(newUser)
        });
        let result = await response.json();

        if (response.status === 400) {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }

        if (response.status === 200) {
          loginInput.value = "";
          passwordInput.value = "";
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          popup.textContent = "";
          inputWrap.removeChild(popup);
        }
      } else if (loginBtn.textContent === "Request Demo") {
        console.log(11);
        let newUser = {
          email: loginInput.value,
          company: passwordInput.value
        };
        const urlAmo = 'test/amo/lead';
        let response = await fetch(urlAmo, {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8",
            'Access-Control-Allow-Origin': '*'
          },
          body: JSON.stringify(newUser)
        });
      } else {
        let newUser = {
          company: "",
          email: loginInput.value,
          password: passwordInput.value,
          confirmed_password: passwordInput.value,
          language: "ru",
          name: ""
        };
        let response = await fetch("".concat(path, "/registration"), {
          method: "POST",
          headers: {
            "Content-Type": "application/json;charset=utf-8"
          },
          body: JSON.stringify(newUser)
        });
        let result = await response.json();

        if (response.status === 400) {
          inputWrap.style.borderColor = 'red';
          inputWrapSecond.style.borderColor = 'red';
          popup.textContent = result.error;
          inputWrap.appendChild(popup);
        }

        if (response.status === 200) {
          loginInput.value = "";
          passwordInput.value = "";
          inputWrap.style.borderColor = 'black';
          inputWrapSecond.style.borderColor = 'black';
          popup.textContent = "";
          inputWrap.removeChild(popup);
        }
      }
    });
  }
}

;