'use client' import { Cloud, Home } from 'lucide-react' import { useEffect, useState } from 'react' import { useRouter } from 'next/navigation' import { useAuth } from '../lib/auth/hooks' import { useProjectStore } from '../lib/projects/store' import { ProfileDropdown } from './profile-dropdown' import { SignInDialog } from './sign-in-dialog' interface CloudSaveButtonProps { projectId?: string } /** * CloudSaveButton - Shows authentication state and project management * * Guest with local project: Shows "Save to cloud" button * Guest without project: Shows "Home" button * Authenticated: Shows ProfileDropdown */ export function CloudSaveButton({ projectId }: CloudSaveButtonProps) { const { isAuthenticated, isLoading } = useAuth() const [isSignInDialogOpen, setIsSignInDialogOpen] = useState(false) const initialize = useProjectStore(state => state.initialize) const router = useRouter() const isLocalProject = projectId?.startsWith('local_') // Initialize project store when authenticated useEffect(() => { if (isAuthenticated) { initialize() } }, [isAuthenticated, initialize]) if (isLoading) { return (
) } // Guest user with local project if (!isAuthenticated && isLocalProject) { return ( <>
) } // Guest user (no project context or browsing) if (!isAuthenticated) { return (
) } // Authenticated user return (
) }