'use client'
import { useNoteEditorContext } from './note-editor-context'
import { LabelManager } from '@/components/label-manager'
import { LabelBadge } from '@/components/label-badge'
import { GhostTags } from '@/components/ghost-tags'
import { EditorImages } from '@/components/editor-images'
import { TitleSuggestions } from '@/components/title-suggestions'
import { NoteTypeSelector } from '@/components/note-type-selector'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { Button } from '@/components/ui/button'
import { Badge } from '@/components/ui/badge'
import {
X, Plus, Palette, Image as ImageIcon, Bell, Eye, Link as LinkIcon, Sparkles,
Maximize2, Copy, ArrowLeft, ChevronRight, Info, Check, Loader2, Save, MoreHorizontal,
Trash2, LogOut
} from 'lucide-react'
import { deleteNote, leaveSharedNote } from '@/app/actions/notes'
import { useNoteRefresh } from '@/context/NoteRefreshContext'
import { useLanguage } from '@/lib/i18n'
import { NOTE_COLORS, NoteColor, Note } from '@/lib/types'
import { cn } from '@/lib/utils'
import { toast } from 'sonner'
import { format } from 'date-fns'
interface NoteEditorToolbarProps {
mode: 'fullPage' | 'dialog'
onClose: () => void
}
export function NoteEditorToolbar({ mode, onClose }: NoteEditorToolbarProps) {
const { state, actions, note, readOnly, fullPage, notebooks, fileInputRef } = useNoteEditorContext()
const { t } = useLanguage()
const { triggerRefresh } = useNoteRefresh()
const notebookName = notebooks.find(nb => nb.id === note.notebookId)?.name || null
if (mode === 'fullPage') {
return (
{/* Left: back */}
{/* Right: status + type + AI + Info */}
{/* Save status */}
{state.isSaving
? <>Saving…>
: state.isDirty
? <>Modified>
: <>Saved>}
{/* Note type */}
{ actions.setNoteType(newType); actions.setIsDirty(true) }}
compact
/>
{/* Preview toggle — only for text/markdown, in toolbar where it's visible */}
{(state.noteType === 'text' || state.noteType === 'markdown') && !readOnly && (
)}
{/* AI — rounded-full, exact prototype style */}
{/* Info — rounded-full */}
{/* Save button */}
{!readOnly && (
)}
{/* Three-dot options menu */}
{!readOnly && (
{
try {
await deleteNote(note.id)
triggerRefresh()
toast.success('Note supprimée.')
onClose()
} catch { toast.error('Impossible de supprimer.') }
}}
className="text-red-600 dark:text-red-400 focus:text-red-600"
>
Supprimer la note
)}
)
}
// Dialog toolbar
return (
{!readOnly && (
<>
{/* Reminder */}
{/* Add Image */}
{/* Add Link */}
{ actions.setNoteType(newType); if (newType !== 'markdown') actions.setShowMarkdownPreview(false) }} />
{state.noteType === 'markdown' && (
)}
{/* AI Copilot */}
{state.noteType !== 'checklist' && (
)}
{/* Size Selector */}
{(['small', 'medium', 'large'] as const).map((s) => (
))}
{/* Color Picker */}
{Object.entries(NOTE_COLORS).map(([colorName, classes]) => (
{/* Label Manager */}
>
)}
{readOnly && (
{t('notes.sharedReadOnly')}
)}
{readOnly ? (
<>
>
) : (
<>
>
)}
)
}