'use client' import React, { useEffect, useRef } from 'react' import { createPortal } from 'react-dom' import type { Editor } from '@tiptap/core' import { Trash2, Copy, FileText, Sparkles, Lightbulb, Scissors, Wand2, Expand, X, CheckSquare, Quote, Heading1, Heading2, Heading3 } from 'lucide-react' import { useLanguage } from '@/lib/i18n' import { toast } from 'sonner' export type MobileActionSheetProps = { editor: Editor | null isOpen: boolean onClose: () => void } export function MobileActionSheet({ editor, isOpen, onClose, }: MobileActionSheetProps) { const { t } = useLanguage() const sheetRef = useRef(null) useEffect(() => { if (!isOpen) return function handleClickOutside(e: MouseEvent) { if (sheetRef.current && !sheetRef.current.contains(e.target as Node)) { onClose() } } document.addEventListener('mousedown', handleClickOutside) return () => document.removeEventListener('mousedown', handleClickOutside) }, [isOpen, onClose]) if (!isOpen || !editor) return null const handleSelectAllBlock = () => { const { from } = editor.state.selection const $pos = editor.state.doc.resolve(from) const depth = $pos.depth if (depth === 0) return const start = $pos.start(1) const end = $pos.end(1) editor.chain().focus().setTextSelection({ from: start, to: end }).run() toast.success(t('richTextEditor.blockSelected') || 'Bloc sélectionné en entier') onClose() } const handleDuplicateBlock = () => { const { from } = editor.state.selection const $pos = editor.state.doc.resolve(from) const depth = $pos.depth if (depth === 0) return const start = $pos.before(1) const end = $pos.after(1) const nodeText = editor.state.doc.slice(start, end) editor.chain().focus().insertContentAt(end, nodeText.content.toJSON()).run() toast.success(t('richTextEditor.blockDuplicated') || 'Bloc dupliqué') onClose() } const handleDeleteBlock = () => { const { from } = editor.state.selection const $pos = editor.state.doc.resolve(from) const depth = $pos.depth if (depth === 0) return const start = $pos.before(1) const end = $pos.after(1) editor.chain().focus().deleteRange({ from: start, to: end }).run() toast.success(t('richTextEditor.blockDeleted') || 'Bloc supprimé') onClose() } const handleAiAction = (action: 'clarify' | 'shorten' | 'improve' | 'expand') => { // Déclenche l'appel IA en émettant un événement personnalisé ou en modifiant le contenu // Réutilisons l'API IA existante ou ouvrons le panneau IA d'actions onClose() const tab = action === 'improve' ? 'actions' : 'chat' window.dispatchEvent(new CustomEvent('memento-open-ai', { detail: { tab, scroll: action } })) toast.info(t('richTextEditor.aiActionStarted') || 'IA Note sollicitée...') } return createPortal(
{/* Section 1 : Actions de bloc */}

{t('mobile.blockActions') || 'Actions sur le bloc'}

{/* Section 2 : IA Note */}

{t('mobile.aiNote') || 'IA Note'}

{/* Section 3 : Format de bloc */}

{t('mobile.convertFormat') || 'Convertir le format'}

, document.body, ) }