// Capture Plan Document Exporter - Complete React Component
import React, { useState, useRef } from 'react';
import { FileText, Download, Copy, Eye, EyeOff, FileDown } from 'lucide-react';
const CaptureplanExporter = () => {
const [content, setContent] = useState('');
const [showPreview, setShowPreview] = useState(true);
const [isProcessing, setIsProcessing] = useState(false);
const printRef = useRef(null);
// Parse the content into structured sections
const parseContent = (text) => {
const lines = text.split('\n');
const sections = [];
let currentSection = null;
let currentSubsection = null;
let currentContent = [];
lines.forEach((line) => {
const trimmedLine = line.trim();
// Main section headers (numbered)
const mainSectionMatch = trimmedLine.match(/^(\d+)\.\s+(.+)$/);
if (mainSectionMatch) {
if (currentSection) {
if (currentSubsection) {
currentSubsection.content = currentContent.join('\n');
currentContent = [];
currentSubsection = null;
} else {
currentSection.content = currentContent.join('\n');
currentContent = [];
}
}
currentSection = {
number: mainSectionMatch[1],
title: mainSectionMatch[2],
subsections: [],
content: ''
};
sections.push(currentSection);
return;
}
// Subsection headers (letters)
const subSectionMatch = trimmedLine.match(/^([A-Z])\.\s+(.+)$/);
if (subSectionMatch && currentSection) {
if (currentSubsection) {
currentSubsection.content = currentContent.join('\n');
currentContent = [];
} else if (currentContent.length > 0) {
currentSection.content = currentContent.join('\n');
currentContent = [];
}
currentSubsection = {
letter: subSectionMatch[1],
title: subSectionMatch[2],
content: ''
};
currentSection.subsections.push(currentSubsection);
return;
}
// Arrow items (β)
if (trimmedLine.includes('β')) {
currentContent.push(line);
return;
}
// Regular content
if (trimmedLine) {
currentContent.push(line);
}
});
// Handle remaining content
if (currentContent.length > 0) {
if (currentSubsection) {
currentSubsection.content = currentContent.join('\n');
} else if (currentSection) {
currentSection.content = currentContent.join('\n');
}
}
return sections;
};
const FormattedDocument = ({ sections }) => {
return (
{sections.map((section, index) => (
);
};
const handlePrint = () => {
window.print();
};
const handleExportHTML = () => {
const element = printRef.current;
if (!element) return;
const htmlContent = `
Capture Plan
{showPreview && content && (
)}
);
};
export default CaptureplanExporter;
CAPTURE PLAN
0 && index % 3 === 0 ? 'print-break' : ''}`}>
))}
))}
{section.number}. {section.title}
{section.content && (
{section.content.split('\n').map((line, i) => {
if (line.includes('β')) {
const [label, value] = line.split('β').map(s => s.trim());
return (
)}
{section.subsections.map((subsection, subIndex) => (
{label}
β {value}
);
}
return {line}
; })}{subsection.letter}. {subsection.title}
{subsection.content.split('\n').map((line, i) => {
if (line.includes('β')) {
const [label, value] = line.split('β').map(s => s.trim());
return (
{label}:
{value}
);
}
return {line}
; })}Generated on {new Date().toLocaleDateString()}