'use client' import { Check, ChevronDown, Home, Plus } from 'lucide-react' import { useState } from 'react' import { usePropertyStore } from '../lib/properties/store' import { cn } from '@/lib/utils' import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/primitives/dropdown-menu' import { NewPropertyDialog } from './new-property-dialog' import { usePropertyScene } from '../lib/models/hooks' /** * PropertyDropdown - Shows active property and allows switching between properties */ export function PropertyDropdown() { usePropertyScene() // Load and auto-save property scenes // Use property store const properties = usePropertyStore(state => state.properties) const activeProperty = usePropertyStore(state => state.activeProperty) const isLoading = usePropertyStore(state => state.isLoading) const setActiveProperty = usePropertyStore(state => state.setActiveProperty) const fetchProperties = usePropertyStore(state => state.fetchProperties) const [isNewPropertyDialogOpen, setIsNewPropertyDialogOpen] = useState(false) const handlePropertySelect = async (propertyId: string) => { await setActiveProperty(propertyId) } const handleAddNew = () => { setIsNewPropertyDialogOpen(true) } const handlePropertyCreated = async (propertyId: string) => { // Set the newly created property as active (this will also fetch properties) await setActiveProperty(propertyId) } return ( <> {/* Property list */} {properties.length > 0 ? (
{properties.map((property) => ( activeProperty?.id === property.id ? null : handlePropertySelect(property.id) } >
{property.name}
{activeProperty?.id === property.id && ( )}
))}
) : (
No properties yet
)} {/* Add new property option */} Add new property
) }