'use client' import {useState, useEffect} from 'react' import PropTypes from 'prop-types' import dynamic from 'next/dynamic' import Box from '@mui/material/Box' import Typography from '@mui/material/Typography' import {useTheme} from '@mui/material/styles' const MDEditor = dynamic( () => import('@uiw/react-md-editor').then(mod => mod.default), {ssr: false} ) export default function RichTextEditor({ value = '', onChange, placeholder = 'Rédigez votre contenu...', label, isRequired = false, name = 'content' }) { const [content, setContent] = useState(value) const [wordCount, setWordCount] = useState(0) const [charCount, setCharCount] = useState(0) const theme = useTheme() useEffect(() => { setContent(value) }, [value]) useEffect(() => { if (content) { const words = content.trim().split(/\s+/).filter(word => word.length > 0) setWordCount(words.length) setCharCount(content.length) } else { setWordCount(0) setCharCount(0) } }, [content]) const handleChange = val => { setContent(val || '') if (onChange) { onChange({ target: { name, value: val || '' } }) } } return ( {label && ( {label} {isRequired && '*'} )} Formatage Markdown supporté {charCount} caractères • {wordCount} mots {/* Hidden input for form submission */} ) } RichTextEditor.propTypes = { value: PropTypes.string, onChange: PropTypes.func, placeholder: PropTypes.string, label: PropTypes.string, isRequired: PropTypes.bool, name: PropTypes.string }