import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { TrashBin } from '@gravity-ui/icons';
import { Icon, Text } from '@gravity-ui/uikit';
import { block } from "../../../utils/cn.js";
import { ActionButton } from "../../atoms/ActionButton/index.js";
import { i18n } from "./i18n/index.js";
const b = block('history');
/**
 * Chat item component with hover state for actions
 *
 * @returns React element
 */
export function ChatItem({ chat, showActions, isActive, onDeleteClick }) {
    const [isDeleteProccesing, setIsDeleteProcessing] = useState(false);
    const handleClick = (e) => {
        if (isDeleteProccesing) {
            e.stopPropagation();
        }
    };
    const handleDeleteChat = async (e) => {
        try {
            setIsDeleteProcessing(true);
            await (onDeleteClick === null || onDeleteClick === void 0 ? void 0 : onDeleteClick(e, chat));
        }
        finally {
            setIsDeleteProcessing(false);
        }
    };
    const showDeleteAction = isDeleteProccesing || (showActions && onDeleteClick);
    return (_jsxs("div", { className: b('chat-item', {
            active: isActive,
            ['is-delete-processing']: isDeleteProccesing,
        }), onClick: handleClick, children: [_jsx("div", { className: b('chat-content'), children: _jsx(Text, { variant: "body-1", children: chat.lastMessage || chat.name }) }), showDeleteAction ? (_jsx(ActionButton, { view: "flat", size: "s", color: "secondary", loading: isDeleteProccesing, className: b('delete-button'), onClick: handleDeleteChat, tooltipTitle: i18n('tooltip-delete'), children: _jsx(Icon, { className: b('icon-button'), data: TrashBin, size: 16 }) })) : null] }));
}
//# sourceMappingURL=ChatItem.js.map
