import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { useSortable } from '../../../node_modules/.pnpm/@dnd-kit_sortable@8.0.0_@dn_d0203b85309944898f6a8d832beb8e74/node_modules/@dnd-kit/sortable/dist/sortable.esm.js';
import classNames from '../../../_virtual/index.js';
import { memo, useMemo } from 'react';
import { prepareData } from '../../../utils/TableCell/TableCell.js';
import Checkbox from '../../Checkbox/Checkbox.js';
import Icon from '../../Icon/Icon.js';
import Typography from '../../Typography/Typography.js';
import PrePostStepAccordions from './PrePostStepAccordions.js';
import { CSS } from '../../../node_modules/.pnpm/@dnd-kit_utilities@3.2.2_react@18.3.1/node_modules/@dnd-kit/utilities/dist/utilities.esm.js';

const DraggableTableRow = ({ row, columns, tableBodyRowClass, handleOnclick, tableDataTextColor, withCheckbox, onSelectClick, draggable, indexNumber = 0, dataLength = 0, viewModeId, ViewComponent, handleClick, handleStepGroupExpand, isStepGroupExpanded, scriptType, }) => {
    const typeSet = new Set(['group', 'pre', 'post', 'script']);
    const showAccordion = typeSet.has(row?.entityType?.toLowerCase()) ||
        typeSet.has(row?.type?.toLowerCase());
    const isDisabled = row?.isDisabled;
    const rowId = row?._id || row?.stepId;
    const isPrePostTable = scriptType ? row.cascaded === 'cascaded' : false;
    const isDragDisabled = isDisabled || dataLength <= 1 || isPrePostTable;
    let serialNumber = (indexNumber + 1).toString();
    const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
        id: rowId,
        disabled: isDragDisabled,
    });
    const style = useMemo(() => ({
        transform: CSS.Transform.toString(transform),
        transition,
    }), [transform, transition]);
    const expanded = isStepGroupExpanded?.(row.stepId);
    return (jsxs(Fragment, { children: [jsx("tr", { ref: setNodeRef, style: style, className: classNames(tableBodyRowClass, {
                    'disabled-row': isDisabled,
                }), children: columns.map((column, index) => {
                    const firstColumn = index === 0;
                    return (jsx("td", { style: { paddingLeft: firstColumn && draggable ? '0px' : '8px' }, onClick: () => handleOnclick(column, row, index), className: classNames(column.className, {
                            'clickable-cell': column.onClick,
                        }), children: jsxs(Typography, { as: "div", color: tableDataTextColor, className: "ff-data-checkbox-container", children: [firstColumn && withCheckbox && (jsx("span", { className: "ff-table-pre-post-checkbox", children: jsx(Checkbox, { onChange: (e) => onSelectClick(e, row), checked: row.checked, disabled: !!isDisabled }) })), firstColumn && draggable && (jsx("div", { className: isDisabled ? 'ff-table-drag' : 'ff-table-drag-icon', ...listeners, ...attributes, children: jsx(Icon, { name: "drag", className: isDragDisabled ? 'drag-icon-disabled' : 'drag-icon' }) })), prepareData(row, column, indexNumber), firstColumn && showAccordion && (jsx("div", { className: `pre-accordion-arrow ${expanded ? 'expanded' : ''}`, children: jsx(Icon, { name: "arrow_right", color: expanded ? 'var(--brand-color)' : 'var(--default-color)', width: 12, height: 12, className: "pre-arrow-svg", onClick: () => {
                                            handleStepGroupExpand?.({ ...row, serialNumber });
                                        } }) })), column.extraInfo && column.extraInfo({ row, indexNumber })] }) }, `${column.accessor}${index}`));
                }) }, rowId), expanded && (jsx(PrePostStepAccordions, { data: row.data, columnCount: columns.length, viewModeId: viewModeId, ViewComponent: ViewComponent, handleClick: handleClick, handleStepGroupExpand: handleStepGroupExpand, isStepGroupExpanded: isStepGroupExpanded }))] }));
};
var DraggableTableRow$1 = memo(DraggableTableRow);

export { DraggableTableRow$1 as default };
//# sourceMappingURL=DraggableTableRow.js.map
