/**
 * NoteNode Types
 *
 * Storage adapter interface for the NoteNode component.
 * This allows the NoteNode to work with any storage backend
 * (Jazz, Supabase, local state, etc.)
 */

import type { NodeTypeComponentProps } from '../../core/node-type-registry';

/**
 * Storage adapter interface for NoteNode.
 *
 * Implement this interface to connect NoteNode to your storage backend.
 *
 * @example
 * ```tsx
 * // Jazz implementation
 * function useJazzNoteStorage(nodeId: string): NoteNodeStorage {
 *   const coRichText = useJazzRichText(nodeId);
 *   return {
 *     content: coRichText?.toString() ?? '',
 *     onChange: (html) => coRichText?.$jazz.applyDiff(html),
 *     subscribe: (callback) => coRichText?.$jazz.subscribe(callback),
 *   };
 * }
 *
 * // Local state implementation
 * function useLocalNoteStorage(nodeId: string): NoteNodeStorage {
 *   const [content, setContent] = useState('');
 *   return { content, onChange: setContent };
 * }
 * ```
 */
export interface NoteNodeStorage {
	/** Current HTML content of the note */
	content: string;

	/** Called when the editor content changes */
	onChange: (html: string) => void;

	/**
	 * Optional: Subscribe to external content changes (for real-time sync).
	 * Return an unsubscribe function.
	 */
	subscribe?: (callback: (html: string) => void) => () => void;

	/** Optional: Whether storage is ready/loaded */
	isLoading?: boolean;
}

/**
 * Props for the NoteNode component.
 */
export interface NoteNodeProps extends NodeTypeComponentProps {
	/** Storage adapter for persisting note content */
	storage: NoteNodeStorage;

	/** Optional: Theme for BlockNote editor */
	theme?: 'light' | 'dark';

	/** Optional: Placeholder text for empty document */
	placeholder?: string;
}

/**
 * Configuration stored in node's dbData.configuration for NoteNode
 */
export interface NoteNodeConfiguration {
	/** Optional title for the note */
	title?: string;

	/** Theme preference for this note */
	theme?: 'light' | 'dark';
}
