import { useState, useEffect, useCallback, useRef } from 'react'
import { useServerEvents } from '../hooks/useServerEvents'
import type { Note, NoteFilters } from '../api/notes'
import { fetchNotes, createNote, updateNote, deleteNote, addAttachment, deleteAttachment } from '../api/notes'
import Modal from '../components/Modal'
import NoteForm from '../components/notes/NoteForm'
import { useActionButton } from '../contexts/ActionButtonContext'
const noSelect: React.CSSProperties = { userSelect: 'none' }
const inputStyle: React.CSSProperties = {
background: 'var(--bg-3)',
border: '1px solid var(--bg-5)',
borderRadius: 8,
padding: '6px 10px',
color: 'var(--ink-1)',
fontFamily: 'var(--font-ui)',
fontSize: 13,
}
const actionBtnStyle: React.CSSProperties = {
padding: '5px 10px',
borderRadius: 6,
border: '1px solid var(--bg-5)',
background: 'var(--bg-4)',
color: 'var(--ink-3)',
cursor: 'pointer',
fontSize: 13,
minHeight: 32,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}
function formatDate(iso: string) {
return new Date(iso).toLocaleDateString('fr-FR', { day: '2-digit', month: 'short', year: 'numeric' })
}
// Formate le texte inline : **gras**, *italique*, `code`
function inlineFmt(text: string): React.ReactNode {
const parts = text.split(/(\*\*[^*]+\*\*|\*[^*]+\*|`[^`]+`)/)
return (
<>
{parts.map((p, i) => {
if (p.startsWith('**') && p.endsWith('**')) return {p.slice(2, -2)}
if (p.startsWith('*') && p.endsWith('*')) return {p.slice(1, -1)}
if (p.startsWith('`') && p.endsWith('`')) return {p.slice(1, -1)}
return p || null
})}
>
)
}
// Renderer pseudo-markdown ligne par ligne
function renderMarkdown(text: string): React.ReactNode {
const lines = text.split('\n')
const nodes: React.ReactNode[] = []
let i = 0
while (i < lines.length) {
const line = lines[i]
if (line.startsWith('```')) {
const lang = line.slice(3).trim()
const code: string[] = []
i++
while (i < lines.length && !lines[i].startsWith('```')) { code.push(lines[i]); i++ }
nodes.push(
{lang && {lang}}
{code.join('\n')}
)
} else if (line.startsWith('# ')) {
nodes.push({error}
)} {showForm && (Chargement…
} {!loading && notes.length === 0 && (Aucune note
)}