import 'package:flutter/widgets.dart'; import '../../../core/api_gateway.dart'; import '../../graph/domain/stage_visits.dart'; import '../domain/artifact_groups.dart'; import '../domain/artifact_record.dart'; import '../domain/artifact_summary.dart'; import '../domain/artifact_url.dart'; import 'artifact_visit_list.dart'; /// The key one recorded group maps to, used only to find its step. String artifactGroupKey(String stageKey, int visit) => '$stageKey\u0000$visit'; /// Each recorded group's step, keyed by stage and display visit, so a selected /// row can show its own visit's capture facts. Derives the same grouping the /// gallery uses; an absent key yields null rather than a fabricated capture. Map recordedStepsByGroup(List steps) { final result = {}; for (final entry in visitsByStage(steps).entries) { for (var index = 0; index < entry.value.length; index += 1) { final step = entry.value[index]; result[artifactGroupKey(entry.key, displayVisit(step, index))] = step; } } return result; } /// The recorded facts of one selected artifact: name, MIME/size, its visit's /// capture summary and notes, and the url state. Nothing is inferred. class ArtifactSelectionFacts extends StatelessWidget { const ArtifactSelectionFacts({ super.key, required this.group, required this.artifact, required this.step, required this.resolved, }); final ArtifactGroup group; final ArtifactRecord artifact; final JsonMap? step; final ResolvedArtifactUrl? resolved; @override Widget build(BuildContext context) { final recordedStep = step; final url = resolved; return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ Text(artifactFactsLabel(artifact)), const SizedBox(height: 8), Text(artifactGroupLabel(group)), if (recordedStep != null) ...[ const SizedBox(height: 8), Text(artifactsSummary(recordedStep, count: group.artifacts.length)), for (final note in artifactCaptureNotes(recordedStep)) Padding(padding: const EdgeInsets.only(top: 4), child: Text(note)), ], if (!artifact.hasUrl) ...[ const SizedBox(height: 8), const Text('No artifact URL recorded.'), ] else if (url == null) ...[ const SizedBox(height: 8), const Text('The recorded artifact URL cannot be opened safely.'), ], ], ); } }