const imageInput = document.querySelector("#imageInput"); const imageUrlInput = document.querySelector("#imageUrlInput"); const previewCard = document.querySelector("#previewCard"); const imagePreview = document.querySelector("#imagePreview"); function showPreview(src) { if (!previewCard || !imagePreview || !src) return; imagePreview.src = src; previewCard.hidden = false; } if (imageInput) { imageInput.addEventListener("change", () => { const file = imageInput.files && imageInput.files[0]; if (!file) return; showPreview(URL.createObjectURL(file)); if (imageUrlInput) imageUrlInput.value = ""; }); } if (imageUrlInput) { imageUrlInput.addEventListener("input", () => { const value = imageUrlInput.value.trim(); if (!value) return; showPreview(value); if (imageInput) imageInput.value = ""; }); }