import { useState, useEffect, useCallback } from 'react'; import { createLogger } from '@automaker/utils/logger'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { useSetupStore } from '@/store/setup-store'; import { getElectronAPI } from '@/lib/electron'; import { CheckCircle2, ArrowRight, ArrowLeft, ExternalLink, Copy, RefreshCw, AlertTriangle, Github, XCircle, } from 'lucide-react'; import { Spinner } from '@/components/ui/spinner'; import { toast } from 'sonner'; import { StatusBadge } from '../components'; const logger = createLogger('GitHubSetupStep'); interface GitHubSetupStepProps { onNext: () => void; onBack: () => void; onSkip: () => void; } export function GitHubSetupStep({ onNext, onBack, onSkip }: GitHubSetupStepProps) { const { ghCliStatus, setGhCliStatus } = useSetupStore(); const [isChecking, setIsChecking] = useState(false); const checkStatus = useCallback(async () => { setIsChecking(true); try { const api = getElectronAPI(); if (!api.setup?.getGhStatus) { return; } const result = await api.setup.getGhStatus(); if (result.success) { setGhCliStatus({ installed: result.installed, authenticated: result.authenticated, version: result.version, path: result.path, user: result.user, }); } } catch (error) { logger.error('Failed to check gh status:', error); } finally { setIsChecking(false); } }, [setGhCliStatus]); useEffect(() => { checkStatus(); }, [checkStatus]); const copyCommand = (command: string) => { navigator.clipboard.writeText(command); toast.success('Command copied to clipboard'); }; const isReady = ghCliStatus?.installed && ghCliStatus?.authenticated; const getStatusBadge = () => { if (isChecking) { return ; } if (ghCliStatus?.authenticated) { return ; } if (ghCliStatus?.installed) { return ; } return ; }; return (

GitHub CLI Setup

Optional - Used for creating pull requests

{/* Info Banner */}

This step is optional

The GitHub CLI allows you to create pull requests directly from the app. Without it, you can still create PRs manually in your browser.

{/* Status Card */}
GitHub CLI Status
{getStatusBadge()}
{ghCliStatus?.installed ? ghCliStatus.authenticated ? `Logged in${ghCliStatus.user ? ` as ${ghCliStatus.user}` : ''}` : 'Installed but not logged in' : 'Not installed on your system'}
{/* Success State */} {isReady && (

GitHub CLI is ready!

You can create pull requests directly from the app. {ghCliStatus?.version && ( Version: {ghCliStatus.version} )}

)} {/* Not Installed */} {!ghCliStatus?.installed && !isChecking && (

GitHub CLI not found

Install the GitHub CLI to enable PR creation from the app.

Installation Commands:

macOS (Homebrew)

brew install gh

Windows (winget)

winget install GitHub.cli

Linux (apt)

sudo apt install gh
View all installation options
)} {/* Installed but not authenticated */} {ghCliStatus?.installed && !ghCliStatus?.authenticated && !isChecking && (

GitHub CLI not logged in

Run the login command to authenticate with GitHub.

Run this command in your terminal:

gh auth login
)} {/* Loading State */} {isChecking && (

Checking GitHub CLI status...

)}
{/* Navigation */}
); }