You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: branches_by_mode_service.rb
    path of file: ./repos/gitlabhq/app/services/projects
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

# Projects::BranchesByModeService uses Gitaly page-token pagination
# in order to optimally fetch branches.
# The drawback of the page-token pagination is that it doesn't provide
# an option of going to the previous page of the collection.
# That
    
  def branches_with_links(branches, last_page:)
    # To fall back to offset pagination we need to track current page via offset param
    # And increase it whenever we go to the next page
    previous_offset = params[:offset].to_i

    previous_path = nil
    next_path = nil

    return [branches, previous_path, next_path] if branches.blank?

    unless last_page
      next_path = project_branches_filtered_path(project, state: mode, page_token: branches.last.name, sort: params[:sort], offset: previous_offset + 1)
    end