// ВАЖНО: Добавлена проверка на наличие ответов при восстановлении
async function restoreSession() {
const savedProfile = localStorage.getItem('astro_user_profile');
const savedMessages = localStorage.getItem('astro_chat_messages');
if (savedProfile) {
try {
userProfile = JSON.parse(savedProfile);
currentLanguage = detectLanguage(userProfile.name);
$('#onboard-screen').classList.add('hidden');
$('#loading-screen').classList.remove('hidden');
const res = await fetch(WORKER_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
...userProfile,
messages: [{ role: 'user', content: 'ОБНОВИ_ПРОФИЛЬ' }]
})
});
const data = await res.json();
$('#loading-screen').classList.add('hidden');
$('#chat-screen').classList.remove('hidden');
userProfile.syucai = data.computedProfile.syucai;
userProfile.zodiac = data.computedProfile.zodiac;
userProfile.cyclePhase = data.computedProfile.cyclePhase;
localStorage.setItem('astro_user_profile', JSON.stringify(userProfile));
renderProfileHeader(userProfile);
if (savedMessages) {
messages = JSON.parse(savedMessages);
messages.forEach(msg => addMessage(msg.role, formatText(msg.content)));
// ДОБАВЛЕНО: возвращаем кнопки даже после перезагрузки
renderChips(userProfile.gender, currentLanguage);
}
} catch(e) {
localStorage.clear();
location.reload();
}
}
}