| 1 | using AgentForge.Data.Entities; |
| 2 | using AgentForge.Models; |
| 3 | using AgentForge.Plugin.View; |
| 4 | |
| 5 | namespace AgentForge.Plugin.Org.Web.Components; |
| 6 | |
| 7 | internal static class ForgeViewOrgGroupHead |
| 8 | { |
| 9 | internal readonly record struct Model(string SummaryInner, string SummaryCssClass); |
| 10 | |
| 11 | internal static Model Render( |
| 12 | in ForgeViewOrgCatalogContext context, |
| 13 | ForgeRepoGroupEntity group, |
| 14 | string path, |
| 15 | int repoCount, |
| 16 | int folderCount, |
| 17 | bool active) |
| 18 | { |
| 19 | var headClass = active ? "org-group-head active" : "org-group-head"; |
| 20 | var visibility = group.DefaultVisibility?.ToSlug(); |
| 21 | var metaParts = new List<string> { $"{repoCount} repos" }; |
| 22 | if (folderCount > 0) |
| 23 | metaParts.Add($"{folderCount} folders"); |
| 24 | var metaText = string.Join(" · ", metaParts); |
| 25 | |
| 26 | var meta = string.IsNullOrWhiteSpace(visibility) |
| 27 | ? ForgeHtml.Text(metaText) |
| 28 | : ForgeHtml.Fragment( |
| 29 | ForgeHtml.Badge(visibility), |
| 30 | ForgeHtml.Text(" · "), |
| 31 | ForgeHtml.Text(metaText)); |
| 32 | |
| 33 | var href = context.Grouping is not null |
| 34 | ? context.Grouping.BuildCatalogUrl(context.GroupingContext, path) |
| 35 | : ForgeViewOrgCatalogLinks.Build(context.CatalogBasePath, path); |
| 36 | |
| 37 | var summary = ForgeHtml.Fragment( |
| 38 | ForgeHtml.A(href, group.DisplayName), |
| 39 | ForgeHtml.Text(" "), |
| 40 | ForgeHtml.Span("meta", meta)); |
| 41 | |
| 42 | return new Model(summary, headClass); |
| 43 | } |
| 44 | } |
| 45 | |