import { useEffect, useRef, useState } from "react"; import { Stack, Group, Text, Badge, Paper, ScrollArea, TextInput, ActionIcon, Center, ThemeIcon, Box, CopyButton, Tooltip, } from "@mantine/core"; import { IconLock, IconHash, IconSend, IconMessages, IconCopy, IconCheck, } from "@tabler/icons-react"; import type { Message, Room } from "../types"; interface Props { room: Room | null; messages: Message[]; myEndpoint: string; nameFor: (endpoint: string) => string; onPublish: (text: string) => void; } // formatTime renders a message timestamp as HH:mm:ss in 24h European style. function formatTime(ts: number): string { return new Date(ts).toLocaleTimeString("es-ES", { hour: "2-digit", minute: "2-digit", second: "2-digit", }); } // MessagePane is the center column: the active room's live message log plus the // composer. Own messages align right; others align left and show the sender. export function MessagePane({ room, messages, myEndpoint, nameFor, onPublish }: Props) { const [text, setText] = useState(""); const viewport = useRef(null); // Auto-scroll to the newest message. useEffect(() => { viewport.current?.scrollTo({ top: viewport.current.scrollHeight, behavior: "smooth" }); }, [messages.length]); if (!room) { return (
Elige o crea una room para empezar a chatear
); } const send = () => { const t = text.trim(); if (t) { onPublish(t); setText(""); } }; return ( {room.encrypt ? : } {room.subject} {room.encrypt && ( cifrada E2E )} {({ copied, copy }) => ( {copied ? : } )} {messages.length === 0 && ( No hay mensajes todavía. )} {messages.map((m) => { const mine = m.sender === myEndpoint; return ( {!mine && ( {nameFor(m.sender)} )} {m.text} {formatTime(m.ts)} ); })} setText(e.currentTarget.value)} onKeyDown={(e) => e.key === "Enter" && send()} /> ); }