use crate::profile::Profile;
use crate::usage::{PlanInfo, PlanTier};
pub(crate) fn truncate(s: &str, max: usize) -> String {
if s.chars().count() <= max {
return s.to_string();
}
if max == 0 {
return String::new();
}
let mut out: String = s.chars().take(max.saturating_sub(1)).collect();
out.push('…');
out
}
pub(crate) fn endpoint_label(profile: &Profile) -> String {
if let Some(url) = &profile.base_url {
return url.clone();
}
if let Some(plan) = profile.usage.as_ref().and_then(|u| u.plan.as_ref()) {
return plan_label(plan);
}
let sub = profile
.credentials
.as_ref()
.and_then(|c| c.claude_ai_oauth.as_ref())
.and_then(|o| o.subscription_type.as_deref());
PlanTier::from_subscription_type(sub).display()
}
pub(crate) fn plan_label(plan: &PlanInfo) -> String {
plan.tier.display()
}