import DeleteIcon from "../icons/delete.svg";
import styles from "./home.module.scss";
import BotIcon from "../icons/bot.svg";
import {
DragDropContext,
Droppable,
Draggable,
OnDragEndResponder,
} from "@hello-pangea/dnd";
import { useChatStore } 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;
id: number;
index: number;
}) {
const [sidebarCollapse] = useChatStore((state) => [state.sidebarCollapse]);
return sidebarCollapse ? (
{(provided) => (
{Locale.ChatItem.ChatItemCount(props.count).replace(/[^0-9]/g, "")
.length <= 3
? Locale.ChatItem.ChatItemCount(props.count).replace(
/[^0-9]/g,
"",
)
: ":)"}
)}
) : (
{(provided) => (
{props.title}
{Locale.ChatItem.ChatItemCount(props.count)}
{props.time}
)}
);
}
export function ChatList() {
const [
sidebarCollapse,
sessions,
selectedIndex,
selectSession,
removeSession,
moveSession,
] = useChatStore((state) => [
state.sidebarCollapse,
state.sessions,
state.currentSessionIndex,
state.selectSession,
state.removeSession,
state.moveSession,
]);
const chatStore = useChatStore();
const onDragEnd: OnDragEndResponder = (result) => {
const { destination, source } = result;
if (!destination) {
return;
}
if (
destination.droppableId === source.droppableId &&
destination.index === source.index
) {
return;
}
moveSession(source.index, destination.index);
};
return (
<>
{sidebarCollapse && (
)}
{(provided: any) => (
{sessions.map((item, i) => (
selectSession(i)}
onDelete={chatStore.deleteSession}
/>
))}
{provided.placeholder}
)}
>
);
}