`;
transcriptContainer.appendChild(entryDiv);
transcriptContainer.scrollTop = transcriptContainer.scrollHeight;
document.getElementById('transcriptPlaceholder').classList.add('hidden');
}
// --- TIMER & CONTROLS ---
function startTimer() {
isPaused = false;
startBtn.disabled = true;
startBtn.classList.remove('pulse');
pauseBtn.disabled = false;
stopBtn.disabled = false;
timerInterval = setInterval(() => {
if (!isPaused) {
secondsElapsed++;
timerDisplay.textContent = new Date(secondsElapsed * 1000).toISOString().substr(11, 8);
// Add a new entry periodically to simulate conversation
if (secondsElapsed % 7 === 0) {
addTranscriptEntry();
}
}
}, 1000);
}
function pauseTimer() {
isPaused = !isPaused;
pauseBtn.textContent = isPaused ? 'Resume' : 'Pause';
pauseBtn.classList.toggle('bg-yellow-500', !isPaused);
pauseBtn.classList.toggle('hover:bg-yellow-600', !isPaused);
pauseBtn.classList.toggle('bg-teal-500', isPaused);
pauseBtn.classList.toggle('hover:bg-teal-600', isPaused);
}
function stopTimer() {
clearInterval(timerInterval);
isPaused = true;
startBtn.disabled = false;
pauseBtn.disabled = true;
stopBtn.disabled = true;
pauseBtn.textContent = 'Pause';
startBtn.classList.remove('pulse');
document.getElementById('pdfButton').classList.remove('hidden');
// Save final edits from textareas
transcript.forEach(entry => {
const textarea = document.getElementById(`text-${entry.id}`);
if (textarea) entry.text = textarea.value;
});
}
// --- EVENT HANDLERS & LOGIC ---
window.changeTab = (tabName) => {
currentTab = tabName;
Object.values(tabElements).forEach(el => el.classList.add('hidden'));
Object.values(tabButtons).forEach(btn => btn.classList.remove('active'));
tabElements[tabName].classList.remove('hidden');
tabButtons[tabName].classList.add('active');
updateNavButtons();
};
window.navigateTabs = (direction) => {
const currentIndex = tabs.indexOf(currentTab);
const nextIndex = direction === 'next' ? (currentIndex + 1) : (currentIndex - 1);
if (nextIndex >= 0 && nextIndex < tabs.length) changeTab(tabs[nextIndex]);
};
const updateNavButtons = () => {
const currentIndex = tabs.indexOf(currentTab);
prevButton.classList.toggle('invisible', currentIndex === 0);
nextButton.classList.toggle('invisible', currentIndex === tabs.length - 1);
};
if (addSpeakerForm) {
addSpeakerForm.addEventListener('submit', (e) => {
e.preventDefault();
const input = document.getElementById('newSpeakerName');
const newName = input.value.trim();
if (newName) {
const newId = speakers.length > 0 ? Math.max(...speakers.map(s => s.id)) + 1 : 1;
speakers.push({ id: newId, name: newName });
renderSpeakerList();
renderSpeakerTags();
input.value = '';
}
});
}
window.deleteSpeaker = (id) => {
if (confirm('Are you sure you want to delete this speaker?')) {
speakers = speakers.filter(s => s.id !== id);
renderSpeakerList();
renderSpeakerTags();
}
};
// --- PDF DOWNLOAD ---
window.downloadPDF = function() {
if (transcript.length === 0) {
alert('No transcript to download.');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'pt', 'a4');
const title = document.getElementById('meetingTitle').value || 'Meeting Transcript';
const date = new Date(document.getElementById('meetingDate').value + 'T12:00:00').toLocaleDateString('en-US', { dateStyle: 'long' });
const pageWidth = doc.internal.pageSize.getWidth();
const pageHeight = doc.internal.pageSize.getHeight();
doc.setFillColor(41, 128, 185);
doc.rect(0, 0, pageWidth, 60, 'F');
doc.setFontSize(20); doc.setTextColor(255); doc.setFont('helvetica', 'bold');
doc.text(title, 30, 38);
doc.setFontSize(10); doc.setFont('helvetica', 'normal'); doc.setTextColor(50);
doc.text(`Date: ${date}`, 30, 90);
doc.text(`Duration: ${timerDisplay.textContent}`, 30, 105);
doc.text(`Speakers: ${speakers.map(s => s.name).join(', ')}`, 30, 120);
const tableBody = transcript.map(entry => [entry.timestamp, entry.speaker, entry.text]);
doc.autoTable({
head: [['Timestamp', 'Speaker', 'Message']],
body: tableBody,
startY: 140,
theme: 'grid',
headStyles: { fillColor: [41, 128, 185] },
columnStyles: {
2: { cellWidth: 'auto' }
}
});
const pageCount = doc.internal.getNumberOfPages();
for(let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setFontSize(8); doc.setTextColor(150);
doc.text(`Page ${i} of ${pageCount}`, pageWidth / 2, pageHeight - 20, { align: 'center' });
}
doc.save('Meeting_Transcript.pdf');
};
// --- EVENT LISTENERS ---
startBtn.addEventListener('click', startTimer);
pauseBtn.addEventListener('click', pauseTimer);
stopBtn.addEventListener('click', stopTimer);
// --- INITIALIZE ---
initializeApp();
});