"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TreeItem = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const Collapse_1 = require("../../Collapse");
const Tooltip_1 = require("../../Tooltip");
const constants_1 = require("./constants");
const styles_1 = require("./styles");
const useLogic_1 = require("./useLogic");
const TreeItem = (props) => {
    const { isOpen, handleToggle, itemProps, itemContentProps, tooltipProps } = (0, useLogic_1.useLogic)(props);
    const { id, prefixId, label, note, renderItem, children, className, isSelected, isDisabled = false, disabledReason, isDefaultExpanded, isForceExpanded, isNotBlockingExpandList = false, level = 0, component = 'div', onClick, ...restProps } = props;
    const renderCollapseButton = () => ((0, jsx_runtime_1.jsx)(styles_1.CollapseButton, { "$isNotBlockingExpandList": isNotBlockingExpandList, disabled: !isNotBlockingExpandList && isDisabled, variant: "text", onClick: handleToggle, children: (0, jsx_runtime_1.jsx)(styles_1.ChevronIcon, { "$isActive": isOpen }) }));
    if (children) {
        return ((0, jsx_runtime_1.jsxs)(styles_1.Item, { ...restProps, "$level": level, as: component, className: className, ...itemProps, children: [(0, jsx_runtime_1.jsx)(styles_1.ItemContent, { "$isSelected": isSelected, "$isDisabled": isDisabled, "$level": level, ...itemContentProps, children: (0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { placement: constants_1.TOOLTIP_PLACEMENT, ...tooltipProps, children: renderItem ? ((0, jsx_runtime_1.jsxs)(styles_1.LabelWrapper, { "$level": level, children: [renderCollapseButton(), renderItem({ label, note, id })] })) : ((0, jsx_runtime_1.jsxs)(styles_1.ItemWrapper, { children: [(0, jsx_runtime_1.jsxs)(styles_1.LabelWrapper, { "$level": level, children: [renderCollapseButton(), (0, jsx_runtime_1.jsx)(styles_1.Label, { component: "div", children: label })] }), note && ((0, jsx_runtime_1.jsx)(styles_1.Note, { className: constants_1.treeClassnames.note, variant: "caption", color: "textSecondary", children: note }))] })) }) }), (0, jsx_runtime_1.jsx)(Collapse_1.Collapse, { in: isOpen, unmountOnExit: true, children: children })] }));
    }
    return ((0, jsx_runtime_1.jsx)(styles_1.Item, { ...restProps, "$level": level, as: component, className: className, ...itemProps, children: (0, jsx_runtime_1.jsx)(styles_1.ItemContent, { "$isSelected": isSelected, "$isDisabled": isDisabled, "$level": level, ...itemContentProps, children: (0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, { placement: constants_1.TOOLTIP_PLACEMENT, ...tooltipProps, children: renderItem ? ((0, jsx_runtime_1.jsx)(styles_1.LabelWrapper, { "$level": level, children: renderItem({ label, note, id }) })) : ((0, jsx_runtime_1.jsxs)(styles_1.ItemWrapper, { children: [(0, jsx_runtime_1.jsx)(styles_1.LabelWrapper, { "$level": level, children: (0, jsx_runtime_1.jsx)(styles_1.Label, { component: "div", children: label }) }), note && ((0, jsx_runtime_1.jsx)(styles_1.Note, { className: constants_1.treeClassnames.note, variant: "caption", color: "textSecondary", children: note }))] })) }) }) }));
};
exports.TreeItem = TreeItem;
