import React, { useState } from 'react'; import { Download, FileText, BookOpen, GraduationCap, Calendar, User, Mail, Award, CheckCircle, XCircle, Loader } from 'lucide-react'; const AcademicReportGenerator = () => { const [formData, setFormData] = useState({ studentName: '', studentId: '', department: '', university: '', courseTitle: '', courseCode: '', teacherName: '', teacherDesignation: '', submissionDate: new Date().toISOString().split('T')[0], reportType: 'assignment', reportTitle: '', topic: '', includeAbstract: true, includeTOC: true, includeReferences: true, pageNumbers: true, fontFamily: 'Times New Roman', fontSize: '12', lineSpacing: '1.5' }); const [generating, setGenerating] = useState(false); const [generated, setGenerated] = useState(false); const [error, setError] = useState(''); const handleInputChange = (e) => { const { name, value, type, checked } = e.target; setFormData(prev => ({ ...prev, [name]: type === 'checkbox' ? checked : value })); }; const generateReport = async () => { setGenerating(true); setError(''); setGenerated(false); try { const response = await fetch('https://api.anthropic.com/v1/messages', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ model: 'claude-sonnet-4-20250514', max_tokens: 4000, messages: [{ role: 'user', content: `Generate a professional academic report structure based on these details: Student Information: - Name: ${formData.studentName} - ID: ${formData.studentId} - Department: ${formData.department} - University: ${formData.university} Course Information: - Course Title: ${formData.courseTitle} - Course Code: ${formData.courseCode} - Instructor: ${formData.teacherName}${formData.teacherDesignation ? `, ${formData.teacherDesignation}` : ''} Report Details: - Type: ${formData.reportType} - Title: ${formData.reportTitle} - Topic: ${formData.topic} - Submission Date: ${formData.submissionDate} Please generate a comprehensive academic report with: ${formData.includeAbstract ? '- Abstract (150-200 words)' : ''} - Introduction (2-3 paragraphs with background and objectives) - Literature Review (4-5 key sources with critical analysis) - Methodology (detailed approach and methods) - Results/Findings (3-4 major findings with explanations) - Discussion (interpretation and implications) - Conclusion (summary and recommendations) ${formData.includeReferences ? '- References (APA format, 8-10 sources)' : ''} Format as JSON with this structure: { "abstract": "text", "introduction": "text with multiple paragraphs", "literatureReview": "text with subsections", "methodology": "text", "results": "text", "discussion": "text", "conclusion": "text", "references": ["ref1", "ref2", ...] } Return ONLY the JSON, no other text.` }] }) }); const data = await response.json(); let content = data.content.find(c => c.type === 'text')?.text || ''; // Clean JSON from markdown backticks if present content = content.replace(/```json\s*/g, '').replace(/```\s*/g, '').trim(); const reportContent = JSON.parse(content); // Now generate the DOCX file await generateDocx(reportContent); setGenerated(true); } catch (err) { setError('Failed to generate report: ' + err.message); console.error(err); } finally { setGenerating(false); } }; const generateDocx = async (reportContent) => { // Create Node.js script to generate DOCX const docxScript = ` const { Document, Packer, Paragraph, TextRun, AlignmentType, HeadingLevel, PageNumber, PageBreak, BorderStyle, TableOfContents, LevelFormat } = require('docx'); const fs = require('fs'); const reportData = ${JSON.stringify(formData)}; const content = ${JSON.stringify(reportContent)}; // Helper function to create paragraphs from text with multiple paragraphs function createParagraphs(text, options = {}) { return text.split('\\n\\n').filter(p => p.trim()).map(para => new Paragraph({ children: [new TextRun(para.trim())], spacing: { before: 240, after: 240 }, alignment: AlignmentType.JUSTIFIED, ...options }) ); } const doc = new Document({ styles: { default: { document: { run: { font: "${formData.fontFamily}", size: ${parseInt(formData.fontSize) * 2} } } }, paragraphStyles: [ { id: "Heading1", name: "Heading 1", basedOn: "Normal", next: "Normal", quickFormat: true, run: { size: 32, bold: true, font: "${formData.fontFamily}", color: "1F4788" }, paragraph: { spacing: { before: 480, after: 240 }, outlineLevel: 0, border: { bottom: { color: "1F4788", space: 1, style: BorderStyle.SINGLE, size: 6 } } } }, { id: "Heading2", name: "Heading 2", basedOn: "Normal", next: "Normal", quickFormat: true, run: { size: 28, bold: true, font: "${formData.fontFamily}", color: "2E5C8A" }, paragraph: { spacing: { before: 360, after: 180 }, outlineLevel: 1 } }, { id: "Heading3", name: "Heading 3", basedOn: "Normal", next: "Normal", quickFormat: true, run: { size: 26, bold: true, font: "${formData.fontFamily}", color: "4472C4" }, paragraph: { spacing: { before: 240, after: 120 }, outlineLevel: 2 } } ] }, numbering: { config: [ { reference: "references-numbering", levels: [ { level: 0, format: LevelFormat.DECIMAL, text: "[%1]", alignment: AlignmentType.LEFT, style: { paragraph: { indent: { left: 720, hanging: 360 } } } } ] } ] }, sections: [ // Cover Page Section { properties: { page: { size: { width: 12240, height: 15840 }, margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } }, children: [ // University Name new Paragraph({ children: [ new TextRun({ text: reportData.university.toUpperCase(), bold: true, size: 32, font: "${formData.fontFamily}" }) ], alignment: AlignmentType.CENTER, spacing: { before: 1440, after: 240 } }), // Department new Paragraph({ children: [ new TextRun({ text: \`Department of \${reportData.department}\`, bold: true, size: 28, font: "${formData.fontFamily}" }) ], alignment: AlignmentType.CENTER, spacing: { after: 960 } }), // Decorative line new Paragraph({ border: { top: { color: "1F4788", space: 1, style: BorderStyle.DOUBLE, size: 12 } }, spacing: { before: 480, after: 480 } }), // Report Type new Paragraph({ children: [ new TextRun({ text: reportData.reportType.charAt(0).toUpperCase() + reportData.reportType.slice(1), bold: true, size: 24, font: "${formData.fontFamily}", italics: true }) ], alignment: AlignmentType.CENTER, spacing: { after: 240 } }), // Report Title new Paragraph({ children: [ new TextRun({ text: reportData.reportTitle, bold: true, size: 36, font: "${formData.fontFamily}", color: "1F4788" }) ], alignment: AlignmentType.CENTER, spacing: { before: 240, after: 240 } }), // Topic (if different from title) ...(reportData.topic && reportData.topic !== reportData.reportTitle ? [ new Paragraph({ children: [ new TextRun({ text: reportData.topic, size: 28, font: "${formData.fontFamily}", italics: true }) ], alignment: AlignmentType.CENTER, spacing: { after: 960 } }) ] : [new Paragraph({ spacing: { after: 960 } })]), // Decorative line new Paragraph({ border: { bottom: { color: "1F4788", space: 1, style: BorderStyle.DOUBLE, size: 12 } }, spacing: { before: 480, after: 960 } }), // Course Information new Paragraph({ children: [ new TextRun({ text: "Course: ", bold: true, size: 24, font: "${formData.fontFamily}" }), new TextRun({ text: \`\${reportData.courseTitle} (\${reportData.courseCode})\`, size: 24, font: "${formData.fontFamily}" }) ], alignment: AlignmentType.CENTER, spacing: { after: 240 } }), // Instructor new Paragraph({ children: [ new TextRun({ text: "Submitted To:\\n", bold: true, size: 24, font: "${formData.fontFamily}" }), new TextRun({ text: reportData.teacherName, size: 24, font: "${formData.fontFamily}" }), ...(reportData.teacherDesignation ? [ new TextRun({ text: \`\\n\${reportData.teacherDesignation}\`, size: 22, font: "${formData.fontFamily}", italics: true }) ] : []) ], alignment: AlignmentType.CENTER, spacing: { before: 480, after: 480 } }), // Student Information new Paragraph({ children: [ new TextRun({ text: "Submitted By:\\n", bold: true, size: 24, font: "${formData.fontFamily}" }), new TextRun({ text: reportData.studentName, size: 24, font: "${formData.fontFamily}" }), new TextRun({ text: \`\\nStudent ID: \${reportData.studentId}\`, size: 22, font: "${formData.fontFamily}" }) ], alignment: AlignmentType.CENTER, spacing: { after: 480 } }), // Submission Date new Paragraph({ children: [ new TextRun({ text: "Date of Submission:\\n", bold: true, size: 22, font: "${formData.fontFamily}" }), new TextRun({ text: new Date(reportData.submissionDate).toLocaleDateString('en-GB', { day: 'numeric', month: 'long', year: 'numeric' }), size: 22, font: "${formData.fontFamily}" }) ], alignment: AlignmentType.CENTER, spacing: { before: 480 } }), // Page Break new Paragraph({ children: [new PageBreak()] }) ] }, // Main Content Section { properties: { page: { size: { width: 12240, height: 15840 }, margin: { top: 1440, right: 1440, bottom: 1440, left: 1440 } } }, children: [ // Table of Contents ...(reportData.includeTOC ? [ new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("Table of Contents")], pageBreakBefore: false }), new TableOfContents("Table of Contents", { hyperlink: true, headingStyleRange: "1-3" }), new Paragraph({ children: [new PageBreak()] }) ] : []), // Abstract ...(reportData.includeAbstract && content.abstract ? [ new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("Abstract")] }), new Paragraph({ children: [new TextRun(content.abstract)], alignment: AlignmentType.JUSTIFIED, spacing: { before: 240, after: 480 }, italics: true }), new Paragraph({ children: [new PageBreak()] }) ] : []), // Introduction new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("1. Introduction")] }), ...createParagraphs(content.introduction), new Paragraph({ spacing: { after: 480 } }), // Literature Review new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("2. Literature Review")] }), ...createParagraphs(content.literatureReview), new Paragraph({ spacing: { after: 480 } }), // Methodology new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("3. Methodology")] }), ...createParagraphs(content.methodology), new Paragraph({ spacing: { after: 480 } }), // Results/Findings new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("4. Results and Findings")] }), ...createParagraphs(content.results), new Paragraph({ spacing: { after: 480 } }), // Discussion new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("5. Discussion")] }), ...createParagraphs(content.discussion), new Paragraph({ spacing: { after: 480 } }), // Conclusion new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("6. Conclusion")] }), ...createParagraphs(content.conclusion), // References ...(reportData.includeReferences && content.references ? [ new Paragraph({ children: [new PageBreak()] }), new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("References")] }), ...content.references.map((ref, idx) => new Paragraph({ numbering: { reference: "references-numbering", level: 0 }, children: [new TextRun(ref)], spacing: { before: 120, after: 120 }, alignment: AlignmentType.LEFT }) ) ] : []) ] } ] }); Packer.toBuffer(doc).then(buffer => { fs.writeFileSync('/mnt/user-data/outputs/academic-report.docx', buffer); console.log('Document generated successfully!'); }); `; // Write the script const scriptPath = '/home/claude/generate-docx.js'; await fetch('/api/files/write', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ path: scriptPath, content: docxScript }) }); // Execute the script - this is simulated, actual implementation would need backend console.log('DOCX generation script created'); }; return (
Professional PhD-Level Reports in Minutes ✨
🎓 Smart Academic Report Generator
Professional PhD-Level Reports • Auto Cover Page • Table of Contents • APA References