{"size": 3487, "ext": "js", "max_stars_repo_path": "src/assets/js/events.js", "max_stars_repo_name": "CuongKonBug/chandoilam", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/assets/js/events.js", "max_issues_repo_name": "CuongKonBug/chandoilam", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/assets/js/events.js", "max_forks_repo_name": "CuongKonBug/chandoilam", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.7, "max_line_length": 100, "alphanum_fraction": 0.6314883854}
import helpers from "./helpers.js";

window.addEventListener("load", () => {
  document.querySelector("#toggle-chat-pane").addEventListener("click", (e) => {
    let chatElem = document.querySelector("#chat-pane");
    let mainSecElem = document.querySelector("#main-section");

    if (chatElem.classList.contains("chat-opened")) {
      chatElem.setAttribute("hidden", true);
      mainSecElem.classList.remove("col-md-9");
      mainSecElem.classList.add("col-md-12");
      chatElem.classList.remove("chat-opened");
    } else {
      chatElem.attributes.removeNamedItem("hidden");
      mainSecElem.classList.remove("col-md-12");
      mainSecElem.classList.add("col-md-9");
      chatElem.classList.add("chat-opened");
    }

    setTimeout(() => {
      if (
        document.querySelector("#chat-pane").classList.contains("chat-opened")
      ) {
        helpers.toggleChatNotificationBadge();
      }
    }, 300);
  });

  document.getElementById("local").addEventListener("click", () => {
    if (!document.pictureInPictureElement) {
      document
        .getElementById("local")
        .requestPictureInPicture()
        .catch((error) => {
          console.error(error);
        });
    } else {
      document.exitPictureInPicture().catch((error) => {
        console.error(error);
      });
    }
  });
  var formDelete = document.forms["delete-form"];

  document.getElementById("create-room").addEventListener("click", (e) => {
    e.preventDefault();

    let roomName = document.querySelector("#room-name").value;
    let yourName = document.querySelector("#your-name").value;

    var loginForm = document.forms["form-sub"];
    console.log(loginForm);

    var setRoomName = JSON.stringify(roomName);
    var setYourName = JSON.stringify(yourName);
    localStorage.setItem("key", [setRoomName, setYourName]);
    const getLocal = localStorage.getItem("key");

    if (roomName && yourName) {
      document.querySelector("#err-msg").innerHTML = "";

      sessionStorage.setItem("username", yourName);

      let roomLink = `${location.origin}?room=${roomName
        .trim()
        .replace(" ", "_")}_${helpers.generateRandomString()}`;

      document.querySelector(
        "#room-created"
      ).innerHTML = `Room successfully created. Click <a href='${roomLink}'>here</a> to enter room. 
                Share the room link with your partners.`;
      loginForm.submit();

      document.querySelector("#room-name").value = "";
      document.querySelector("#your-name").value = "";
    } else {
      document.querySelector("#err-msg").innerHTML = "All fields are required";
    }
  });

  document.getElementById("enter-room").addEventListener("click", (e) => {
    e.preventDefault();

    let name = document.querySelector("#username").value;

    if (name) {
      document.querySelector("#err-msg-username").innerHTML = "";

      sessionStorage.setItem("username", name);

      location.reload();
    } else {
      document.querySelector("#err-msg-username").innerHTML =
        "Please input your name";
    }
  });

  document.addEventListener("click", (e) => {
    if (e.target && e.target.classList.contains("expand-remote-video")) {
      helpers.maximiseStream(e);
    } else if (e.target && e.target.classList.contains("mute-remote-mic")) {
      helpers.singleStreamToggleMute(e);
    }
  });

  document.getElementById("closeModal").addEventListener("click", () => {
    helpers.toggleModal("recording-options-modal", false);
  });
});
