import React, { useMemo, useState } from 'react';
import { TableHeadCell } from '../TableHeadCell';
import { TableCell } from '../TableCell';
import { TableCellWithDnd } from '../TableCellWithDnd';
import { DndItemTypes } from '../../types';
import { useDndMonitor, useDroppable } from '@dnd-kit/core';
export var TableRowWithDnd = function (_a) {
    var rowData = _a.rowData, columnsData = _a.columnsData, isMoveColumnEnabled = _a.isMoveColumnEnabled, setHoveredColumn = _a.setHoveredColumn, resetHoveredColumn = _a.resetHoveredColumn;
    var setDroppableNodeRef = useDroppable({
        id: rowData.id
    }).setNodeRef;
    var _b = useState(false), enableDropForRow = _b[0], setEnableDropForRow = _b[1];
    var _c = useState(false), rowIsDragging = _c[0], setRowIsDragging = _c[1];
    useDndMonitor({
        onDragStart: function (event) {
            if (event.active.data.current.type === DndItemTypes.Row) {
                setEnableDropForRow(true);
                setRowIsDragging(event.active.id === rowData.id);
            }
        },
        onDragEnd: function () {
            setRowIsDragging(false);
            setEnableDropForRow(false);
        }
    });
    var rowStyle = useMemo(function () { return ({ opacity: rowIsDragging ? 0 : 1 }); }, [rowIsDragging]);
    return (React.createElement("tr", { className: rowData.rowClassName, style: rowStyle, ref: enableDropForRow ? setDroppableNodeRef : undefined },
        React.createElement(TableHeadCell, { rowData: rowData, isDraggable: true, columnsData: columnsData }),
        columnsData.map(function (columnValue, index) {
            return isMoveColumnEnabled ? (React.createElement(TableCellWithDnd, { key: columnValue.id || index, columnValue: columnValue, rowData: rowData, index: index, shouldRenderDragIndicator: false, setHoveredColumn: setHoveredColumn, resetHoveredColumn: resetHoveredColumn, rowIsDragging: rowIsDragging })) : (React.createElement(TableCell, { key: columnValue.id || index, columnValue: columnValue, rowData: rowData, setHoveredColumn: setHoveredColumn, resetHoveredColumn: resetHoveredColumn, rowIsDragging: rowIsDragging }));
        })));
};
