import { BaseStyle, TabItemStyle } from "@cometchat/uikit-shared";
import {
CometChatConversationsWithMessages,
CometChatGroupsWithMessages,
CometChatTabs,
CometChatUsersWithMessages,
TabsStyle
} from "@cometchat/chat-uikit-react";
import { CometChatTabItem, TabAlignment } from "@cometchat/uikit-resources";
import { useEffect, useState } from "react";
import usersTabIcon from "./assets/users.svg";
import groupsTabIcon from "./assets/groups.svg";
import chatsTabIcon from "./assets/chats.svg";
export function CometChatUI() {
const [isMobileView, setIsMobileView] = useState(false);
const tabItemStyle = new TabItemStyle({
iconTint: "#6851D6",
width: "93px",
height: "auto",
activeTitleTextColor: "#6851D6",
background:'#fff',
activeIconTint:'#6851D6',
});
const tStyle = new TabsStyle({
tabListHeight: "50px",
tabListWidth: "280px",
});
const chatsTab = new CometChatTabItem({
id: "chats",
title: "Chats",
iconURL: chatsTabIcon,
style: tabItemStyle,
isActive: true,
childView: (
<CometChatConversationsWithMessages isMobileView={isMobileView} />
),
});
const usersTab = new CometChatTabItem({
id: "users",
title: "Users",
iconURL: usersTabIcon,
style: tabItemStyle,
childView: <CometChatUsersWithMessages />,
});
const groupsTab = new CometChatTabItem({
id: "groups",
title: "Groups",
iconURL: groupsTabIcon,
style: tabItemStyle,
childView: <CometChatGroupsWithMessages isMobileView={isMobileView} />,
});
const tabs = [chatsTab, usersTab, groupsTab];
const resizeWindow = () => {
const innerWidth = window.innerWidth;
if (innerWidth >= 320 && innerWidth <= 767) {
setIsMobileView(true);
} else {
setIsMobileView(false);
}
};
useEffect(() => {
resizeWindow();
window.addEventListener("resize", resizeWindow);
return () => window.removeEventListener("resize", resizeWindow);
}, []);
return (
<div style={{ width: "100%", height: "100%" }}>
<CometChatTabs
tabAlignment={TabAlignment.bottom}
tabs={tabs}
tabsStyle={tStyle}
/>
</div>
);
}