| 1 | using AgentForge.Abstractions; |
| 2 | using AgentForge.Plugin.View.Components.Layout; |
| 3 | |
| 4 | namespace AgentForge.Plugin.Grouping.Core; |
| 5 | |
| 6 | public static class ForgeGroupingNestedRenderer |
| 7 | { |
| 8 | public static string Render<TItem, TAxis>( |
| 9 | ForgeGroupingAxisCatalog<TAxis, TItem> catalog, |
| 10 | IReadOnlyList<TItem> items, |
| 11 | IReadOnlyList<string> groupStack, |
| 12 | Func<TItem, string> renderItem, |
| 13 | string listClass, |
| 14 | string sectionDetailsClass = "view-group-section", |
| 15 | string sectionHeadClass = "view-group-head") |
| 16 | where TAxis : IForgeGroupingAxis<TItem> |
| 17 | { |
| 18 | if (groupStack.Count == 0) |
| 19 | return ""; |
| 20 | |
| 21 | var utcNow = DateTimeOffset.UtcNow; |
| 22 | var axisLayers = new List<(Func<TItem, string> KeySelector, IReadOnlyList<ForgeViewGroupedList.Section> Sections)>(); |
| 23 | |
| 24 | foreach (var axisId in groupStack) |
| 25 | { |
| 26 | if (!catalog.TryGetAxis(axisId, out var axis) || axis is null) |
| 27 | continue; |
| 28 | |
| 29 | var sections = axis.SectionsFor(items, utcNow) |
| 30 | .Select(section => new ForgeViewGroupedList.Section(section.Key, section.Label)) |
| 31 | .ToList(); |
| 32 | axisLayers.Add((item => axis.GetKey(item, utcNow), sections)); |
| 33 | } |
| 34 | |
| 35 | if (axisLayers.Count == 0) |
| 36 | return ""; |
| 37 | |
| 38 | return ForgeViewGroupedList.RenderNested( |
| 39 | items, |
| 40 | axisLayers, |
| 41 | renderItem, |
| 42 | listClass: listClass, |
| 43 | sectionDetailsClass: sectionDetailsClass, |
| 44 | sectionHeadClass: sectionHeadClass); |
| 45 | } |
| 46 | } |
| 47 | |