'use client' import { useState, useMemo } from 'react' import { Share2 } from 'lucide-react' import ItemCard from './ItemCard' import EmptyState from './EmptyState' import ShareListModal from './ShareListModal' import PermissionBadge from './PermissionBadge' import { useScrollPosition } from '@/hooks' import { useRealtimeSync } from '@/hooks/useRealtimeSync' interface Item { id: string title: string description: string | null completed: boolean priority: string dueDate: Date | null tags: any notes: string | null createdAt: Date updatedAt: Date listId: string } interface ListDetailViewProps { listId: string initialItems: Item[] permission?: 'owner' | 'editor' | 'viewer' canShare?: boolean listTitle?: string ownerId?: string ownerName?: string | null ownerEmail?: string collaborators?: Array<{ id: string permission: 'editor' | 'viewer' user: { id: string name: string | null email: string } }> showOnlyHeader?: boolean showOnlyItems?: boolean } export default function ListDetailView({ listId, initialItems, permission, canShare = false, listTitle = '', ownerId = '', ownerName = null, ownerEmail = '', collaborators = [], showOnlyHeader = false, showOnlyItems = false }: ListDetailViewProps) { const [isShareModalOpen, setIsShareModalOpen] = useState(false) // Conditionally use hooks based on view mode const shouldUseHooks = !showOnlyHeader // Use scroll position preservation hook (only for items view) useScrollPosition({ key: shouldUseHooks ? `list-${listId}` : 'disabled' }) // Use real-time sync hook to poll for updates (only for items view) useRealtimeSync({ listId, enabled: shouldUseHooks, pollInterval: 1000, // Poll every 1 second for faster updates }) // Determine which items to display const completedItems = useMemo(() => initialItems.filter(item => item.completed), [initialItems]) const incompleteItems = useMemo(() => initialItems.filter(item => !item.completed), [initialItems]) // If showing only header, return just the permission badge and share button if (showOnlyHeader) { return ( <> {(permission || canShare) && (