/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

pub mod import;
pub mod log;

use super::error::MyResult;
use crate::{request_info::RequestInfo, ui_responder::UiResponse};
use jellycommon::{jellyobject::ObjectBuffer, *};
use jellyui::tr;
use rocket::get;

#[get("/admin/dashboard")]
pub async fn r_admin_dashboard(ri: RequestInfo<'_>) -> MyResult<UiResponse> {
    ri.require_admin()?;

    let mut db_debug = String::new();
    ri.state.database.transaction(&mut |txn| {
        db_debug = txn.debug_info()?;
        Ok(())
    })?;

    Ok(ri.respond_ui(ObjectBuffer::new(&mut [
        (VIEW_TITLE.0, &&*tr(ri.lang, "admin.dashboard.title")),
        (VIEW_ADMIN_DASHBOARD.0, &()),
        (
            VIEW_ADMIN_INFO.0,
            &ObjectBuffer::new(&mut [
                (ADMIN_INFO_TITLE.0, &"Database Debug"),
                (ADMIN_INFO_TEXT.0, &db_debug.as_str()),
            ]),
        ),
    ])))
}
