1use ratatui::Frame;
2use ratatui::layout::Rect;
3use ratatui::style::{Color, Modifier, Style};
4use ratatui::text::{Line, Span};
5use ratatui::widgets::{Block, Borders, Paragraph};
6
7use crate::app::{App, Pane};
8
9pub(crate) fn render(app: &App, frame: &mut Frame<'_>, list_area: Rect, detail_area: Rect) {
10 let block = Block::default()
11 .title(" FM Radio ")
12 .borders(Borders::ALL)
13 .border_style(super::border_style(app, Pane::Main));
14
15 let (status_text, status_color) = if app.fm_radio_on {
16 ("On", Color::Green)
17 } else {
18 ("Off", Color::DarkGray)
19 };
20
21 let lines = vec![
22 Line::from(""),
23 Line::from(vec![
24 Span::styled(" Status: ", Style::default().fg(Color::DarkGray)),
25 Span::styled(
26 status_text,
27 Style::default()
28 .fg(status_color)
29 .add_modifier(Modifier::BOLD),
30 ),
31 ]),
32 Line::from(""),
33 Line::from(Span::styled(
34 " [f] Toggle FM Radio On/Off",
35 Style::default().fg(Color::Yellow),
36 )),
37 Line::from(""),
38 Line::from(Span::styled(
39 " FM Radio mode uses Band B (76-108 MHz WFM).",
40 Style::default().fg(Color::DarkGray),
41 )),
42 Line::from(Span::styled(
43 " When active, APRS and D-STAR continue on Band A.",
44 Style::default().fg(Color::DarkGray),
45 )),
46 Line::from(Span::styled(
47 " The radio auto-mutes FM on incoming signals.",
48 Style::default().fg(Color::DarkGray),
49 )),
50 Line::from(""),
51 Line::from(Span::styled(
52 " Note: FR is write-only on D75 — status is tracked",
53 Style::default().fg(Color::DarkGray),
54 )),
55 Line::from(Span::styled(
56 " locally and may not reflect radio state at startup.",
57 Style::default().fg(Color::DarkGray),
58 )),
59 ];
60
61 frame.render_widget(Paragraph::new(lines).block(block), list_area);
62
63 let detail_block = Block::default()
65 .title(" Band B (FM) ")
66 .borders(Borders::ALL)
67 .border_style(super::border_style(app, Pane::Detail));
68
69 let detail_lines = if app.fm_radio_on {
70 let freq = app.state.band_b.frequency.as_mhz();
71 let mode = &app.state.band_b.mode;
72 vec![
73 Line::from(""),
74 Line::from(vec![
75 Span::styled(" Frequency: ", Style::default().fg(Color::DarkGray)),
76 Span::styled(
77 format!("{freq:.3} MHz"),
78 Style::default()
79 .fg(Color::Green)
80 .add_modifier(Modifier::BOLD),
81 ),
82 ]),
83 Line::from(vec![
84 Span::styled(" Mode: ", Style::default().fg(Color::DarkGray)),
85 Span::styled(format!("{mode}"), Style::default().fg(Color::White)),
86 ]),
87 Line::from(""),
88 Line::from(Span::styled(
89 " Use Band B pane (2) to tune FM stations.",
90 Style::default().fg(Color::DarkGray),
91 )),
92 ]
93 } else {
94 vec![
95 Line::from(""),
96 Line::from(Span::styled(
97 " FM Radio is off.",
98 Style::default().fg(Color::DarkGray),
99 )),
100 Line::from(Span::styled(
101 " Press [f] to enable.",
102 Style::default().fg(Color::DarkGray),
103 )),
104 ]
105 };
106
107 frame.render_widget(
108 Paragraph::new(detail_lines).block(detail_block),
109 detail_area,
110 );
111}