const routes = Object.freeze({ packages: { label: 'Review packages', href: '/continue' }, gift: { label: 'Review gift information', href: '/gift' }, login: { label: 'Sign in', href: '/login' }, dashboard: { label: 'Open my dashboard', href: '/dashboard' }, interview: { label: 'Begin the interview', href: '/interview' }, vault: { label: 'Explore the Family Vault', href: '/family-vault' }, celebration: { label: 'Explore Celebration of Life', href: '/celebration-of-life' }, }) const answer = (text, action) => ({ text, action: action ? routes[action] : undefined }) export function answerLegacySavedQuestion(question) { const q = String(question || '').trim().toLowerCase() if (!q) return answer('Ask me about the interview, packages, gifts, privacy, or returning to your story.') if (/gift|present|surprise/.test(q)) return answer( 'Gift checkout and recipient invitations are not enabled yet. The Gift page is informational and does not create an order or send an invitation.', 'gift', ) if (/price|cost|how much|package|compare|difference|essential|family legacy|collection|archive/.test(q)) return answer( 'The configured test catalog lists Story Essential at $499 for 10 guided questions and Family Legacy at $999 for all 25. Checkout is available only where the matching verified payment setup is active. Printed books, photo add-ons, rush service, Family Vault plans, Collection, and Archive are not enabled for purchase in the current flow.', 'packages', ) if (/finish|finished|deliver|delivery|edit|editing|documentary|film|movie|after.*record/.test(q)) return answer( 'After saving every question in a paid package, submit the interview for the owner-reviewed production queue. Production is handled manually. A finished film is uploaded privately and becomes available in the account after an owner marks the order delivered. No timeline or revision allowance is promised.', 'dashboard', ) if (/privacy|secure|private|data|recording.*(stored|protected)|storage|protect/.test(q)) return answer( 'This assistant cannot see your account or recordings. Saved answers require an authenticated account and are retrieved through private, account-scoped routes. Production storage, backup, and key recovery still need to be verified for the website you are using.', ) if (/resume|return|continue|sign.?in|login|account|password/.test(q)) return answer( 'Sign in to return to your account. The reviewed staging dashboard displays server-confirmed saved answers and progress, and Continue My Story follows your current access. Use Forgot password on the sign-in page for account recovery.', 'login', ) if (/vault|photo|album|organize|family memories/.test(q)) return answer( 'Family Vault access, photo sharing, and photo uploads are not enabled in the current checkout flow. The active interview packages cover 10 or 25 guided questions and the manual documentary production queue.', 'vault', ) if (/passed|died|funeral|memorial|tribute|celebration/.test(q)) return answer( 'Celebration of Life is the LegacySaved experience for honoring someone who has died, using treasured memories to shape a tribute. Production editing and delivery are not verified; confirm scope and timing before purchase.', 'celebration', ) if (/story|interview|voice|question|record|how does.*work/.test(q)) return answer( 'Life Stories is a guided interview. The first three answers are complimentary. Story Essential covers 10 total questions; Family Legacy covers all 25. Each answer counts only after you review it, save it, and receive server confirmation. Paid access follows verified payment, not the checkout return page.', 'interview', ) return answer('LegacySaved helps people record their life stories through a guided video interview, with a private account to save and review answers. The first three questions are complimentary. I can explain the two configured test packages, how to resume your account, or the manual production process. What would help you decide?') } function initGuide() { const assistant = document.getElementById('assistant') const launcher = document.getElementById('assistant-launch') const messages = document.getElementById('assistant-messages') const field = document.getElementById('assistant-input') const form = document.getElementById('assistant-form') const close = document.getElementById('assistant-close') const mic = document.getElementById('assistant-mic') if (!assistant || !launcher || !messages || !field || !form || !close || !mic) return function toggle(open) { assistant.classList.toggle('open', open) launcher.setAttribute('aria-expanded', String(open)) if (open) requestAnimationFrame(() => field.focus({ preventScroll: true })) else launcher.focus() } launcher.addEventListener('click', () => toggle(!assistant.classList.contains('open'))) close.addEventListener('click', () => toggle(false)) document.addEventListener('keydown', event => { if (event.key === 'Escape' && assistant.classList.contains('open')) toggle(false) }) const syncViewport = () => document.documentElement.style.setProperty('--assistant-vh', `${window.visualViewport?.height || window.innerHeight}px`) syncViewport() window.visualViewport?.addEventListener('resize', syncViewport, { passive: true }) function bubble(value, isUser = false) { const item = document.createElement('div') item.className = `bubble${isUser ? ' user' : ''}` const text = document.createElement('span') text.textContent = typeof value === 'string' ? value : value.text item.appendChild(text) if (!isUser && value?.action && Object.values(routes).includes(value.action)) { const link = document.createElement('a') link.href = value.action.href link.target = '_top' link.textContent = value.action.label link.style.cssText = 'display:block;width:fit-content;margin-top:10px;color:#f2cf9f;text-decoration:underline;text-underline-offset:3px' item.appendChild(link) } messages.appendChild(item) messages.scrollTop = messages.scrollHeight } form.addEventListener('submit', event => { event.preventDefault() const question = field.value.trim() if (!question) return bubble(question, true) field.value = '' bubble(answerLegacySavedQuestion(question)) }) const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition if (SpeechRecognition) { mic.addEventListener('click', () => { const recognition = new SpeechRecognition() recognition.lang = 'en-US' recognition.interimResults = false recognition.onresult = event => { field.value = event.results[0][0].transcript; field.focus() } recognition.onerror = () => { mic.title = 'Speech input unavailable; type your question instead.' } recognition.start() }) } else { mic.disabled = true mic.title = 'Speech recognition is not available in this browser. Type your question instead.' } } if (typeof document !== 'undefined') initGuide()