import { useEffect } from "react"; import { navigate } from "../router"; import { useT } from "../i18n"; import { ChatView } from "./ChatView"; import { Icon } from "./Icon"; /** Desktop only: chats of the factory open over the board and are closed with one click. */ export const isDesktop = () => window.matchMedia("(min-width: 801px)").matches; /** Open the chat of a phase: in the overlay on the desktop, as a page on small screens. */ export function openFactoryChat(sessionId: string) { navigate(isDesktop() ? `/factory/s/${sessionId}` : `/s/${sessionId}`); } export function ChatOverlay({ id }: { id: string }) { const t = useT(); const close = () => navigate("/factory"); useEffect(() => { const onKey = (e: KeyboardEvent) => { // Esc closes – unless it is meant for a field, a dialog or the image viewer on top. const el = document.activeElement; const typing = el instanceof HTMLTextAreaElement || el instanceof HTMLInputElement || el instanceof HTMLSelectElement; if (e.key === "Escape" && !typing && !document.querySelector(".modal-backdrop, .viewer-overlay")) close(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, []); return (