var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { isDescendant } from '../../helpers/tree';
//import {useStyles} from './nodeRendererDefaultStyle';
export var NodeRendererDefault = function (_a) {
    var scaffoldBlockPxWidth = _a.scaffoldBlockPxWidth, toggleChildrenVisibility = _a.toggleChildrenVisibility, connectDragPreview = _a.connectDragPreview, connectDragSource = _a.connectDragSource, isDragging = _a.isDragging, canDrop = _a.canDrop, canDrag = _a.canDrag, node = _a.node, title = _a.title, subtitle = _a.subtitle, draggedNode = _a.draggedNode, path = _a.path, treeIndex = _a.treeIndex, isSearchMatch = _a.isSearchMatch, isSearchFocus = _a.isSearchFocus, buttons = _a.buttons, className = _a.className, style = _a.style, didDrop = _a.didDrop, 
    /* eslint-disable */
    treeId = _a.treeId, isOver = _a.isOver, // Not needed, but preserved for other renderers
    parentNode = _a.parentNode, // Needed for dndManager
    /* eslint-enable */
    rowDirection = _a.rowDirection, otherProps = __rest(_a, ["scaffoldBlockPxWidth", "toggleChildrenVisibility", "connectDragPreview", "connectDragSource", "isDragging", "canDrop", "canDrag", "node", "title", "subtitle", "draggedNode", "path", "treeIndex", "isSearchMatch", "isSearchFocus", "buttons", "className", "style", "didDrop", "treeId", "isOver", "parentNode", "rowDirection"]);
    //useStyles();
    var nodeTitle = title || node.title;
    var nodeSubtitle = subtitle || node.subtitle;
    var rowDirectionClass = rowDirection === 'rtl' ? 'rst__rtl' : null;
    var handle;
    if (canDrag) {
        if (typeof node.children === 'function' && node.expanded) {
            // Show a loading symbol on the handle when the children are expanded
            //  and yet still defined by a function (a callback to fetch the children)
            handle = (React.createElement("div", { className: "rst__loadingHandle" },
                React.createElement("div", { className: "rst__loadingCircle" }, __spreadArray([], new Array(12), true).map(function (_, index) { return (React.createElement("div", { key: index, className: classnames('rst__loadingCirclePoint', rowDirectionClass) })); }))));
        }
        else {
            // Show the handle used to initiate a drag-and-drop
            handle = connectDragSource(React.createElement("div", { className: "rst__moveHandle" }), {
                dropEffect: 'copy'
            });
        }
    }
    var isDraggedDescendant = draggedNode && isDescendant(draggedNode, node);
    var isLandingPadActive = !didDrop && isDragging;
    var buttonStyle = { left: -0.5 * scaffoldBlockPxWidth };
    if (rowDirection === 'rtl') {
        buttonStyle = { right: -0.5 * scaffoldBlockPxWidth };
    }
    return (React.createElement("div", __assign({ style: { height: '100%' } }, otherProps),
        toggleChildrenVisibility &&
            node.children &&
            (node.children.length > 0 || typeof node.children === 'function') && (React.createElement("div", null,
            React.createElement("button", { type: "button", "aria-label": node.expanded ? 'Collapse' : 'Expand', className: classnames(node.expanded ? 'rst__collapseButton' : 'rst__expandButton', rowDirectionClass), style: buttonStyle, onClick: function () {
                    return toggleChildrenVisibility({
                        node: node,
                        path: path,
                        treeIndex: treeIndex
                    });
                } }),
            node.expanded && !isDragging && (React.createElement("div", { style: { width: scaffoldBlockPxWidth }, className: classnames('rst__lineChildren', rowDirectionClass) })))),
        React.createElement("div", { className: classnames('rst__rowWrapper', rowDirectionClass) }, connectDragPreview(React.createElement("div", { className: classnames('rst__row', isLandingPadActive && 'rst__rowLandingPad', isLandingPadActive && !canDrop && 'rst__rowCancelPad', isSearchMatch && 'rst__rowSearchMatch', isSearchFocus && 'rst__rowSearchFocus', rowDirectionClass, className), style: __assign({ opacity: isDraggedDescendant ? 0.5 : 1 }, style) },
            handle,
            React.createElement("div", { className: classnames('rst__rowContents', !canDrag && 'rst__rowContentsDragDisabled', rowDirectionClass) },
                React.createElement("div", { className: classnames('rst__rowLabel', rowDirectionClass) },
                    React.createElement("span", { className: classnames('rst__rowTitle', node.subtitle && 'rst__rowTitleWithSubtitle') }, typeof nodeTitle === 'function'
                        ? nodeTitle({
                            node: node,
                            path: path,
                            treeIndex: treeIndex
                        })
                        : nodeTitle),
                    nodeSubtitle && (React.createElement("span", { className: "rst__rowSubtitle" }, typeof nodeSubtitle === 'function'
                        ? nodeSubtitle({
                            node: node,
                            path: path,
                            treeIndex: treeIndex
                        })
                        : nodeSubtitle))),
                React.createElement("div", { className: "rst__rowToolbar" }, buttons.map(function (btn, index) { return (React.createElement("div", { key: index, className: "rst__toolbarButton" }, btn)); }))))))));
};
NodeRendererDefault.defaultProps = {
    isSearchMatch: false,
    isSearchFocus: false,
    canDrag: false,
    toggleChildrenVisibility: null,
    buttons: [],
    className: '',
    style: {},
    parentNode: null,
    draggedNode: null,
    canDrop: false,
    title: null,
    subtitle: null,
    rowDirection: 'ltr'
};
NodeRendererDefault.propTypes = {
    node: PropTypes.shape({}).isRequired,
    title: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
    subtitle: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
    path: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])).isRequired,
    treeIndex: PropTypes.number.isRequired,
    treeId: PropTypes.string.isRequired,
    isSearchMatch: PropTypes.bool,
    isSearchFocus: PropTypes.bool,
    canDrag: PropTypes.bool,
    scaffoldBlockPxWidth: PropTypes.number.isRequired,
    toggleChildrenVisibility: PropTypes.func,
    buttons: PropTypes.arrayOf(PropTypes.node),
    className: PropTypes.string,
    style: PropTypes.shape({}),
    // Drag and drop API functions
    // Drag source
    connectDragPreview: PropTypes.func.isRequired,
    connectDragSource: PropTypes.func.isRequired,
    parentNode: PropTypes.shape({}), // Needed for dndManager
    isDragging: PropTypes.bool.isRequired,
    didDrop: PropTypes.bool.isRequired,
    draggedNode: PropTypes.shape({}),
    // Drop target
    isOver: PropTypes.bool.isRequired,
    canDrop: PropTypes.bool,
    // rtl support
    rowDirection: PropTypes.string
};
