'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 { usePropertyStore } from '../lib/properties/store' import { ProfileDropdown } from './profile-dropdown' import { SignInDialog } from './sign-in-dialog' interface CloudSaveButtonProps { propertyId?: string } /** * CloudSaveButton - Shows authentication state and property management * * Guest with local property: Shows "Save to cloud" button * Guest without property: Shows "Home" button * Authenticated: Shows ProfileDropdown */ export function CloudSaveButton({ propertyId }: CloudSaveButtonProps) { const { isAuthenticated, isLoading } = useAuth() const [isSignInDialogOpen, setIsSignInDialogOpen] = useState(false) const initialize = usePropertyStore(state => state.initialize) const router = useRouter() const isLocalProperty = propertyId?.startsWith('local_') // Initialize property store when authenticated useEffect(() => { if (isAuthenticated) { initialize() } }, [isAuthenticated, initialize]) if (isLoading) { return (
) } // Guest user with local property if (!isAuthenticated && isLocalProperty) { return ( <>
) } // Guest user (no property context or browsing) if (!isAuthenticated) { return (
) } // Authenticated user return (
) }