import AppKit import SwiftUI import ShotdeckCore /// The popover's page strip: at most `limit` thumbnails plus a "+N" tile, so the /// popover never turns into a filmstrip of the whole session. struct SessionStrip: View { @Environment(AppModel.self) private var model var limit: Int? = nil var body: some View { let captures = Array(model.session.captures.prefix(limit ?? model.session.captures.count)) let hidden = model.session.captures.count - captures.count if model.session.captures.isEmpty { Text("Nothing captured yet.") .font(.caption) .foregroundStyle(.secondary) .frame(maxWidth: .infinity, minHeight: 64, alignment: .leading) } else { HStack(alignment: .top, spacing: 6) { ForEach(captures) { capture in SessionThumb(capture: capture) } if hidden > 0 { Text("+\(hidden)") .font(.system(size: 11, weight: .semibold)) .foregroundStyle(.secondary) .frame(width: 52, height: 64) .background(.quaternary.opacity(0.5), in: RoundedRectangle(cornerRadius: 4, style: .continuous)) .help("\(hidden) more page\(hidden == 1 ? "" : "s") — open Redline to see them") } Spacer(minLength: 0) } .frame(height: 64) } } } private struct SessionThumb: View { @Environment(AppModel.self) private var model let capture: Capture @State private var hovering = false var body: some View { ZStack(alignment: .topLeading) { thumbnail Text("\(capture.sequence)") .font(.system(size: 9, weight: .bold)) .foregroundStyle(.white) .padding(.horizontal, 4) .padding(.vertical, 1) .background(.black.opacity(0.65)) .clipShape(RoundedRectangle(cornerRadius: 2, style: .continuous)) .padding(3) if hovering { VStack { Spacer() Button("Remove") { Task { await model.removeCapture(id: capture.id) } } .font(.system(size: 10, weight: .semibold)) .buttonStyle(.plain) .foregroundStyle(.white) .frame(maxWidth: .infinity) .padding(.vertical, 3) .background(.black.opacity(0.7)) } } } .frame(height: 64) .clipped() .onHover { hovering = $0 } .help(DubaiTime.stamp(capture.capturedAt)) } @ViewBuilder private var thumbnail: some View { let url = model.imageURL(for: capture, in: model.session) if let image = NSImage(contentsOf: url) { Image(nsImage: image) .resizable() .aspectRatio(contentMode: .fit) .frame(height: 64) } else { Rectangle() .fill(Color.secondary.opacity(0.2)) .frame(width: 64, height: 64) } } }