use super::*;
use crate::core::seat_use::hides_harness;
impl App {
pub fn limits_rows(&self) -> Vec<LimitsRow> {
let hidden = if self.show_hidden {
Vec::new()
} else {
self.hidden_harnesses()
};
let mut rows = Vec::new();
for h in Harness::ALL {
if hidden.iter().any(|(x, _)| *x == h) {
continue;
}
rows.extend(
self.seats
.iter()
.filter(|s| s.harness == h)
.map(|s| LimitsRow::Seat(s.label.clone())),
);
let mut logins: Vec<&crate::vault::Login> = self
.vault
.logins
.iter()
.filter(|l| l.harness == h)
.collect();
logins.sort_by(|a, b| self.login_pressure(a).total_cmp(&self.login_pressure(b)));
rows.extend(
logins
.into_iter()
.map(|l| LimitsRow::Login(l.id.to_string())),
);
}
rows
}
pub fn hidden_harnesses(&self) -> Vec<(Harness, Vec<&Seat>)> {
Harness::ALL
.into_iter()
.filter_map(|h| {
let seats: Vec<&Seat> = self.seats.iter().filter(|s| s.harness == h).collect();
let empty: Vec<bool> = seats
.iter()
.map(|s| {
self.analytics
.seats
.iter()
.find(|r| r.id == s.id)
.is_some_and(|r| r.empty)
})
.collect();
let saved = self.vault.logins.iter().filter(|l| l.harness == h).count();
hides_harness(&empty, saved).then_some((h, seats))
})
.collect()
}
pub fn row_harness(&self, r: &LimitsRow) -> Harness {
match r {
LimitsRow::Seat(label) => self
.seats
.iter()
.find(|s| &s.label == label)
.map_or(Harness::Claude, |s| s.harness),
LimitsRow::Login(id) => self
.vault
.logins
.iter()
.find(|l| l.id.as_str() == id)
.map_or(Harness::Claude, |l| l.harness),
}
}
pub fn limits_sections(&self) -> bool {
let rows = self.limits_rows();
rows.iter()
.map(|r| self.row_harness(r))
.collect::<std::collections::BTreeSet<_>>()
.len()
> 1
}
pub(super) fn toggle_hidden(&mut self) {
if self.hidden_harnesses().is_empty() {
self.toast("no empty seats to hide", Tone::Info);
return;
}
self.keep_limits_row(|app| app.show_hidden = !app.show_hidden);
self.toast(
if self.show_hidden {
"LIMITS · SEATS: empty seats shown (. hides them)"
} else {
"LIMITS · SEATS: empty seats hidden (. shows them)"
},
Tone::Info,
);
}
pub(super) fn keep_limits_row(&mut self, change: impl FnOnce(&mut App)) {
let before = self.limits_rows().get(self.cur(Panel::Limits)).cloned();
change(self);
let rows = self.limits_rows();
let at = before
.and_then(|b| rows.iter().position(|r| *r == b))
.unwrap_or_else(|| self.cur(Panel::Limits).min(rows.len().saturating_sub(1)));
self.set_cur(Panel::Limits, at);
}
}