import { state } from './state.js'; import { UI } from './components.js'; export const Onboarding = { onComplete: null, render(onCompleteCallback) { if (onCompleteCallback) this.onComplete = onCompleteCallback; const container = document.getElementById('view-container'); container.innerHTML = `
${[1,2,3,4,5].map(i => `
`).join('')}
`; this.renderStep(state.currentStep || 1); this.initEvents(); }, renderStep(step) { const content = document.getElementById('step-content'); const nextBtn = document.getElementById('next-step'); const prevBtn = document.getElementById('prev-step'); for(let i=1; i<=5; i++){ const dot = document.querySelector(`.step-dot-${i}`); if(dot) dot.className = `step-dot-${i} h-1 rounded-full transition-all duration-500 ${i === step ? 'w-8 bg-orange-200' : 'w-3 bg-white/10'}`; } prevBtn.classList.toggle('hidden', step === 1); nextBtn.innerHTML = step === 5 ? '开启人生 ' : '继续 '; let html = ''; if (step === 1) { html = `

你是谁?

定义你生命坐标的初始属性。

${UI.renderInput('称呼', 'reg-nickname', 'text', '例如:林中鹿', state.registrationData.nickname)} ${UI.renderInput('性别', 'reg-gender', 'text', '自由填写', state.registrationData.gender)} ${UI.renderInput('MBTI', 'reg-mbti', 'text', '如:INFJ', state.registrationData.mbti)} ${UI.renderInput('星座', 'reg-zodiac', 'text', '星辰指引', state.registrationData.zodiac)}
${UI.renderInput('兴趣爱好', 'reg-hobbies', 'text', '用逗号分隔你的热爱', (state.registrationData.hobbies || []).join(','))}
`; } else if (step === 2) { html = this.renderMemoryStep('那段纯真的时光', '童年记忆', 'reg-child-text', 'reg-child-date', 'childhood', state.registrationData.childhood); } else if (step === 3) { html = this.renderMemoryStep('光芒闪耀的时刻', '开心的经历', 'reg-joy-text', 'reg-joy-date', 'joy', state.registrationData.joy); } else if (step === 4) { html = this.renderMemoryStep('在暗夜中潜行', '沮丧与低谷', 'reg-low-text', 'reg-low-date', 'low', state.registrationData.low); } else if (step === 5) { html = `

未来想成为谁?

勾勒你对理想生活的全部向往。

${UI.renderTextArea('对未来的憧憬', 'reg-future-vision', '你想成为一个什么样的人?', state.registrationData.future.vision || '')} ${UI.renderTextArea('理想生活状态', 'reg-future-ideal', '你的理想清晨与傍晚是怎样的?', state.registrationData.future.ideal || '')}
`; } content.innerHTML = html; lucide.createIcons(); }, renderMemoryStep(title, label, textId, dateId, type, data) { return `

${title}

回望足迹,这些瞬间如何塑造了此时的你。

${UI.renderInspiration(type, textId)}
`; }, saveStepData() { const step = state.currentStep; if (step === 1) { state.updateRegistration({ nickname: document.getElementById('reg-nickname').value, gender: document.getElementById('reg-gender').value, mbti: document.getElementById('reg-mbti').value, zodiac: document.getElementById('reg-zodiac').value, hobbies: document.getElementById('reg-hobbies').value.split(',').map(s => s.trim()).filter(s => s) }); } else if (step === 2) { state.updateRegistration({ childhood: { date: document.getElementById('reg-child-date').value, text: document.getElementById('reg-child-text').value } }); } else if (step === 3) { state.updateRegistration({ joy: { date: document.getElementById('reg-joy-date').value, text: document.getElementById('reg-joy-text').value } }); } else if (step === 4) { state.updateRegistration({ low: { date: document.getElementById('reg-low-date').value, text: document.getElementById('reg-low-text').value } }); } else if (step === 5) { state.updateRegistration({ future: { vision: document.getElementById('reg-future-vision').value, ideal: document.getElementById('reg-future-ideal').value } }); } }, initEvents() { document.getElementById('next-step').onclick = () => { this.saveStepData(); if (state.currentStep < 5) { state.currentStep++; this.renderStep(state.currentStep); } else { state.view = 'dashboard'; state.save(); if (this.onComplete) this.onComplete(); } }; document.getElementById('prev-step').onclick = () => { if (state.currentStep > 1) { state.currentStep--; this.renderStep(state.currentStep); } }; } };