import React from "react"; import { useDispatch, useSelector } from "react-redux"; import useChat from "../../../hooks/useChat"; import useTime from "../../../hooks/useTime"; import { chatActions } from "../../../store/chatSlice"; import { modalActions } from "../../../store/modalSlice"; import { userProfileActions } from "../../../store/userProfileSlice"; import Header from "../../globals/Header"; import IconWrapper from "../../globals/IconWrapper"; import Image from "../../globals/Image"; import ActionsModal from "./ActionsModal"; function ChatHeader({ chatProfile, className }) { const dispatch = useDispatch(); const chatActive = useSelector((state) => state.chatReducer.active); const lastSeenTime = useTime(chatProfile?.status?.lastSeen); return (
{ if (chatActive) { dispatch(chatActions.setChatUnactive()); } else { dispatch(chatActions.setChatActive()); } }} className="chatArrow lg:flex mr-[2rem] hidden" > {/* */}
{ if (window.innerWidth <= 1000) { if (chatActive) { event.stopPropagation(); dispatch(userProfileActions.showProfile()); } } else { dispatch(userProfileActions.showProfile()); } }} className="flex-grow flex items-center gap-[1.5rem] cursor-pointer" > {chatProfile.name

{chatProfile.name || chatProfile.username}

{chatProfile.mode && ( {chatProfile.mode} {chatProfile.mode === "recording" && "audio"} ... )} {!chatProfile.mode && ( {chatProfile.status?.online ? "online" : `last seen at ${lastSeenTime}`} )}
{ dispatch( modalActions.openModal({ type: "actionsModal", positions: { top: 60, right: 30 }, }) ); }} >
); } export default ChatHeader;