use crate::Localized;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AlertKind {
Error,
Warning,
Confirm,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AlertButtonRole {
Primary,
Secondary,
Destructive,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AlertAction<'a> {
pub id: u8,
pub label: Localized<'a>,
pub role: AlertButtonRole,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct AlertSpec<'a, const N: usize> {
pub kind: AlertKind,
pub title: Localized<'a>,
pub message: Localized<'a>,
pub actions: [AlertAction<'a>; N],
}
impl<'a> AlertSpec<'a, 1> {
pub const fn error(message: Localized<'a>) -> Self {
Self {
kind: AlertKind::Error,
title: Localized::new("fs.alert.error", "Error"),
message,
actions: [AlertAction {
id: 0,
label: Localized::new("fs.alert.ok", "OK"),
role: AlertButtonRole::Destructive,
}],
}
}
pub const fn warning(message: Localized<'a>) -> Self {
Self {
kind: AlertKind::Warning,
title: Localized::new("fs.alert.warning", "Warning"),
message,
actions: [AlertAction {
id: 0,
label: Localized::new("fs.alert.ok", "OK"),
role: AlertButtonRole::Primary,
}],
}
}
}
impl<'a> AlertSpec<'a, 2> {
pub const fn confirm(title: Localized<'a>, message: Localized<'a>) -> Self {
Self {
kind: AlertKind::Confirm,
title,
message,
actions: [
AlertAction {
id: 0,
label: Localized::new("fs.alert.cancel", "Cancel"),
role: AlertButtonRole::Secondary,
},
AlertAction {
id: 1,
label: Localized::new("fs.alert.confirm", "Confirm"),
role: AlertButtonRole::Primary,
},
],
}
}
}