import SwiftUI import HaloDesign import MediaKit /// Der Weg nach oben: von der Folge zur Staffel, von der Staffel zur Serie. /// /// Bisher gab es ihn nicht. Wer über „Weiterschauen" oder „Zuletzt /// hinzugefügt" bei einer einzelnen Folge landete, saß dort fest — die /// übrigen Folgen derselben Staffel waren nur über den Umweg Bibliothek → /// Serie → Staffel erreichbar. Genau dieser Umweg ist der Grund, dass die /// Zeile existiert. struct ParentLinks: View { let item: MediaItem var body: some View { if !destinations.isEmpty { ScrollView(.horizontal) { HStack(spacing: HaloSpacing.snug) { ForEach(destinations, id: \.route.ratingKey) { destination in NavigationLink(value: destination.route) { Label { Text(destination.route.title) .lineLimit(1) } icon: { Image(systemName: destination.symbol) } .font(.haloCaption) .foregroundStyle(Color.haloTextPrimary) .padding(.horizontal, HaloSpacing.regular) .padding(.vertical, HaloSpacing.snug) .background(Color.haloElevated, in: .capsule) } .buttonStyle(.plain) } } .padding(.horizontal, HaloSpacing.screenMargin) } .scrollIndicators(.never) } } private struct Destination { let route: MediaRoute let symbol: String } /// Die Stationen über diesem Eintrag. /// /// Bei einer Folge zwei — Staffel und Serie; bei einer Staffel eine. /// Plex führt beide Kennungen am Eintrag mit, deshalb braucht es dafür /// keine zusätzliche Abfrage. private var destinations: [Destination] { switch item.kind { case .episode: var stops: [Destination] = [] if let season = item.parentID { let title = item.parentIndex.map { String(localized: "season.short \($0)") } ?? item.parentTitle ?? String(localized: "detail.toSeason") stops.append(Destination( route: MediaRoute(ratingKey: season, title: title), symbol: "rectangle.stack" )) } if let show = item.seriesID { stops.append(Destination( route: MediaRoute( ratingKey: show, title: item.seriesTitle ?? String(localized: "detail.toSeries") ), symbol: "tv" )) } return stops case .season: guard let show = item.parentID else { return [] } return [Destination( route: MediaRoute( ratingKey: show, title: item.parentTitle ?? String(localized: "detail.toSeries") ), symbol: "tv" )] default: return [] } } }