// DOM Elements
const shareBtn = document.getElementById("shareBtn");
const shareModal = document.getElementById("shareModal");
const closeModal = document.getElementById("closeModal");
const followBtn = document.getElementById("followBtn");

// Toggle Modal
shareBtn.addEventListener("click", () => {
  shareModal.classList.remove("hidden");
  shareModal.classList.add("flex");
});

closeModal.addEventListener("click", () => {
  shareModal.classList.add("hidden");
  shareModal.classList.remove("flex");
});

// Close on Outside Click
window.addEventListener("click", (e) => {
  if (e.target === shareModal) {
    shareModal.classList.add("hidden");
    shareModal.classList.remove("flex");
  }
});

// Follow Button Logic
followBtn.addEventListener("click", function () {
  if (this.innerText === "Follow Instructor") {
    this.innerText = "Following";
    this.style.backgroundColor = "#120D1F";
    this.style.border = "1px solid #7B48FF";
  } else {
    this.innerText = "Follow Instructor";
    this.style.backgroundColor = "#7B48FF";
  }
});

// Copy Link function
function copyLink() {
  const copyText = document.getElementById("shareInput");
  copyText.select();
  copyText.setSelectionRange(0, 99999);
  navigator.clipboard.writeText(copyText.value);
  alert("Link Copied: " + copyText.value);
}
