(() => {
  const copyButton = document.getElementById("copy-install-command");
  const commandNode = document.getElementById("install-command");
  const statusNode = document.getElementById("copy-install-status");
  if (!copyButton || !commandNode || !statusNode) {
    return;
  }

  const installCommand = commandNode.textContent.trim();

  async function copyInstallCommand() {
    try {
      await navigator.clipboard.writeText(installCommand);
      copyButton.textContent = "Copied";
      statusNode.textContent = "Install command copied. Paste it into Terminal on the Mac you want to enroll.";
    } catch (error) {
      copyButton.textContent = "Copy failed";
      statusNode.textContent = "Clipboard access failed. Copy the command manually from the code block above.";
    }
  }

  copyButton.addEventListener("click", () => {
    void copyInstallCommand();
  });
})();
