import { jsxs, jsx } from 'react/jsx-runtime';
import React__default, { useRef, useState, useEffect } from 'react';
import Checkbox from '../../Checkbox/Checkbox.js';
import RadioButton from '../../RadioButton/RadioButton.js';
import { prepareData } from '../../../utils/TableCell/TableCell.js';
import { formatCellData } from '../Utils/formatDataCell.js';

const TableHead = React__default.memo(({ columnsData, rootNode, selected, onCheckBoxChange, selectedNode, tableHeaderBgColor, hideOnDisable, transparentHeader, scriptLengthTruncate = 25, }) => {
    // const hasDefaultValues = useMemo(
    //   () => columnsData.some(({ defaultValue }) => !!defaultValue),
    //   [columnsData]
    // );
    const rootNodeRowRef = useRef(null);
    const [isMounted, setIsMounted] = useState(false);
    useEffect(() => {
        setIsMounted(true);
    }, []);
    return (jsxs("thead", { className: "ff-table-tree-head", children: [jsx("tr", { className: "ff-table-tree-row no-hover", children: columnsData.map(({ name, width }) => (jsx("th", { className: "ff-table-tree-th", style: {
                        width: width,
                        backgroundColor: transparentHeader
                            ? 'transparent'
                            : tableHeaderBgColor,
                    }, children: name }, name))) }), rootNode && (jsx("tr", { className: `ff-table-tree-row show ${selectedNode && selectedNode === rootNode?.node?.key
                    ? 'hover'
                    : ''}`, ref: rootNodeRowRef, children: columnsData.map((col, index) => (jsx("td", { className: "ff-table-tree-td", children: jsxs("span", { className: "tree-table-default-content", children: [index === 0 &&
                                rootNode.select === 'checkbox' &&
                                !(hideOnDisable && rootNode.node.isDisabled) && (jsx(Checkbox, { checked: rootNode?.node?.selectedStatus !== 'partially' &&
                                    (rootNode?.node?.selectedStatus === 'completely' ||
                                        false), partial: rootNode.node.selectedStatus === 'partially', onChange: (e) => onCheckBoxChange(e, rootNode.node), disabled: rootNode.node.isDisabled })), index === 0 &&
                                rootNode.select === 'radio' &&
                                !(hideOnDisable && rootNode.node.isDisabled) && (jsx(RadioButton, { name: rootNode.node.key, checked: selected.includes(rootNode.node.key), value: rootNode.node.key, onChange: (e) => onCheckBoxChange(e, rootNode.node), disabled: rootNode.node.isDisabled })), jsxs("span", { className: "tree-table-td-content-text", children: [col.accessor === 'name' ? (jsx("span", { children: rootNode.node[col.accessor] })) : (jsx("span", { children: formatCellData(prepareData(rootNode.node, col), scriptLengthTruncate) })), rootNode.cell && index === 0 && (jsx("span", { className: "table-tree-root-cell", children: (() => {
                                            return rootNode.cell(rootNode.node);
                                        })() }))] }), rootNode.actions &&
                                index === 0 &&
                                isMounted &&
                                rootNodeRowRef.current && (jsx("div", { className: "table-tree-row-action", children: (() => {
                                    return rootNode.actions(rootNode.node, rootNodeRowRef);
                                })() }))] }) }, index))) }))] }));
});

export { TableHead as default };
//# sourceMappingURL=TableHead.js.map
