import type { ReactNode, Ref } from "react"; import { forwardRef, useEffect, useState } from "react"; import { Badge, Box, Dialog, Fab, Modal, Slide, Typography, useMediaQuery, useTheme, } from "@mui/material"; import CircleDoubleDown from "./QuestionIcon"; import Chat from "./Chat"; import { TransitionProps } from "@mui/material/transitions"; import { useLocation } from "react-router-dom"; import { useTicketStore } from "@root/ticket"; import { useUserStore } from "@root/user"; import { TicketMessage } from "@frontend/kitui"; const animation = { "@keyframes runningStripe": { "0%": { left: "10%", backgroundColor: "transparent" }, "10%": { backgroundColor: "#ffffff" }, "50%": { backgroundColor: "#ffffff", transform: "translate(400px, 0)" }, "80%": { backgroundColor: "#ffffff" }, "100%": { backgroundColor: "transparent", boxShadow: "none", left: "100%" }, }, }; const Transition = forwardRef(function Transition( props: TransitionProps & { children: ReactNode; }, ref: Ref, ) { return ; }); interface Props { isChatOpened: boolean; handleChatClickOpen: () => void; handleChatClickClose: () => void; handleChatClickSwitch: () => void; sendMessage: (a: string) => Promise; sendFile: (a: File | undefined) => Promise; modalWarningType: string | null; setModalWarningType: any; greetingMessage: TicketMessage; } export default function FloatingSupportChat({ isChatOpened, handleChatClickOpen, handleChatClickClose, handleChatClickSwitch, sendMessage, sendFile, modalWarningType, setModalWarningType, greetingMessage, }: Props) { const [monitorType, setMonitorType] = useState<"desktop" | "mobile" | "">(""); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down(800)); const location = useLocation(); const locationChat = location.pathname; const user = useUserStore((state) => state.user?._id); const { messages } = useTicketStore( (state) => state[user ? "authData" : "unauthData"], ); useEffect(() => { const onResize = () => { if (document.fullscreenElement) { setMonitorType(isMobile ? "mobile" : "desktop"); return; } setMonitorType(""); }; window.addEventListener("resize", onResize); return () => { window.removeEventListener("resize", onResize); }; }, [isMobile]); return ( { handleChatClickSwitch(); }} > {!isChatOpened && ( )} shown?.me !== 1).length || 0 } sx={{ "& .MuiBadge-badge": { display: isChatOpened ? "none" : "flex", color: "#FFFFFF", background: theme.palette.brightPurple.main, top: "4px", right: "4px", transform: "scale(0.8) translate(50%, -50%)", }, }} > setModalWarningType(null)} > ); } const CurrentModal = ({ status }: { status: ["errorType" | "errorSize"] }) => { switch (status) { case null: return null; case "errorType": return Выбран некорректный тип файла; case "errorSize": return ( Файл слишком большой. Максимальный размер 50 МБ ); default: return <>; } };