import React, { useEffect, useState } from 'react'; import { Box, Typography, Alert, Fade, Container, Grid, Snackbar, } from '@mui/material'; import Lock from '@mui/icons-material/Lock'; import OnboardingButton from './common/OnboardingButton'; import { HelpSection, BenefitsModal, useApiKeyStep } from './ApiKeyStep/utils'; import ApiKeyCarousel from './ApiKeyStep/utils/ApiKeyCarousel'; import ApiKeySidebar from './ApiKeyStep/utils/ApiKeySidebar'; interface ApiKeyStepProps { onContinue: (stepData?: any) => void; updateHeaderContent: (content: { title: string; description: string }) => void; onValidationChange?: (isValid: boolean) => void; } const ApiKeyStep: React.FC = ({ onContinue, updateHeaderContent, onValidationChange }) => { const [focusedProvider, setFocusedProvider] = useState(null); const { loading, error, success, showHelp, savedKeys, benefitsModalOpen, selectedProvider, providers, isValid, currentProviderIndex, setCurrentProviderIndex, showCompletionToast, setShowCompletionToast, setShowHelp, handleContinue, handleBenefitsClick, handleCloseBenefitsModal, } = useApiKeyStep(onContinue); const handleProviderFocus = (provider: any) => { setFocusedProvider(provider); }; useEffect(() => { // Update header content when component mounts updateHeaderContent({ title: 'Connect Your AI Services', description: 'Configure your AI providers to unlock intelligent content creation, research capabilities, and enhanced user assistance.' }); // Set initial focused provider if (providers.length > 0) { setFocusedProvider(providers[currentProviderIndex] ?? providers[0]); } }, [updateHeaderContent, providers, currentProviderIndex]); // Notify parent of validation changes useEffect(() => { console.log('ApiKeyStep: isValid changed to:', isValid); console.log('ApiKeyStep: onValidationChange exists:', !!onValidationChange); if (onValidationChange) { console.log('ApiKeyStep: Calling onValidationChange with:', isValid); onValidationChange(isValid); } }, [isValid, onValidationChange]); return ( <> {/* Main Content Layout */} {/* Carousel Section */} {/* Sidebar Section */} {/* Get Help Section */} setShowHelp(!showHelp)} size="small" sx={{ mb: 2 }} > {showHelp ? 'Hide Setup Help' : 'Need Setup Help?'} {/* Benefits Modal */} {/* Help Section */} {/* Alerts */} {error && ( {error} )} {success && ( {success} )} {/* Security Notice */} Your API keys are encrypted and stored securely on your device {/* Completion Toast */} setShowCompletionToast(false)} anchorOrigin={{ vertical: 'top', horizontal: 'center' }} sx={{ '& .MuiSnackbarContent-root': { background: 'linear-gradient(135deg, #10B981 0%, #059669 100%)', color: 'white', fontWeight: 600, fontSize: '1rem', borderRadius: '12px', boxShadow: '0 8px 32px rgba(16, 185, 129, 0.3)', }, }} > setShowCompletionToast(false)} severity="success" sx={{ width: '100%', background: 'transparent', color: 'white', '& .MuiAlert-icon': { color: 'white', }, }} > 🎉 All API keys configured! Click Continue to proceed to Website Analysis. ); }; export default ApiKeyStep;