export function ShareSection(roomName: string): HTMLElement { const url = `${window.location.origin}${window.location.pathname}?room=${encodeURIComponent(roomName)}`; const section = document.createElement("div"); section.className = "share-section"; section.innerHTML = `

Share this poll

${url}
`; const copyBtn = section.querySelector(".share-copy-btn")!; copyBtn.addEventListener("click", async () => { try { await navigator.clipboard.writeText(url); copyBtn.textContent = "Copied!"; copyBtn.classList.add("share-copy-btn--success"); setTimeout(() => { copyBtn.textContent = "Copy link"; copyBtn.classList.remove("share-copy-btn--success"); }, 2000); } catch { // Fallback: select the text const range = document.createRange(); const urlEl = section.querySelector(".share-url"); if (urlEl) { range.selectNode(urlEl); window.getSelection()?.removeAllRanges(); window.getSelection()?.addRange(range); } } }); return section; }