diff --git a/frontend/lib/widgets/admin/common/admin_child_detail_modal.dart b/frontend/lib/widgets/admin/common/admin_child_detail_modal.dart index baf4c0e..a08948e 100644 --- a/frontend/lib/widgets/admin/common/admin_child_detail_modal.dart +++ b/frontend/lib/widgets/admin/common/admin_child_detail_modal.dart @@ -8,6 +8,7 @@ import 'package:p_tits_pas/utils/date_display_utils.dart'; import 'package:p_tits_pas/utils/enfant_status_utils.dart'; import 'package:p_tits_pas/widgets/admin/common/admin_am_edit_modal.dart'; import 'package:p_tits_pas/widgets/admin/common/admin_am_photo_frame.dart'; +import 'package:p_tits_pas/widgets/admin/common/admin_parent_edit_modal.dart'; import 'package:p_tits_pas/widgets/admin/common/validation_detail_section.dart'; import 'package:p_tits_pas/widgets/admin/validation_modal_theme.dart'; import 'package:p_tits_pas/widgets/common/auth_network_image.dart'; @@ -170,16 +171,77 @@ class _AdminChildDetailModalState extends State { return '$fn $ln'.trim(); } - String? _parentsSubtitle() { - final names = widget.enfant.parentLinks - .map((l) { - final n = (l.parentName ?? '').trim(); - return n.isNotEmpty ? n : 'Parent rattaché'; - }) - .where((s) => s.isNotEmpty) - .toList(); - if (names.isEmpty) return null; - return 'Responsables : ${names.join(', ')}'; + List get _parentLinks => widget.enfant.parentLinks + .where((l) => l.parentId.trim().isNotEmpty) + .toList(); + + Future _openParent(EnfantParentLink link) async { + if (_busy) return; + final id = link.parentId.trim(); + if (id.isEmpty) return; + + try { + final parent = await UserService.getParent(id); + if (!mounted) return; + await showDialog( + context: context, + builder: (ctx) => AdminParentEditModal( + parent: parent, + onSaved: () => widget.onSaved?.call(), + ), + ); + } catch (e) { + if (!mounted) return; + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(e.toString().replaceFirst('Exception: ', ''))), + ); + } + } + + Widget? _parentsSubtitle() { + final links = _parentLinks; + if (links.isEmpty) return null; + + return Wrap( + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + const Text( + 'Responsables : ', + style: TextStyle(fontSize: 13, color: Colors.black54), + ), + for (var i = 0; i < links.length; i++) ...[ + if (i > 0) + const Text( + ', ', + style: TextStyle(fontSize: 13, color: Colors.black54), + ), + _parentNameLink(links[i]), + ], + ], + ); + } + + Widget _parentNameLink(EnfantParentLink link) { + final name = (link.parentName ?? '').trim(); + final label = name.isNotEmpty ? name : 'Parent rattaché'; + return InkWell( + onTap: _busy ? null : () => _openParent(link), + borderRadius: BorderRadius.circular(4), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 2), + child: Text( + label, + style: TextStyle( + fontSize: 13, + fontWeight: FontWeight.w600, + color: ValidationModalTheme.primaryActionBackground, + decoration: TextDecoration.underline, + decorationColor: ValidationModalTheme.primaryActionBackground + .withValues(alpha: 0.5), + ), + ), + ), + ); } Future _save() async { @@ -994,13 +1056,7 @@ class _AdminChildDetailModalState extends State { ), if (_parentsSubtitle() != null) ...[ const SizedBox(height: 4), - Text( - _parentsSubtitle()!, - style: const TextStyle( - fontSize: 13, - color: Colors.black54, - ), - ), + _parentsSubtitle()!, ], ], ),