use super::{Panel, PanelKind};
use crate::source::{SourceId, Symbol};
use crate::state::AppState;
use crate::view::{PanelView, ProfileRow, ProfileView};
#[derive(Debug)]
pub struct ProfilePanel;
impl Panel for ProfilePanel {
fn kind(&self) -> PanelKind {
PanelKind::Profile
}
fn view(&self, state: &AppState, focus: (SourceId, &Symbol)) -> PanelView {
let symbol = focus.1.to_string();
let profiles = state
.get(&(focus.0, focus.1.clone()))
.map(|st| {
st.profiles
.readings()
.into_iter()
.map(|(label, reading)| ProfileRow {
label: label.to_string(),
bins: reading.map(|r| r.bins.clone()).unwrap_or_default(),
price_low: reading.and_then(|r| r.price_low),
price_high: reading.and_then(|r| r.price_high),
})
.collect()
})
.unwrap_or_default();
PanelView::Profile(ProfileView { symbol, profiles })
}
}