`).join('');
};
// Appointments Logic
addApptBtn.addEventListener('click', () => {
if (!apptDateInput.value || !apptProviderInput.value) return;
const appointment = {
id: Date.now(),
for: apptForInput.value,
date: apptDateInput.value,
time: apptTimeInput.value,
provider: apptProviderInput.value,
notes: apptNotesInput.value,
};
plannerData.appointments.push(appointment);
renderAppointments();
updateDashboard();
apptDateInput.value = ''; apptTimeInput.value = ''; apptProviderInput.value = ''; apptNotesInput.value = '';
});
renderAppointments = () => {
if (plannerData.appointments.length === 0) {
appointmentListContainer.innerHTML = `
`).join('');
};
// Resources Logic
addResourceBtn.addEventListener('click', () => {
if (!contactNameInput.value || !contactRoleInput.value) return;
const resource = {
id: Date.now(),
name: contactNameInput.value,
role: contactRoleInput.value,
phone: contactPhoneInput.value,
email: contactEmailInput.value,
};
plannerData.resources.push(resource);
renderResources();
contactNameInput.value = ''; contactRoleInput.value = ''; contactPhoneInput.value = ''; contactEmailInput.value = '';
});
renderResources = () => {
if (plannerData.resources.length === 0) {
resourceListContainer.innerHTML = `
`).join('');
};
// --- AI FEATURE HANDLERS ---
getInsightsBtn.addEventListener('click', async () => {
const mood = moodInput.value;
const symptoms = physicalSymptomsInput.value;
const journal = journalEntryInput.value;
if (!mood && !symptoms && !journal) {
insightsResult.innerHTML = "Please enter how you're feeling or your symptoms to get an insight.";
insightsResult.classList.remove('hidden');
return;
}
const prompt = `As a friendly and supportive AI assistant for a new mother, provide a short, gentle, and encouraging insight based on her daily log. Do not provide medical advice. Be warm and empathetic.
Her log today:
- Mood: ${mood}
- Physical Symptoms: ${symptoms || 'Not specified'}
- Private thoughts: ${journal || 'Not specified'}
Respond with 2-3 sentences of encouragement or a simple mindfulness tip.`;
const response = await callGeminiApi(prompt, insightsLoader, insightsResult, getInsightsBtn);
insightsResult.innerHTML = `
Your appointments will appear here.
`; return; } appointmentListContainer.innerHTML = plannerData.appointments .sort((a, b) => new Date(a.date) - new Date(b.date)) .map(appt => `${formatDate(appt.date)} at ${appt.time || 'N/A'}
${appt.provider} (For: ${appt.for})
${appt.notes ? `Notes: ${appt.notes}
` : ''}Your support contacts will appear here.
`; return; } resourceListContainer.innerHTML = plannerData.resources.map(res => `${res.name} - ${res.role}
${res.phone ? `Phone: ${res.phone}
` : ''} ${res.email ? `Email: ${res.email}
` : ''}${response.replace(/\n/g, '
')}
Disclaimer: This is an AI-generated insight and not medical advice. Always consult a healthcare professional.
`; insightsResult.classList.remove('hidden'); }); getQuestionsBtn.addEventListener('click', async () => { const apptFor = apptForInput.value; const reason = apptProviderInput.value; if (!reason) { apptNotesInput.value = "Please enter a reason for the appointment to get suggested questions."; return; } const prompt = `Generate a helpful list of 5-7 questions a new parent should ask a healthcare provider during an appointment. The appointment is for the "${apptFor}" and the reason is "${reason}". Format the output as a numbered list. Do not include a preamble or conclusion, just the list of questions.`; const response = await callGeminiApi(prompt, questionsLoader, null, getQuestionsBtn); const currentNotes = apptNotesInput.value; const separator = currentNotes.trim() === '' ? '' : '\n\n--- Suggested Questions ---\n'; apptNotesInput.value = currentNotes + separator + response; }); // --- SUMMARY & PDF GENERATION --- renderSummary = () => { summaryDateEl.textContent = `Report generated on ${new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })}`; summaryAppointmentsContainer.innerHTML = plannerData.appointments.length > 0 ? `Appointments
${plannerData.appointments.map(a => ``).join('')}
` : `${formatDate(a.date)}: ${a.provider} (For: ${a.for})
${a.notes ? `Notes: ${a.notes}
` : ''}No Appointments Logged
`; summaryLogsContainer.innerHTML = plannerData.logs.length > 0 ? `Daily Log Summary
${plannerData.logs.map(l => ``).join('')}
` : `${formatDate(l.date)}: Mood: ${l.mood}
${l.symptoms ? `Symptoms: ${l.symptoms}
` : ''}${l.journal ? `Journal: ${l.journal}
` : ''}${l.feedType ? `Feeding: ${l.feedTime}, ${l.feedType}, ${l.feedAmount}
` : ''}No Daily Logs Recorded
`; summaryResourcesContainer.innerHTML = plannerData.resources.length > 0 ? `My Support Team
${plannerData.resources.map(r => ``).join('')}
` : `${r.name} - ${r.role}
${r.phone || ''} ${r.email ? `| ${r.email}` : ''}
