#[cfg(not(target_arch = "wasm32"))]
use crate::mosaic::ToastKind;
#[cfg(not(target_arch = "wasm32"))]
use nightshade::prelude::*;

#[cfg(not(target_arch = "wasm32"))]
pub fn set_as_startup_project(
    project_edit: &crate::app_context::ProjectEditState,
    settings: &mut crate::mosaic::Settings<crate::settings::EditorSettingsData>,
    toasts: &mut crate::mosaic::Toasts,
) {
    if let Some(path) = &project_edit.current_path {
        let path_str = path
            .canonicalize()
            .ok()
            .and_then(|canonical| canonical.to_str().map(|str| str.to_string()))
            .unwrap_or_else(|| path.display().to_string());
        settings.data.startup_project = Some(path_str.clone());
        if let Err(error) = settings.save() {
            tracing::error!("Failed to save settings: {error}");
        }
        toasts.push(ToastKind::Success, "Set as startup project", 3.0);
    }
}

#[cfg(not(target_arch = "wasm32"))]
pub fn unset_startup_project(
    settings: &mut crate::mosaic::Settings<crate::settings::EditorSettingsData>,
    toasts: &mut crate::mosaic::Toasts,
) {
    settings.data.startup_project = None;
    if let Err(error) = settings.save() {
        tracing::error!("Failed to save settings: {error}");
    }
    toasts.push(ToastKind::Success, "Unset startup project", 3.0);
}
