import { useState, useRef, useEffect, useLayoutEffect } from "react";
import DeleteIcon from "../icons/delete.svg";
import styles from "./home.module.scss";
import BotIcon from "../icons/bot.svg";
import {
Message,
SubmitKey,
useChatStore,
ChatSession,
BOT_HELLO,
} from "../store";
import Locale from "../locales";
import { isMobileScreen } from "../utils";
export function ChatItem(props: {
onClick?: () => void;
onDelete?: () => void;
title: string;
count: number;
time: string;
selected: boolean;
}) {
const [sidebarCollapse] = useChatStore((state) => [state.sidebarCollapse]);
return sidebarCollapse ? (
{Locale.ChatItem.ChatItemCount(props.count).replace(/[^0-9]/g, "")
.length <= 3
? Locale.ChatItem.ChatItemCount(props.count).replace(/[^0-9]/g, "")
: ":)"}
) : (
{props.title}
{Locale.ChatItem.ChatItemCount(props.count)}
{props.time}
);
}
export function ChatList() {
const [
sidebarCollapse,
sessions,
selectedIndex,
selectSession,
removeSession,
] = useChatStore((state) => [
state.sidebarCollapse,
state.sessions,
state.currentSessionIndex,
state.selectSession,
state.removeSession,
]);
return (
<>
{sidebarCollapse ? : null}
{sessions.map((item, i) => (
selectSession(i)}
onDelete={() => confirm(Locale.Home.DeleteChat) && removeSession(i)}
/>
))}
>
);
}