"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableRowWithDnd = void 0;
var react_1 = __importStar(require("react"));
var TableHeadCell_1 = require("../TableHeadCell");
var TableCell_1 = require("../TableCell");
var TableCellWithDnd_1 = require("../TableCellWithDnd");
var types_1 = require("../../types");
var core_1 = require("@dnd-kit/core");
var TableRowWithDnd = function (_a) {
    var rowData = _a.rowData, columnsData = _a.columnsData, isMoveColumnEnabled = _a.isMoveColumnEnabled, setHoveredColumn = _a.setHoveredColumn, resetHoveredColumn = _a.resetHoveredColumn;
    var setDroppableNodeRef = (0, core_1.useDroppable)({
        id: rowData.id
    }).setNodeRef;
    var _b = (0, react_1.useState)(false), enableDropForRow = _b[0], setEnableDropForRow = _b[1];
    var _c = (0, react_1.useState)(false), rowIsDragging = _c[0], setRowIsDragging = _c[1];
    (0, core_1.useDndMonitor)({
        onDragStart: function (event) {
            if (event.active.data.current.type === types_1.DndItemTypes.Row) {
                setEnableDropForRow(true);
                setRowIsDragging(event.active.id === rowData.id);
            }
        },
        onDragEnd: function () {
            setRowIsDragging(false);
            setEnableDropForRow(false);
        }
    });
    var rowStyle = (0, react_1.useMemo)(function () { return ({ opacity: rowIsDragging ? 0 : 1 }); }, [rowIsDragging]);
    return (react_1.default.createElement("tr", { className: rowData.rowClassName, style: rowStyle, ref: enableDropForRow ? setDroppableNodeRef : undefined },
        react_1.default.createElement(TableHeadCell_1.TableHeadCell, { rowData: rowData, isDraggable: true, columnsData: columnsData }),
        columnsData.map(function (columnValue, index) {
            return isMoveColumnEnabled ? (react_1.default.createElement(TableCellWithDnd_1.TableCellWithDnd, { key: columnValue.id || index, columnValue: columnValue, rowData: rowData, index: index, shouldRenderDragIndicator: false, setHoveredColumn: setHoveredColumn, resetHoveredColumn: resetHoveredColumn, rowIsDragging: rowIsDragging })) : (react_1.default.createElement(TableCell_1.TableCell, { key: columnValue.id || index, columnValue: columnValue, rowData: rowData, setHoveredColumn: setHoveredColumn, resetHoveredColumn: resetHoveredColumn, rowIsDragging: rowIsDragging }));
        })));
};
exports.TableRowWithDnd = TableRowWithDnd;
