import { siteConfig } from './config.mjs'; import { getVideoSource } from './video.mjs'; const routes = { beginner: { url: siteConfig.checkoutUrl, title: 'Do Zero ao Trade', description: 'O acesso ao Do Zero ao Trade será disponibilizado em breve.' }, consistency: { url: siteConfig.consistencyFormUrl, title: 'Conheça 5C e Nexum', description: 'O formulário para conhecer 5C ou Nexum será disponibilizado em breve.' }, mentorship: { url: siteConfig.mentorshipFormUrl, title: 'Dê o próximo passo com a mentoria', description: 'O formulário de interesse na mentoria será disponibilizado em breve.' }, }; const dialog = document.querySelector('#availability-dialog'); let activeLink; for (const link of document.querySelectorAll('[data-route]')) { const route = routes[link.dataset.route]; let destination; try { const url = new URL(route.url); if (url.protocol === 'https:') destination = url.href; } catch { /* Link ainda não fornecido. */ } if (destination) link.href = destination; link.addEventListener('click', (event) => { if (destination) return; event.preventDefault(); activeLink = link; document.querySelector('#dialog-title').textContent = route.title; document.querySelector('#dialog-description').textContent = route.description; dialog.showModal(); }); } for (const button of dialog.querySelectorAll('button')) button.addEventListener('click', () => dialog.close()); dialog.addEventListener('click', (event) => { if (event.target !== dialog) return; const bounds = dialog.getBoundingClientRect(); if (event.clientX < bounds.left || event.clientX > bounds.right || event.clientY < bounds.top || event.clientY > bounds.bottom) dialog.close(); }); dialog.addEventListener('close', () => activeLink?.focus()); const videoSource = getVideoSource(siteConfig.videoUrl); if (videoSource) { const media = document.createElement(videoSource.type); media.src = videoSource.url; if (videoSource.type === 'iframe') { media.title = 'Vídeo de apresentação — 5C e Nexum'; media.allow = 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen'; media.allowFullscreen = true; media.referrerPolicy = 'strict-origin-when-cross-origin'; } else { media.controls = true; media.playsInline = true; media.preload = 'metadata'; media.setAttribute('aria-label', 'Vídeo de apresentação — 5C e Nexum'); media.addEventListener('error', () => { const notice = document.createElement('p'); notice.className = 'video-availability'; notice.textContent = 'Não foi possível carregar o vídeo. Tente novamente mais tarde.'; document.querySelector('.video-section').append(notice); }, { once: true }); } document.querySelector('#video-container').replaceChildren(media); }