import { useCallback } from 'react';

function useTableExpansion({ expandedRows = [], onExpandedRowsChange, }) {
    const handleExpandChange = useCallback((rowId, expanded) => {
        if (!onExpandedRowsChange)
            return;
        const newExpandedRows = expanded
            ? [...expandedRows, rowId]
            : expandedRows.filter(id => id !== rowId);
        onExpandedRowsChange(newExpandedRows);
    }, [expandedRows, onExpandedRowsChange]);
    return { handleExpandChange };
}

export { useTableExpansion };
