use indicatrix_vault::model::design_variant::VariantSummary;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub(super) enum Form {
#[default]
Closed,
Save {
position: Option<usize>,
revision: Option<u64>,
design: (String, u64),
},
Rename(i64),
Note(i64),
Delete(i64),
}
impl Form {
pub(super) const fn code(&self) -> i32 {
match self {
Self::Closed => 0,
Self::Save { .. } => 1,
Self::Rename(_) => 2,
Self::Note(_) => 3,
Self::Delete(_) => 4,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) struct FormView {
pub(super) title: String,
pub(super) hint: String,
pub(super) ok: &'static str,
pub(super) name: String,
pub(super) note: String,
}
pub(super) fn save_view(step: Option<(usize, &str)>, name: String) -> FormView {
let hint = match step {
None => "Keeps the design as it is now.".to_owned(),
Some((0, _)) => {
"Keeps the design as it was at the start, before your first change.".to_owned()
}
Some((number, label)) => {
format!("Keeps the design as it was after step {number}: {label}.")
}
};
FormView {
title: "Save as a variant".to_owned(),
hint,
ok: "Save",
name,
note: String::new(),
}
}
pub(super) fn rename_view(variant: &VariantSummary) -> FormView {
FormView {
title: "Rename variant".to_owned(),
hint: String::new(),
ok: "Rename",
name: variant.name.clone(),
note: String::new(),
}
}
pub(super) fn note_view(variant: &VariantSummary) -> FormView {
FormView {
title: format!("Note for \"{}\"", variant.name),
hint: String::new(),
ok: "Save note",
name: String::new(),
note: variant.note.clone().unwrap_or_default(),
}
}
pub(super) fn delete_view(variant: &VariantSummary) -> FormView {
FormView {
title: "Delete this variant?".to_owned(),
hint: format!(
"\"{}\" will be removed from your library. This cannot be undone. Your current design is not changed.",
variant.name
),
ok: "Delete",
name: String::new(),
note: String::new(),
}
}