import { __assign } from "tslib";
import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { TreeArrow } from '../_utils/components';
import CollapseTransition from '../collapse-transition';
import Checkbox from '../checkbox/checkbox';
var TreeNode = function (props) {
    var _a, _b;
    var indent = props.indent, blockNode = props.blockNode, level = props.level, node = props.node, checkable = props.checkable, className = props.className, treeClassName = props.treeClassName, onCheckboxChange = props.onCheckboxChange, onExpandChange = props.onExpandChange, customisedCls = props.prefixCls;
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('tree-node', configContext.prefixCls, customisedCls);
    var title = node.title, checked = node.checked, icon = node.icon, expanded = node.expanded, disableCheckbox = node.disableCheckbox, indeterminate = node.indeterminate;
    var nodeIcon = icon || props.icon;
    var disabled = node.disabled || props.disabled;
    var cls = classNames(prefixCls, className, (_a = {},
        _a[prefixCls + "_block"] = blockNode,
        _a[prefixCls + "_disabled"] = disabled,
        _a));
    var switcherOnClick = function (e) {
        e.stopPropagation();
        onExpandChange(node.uniqueKey, !expanded, e);
    };
    var checkboxOnChange = function (e) {
        e.stopPropagation();
        onCheckboxChange(node.uniqueKey, e);
    };
    return (React.createElement("li", { className: cls },
        React.createElement("div", { className: prefixCls + "__title", style: { paddingLeft: indent * level } },
            React.createElement("span", { className: prefixCls + "__switcher", onClick: switcherOnClick }, node.children &&
                (nodeIcon ? (nodeIcon(expanded)) : (React.createElement(TreeArrow, { className: classNames(prefixCls + "__arrow", (_b = {},
                        _b[prefixCls + "__arrow_active"] = expanded,
                        _b)) })))),
            checkable && (React.createElement(Checkbox, { checked: checked, indeterminate: indeterminate, onChange: checkboxOnChange, disabled: disabled || disableCheckbox })),
            React.createElement("span", { className: prefixCls + "__label", onClick: switcherOnClick }, title)),
        node.children && (React.createElement(CollapseTransition, { isShow: expanded },
            React.createElement("ul", { className: treeClassName, "aria-level": level + 1 }, node.children &&
                node.children.map(function (node) { return (React.createElement(TreeNode, __assign({}, props, { key: node.uniqueKey, node: node, level: level + 1 }))); }))))));
};
TreeNode.displayName = 'TreeNode';
export default TreeNode;
//# sourceMappingURL=tree-node.js.map