use crate::ui::state::AppState;
use axum::Json;
use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum::response::IntoResponse;
use serde_json::{Value, json};
use std::sync::Arc;
pub async fn list_themes(State(state): State<Arc<AppState>>) -> Json<Value> {
let themes: Vec<Value> = state
.registry
.themes
.list()
.iter()
.map(|t| {
json!({
"name": t.name,
"display_name": t.display_name,
"description": t.description,
})
})
.collect();
Json(json!({ "themes": themes }))
}
pub async fn get_theme(
State(state): State<Arc<AppState>>,
Path(name): Path<String>,
) -> impl IntoResponse {
match state.registry.themes.get(&name) {
Some(theme) => Json(json!(theme)).into_response(),
None => (
StatusCode::NOT_FOUND,
Json(json!({"error": format!("theme '{name}' not found")})),
)
.into_response(),
}
}