use std::collections::{HashMap, HashSet};
use crate::{deps::DepKind, i18n::Strings};
#[derive(Debug, Default)]
pub struct DepOpState {
pub installing: bool,
pub install_result: Option<Result<(), String>>,
pub progress: (u64, u64),
pub deleting: bool,
pub delete_result: Option<Result<(), String>>,
}
#[derive(Debug, Default)]
pub struct DependencyDialog {
pub missing: Vec<DepKind>,
pub found: Vec<DepKind>,
pub selected: HashSet<DepKind>,
}
impl DependencyDialog {
pub fn new(missing: Vec<DepKind>, found: Vec<DepKind>) -> Self {
let selected = missing
.iter()
.copied()
.filter(|d| {
d.auto_installable()
&& (d != &DepKind::YtMusicApi || crate::deps::availability().python3)
})
.collect();
Self {
missing,
found,
selected,
}
}
pub fn pending(&self, ops: &HashMap<DepKind, DepOpState>) -> Vec<DepKind> {
self.selected
.iter()
.copied()
.filter(|d| {
let op = ops.get(d);
!(op.is_some_and(|o| o.installing)
|| op.is_some_and(|o| o.install_result.is_some()))
})
.collect()
}
pub fn all_resolved(&self, ops: &HashMap<DepKind, DepOpState>) -> bool {
self.selected
.iter()
.all(|d| ops.get(d).is_some_and(|o| o.install_result.is_some()))
}
}
pub fn dep_desc(tr: &Strings, kind: DepKind) -> &'static str {
match kind {
DepKind::YtDlp => tr.deps_yt_dlp_desc,
DepKind::YtMusicApi => tr.deps_ytmusicapi_desc,
DepKind::Python3 => tr.deps_python3_desc,
}
}