import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { useCallback, useMemo } from "react";
import cx from "classnames";
import { simplifyText } from "@gooddata/util";
import { Bubble } from "../../Bubble/Bubble.js";
import { BubbleHoverTrigger } from "../../Bubble/BubbleHoverTrigger.js";
import { ShortenedText } from "../../ShortenedText/ShortenedText.js";
const ICON_TOOLTIP_ALIGN_POINTS = [
    { align: "cr cl", offset: { x: 10, y: 0 } },
    { align: "cl cr", offset: { x: -10, y: 0 } },
];
const TEXT_TOOLTIP_ALIGN_POINTS = [
    { align: "tc bc", offset: { x: 0, y: 0 } },
    { align: "bc tc", offset: { x: 0, y: 0 } },
];
/**
 * @internal
 */
export function DialogListItemBasic({ item, className, onClick, onDelete }) {
    const { id, title, subtitle, isDisabled = false, isClickable = true, isDeletable = true, icon, action, deleteTooltipText, badgeAfter, } = item;
    const rootClassNames = useMemo(() => cx("gd-dialog-list-item-basic", "s-dialog-list-item-basic", `s-dialog-list-item-${simplifyText(id)}`, {
        clickable: !isDisabled && isClickable,
        disabled: isDisabled,
    }, className), [id, isClickable, isDisabled, className]);
    const showDeleteButton = useMemo(() => (!isDisabled || !!action) && isDeletable, [isDisabled, isDeletable, action]);
    const handleItemClick = useCallback(() => {
        if (!isDisabled && isClickable) {
            onClick?.(item);
        }
    }, [isDisabled, isClickable, item, onClick]);
    const handleItemDelete = useCallback(() => {
        if (!isDisabled && isDeletable) {
            onDelete?.(item);
        }
    }, [isDisabled, isDeletable, item, onDelete]);
    return (_jsxs("div", { role: "dialog-list-item", className: rootClassNames, children: [showDeleteButton ? (_jsx("div", { className: "gd-dialog-list-item-delete", children: _jsxs(BubbleHoverTrigger, { showDelay: 0, hideDelay: 0, children: [
                        _jsx("span", { role: "icon-delete", className: cx("gd-dialog-list-item-delete-icon s-dialog-list-item-delete-icon", {
                                disabled: isDisabled,
                            }), onClick: handleItemDelete }), deleteTooltipText ? (_jsx(Bubble, { className: "bubble-primary", alignPoints: ICON_TOOLTIP_ALIGN_POINTS, children: deleteTooltipText })) : null] }) })) : null, action ? _jsx("div", { className: "gd-dialog-list-item-action", children: action }) : null, _jsxs("div", { role: "dialog-list-item-content", className: "gd-dialog-list-item-content s-dialog-list-item-content", onClick: handleItemClick, children: [icon ? _jsx("div", { className: "gd-dialog-list-item-icon", children: icon }) : null, _jsxs("div", { className: "gd-dialog-list-item-text s-dialog-list-item-text", children: [
                            _jsxs("div", { className: "gd-dialog-list-item-title s-dialog-list-item-title", children: [
                                    _jsx(ShortenedText, { className: "gd-dialog-list-item-shortened-text", tooltipAlignPoints: TEXT_TOOLTIP_ALIGN_POINTS, children: title }), badgeAfter ? (_jsx("div", { className: "gd-dialog-list-item-badge-after", children: badgeAfter })) : null] }), subtitle ? (_jsx("div", { className: "gd-dialog-list-item-subtitle s-dialog-list-item-subtitle", children: _jsx(ShortenedText, { className: "gd-dialog-list-item-shortened-text", tooltipAlignPoints: TEXT_TOOLTIP_ALIGN_POINTS, children: subtitle }) })) : null] })
                ] })
        ] }));
}
