import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Collapse } from '../../Collapse';
import { Tooltip } from '../../Tooltip';
import { TOOLTIP_PLACEMENT, treeClassnames } from './constants';
import { ChevronIcon, CollapseButton, Item, ItemContent, ItemWrapper, Label, LabelWrapper, Note, } from './styles';
import { useLogic } from './useLogic';
export const TreeItem = (props) => {
    const { isOpen, handleToggle, itemProps, itemContentProps, tooltipProps } = 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 = () => (_jsx(CollapseButton, { "$isNotBlockingExpandList": isNotBlockingExpandList, disabled: !isNotBlockingExpandList && isDisabled, variant: "text", onClick: handleToggle, children: _jsx(ChevronIcon, { "$isActive": isOpen }) }));
    if (children) {
        return (_jsxs(Item, { ...restProps, "$level": level, as: component, className: className, ...itemProps, children: [_jsx(ItemContent, { "$isSelected": isSelected, "$isDisabled": isDisabled, "$level": level, ...itemContentProps, children: _jsx(Tooltip, { placement: TOOLTIP_PLACEMENT, ...tooltipProps, children: renderItem ? (_jsxs(LabelWrapper, { "$level": level, children: [renderCollapseButton(), renderItem({ label, note, id })] })) : (_jsxs(ItemWrapper, { children: [_jsxs(LabelWrapper, { "$level": level, children: [renderCollapseButton(), _jsx(Label, { component: "div", children: label })] }), note && (_jsx(Note, { className: treeClassnames.note, variant: "caption", color: "textSecondary", children: note }))] })) }) }), _jsx(Collapse, { in: isOpen, unmountOnExit: true, children: children })] }));
    }
    return (_jsx(Item, { ...restProps, "$level": level, as: component, className: className, ...itemProps, children: _jsx(ItemContent, { "$isSelected": isSelected, "$isDisabled": isDisabled, "$level": level, ...itemContentProps, children: _jsx(Tooltip, { placement: TOOLTIP_PLACEMENT, ...tooltipProps, children: renderItem ? (_jsx(LabelWrapper, { "$level": level, children: renderItem({ label, note, id }) })) : (_jsxs(ItemWrapper, { children: [_jsx(LabelWrapper, { "$level": level, children: _jsx(Label, { component: "div", children: label }) }), note && (_jsx(Note, { className: treeClassnames.note, variant: "caption", color: "textSecondary", children: note }))] })) }) }) }));
};
