"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChatItem = ChatItem;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const icons_1 = require("@gravity-ui/icons");
const uikit_1 = require("@gravity-ui/uikit");
const cn_1 = require("../../../utils/cn.js");
const ActionButton_1 = require("../../atoms/ActionButton/index.js");
const i18n_1 = require("./i18n/index.js");
const b = (0, cn_1.block)('history');
/**
 * Chat item component with hover state for actions
 *
 * @returns React element
 */
function ChatItem({ chat, showActions, isActive, onDeleteClick }) {
    const [isDeleteProccesing, setIsDeleteProcessing] = (0, react_1.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 ((0, jsx_runtime_1.jsxs)("div", { className: b('chat-item', {
            active: isActive,
            ['is-delete-processing']: isDeleteProccesing,
        }), onClick: handleClick, children: [(0, jsx_runtime_1.jsx)("div", { className: b('chat-content'), children: (0, jsx_runtime_1.jsx)(uikit_1.Text, { variant: "body-1", children: chat.lastMessage || chat.name }) }), showDeleteAction ? ((0, jsx_runtime_1.jsx)(ActionButton_1.ActionButton, { view: "flat", size: "s", color: "secondary", loading: isDeleteProccesing, className: b('delete-button'), onClick: handleDeleteChat, tooltipTitle: (0, i18n_1.i18n)('tooltip-delete'), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { className: b('icon-button'), data: icons_1.TrashBin, size: 16 }) })) : null] }));
}
//# sourceMappingURL=ChatItem.js.map
