//! Shared authored-document state presentation for editor authoring surfaces.

use bevy_egui::egui;

use crate::asset_documents::{
    AuthoredDocumentSnapshot, AuthoredDocumentState, DerivedProcessingState,
};

use super::theme::{ACCENT, ERROR, WARNING};

pub(crate) fn authored_document_status_ui(ui: &mut egui::Ui, snapshot: &AuthoredDocumentSnapshot) {
    ui.horizontal_wrapped(|ui| {
        if snapshot.dirty {
            ui.small(egui::RichText::new("UNSAVED").color(WARNING).strong());
        }
        match snapshot.state {
            AuthoredDocumentState::ExternalConflict => {
                ui.small(egui::RichText::new("CONFLICT").color(ERROR).strong());
            }
            AuthoredDocumentState::SaveFailed => {
                ui.small(egui::RichText::new("SAVE FAILED").color(ERROR).strong());
            }
            AuthoredDocumentState::Saving => {
                ui.small(egui::RichText::new("SAVING").color(ACCENT));
            }
            AuthoredDocumentState::Clean | AuthoredDocumentState::Dirty => {}
        }
        match snapshot.processing {
            DerivedProcessingState::Queued | DerivedProcessingState::Processing => {
                ui.small(egui::RichText::new("PROCESSING").color(ACCENT));
            }
            DerivedProcessingState::Failed => {
                ui.small(egui::RichText::new("PROCESS FAILED").color(ERROR));
            }
            DerivedProcessingState::Idle => {}
        }
    });
}
