﻿Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic

Partial Friend NotInheritable Class ShowcaseNavigationCatalog

    Friend Shared Function GetJourneys(entry As ShowcaseNavigationEntry) As IReadOnlyList(Of ShowcaseProductJourney)
        Dim result As New List(Of ShowcaseProductJourney)()
        If entry Is Nothing Then Return result.AsReadOnly()

        For Each journey As ShowcaseProductJourney In _productJourneys
            If journey Is Nothing OrElse journey.EntryIds Is Nothing Then Continue For

            For Each entryId As String In journey.EntryIds
                If String.Equals(entry.Id, entryId, StringComparison.OrdinalIgnoreCase) Then
                    result.Add(journey)
                    Exit For
                End If
            Next
        Next

        Return result.AsReadOnly()
    End Function

    Friend Shared Function ResolveJourneyMembershipText(entry As ShowcaseNavigationEntry) As String
        Dim journeys As IReadOnlyList(Of ShowcaseProductJourney) = GetJourneys(entry)
        If journeys.Count = 0 Then Return "Metadata only"

        Dim titles As New List(Of String)()
        For Each journey As ShowcaseProductJourney In journeys
            titles.Add(journey.Title)
        Next

        Return String.Join(" • ", titles.ToArray())
    End Function

    Friend Shared Function ResolvePrimaryJourneyTitle(entry As ShowcaseNavigationEntry) As String
        Dim journeys As IReadOnlyList(Of ShowcaseProductJourney) = GetJourneys(entry)
        If journeys.Count = 0 Then Return "Metadata"
        Return journeys(0).Title
    End Function
End Class
