: "none"; }); }); }); function val(id, fallback = "") { const el = document.getElementById(id); return el ? (el.value || fallback) : fallback; } function updatePreview() { document.getElementById("previewNames").textContent = val("names", "Anna & Davit"); const date = val("date"); document.getElementById("previewDate").textContent = date ? date.split("-").reverse().join(" · ") : "15 · 08 · 2027"; document.getElementById("previewTime").textContent = val("time", "18:00"); document.getElementById("previewLocation").textContent = val("location", "Yerevan, Armenia"); document.getElementById("previewDescription").textContent = val("description", ""); } ["names","date","time","location","description"].forEach(id => { const el = document.getElementById(id); if (el) { el.addEventListener("input", updatePreview); el.addEventListener("change", updatePreview); } }); function updatePreviewStyle(id) { const card = document.querySelector(`[data-template="${CSS.escape(id)}"]`); const preview = document.querySelector(".live-card-inner"); const small = document.getElementById("previewSmall"); if (!card) return; const category = card.dataset.category; preview.style.background = ""; preview.style.color = ""; if (category === "birthday") { preview.style.background = "#f7fbff"; small.textContent = "BIRTHDAY PARTY"; } else if (category === "baptism") { preview.style.background = "#f5fbfc"; small.textContent = "BAPTISM"; } else if (category === "engagement") { preview.style.background = "#fff7f9"; small.textContent = "ENGAGEMENT"; } else if (category === "anniversary") { preview.style.background = "#fffaf0"; small.textContent = "ANNIVERSARY"; } else if (category === "corporate") { preview.style.background = "#f5f7f9"; small.textContent = "EVENT"; } else { small.textContent = "SAVE THE DATE"; } } const coverInput = document.getElementById("cover"); const galleryInput = document.getElementById("gallery"); const previewCover = document.getElementById("previewCover"); const previewGallery = document.getElementById("previewGallery"); const uploadPreviews = document.getElementById("uploadPreviews"); coverInput.addEventListener("change", () => { const file = coverInput.files[0]; if (!file) { previewCover.classList.remove("has-image"); return; } previewCover.src = URL.createObjectURL(file); previewCover.classList.add("has-image"); }); galleryInput.addEventListener("change", () => { previewGallery.innerHTML = ""; uploadPreviews.innerHTML = ""; Array.from(galleryInput.files).slice(0, 10).forEach(file => { const url = URL.createObjectURL(file); const img1 = document.createElement("img"); img1.src = url; uploadPreviews.appendChild(img1); const img2 = document.createElement("img"); img2.src = url; previewGallery.appendChild(img2); }); }); function copyInvitationLink() { const link = document.getElementById("inviteLink"); if (!link) return; navigator.clipboard.writeText(link.href) .then(() => alert("Հղումը պատճենվեց։")) .catch(() => alert("Չհաջողվեց պատճենել հղումը։")); } updatePreview(); updatePreviewStyle(templateInput.value);