'use client' import { useEffect, useState } from 'react' import { Plus, Trash2 } from 'lucide-react' import type { NotebookSchemaPayload, NotePropertyValues } from '@/lib/structured-views/types' import { PropertyValueEditor, useDebouncedPropertySave } from './property-value-editor' import { useLanguage } from '@/lib/i18n' import { MAX_PROPERTIES_PER_NOTEBOOK } from '@/lib/structured-views/types' type NotePropertiesSectionProps = { noteId: string schema: NotebookSchemaPayload initialValues?: NotePropertyValues onAddProperty?: () => void onValuesChange?: (values: NotePropertyValues) => void readOnly?: boolean } export function NotePropertiesSection({ noteId, schema, initialValues = {}, onAddProperty, onValuesChange, readOnly, }: NotePropertiesSectionProps) { const { t } = useLanguage() const [values, setValues] = useState(initialValues) useEffect(() => { setValues(initialValues) }, [noteId, initialValues]) const queueSave = useDebouncedPropertySave(noteId, (saved) => { setValues((v) => ({ ...v, ...saved })) onValuesChange?.({ ...values, ...saved }) }) const handleChange = (propertyId: string, value: unknown) => { setValues((prev) => { const next = { ...prev, [propertyId]: value } onValuesChange?.(next) return next }) if (!readOnly) queueSave(propertyId, value) } if (schema.properties.length === 0) { return (

{t('structuredViews.propertiesSection')}

{t('structuredViews.noPropertiesYet')}

{onAddProperty && !readOnly && ( )}
) } return (

{t('structuredViews.propertiesSection')}

{onAddProperty && !readOnly && schema.properties.length < MAX_PROPERTIES_PER_NOTEBOOK && ( )}
{schema.properties.map((prop) => (
{readOnly ? (

{String(values[prop.id] ?? '—')}

) : ( handleChange(prop.id, v)} /> )}
))}
) } export function SchemaPropertyList({ schema, onDeleteProperty, }: { schema: NotebookSchemaPayload onDeleteProperty?: (id: string) => void }) { const { t } = useLanguage() return ( ) }