import { NestedTableParentCell } from './NestedTableParentCell';
import React from 'react';
import { useCreateWSRColumnBase } from '../../hooks/useCreateWSRColumnBase';
import { useNestedTableActionCell } from './useNestedTableActionCell';
import { NestedTableMainColumnTitle } from './NestedTableMainColumnTitle';
export function useNestedModeColumns(props) {
    const { state, actionCellProps, actionCellWidth, horizontalScroll, dragAndDrop, } = props;
    const { toolbar } = state;
    const { selectedOrderedColumnsOrAll } = toolbar;
    const createWSRColumnBase = useCreateWSRColumnBase({ horizontalScroll, showFieldTypeIcons: toolbar.showFieldTypeIcons });
    const actionCellColumn = useNestedTableActionCell({
        state: state.nested,
        actionCellWidth,
        actionCellProps,
    });
    const mainColumn = {
        key: 'nested-mode-main-column',
        dataHook: 'nested-mode-main-column',
        title: React.createElement(NestedTableMainColumnTitle, { state: state }),
        width: state.mainColumn?.width || '326px',
        style: undefined,
        render: (keyedItem, rowNum) => {
            if (keyedItem.item.originalKeyedItem) {
                return (React.createElement(NestedTableParentCell, { state: keyedItem.item.state, item: keyedItem.item, rowNum: rowNum, dragAndDrop: dragAndDrop }));
            }
            return null;
        },
    };
    const passedColumns = selectedOrderedColumnsOrAll.map((column) => {
        const { id, sortable } = column;
        return {
            ...column,
            sortDescending: sortable && id ? state.query.sort.getIsSortDescending(id) : undefined,
            render: ({ item }, rowNum) => {
                if (item.originalKeyedItem) {
                    return item.state.columns?.[id]?.(item.originalKeyedItem.item, rowNum);
                }
                return null;
            },
        };
    });
    return [
        ...[mainColumn, ...passedColumns].map((column, index, { length }) => {
            return {
                ...column,
                ...createWSRColumnBase(column, index, length),
            };
        }),
        ...(actionCellColumn ? [actionCellColumn] : []),
    ];
}
//# sourceMappingURL=useNestedModeColumns.js.map