1package stats
2
3import (
4 "strconv"
5 "strings"
6 "github.com/The-Robin-Hood/ufWall/internal/ufw"
7 "github.com/The-Robin-Hood/ufWall/internal/ui"
8
9 "github.com/charmbracelet/lipgloss"
10)
11
12func (m Model) View(stats ufw.Stats) string {
13 var statusText string
14 var statusStyle lipgloss.Style
15
16 if stats.Active {
17 statusText = "ACTIVE"
18 statusStyle = m.styles.ActiveStatus
19 } else {
20 statusText = "INACTIVE"
21 statusStyle = m.styles.InactiveStatus
22 }
23
24 statusLine := lipgloss.JoinHorizontal(
25 lipgloss.Left,
26 m.styles.Label.Width(15).Render("Status:"),
27 statusStyle.Render(statusText),
28 )
29
30 loggingLine := lipgloss.JoinHorizontal(
31 lipgloss.Left,
32 m.styles.Label.Width(15).Render("Logging:"),
33 m.styles.Value.Render(strings.ToUpper(stats.Logging)),
34 )
35
36 rulesLine := lipgloss.JoinHorizontal(
37 lipgloss.Left,
38 m.styles.Label.Width(15).Render("Total Rules:"),
39 m.styles.Value.Render(strconv.Itoa(stats.TotalRules)),
40 )
41
42 sectionActiveNoMenu := m.menu == nil && m.active
43
44 content := lipgloss.JoinVertical(
45 lipgloss.Top,
46 ui.InsertCursor(statusLine, m.cursorLine == 0 && sectionActiveNoMenu, m.styles),
47 ui.InsertCursor(loggingLine, m.cursorLine == 1 && sectionActiveNoMenu, m.styles),
48 ui.InsertCursor(rulesLine, false, m.styles),
49 )
50
51 return ui.TitledBox("Firewall Stats", content, m.styles, 38, m.active)
52}