"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RFPApp = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_2 = require("@chakra-ui/react");
const icons_1 = require("@chakra-ui/icons");
const rfp_js_1 = require("../components/rfp.js");
const steps = [
    { title: 'Project Setup', description: 'Create new RFP project' },
    { title: 'Document Upload', description: 'Upload RFP documents' },
    { title: 'Content Generation', description: 'Generate AI responses' },
    { title: 'Review & Export', description: 'Review and export final proposal' }
];
const RFPApp = () => {
    const [currentProject, setCurrentProject] = (0, react_1.useState)(null);
    const [view, setView] = (0, react_1.useState)('dashboard');
    const [projectData, setProjectData] = (0, react_1.useState)({
        documents: [],
        competitiveAnalysis: null,
        companyProfile: null
    });
    const { activeStep, setActiveStep } = (0, react_2.useSteps)({
        index: 0,
        count: steps.length,
    });
    const toast = (0, react_2.useToast)();
    (0, react_1.useEffect)(() => {
        // Load any existing project from localStorage or API
        loadProjectData();
    }, []);
    const loadProjectData = () => {
        // Mock company profile - in production, this would be loaded from the API
        const mockCompanyProfile = {
            name: 'TechSolutions Inc.',
            businessType: ['Small Business', 'Veteran-Owned'],
            coreCapabilities: ['AI/ML', 'Cloud Computing', 'Cybersecurity'],
            differentiators: ['PhD-level expertise', 'Government experience', 'FedRAMP authorized'],
            pastPerformance: [
                {
                    projectName: 'DoD AI Classification System',
                    client: 'Department of Defense',
                    contractValue: 2100000,
                    duration: '18 months',
                    scope: 'AI/ML implementation for data classification',
                    outcomes: ['99.2% accuracy achieved', 'On-time delivery', 'Under budget'],
                    relevantTechnologies: ['Python', 'TensorFlow', 'AWS', 'Kubernetes'],
                    teamSize: 8,
                    challenges: ['Legacy system integration', 'Security compliance'],
                    innovations: ['Novel ensemble method', 'Real-time processing']
                }
            ],
            certifications: ['ISO 27001', 'FedRAMP Moderate', 'CMMI Level 3'],
            teamProfiles: [
                {
                    name: 'Dr. Jane Smith',
                    role: 'Technical Lead',
                    experience: '15 years in AI/ML',
                    education: ['PhD Computer Science - Stanford'],
                    certifications: ['AWS Certified', 'PMP', 'CISSP'],
                    relevantProjects: ['DoD AI Classification', 'NASA Data Analytics'],
                    clearanceLevel: 'Secret'
                }
            ]
        };
        setProjectData(prev => ({
            ...prev,
            companyProfile: mockCompanyProfile
        }));
    };
    const createNewProject = () => {
        const newProject = {
            id: `rfp-${Date.now()}`,
            name: 'New RFP Project',
            opportunity: null,
            documents: [],
            status: 'setup',
            createdAt: new Date(),
            updatedAt: new Date()
        };
        setCurrentProject(newProject);
        setView('project');
        setActiveStep(0);
        toast({
            title: 'Project Created',
            description: 'New RFP project has been created',
            status: 'success',
            duration: 3000,
            isClosable: true
        });
    };
    const openProject = (projectId) => {
        // Mock project loading - in production, this would fetch from API
        const mockProject = {
            id: projectId,
            name: 'AI/ML Platform Development',
            opportunity: {
                opportunityId: 'DOD-2024-001',
                title: 'AI/ML Platform Development',
                agency: 'Department of Defense',
                estimatedValue: 2500000,
                deadline: new Date('2024-12-31')
            },
            documents: [],
            status: 'upload',
            createdAt: new Date('2024-11-15'),
            updatedAt: new Date('2024-11-20')
        };
        setCurrentProject(mockProject);
        setView('project');
        setActiveStep(1);
    };
    const handleDocumentsProcessed = (documents) => {
        setProjectData(prev => ({
            ...prev,
            documents
        }));
        if (currentProject) {
            setCurrentProject(prev => prev ? { ...prev, documents, status: 'generate' } : null);
            setActiveStep(2);
        }
    };
    const handleAnalysisComplete = (analysisResults) => {
        setProjectData(prev => ({
            ...prev,
            competitiveAnalysis: analysisResults
        }));
        toast({
            title: 'Analysis Complete',
            description: 'Competitive analysis has been completed successfully',
            status: 'success',
            duration: 5000,
            isClosable: true
        });
    };
    const handleContentGenerated = (sections) => {
        if (currentProject) {
            setCurrentProject(prev => prev ? {
                ...prev,
                generatedContent: sections,
                status: 'review',
                updatedAt: new Date()
            } : null);
            setActiveStep(3);
        }
        toast({
            title: 'Content Generated',
            description: 'RFP response content has been generated successfully',
            status: 'success',
            duration: 5000,
            isClosable: true
        });
    };
    const handleExportRequest = (format) => {
        toast({
            title: 'Export Started',
            description: `Exporting RFP response as ${format.toUpperCase()}...`,
            status: 'info',
            duration: 3000,
            isClosable: true
        });
        // Simulate export process
        setTimeout(() => {
            toast({
                title: 'Export Complete',
                description: `RFP response has been exported as ${format.toUpperCase()}`,
                status: 'success',
                duration: 5000,
                isClosable: true
            });
        }, 2000);
    };
    const backToDashboard = () => {
        setView('dashboard');
        setCurrentProject(null);
        setActiveStep(0);
    };
    const getStepStatus = (stepIndex) => {
        if (stepIndex < activeStep)
            return 'complete';
        if (stepIndex === activeStep)
            return 'active';
        return 'incomplete';
    };
    const renderProjectContent = () => {
        if (!currentProject)
            return null;
        switch (activeStep) {
            case 0:
                return ((0, jsx_runtime_1.jsxs)(react_2.Card, { children: [(0, jsx_runtime_1.jsx)(react_2.CardHeader, { children: (0, jsx_runtime_1.jsx)(react_2.Heading, { size: "md", children: "Project Setup" }) }), (0, jsx_runtime_1.jsx)(react_2.CardBody, { children: (0, jsx_runtime_1.jsxs)(react_2.VStack, { spacing: 4, align: "stretch", children: [(0, jsx_runtime_1.jsxs)(react_2.Alert, { status: "info", children: [(0, jsx_runtime_1.jsx)(react_2.AlertIcon, {}), (0, jsx_runtime_1.jsxs)(react_2.Box, { children: [(0, jsx_runtime_1.jsx)(react_2.AlertTitle, { children: "Project Configuration" }), (0, jsx_runtime_1.jsx)(react_2.AlertDescription, { children: "Project setup is complete. Your company profile and capabilities have been loaded and are ready for RFP analysis." })] })] }), (0, jsx_runtime_1.jsxs)(react_2.SimpleGrid, { columns: { base: 1, md: 2 }, spacing: 4, children: [(0, jsx_runtime_1.jsxs)(react_2.Box, { children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontWeight: "medium", mb: 2, children: "Company Information" }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", color: "gray.600", children: projectData.companyProfile?.name }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", color: "gray.600", children: projectData.companyProfile?.businessType?.join(', ') })] }), (0, jsx_runtime_1.jsxs)(react_2.Box, { children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontWeight: "medium", mb: 2, children: "Core Capabilities" }), projectData.companyProfile?.coreCapabilities?.map((cap, idx) => ((0, jsx_runtime_1.jsx)(react_2.Badge, { mr: 1, mb: 1, variant: "outline", children: cap }, idx)))] })] }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "blue", onClick: () => setActiveStep(1), alignSelf: "flex-end", children: "Continue to Document Upload" })] }) })] }));
            case 1:
                return ((0, jsx_runtime_1.jsx)(rfp_js_1.RFPDocumentUpload, { onDocumentsProcessed: handleDocumentsProcessed, onAnalysisComplete: handleAnalysisComplete }));
            case 2:
                return ((0, jsx_runtime_1.jsx)(rfp_js_1.RFPContentGenerator, { opportunityData: currentProject.opportunity, competitiveAnalysis: projectData.competitiveAnalysis, companyProfile: projectData.companyProfile, onContentGenerated: handleContentGenerated, onExportRequest: handleExportRequest }));
            case 3:
                return ((0, jsx_runtime_1.jsxs)(react_2.Card, { children: [(0, jsx_runtime_1.jsx)(react_2.CardHeader, { children: (0, jsx_runtime_1.jsx)(react_2.Heading, { size: "md", children: "Review & Export" }) }), (0, jsx_runtime_1.jsx)(react_2.CardBody, { children: (0, jsx_runtime_1.jsxs)(react_2.VStack, { spacing: 4, align: "stretch", children: [(0, jsx_runtime_1.jsxs)(react_2.Alert, { status: "success", children: [(0, jsx_runtime_1.jsx)(react_2.AlertIcon, {}), (0, jsx_runtime_1.jsxs)(react_2.Box, { children: [(0, jsx_runtime_1.jsx)(react_2.AlertTitle, { children: "Content Generation Complete!" }), (0, jsx_runtime_1.jsx)(react_2.AlertDescription, { children: "Your RFP response has been generated and is ready for review and export." })] })] }), (0, jsx_runtime_1.jsxs)(react_2.SimpleGrid, { columns: { base: 1, md: 3 }, spacing: 4, children: [(0, jsx_runtime_1.jsx)(react_2.Card, { variant: "outline", children: (0, jsx_runtime_1.jsxs)(react_2.CardBody, { textAlign: "center", children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontWeight: "medium", mb: 2, children: "Total Sections" }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "2xl", fontWeight: "bold", children: currentProject.generatedContent?.length || 0 })] }) }), (0, jsx_runtime_1.jsx)(react_2.Card, { variant: "outline", children: (0, jsx_runtime_1.jsxs)(react_2.CardBody, { textAlign: "center", children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontWeight: "medium", mb: 2, children: "Total Words" }), (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "2xl", fontWeight: "bold", children: currentProject.generatedContent?.reduce((sum, section) => sum + (section.wordCount || 0), 0).toLocaleString() || '0' })] }) }), (0, jsx_runtime_1.jsx)(react_2.Card, { variant: "outline", children: (0, jsx_runtime_1.jsxs)(react_2.CardBody, { textAlign: "center", children: [(0, jsx_runtime_1.jsx)(react_2.Text, { fontWeight: "medium", mb: 2, children: "Avg Confidence" }), (0, jsx_runtime_1.jsxs)(react_2.Text, { fontSize: "2xl", fontWeight: "bold", color: "green.500", children: [currentProject.generatedContent?.length > 0
                                                                    ? Math.round(currentProject.generatedContent.reduce((sum, section) => sum + (section.confidence || 0), 0) / currentProject.generatedContent.length * 100)
                                                                    : 0, "%"] })] }) })] }), (0, jsx_runtime_1.jsxs)(react_2.HStack, { justify: "center", spacing: 4, children: [(0, jsx_runtime_1.jsx)(react_2.Button, { variant: "outline", onClick: () => handleExportRequest('markdown'), children: "Export Markdown" }), (0, jsx_runtime_1.jsx)(react_2.Button, { variant: "outline", onClick: () => handleExportRequest('docx'), children: "Export Word" }), (0, jsx_runtime_1.jsx)(react_2.Button, { colorScheme: "blue", onClick: () => handleExportRequest('pdf'), children: "Export PDF" })] })] }) })] }));
            default:
                return null;
        }
    };
    if (view === 'dashboard') {
        return ((0, jsx_runtime_1.jsx)(react_2.Container, { maxW: "7xl", py: 8, children: (0, jsx_runtime_1.jsx)(rfp_js_1.RFPDashboard, { onCreateProject: createNewProject, onOpenProject: openProject }) }));
    }
    return ((0, jsx_runtime_1.jsx)(react_2.Container, { maxW: "7xl", py: 8, children: (0, jsx_runtime_1.jsxs)(react_2.VStack, { spacing: 6, align: "stretch", children: [(0, jsx_runtime_1.jsxs)(react_2.Breadcrumb, { spacing: "8px", separator: (0, jsx_runtime_1.jsx)(icons_1.ChevronRightIcon, { color: "gray.500" }), children: [(0, jsx_runtime_1.jsx)(react_2.BreadcrumbItem, { children: (0, jsx_runtime_1.jsx)(react_2.BreadcrumbLink, { onClick: backToDashboard, cursor: "pointer", children: "RFP Dashboard" }) }), (0, jsx_runtime_1.jsx)(react_2.BreadcrumbItem, { isCurrentPage: true, children: (0, jsx_runtime_1.jsx)(react_2.BreadcrumbLink, { children: currentProject?.name || 'Project' }) })] }), (0, jsx_runtime_1.jsxs)(react_2.HStack, { justify: "space-between", align: "center", children: [(0, jsx_runtime_1.jsxs)(react_2.VStack, { align: "start", spacing: 1, children: [(0, jsx_runtime_1.jsx)(react_2.Heading, { size: "lg", children: currentProject?.name }), currentProject?.opportunity && ((0, jsx_runtime_1.jsxs)(react_2.Text, { color: "gray.600", children: [currentProject.opportunity.agency, " \u2022 ", currentProject.opportunity.opportunityId] }))] }), (0, jsx_runtime_1.jsx)(react_2.Button, { variant: "outline", onClick: backToDashboard, children: "Back to Dashboard" })] }), (0, jsx_runtime_1.jsxs)(react_2.Box, { bg: "white", p: 6, borderRadius: "lg", boxShadow: "sm", children: [(0, jsx_runtime_1.jsx)(react_2.Stepper, { index: activeStep, colorScheme: "blue", children: steps.map((step, index) => ((0, jsx_runtime_1.jsxs)(react_2.Step, { children: [(0, jsx_runtime_1.jsx)(react_2.StepIndicator, { children: (0, jsx_runtime_1.jsx)(react_2.StepStatus, { complete: (0, jsx_runtime_1.jsx)(react_2.StepIcon, {}), incomplete: (0, jsx_runtime_1.jsx)(react_2.StepNumber, {}), active: (0, jsx_runtime_1.jsx)(react_2.StepNumber, {}) }) }), (0, jsx_runtime_1.jsxs)(react_2.Box, { flexShrink: "0", children: [(0, jsx_runtime_1.jsx)(react_2.StepTitle, { children: step.title }), (0, jsx_runtime_1.jsx)(react_2.StepDescription, { children: step.description })] }), (0, jsx_runtime_1.jsx)(react_2.StepSeparator, {})] }, index))) }), (0, jsx_runtime_1.jsx)(react_2.Progress, { value: (activeStep / (steps.length - 1)) * 100, colorScheme: "blue", size: "sm", mt: 4 })] }), renderProjectContent()] }) }));
};
exports.RFPApp = RFPApp;
exports.default = exports.RFPApp;
//# sourceMappingURL=RFPApp.js.map