     let tripMapManager = mapManager ?? TKUITripMapManager(trip: trip)
     self.tripMapManager = tripMapManager
     
-    let cardSegments = trip.segments(with: .inDetails).compactMap { $0 as? TKSegment }    
+    let cardSegments = trip.segments(with: .inDetails).compactMap { $0 as? TKSegment }
     let segmentCards: [SegmentCards] = cardSegments.map {
       let cards = TKUITripModeByModeCard.config.builder.cards(for: $0, mapManager: tripMapManager)
       return SegmentCards(segmentIndex: $0.index, segmentIdentifier: $0.selectionIdentifier!, cards: cards)

      return index.1
    }
    
    /// What's the index of the first card for the provided `segment.selectionIdentifier`,
    /// if all the cards in the haystack are next to each other?
    static func firstCardIndex(ofSegmentWithIdentifier needle: String, in haystack: [SegmentCards]) -> Int? {
      let index: (Int, Int?) = haystack.reduce( (0, nil) ) { acc, card in
        if acc.1 != nil {
          return acc
        } else if card.segmentIdentifier == needle {
          return (0, acc.0)
        } else {
          return (acc.0 + card.cards.count, nil)
        }

extension TKUITripModeByModeCard {
  
  private func reactToMapSelectionChange(_ identifier: String) {
    // When the map selection changed, we potentially have several candidate
    // cards. We then want to move to the closer index, i.e., the last if we
    // previously showed a later card, or the first if we previously showed
    // an earlier card.
    
    guard
      let indices = SegmentCards.cardIndices(ofSegmentWithIdentifier: identifier, in: segmentCards)
      else { return }
    if currentPageIndex < indices.lowerBound {
      move(to: indices.lowerBound)
    } else if currentPageIndex >= indices.upperBound {
      move(to: indices.upperBound - 1)
    }
  }
  
}
