AI-Powered Legal Opinion Analyzer

${analysisData.summary.replace(/\n/g, '
') || 'N/A'}

`; html += '

Key Arguments & Reasoning

'; const argsList = analysisData.arguments.split('\n').filter(arg => arg.trim() !== '').map(arg => `
  • ${arg.replace(/^\s*[\-*]\s*/, '')}
  • `).join(''); html += `
      ${argsList || '
    • N/A
    • '}
    `; html += '

    Conclusion

    '; html += `

    ${analysisData.conclusion.replace(/\n/g, '
    ') || 'N/A'}

    `; html += `
    Disclaimer: This AI-generated analysis is for informational purposes only and does not constitute legal advice. It is based solely on the text provided. Consult with a qualified legal professional for advice on your specific situation.
    `; analysisOutput.innerHTML = html; pdfDownloadContainer.classList.remove('hidden'); }; // --- PDF GENERATION --- const generatePDF = () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const margin = 15; const pageWidth = doc.internal.pageSize.getWidth(); const usableWidth = pageWidth - (margin * 2); let yPos = margin; const addText = (text, size, weight, spaceAfter) => { if (yPos > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); yPos = margin; } doc.setFontSize(size).setFont('helvetica', weight); const splitText = doc.splitTextToSize(text, usableWidth); doc.text(splitText, margin, yPos); yPos += (splitText.length * (size * 0.4)) + spaceAfter; }; // Title addText('AI-Powered Legal Opinion Analysis', 18, 'bold', 10); // Question doc.setDrawColor(200); doc.line(margin, yPos, pageWidth - margin, yPos); yPos += 5; addText('User Question:', 12, 'bold', 4); addText(analysisData.question, 10, 'normal', 10); // Summary yPos += 5; doc.line(margin, yPos, pageWidth - margin, yPos); yPos += 5; addText('Executive Summary', 12, 'bold', 4); addText(analysisData.summary, 10, 'normal', 10); // Arguments addText('Key Arguments & Reasoning', 12, 'bold', 4); const argsArray = analysisData.arguments.split('\n').filter(arg => arg.trim() !== ''); argsArray.forEach(arg => { const argText = `• ${arg.replace(/^\s*[\-*]\s*/, '')}`; addText(argText, 10, 'normal', 3); }); yPos += 7; // Conclusion addText('Conclusion', 12, 'bold', 4); addText(analysisData.conclusion, 10, 'normal', 15); // Disclaimer addText('Disclaimer: This is an AI-generated analysis and does not constitute legal advice. It is based solely on the text provided.', 8, 'italic', 5); doc.save('Legal_Opinion_Analysis.pdf'); }; // --- EVENT HANDLERS --- const handleNextClick = () => { if (currentTabIndex === 0) { // On "Input" tab const question = legalQuestionInput.value.trim(); const text = legalTextInput.value.trim(); if (!question || !text) { alert('Please fill in both the legal question and the opinion text.'); return; } switchTab(1); // Move to analysis tab callGeminiAPI(question, text); } }; // --- EVENT LISTENERS --- tabs.forEach((tab, index) => tab.addEventListener('click', () => { // Prevent clicking to the analysis tab directly if (index === 1 && !analysisOutput.innerHTML.trim()) { return; } switchTab(index); })); prevBtn.addEventListener('click', () => switchTab(currentTabIndex - 1)); nextBtn.addEventListener('click', handleNextClick); downloadPdfBtn.addEventListener('click', generatePDF); // --- KICKOFF --- switchTab(0); });
    Scroll to Top