// // Swiftfin is subject to the terms of the Mozilla Public // License, v2.0. If a copy of the MPL was not distributed with this // file, you can obtain one at https://mozilla.org/MPL/2.0/. // // Copyright (c) 2026 Jellyfin & Jellyfin Contributors // // Adapted for Tunavelo from Swiftfin 8a515c580e8b96eaeffcecdfeb14a1c97ef9264e Shared/Objects/ContentGroup/SeriesEpisodeContentGroup/SeriesEpisodeContentGroup+EpisodeCard.swift // import DesignSystem import SwiftUI /// One episode as a card: the still as a button that plays it (with a thin progress line), then the locator, the title and the /// description as a second button. Upstream's `JellyfinAPI` item, `@Router`, `@PlayMedia`, poster context menu and glass preview are /// replaced by our `EpisodeRow`, two action closures, a plain context menu and `tunaveloGlass`. struct EpisodeCard: View { let episode: EpisodeRow let id: String var isUpNext = false let width: CGFloat /// Plays the episode; the frame is the artwork button's, where the player layer opens from. let play: @MainActor (CGRect) -> Void let toggleWatched: @MainActor () -> Void @Environment(\.dynamicTypeSize) private var typeSize @State private var artworkFrame: CGRect = .zero private var locator: String { P45T20Text.locator(season: episode.season, number: episode.number) } private var markTitle: String { VODText.string(episode.watched ? "vod.markUnwatched" : "vod.markWatched") } private var artwork: some View { VODArtwork(url: episode.posterURL) .aspectRatio(16.0 / 9.0, contentMode: .fit) .overlay(alignment: .bottom) { if EpisodeRowView.showsProgress(episode) { EpisodeProgressLine(fraction: Double(episode.fraction)) } } .overlay(alignment: .topLeading) { if isUpNext { Text(P45T20Text.upNext) .tunaveloFont(.meta) .fontWeight(.bold) .foregroundStyle(Theme.onAccent.color) .padding(.horizontal, Theme.Spacing.s) .padding(.vertical, Theme.Spacing.xs) .background(Theme.accent.color, in: RoundedRectangle(cornerRadius: Theme.Radius.s, style: .continuous)) .padding(Theme.Spacing.s) } } .clipShape(RoundedRectangle(cornerRadius: Theme.Radius.m, style: .continuous)) } var body: some View { VStack(alignment: .leading, spacing: Theme.Spacing.s) { Button { play(artworkFrame) } label: { artwork } #if os(tvOS) .buttonStyle(.borderless) #else .buttonStyle(.plain) #endif .onGeometryChange(for: CGRect.self) { $0.frame(in: .global) } action: { artworkFrame = $0 } .accessibilityElement(children: .ignore) .accessibilityLabel(VODText.episodeLabel( season: episode.season, number: episode.number, title: episode.title, fraction: episode.fraction, watched: episode.watched )) .accessibilityAddTraits(.isButton) .accessibilityIdentifier(id) VStack(alignment: .leading, spacing: Theme.Spacing.xs) { Text(isUpNext ? P45T20Text.upNext + " ยท " + locator : locator) .tunaveloFont(.meta) .foregroundStyle(Theme.textSecondary.color) .lineLimit(1) Text(episode.title) .tunaveloFont(.episodeTitle) .foregroundStyle(Theme.textPrimary.color) .lineLimit(EpisodeRowView.titleLineLimit(typeSize: typeSize)) if let plot = episode.plot, !plot.isEmpty { Text(plot) .tunaveloFont(.meta) .foregroundStyle(Theme.textSecondary.color) .lineLimit(EpisodeRowView.plotLineLimit(typeSize: typeSize, layout: .touchRegular) + 1) .multilineTextAlignment(.leading) } } .frame(maxWidth: .infinity, alignment: .topLeading) .accessibilityHidden(true) } .frame(width: width, alignment: .topLeading) .contextMenu { Button(markTitle, action: toggleWatched) } .accessibilityAction(named: markTitle, toggleWatched) } } /// The line across the foot of a still: a 40% white track and an `accent` fill. private struct EpisodeProgressLine: View { let fraction: Double var body: some View { GeometryReader { proxy in ZStack(alignment: .leading) { Rectangle().fill(RGB.white(0.4).color) Rectangle().fill(Theme.accent.color).frame(width: proxy.size.width * min(max(fraction, 0), 1)) } } .frame(height: 4) .accessibilityHidden(true) } }