import 'package:flutter/material.dart'; import '../../../ui/adaptive/floating_bar_layout.dart'; import '../../../ui/adaptive/segmented_bar.dart'; import '../domain/template_entry.dart'; import 'template_gallery.dart' show templatesColumn; /// Browser wording for the gallery and the selected template, kept verbatim. const templateSourceLabel = 'Definition source'; const templateIncludesScheduleLabel = 'Includes a schedule'; const templateCreateActionLabel = 'Create pipeline from this template'; const templateDetailKey = ValueKey('template-detail'); const templateSourceKey = ValueKey('template-source'); const templateCreateActionKey = ValueKey('template-create-action'); const templateDetailBackKey = ValueKey('template-detail-back'); const templateKeyKey = ValueKey('template-key'); /// What the bar's title pill shows for an open template: its name, and its /// description (when it has one) as the one-line subtitle. ({String title, String? subtitle}) templateBarTitle(TemplateEntry entry) { final description = entry.description.trim(); return ( title: templateDetailName(entry), subtitle: description.isEmpty ? null : description, ); } /// A gallery card's name: a blank name is the explicit unnamed placeholder. String templateGalleryName(TemplateEntry entry) { final name = entry.name.trim(); return name.isEmpty ? '(unnamed template)' : entry.name; } /// A detail's heading: a blank name falls back to the template's key. String templateDetailName(TemplateEntry entry) { final name = entry.name.trim(); return name.isEmpty ? entry.key : entry.name; } /// One template's metadata and its complete, selectable definition source. /// /// Selecting and reading a template sends nothing. The one action opens the /// existing create-only prompt through [onCreate]; this view never submits, /// runs or schedules anything itself. class TemplateDetail extends StatelessWidget { const TemplateDetail({ super.key, required this.entry, required this.showBack, required this.onBack, required this.onCreate, }); final TemplateEntry entry; /// True under a shell/app bar that does not own a back control for this page. final bool showBack; final VoidCallback onBack; final VoidCallback onCreate; @override Widget build(BuildContext context) { final muted = templateMutedStyle(context); final description = entry.description.trim(); return ListView( key: templateDetailKey, padding: withBarClearance(context, const EdgeInsets.only(bottom: 24)), children: [ if (showBack) _backRow(context), templatesColumn( Padding( padding: const EdgeInsets.fromLTRB(16, 8, 16, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // With a bar above, its title pill carries the name and the // description; only a bar-less page names the template here. if (showBack) ...[ Text( templateDetailName(entry), style: templateTitleStyle(context), ), if (description.isNotEmpty) Padding( padding: const EdgeInsets.only(top: 8), child: Text(entry.description), ), const SizedBox(height: 12), ], _createButton(), const SizedBox(height: 16), // The key and the schedule on one quiet line, not a // label/value document. Wrap( spacing: 8, runSpacing: 4, crossAxisAlignment: WrapCrossAlignment.center, children: [ SelectableText( entry.key, key: templateKeyKey, semanticsLabel: 'Key ${entry.key}', style: muted, ), if (entry.scheduled) ...[ Text('ยท', style: muted), Text(templateIncludesScheduleLabel, style: muted), ], ], ), const SizedBox(height: 20), Text(templateSourceLabel, style: templateSectionStyle(context)), const SizedBox(height: 8), // The server's source, byte-for-byte: no trim, re-indent or // re-encoding, so selecting it copies exactly what was // received. SizedBox( width: double.infinity, child: SelectableText( entry.source, key: templateSourceKey, style: templateBodyStyle(context), ), ), ], ), ), ), ], ); } /// A compact button at its own width: the page's one action, never a bar /// spanning a wide window. Widget _createButton() { return FilledButton.icon( key: templateCreateActionKey, onPressed: onCreate, icon: const Icon(Icons.add), label: const Text(templateCreateActionLabel), ); } Widget _backRow(BuildContext context) { // Only without a bar above: the same round Back the bar would show. final back = SegmentedPill( child: SegmentedBackButton(key: templateDetailBackKey, onPressed: onBack), ); return Padding( padding: const EdgeInsets.fromLTRB(12, 8, 16, 0), child: Row( children: [ back, const SizedBox(width: 8), Expanded( child: Text('Templates', style: templateSectionStyle(context)), ), ], ), ); } } TextStyle? templateTitleStyle(BuildContext context) => Theme.of(context).textTheme.headlineSmall; TextStyle? templateSectionStyle(BuildContext context) => Theme.of(context).textTheme.titleMedium; TextStyle? templateBodyStyle(BuildContext context) => Theme.of(context).textTheme.bodyMedium; TextStyle? templateMutedStyle(BuildContext context) { final theme = Theme.of(context); return theme.textTheme.bodySmall?.copyWith( color: theme.colorScheme.onSurfaceVariant, ); }