AI-Driven Legal Contract Negotiation Assistant

AI-Driven Legal Contract Negotiation Assistant

Analyze clauses, identify risks, and get negotiation suggestions.

High-Risk Clauses

${clause.text}

${analysisHtml}
`; }); }; const renderConfiguration = () => { const container = document.getElementById('negotiation-priorities'); container.innerHTML = prioritiesList.map(priority => ` `).join(''); }; const renderAll = () => { renderDashboard(); renderContractInput(); renderClauseAnalysis(); renderConfiguration(); }; // --- EVENT HANDLERS & LOGIC --- window.updateContractData = (key, value) => { contractData[key] = value; }; window.parseContract = () => { const fullText = document.getElementById('full-contract-text').value; contractData.fullText = fullText; // Simple parsing: split by lines that start with a number/word followed by a period, or by double newlines. const clausesText = fullText.split(/\n\s*\n|\n(?=\d+\.\s)|(?=\b[A-Z][a-z]+\s\d+\.\s)/).filter(s => s.trim().length > 10); contractData.clauses = clausesText.map((text, index) => ({ id: index + 1, text: text.trim().replace(/^\d+\.\s*/, ''), // Remove leading numbers like "1. " loading: false, analysis: null })); changeTab(2); // Move to analysis tab }; window.analyzeClause = async (id) => { const clause = contractData.clauses.find(c => c.id === id); if (!clause) return; clause.loading = true; renderClauseAnalysis(); // Re-render to show spinner const analysisResult = await simulateAIAnalysis(clause.text); clause.analysis = analysisResult; clause.loading = false; renderClauseAnalysis(); // Re-render to show results renderDashboard(); // Update dashboard stats }; window.updateSuggestion = (id, value) => { const clause = contractData.clauses.find(c => c.id === id); if(clause && clause.analysis) { clause.analysis.suggestion = value; } }; window.togglePriority = (priority) => { if (contractData.priorities.has(priority)) { contractData.priorities.delete(priority); } else { contractData.priorities.add(priority); } }; // --- TAB NAVIGATION --- window.changeTab = (tabIndex) => { currentTab = tabIndex; renderAll(); // Always refresh data when changing tabs const tabs = document.querySelectorAll('.tab'); const tabContents = document.querySelectorAll('.tab-content'); tabs.forEach((tab, i) => { tab.classList.toggle('tab-active', i === tabIndex); tab.classList.toggle('tab-inactive', i !== tabIndex); }); tabContents.forEach((content, i) => { content.style.display = i === tabIndex ? 'block' : 'none'; }); }; window.navigateTab = (direction) => { const numTabs = document.querySelectorAll('.tab').length; let newTab = currentTab + direction; if (newTab < 0) newTab = 0; if (newTab >= numTabs) newTab = numTabs - 1; changeTab(newTab); }; // --- PDF DOWNLOAD FUNCTIONALITY --- window.downloadPDF = () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); // Header doc.setFontSize(18); doc.text('Contract Negotiation Report', 14, 22); doc.setFontSize(11); doc.setTextColor(100); doc.text(`Contract: ${contractData.title}`, 14, 30); doc.text(`Counterparty: ${contractData.counterparty}`, 14, 36); // Priorities const prioritiesText = Array.from(contractData.priorities).join(', '); if (prioritiesText) { doc.setFont(undefined, 'bold'); doc.text('Priorities:', 14, 44); doc.setFont(undefined, 'normal'); const splitPriorities = doc.splitTextToSize(prioritiesText, 170); doc.text(splitPriorities, 35, 44); } const analyzedClauses = contractData.clauses.filter(c => c.analysis); if (analyzedClauses.length === 0) { doc.text('No clauses have been analyzed yet.', 14, 60); doc.save('Negotiation_Report.pdf'); return; } const head = [['Clause', 'Risk', 'Negotiation Point / Suggested Alternative']]; const body = analyzedClauses.map(clause => [ { content: clause.text, styles: { fontSize: 8 } }, { content: `${clause.analysis.risk}\n\n${clause.analysis.explanation}`, styles: { fontSize: 8 } }, { content: clause.analysis.suggestion, styles: { fontSize: 8 } } ]); doc.autoTable({ startY: prioritiesText ? doc.autoTable.previous.finalY + 15 : 50, head: head, body: body, theme: 'grid', headStyles: { fillColor: [79, 70, 229] }, // indigo-600 didParseCell: function(data) { if (data.section === 'body' && data.column.index === 1) { const risk = data.cell.raw.split('\n')[0]; if (risk === 'High') data.cell.styles.fillColor = '#fee2e2'; if (risk === 'Medium') data.cell.styles.fillColor = '#fef9c3'; } } }); doc.save('Negotiation_Report.pdf'); }; // --- INITIAL RENDER --- changeTab(0); });
Scroll to Top