'use client' import { useCallback, useRef } from 'react' import type { Note } from '@/lib/types' import type { NotebookSchemaPayload, NotePropertyValues, StructuredViewMode } from '@/lib/structured-views/types' import { NotesStructuredTable } from './notes-structured-table' import { NotesKanbanView } from './notes-kanban-view' import { NotesGalleryView } from './notes-gallery-view' type StructuredViewsContainerProps = { mode: StructuredViewMode notes: Note[] schema: NotebookSchemaPayload noteValues: Record notebookColor?: string | null onOpen: (note: Note) => void onNoteValuesPatch: (noteId: string, patch: NotePropertyValues) => void onCreateNote: (prefill: Record) => void onSetKanbanGroupProperty: (propertyId: string) => void onQuickAddKanbanStatus?: () => void onDeleteProperty?: (propertyId: string) => Promise } export function StructuredViewsContainer({ mode, notes, schema, noteValues, notebookColor, onOpen, onNoteValuesPatch, onCreateNote, onSetKanbanGroupProperty, onQuickAddKanbanStatus, onDeleteProperty, }: StructuredViewsContainerProps) { const timersRef = useRef>>(new Map()) const saveProperty = useCallback( (noteId: string, propertyId: string, value: unknown) => { onNoteValuesPatch(noteId, { [propertyId]: value }) const key = `${noteId}:${propertyId}` const existing = timersRef.current.get(key) if (existing) clearTimeout(existing) timersRef.current.set( key, setTimeout(async () => { try { await fetch(`/api/notes/${noteId}/properties`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ properties: { [propertyId]: value } }), }) } catch (e) { console.error(e) } timersRef.current.delete(key) }, 500), ) }, [onNoteValuesPatch], ) if (mode === 'table') { return ( ) } if (mode === 'kanban') { return ( ) } if (mode === 'gallery') { return ( ) } return null }